Offer all CodeCraft tools to the Claude Code CLI over an MCP bridge
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
658148ada7
commit
4e6f74d477
7 files changed
+286
-1
No files matched your search
@@ -113,6 +113,10 @@ fn command(app: &App, owner: Option<&str>, cwd: &Path, args: &[String]) -> Resul
|
||||
|
||||
/// Claude Code tool → (our tool name, input with our key names), so the chat renders it like ours.
|
||||
fn map_tool(name: &str, input: &Value) -> (String, Value) {
|
||||
// Our own tools reach the CLI over MCP: shown and judged under their usual names.
|
||||
if let Some(ours) = name.strip_prefix(crate::mcp_bridge::PREFIX) {
|
||||
return (ours.to_string(), input.clone());
|
||||
}
|
||||
let mut v = input.clone();
|
||||
let rename = |v: &mut Value, from: &str, to: &str| {
|
||||
if let Some(x) = v.get(from).cloned() {
|
||||
@@ -149,6 +153,8 @@ impl ToolInfo for CcTool {
|
||||
}
|
||||
fn read_only(&self) -> bool {
|
||||
matches!(self.name.as_str(), "read" | "glob" | "grep" | "web_fetch" | "web_search" | "task" | "todowrite" | "list")
|
||||
// One of our tools (MCP bridge): as it declares itself.
|
||||
|| crate::tools::builtin_tools().iter().any(|t| t.name() == self.name && t.read_only())
|
||||
}
|
||||
fn is_edit(&self) -> bool {
|
||||
matches!(self.name.as_str(), "write" | "edit")
|
||||
@@ -178,7 +184,10 @@ fn title_of(name: &str, input: &Value, claude_input: &Value) -> String {
|
||||
match name {
|
||||
"bash" => input["description"].as_str().filter(|d| !d.is_empty()).map(String::from).unwrap_or_else(|| input["command"].as_str().unwrap_or("").chars().take(120).collect()),
|
||||
"write" | "edit" | "read" => input["path"].as_str().unwrap_or("").to_string(),
|
||||
_ => claude_input["description"].as_str().map(String::from).unwrap_or_else(|| name.to_string()),
|
||||
_ => match crate::tools::builtin_tools().iter().find(|t| t.name() == name) {
|
||||
Some(t) => t.title(input),
|
||||
None => claude_input["description"].as_str().map(String::from).unwrap_or_else(|| name.to_string()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +374,13 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
|
||||
if let Some(r) = &resume {
|
||||
args.extend(["--resume".into(), r.clone()]);
|
||||
}
|
||||
// CodeCraft's own tools for the CLI (MCP, per-run token).
|
||||
let bridge = crate::mcp_bridge::register(session_id);
|
||||
args.extend(["--mcp-config".into(), crate::mcp_bridge::config_json(&app, &bridge.token)]);
|
||||
let mut appended = session.instructions.trim().to_string();
|
||||
if let Some(note) = crate::mcp_bridge::prompt_section(&crate::mcp_bridge::tools_for(&app, &session)) {
|
||||
appended = format!("{appended}\n{note}").trim().to_string();
|
||||
}
|
||||
for extra in owner.as_deref().into_iter().flat_map(|u| [crate::gitcreds::prompt_section(&app, u), crate::sshkeys::prompt_section(&app, u)]).flatten() {
|
||||
appended = format!("{appended}\n{extra}").trim().to_string();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user