claude_cli without codemode: serve MCP tools via mcp-serve (mcp__hx__*), prompt names them; skip self-referencing servers

This commit is contained in:
hermes committed 2026-11-13 13:12:20 +00:00
1 parent fa0ff339f6
commit 7218d1433b
3 files changed
+42 -22

No files matched your search

+16 -7
View File
@@ -135,6 +135,16 @@ async fn load(cfg: &Server) -> (State, Option<Arc<Client>>) {
}
}
/// How the model reaches the lazy MCP tools.
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Via {
Direct,
/// claude_cli + codemode: only inside `codemode` scripts
Codemode,
/// claude_cli without codemode: `mcp__hx__*` tools served by `hx mcp-serve`
ClaudeCli,
}
impl Hub {
/// Connect to all servers in parallel and wait for every one (CLI commands, tests).
pub async fn start(cfgs: BTreeMap<String, Server>) -> Self {
@@ -395,18 +405,17 @@ impl Hub {
}
pub fn system_prompt(&self) -> String {
self.system_prompt_for(false)
self.system_prompt_for(Via::Direct)
}
/// `via_codemode`: the model cannot call `mcp_*` directly (claude_cli exposes only `codemode`).
pub fn system_prompt_for(&self, via_codemode: bool) -> String {
pub fn system_prompt_for(&self, via: Via) -> String {
let idx = self.index();
let mut s = String::new();
if !idx.is_empty() {
s.push_str(if via_codemode {
"# MCP tools\nNot top-level tools: reach them only through `codemode`. Inside a script: `await tools.mcp_call({server, tool, arguments})`; `await tools.mcp_describe({server, tool})` gives the argument schema (also `tools.mcp_read({server, uri})`).\n"
} else {
"# MCP tools\nCall with `mcp_call` (server, tool, arguments). Use `mcp_describe` first to get the argument schema.\n"
s.push_str(match via {
Via::Codemode => "# MCP tools\nNot top-level tools: reach them only through `codemode`. Inside a script: `await tools.mcp_call({server, tool, arguments})`; `await tools.mcp_describe({server, tool})` gives the argument schema (also `tools.mcp_read({server, uri})`).\n",
Via::ClaudeCli => "# MCP tools\nCall with the `mcp__hx__mcp_call` tool (server, tool, arguments). Use `mcp__hx__mcp_describe` first to get the argument schema (`mcp__hx__mcp_read` reads resources).\n",
Via::Direct => "# MCP tools\nCall with `mcp_call` (server, tool, arguments). Use `mcp_describe` first to get the argument schema.\n",
});
for (_, b) in idx {
s.push_str(&b);
+5 -1
View File
@@ -36,12 +36,16 @@ async fn stdio_lazy_index_describe_call() {
let sp = h.system_prompt();
assert!(sp.contains("- f.echo: Echo a message back\n"), "{sp}");
assert!(!sp.contains("second line"));
let cm = h.system_prompt_for(true);
let cm = h.system_prompt_for(crate::Via::Codemode);
assert!(
cm.contains("only through `codemode`") && cm.contains("- f.echo:"),
"{cm}"
);
assert!(!sp.contains("codemode"));
assert!(
h.system_prompt_for(crate::Via::ClaudeCli)
.contains("mcp__hx__mcp_call")
);
assert!(sp.contains("mem://notes") && sp.contains("Use echo for tests."));
let st = h.status();
assert!(