Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mcp): name no connect tool in agent list_tools refusals (#6313)

M3gA-Mindd8263fe95590
diff --git a/crates/openhuman-core/src/mcp/registry/ops.rs b/crates/openhuman-core/src/mcp/registry/ops.rs
index bbb1f60e97..5b38e9f86a 100644
--- a/crates/openhuman-core/src/mcp/registry/ops.rs
+++ b/crates/openhuman-core/src/mcp/registry/ops.rs
@@ -416,6 +416,12 @@ pub async fn mcp_clients_status(config: &Config) -> Result<Outcome<Value>, Strin
/// settings-UI caller can call `mcp_clients_connect`, a model can only call the
/// tools on its belt. Naming a method the caller cannot reach is an instruction
/// it cannot follow (#6313).
+///
+/// Not every belt that lists tools can connect: the read-only planner carries
+/// `mcp_registry_list_tools` and `mcp_registry_status` but not
+/// `mcp_registry_connect`. So an agent refusal names no connect tool, only the
+/// status tool every such belt has; `refusals_name_only_tools_on_every_listing_belt`
+/// pins that against the built-in agent definitions.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Caller {
/// The `openhuman.mcp_clients_*` RPC surface (settings UI, CLI).
@@ -425,10 +431,10 @@ pub enum Caller {
}
impl Caller {
- fn connect(self) -> &'static str {
+ fn connect(self) -> Option<&'static str> {
match self {
- Self::Rpc => "mcp_clients_connect",
- Self::Agent => "mcp_registry_connect",
+ Self::Rpc => Some("mcp_clients_connect"),
+ Self::Agent => None,
}
}
@@ -483,11 +489,14 @@ pub(crate) fn explain_not_connected(
/// An installed server with no live connection: say where it stands and how to connect it.
fn not_connected_message(install: &tinymcp::ConnStatus, caller: Caller) -> String {
+ let remedy = caller.connect().map_or_else(
+ || "it has to be connected before its tools can be listed".to_string(),
+ |connect| format!("connect it first via {connect}"),
+ );
let mut message = format!(
- "server_id={} is {}; connect it first via {}",
+ "server_id={} is {}; {remedy}",
install.server_id,
install.status.as_str(),
- caller.connect()
);
if let Some(error) = &install.last_error {
message.push_str(&format!(" (last error: {error})"));
diff --git a/crates/openhuman-core/src/mcp/registry/ops_tests.rs b/crates/openhuman-core/src/mcp/registry/ops_tests.rs
index cee8a36d34..748c70b195 100644
--- a/crates/openhuman-core/src/mcp/registry/ops_tests.rs
+++ b/crates/openhuman-core/src/mcp/registry/ops_tests.rs
@@ -50,7 +50,7 @@ async fn install_one(config: &Config) -> String {
}
#[tokio::test]
-async fn agent_refusal_names_the_connect_tool_on_its_belt() {
+async fn agent_refusal_names_no_rpc_method() {
let workspace = tempfile::tempdir().unwrap();
let config = temp_config(&workspace);
let server_id = install_one(&config).await;
@@ -58,9 +58,74 @@ async fn agent_refusal_names_the_connect_tool_on_its_belt() {
let error = mcp_clients_list_tools(&config, server_id.clone(), Caller::Agent)
.await
.expect_err("a disconnected server has no tools to list");
- assert!(error.contains("mcp_registry_connect"), "{error}");
- assert!(!error.contains("mcp_clients_connect"), "{error}");
- assert!(error.contains(&server_id), "{error}");
+ assert!(!error.contains("mcp_clients_"), "{error}");
+ assert!(
+ error.starts_with(&format!(
+ "server_id={server_id} is disconnected; it has to be connected"
+ )),
+ "{error}"
+ );
+}
+
+/// Every tool an agent refusal names must be callable by every agent that can
+/// receive it, i.e. every built-in agent with `mcp_registry_list_tools` on its
+/// belt. The read-only planner has no `mcp_registry_connect`.
+#[test]
+fn refusals_name_only_tools_on_every_listing_belt() {
+ let install = tinymcp::ConnStatus {
+ server_id: "srv-1".into(),
+ qualified_name: QUALIFIED.into(),
+ display_name: "uuid".into(),
+ status: tinymcp::ServerStatus::Disconnected,
+ tool_count: 0,
+ last_error: None,
+ auth_hint: None,
+ };
+ let refusals: Vec<String> = ["srv-1", "io.github.other/absent"]
+ .into_iter()
+ .map(|requested| {
+ match explain_not_connected(requested, std::slice::from_ref(&install), Caller::Agent) {
+ NotConnected::Refused(message) => message,
+ NotConnected::Resolved(id) => panic!("{requested} resolved to {id}"),
+ }
+ })
+ .collect();
+ let named: Vec<&str> = refusals
+ .iter()
+ .flat_map(|message| message.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')))
+ .filter(|word| word.starts_with("mcp_"))
+ .collect();
+ assert!(
+ !named.is_empty(),
+ "the unknown-id refusal names the status tool"
+ );
+
+ let belts: Vec<_> = crate::agent::registry::agents::load_builtins()
+ .expect("built-ins load")
+ .into_iter()
+ .filter_map(|def| {
+ let crate::agent::harness::definition::ToolScope::Named(tools) = &def.tools else {
+ return None;
+ };
+ let belt: Vec<String> = tools.iter().chain(&def.deferred_tools).cloned().collect();
+ belt.iter()
+ .any(|tool| tool == "mcp_registry_list_tools")
+ .then(|| (def.id.clone(), belt))
+ })
+ .collect();
+ assert!(
+ belts.iter().any(|(id, _)| id == "planner"),
+ "fixture: the planner lists MCP tools, got {:?}",
+ belts.iter().map(|(id, _)| id).collect::<Vec<_>>()
+ );
+ for (id, belt) in &belts {
+ for tool in &named {
+ assert!(
+ belt.iter().any(|t| t == tool),
+ "{id} can receive a refusal naming `{tool}`, which is not on its belt"
+ );
+ }
+ }
}
#[tokio::test]