The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(mcp_setup): report a failed connect in band instead of as a false success\n\n`mcp_setup_install_and_connect` declared a required `status` discriminator\n(`connected` | `installed_disconnected`) and a conditional `error`, and emitted\nneither. It returned `{server_id, qualified_name, tools}`, so a caller branching\non the documented discriminator branched on `undefined` forever.\n\nThe issue diagnosed `installed_disconnected` as structurally unreachable because\na failed connect left the handler via `?`. That is not what happens. The\nregistry's own `setup_install_and_connect` already handles the partial success:\non a connect failure it logs the reason and returns\n`Ok(ConnectOutcome { server_id, tools: vec![] })`. The `?` fires only when the\n*install* fails.\n\nThe real defect was worse than reported. Because `ConnectOutcome` carries only\n`server_id` and `tools`, a failed connect was byte-identical to a server that\nconnected and advertises no tools — a legitimate state this handler deliberately\ntreats as connected. So a failed connect was reported as a **success**, and it\npublished `DomainEvent::McpServerConnected { tool_count: 0 }` to every\nsubscriber: a false claim that the server came up.\n\nCounting tools cannot separate the two. `ConnStatus` can — it carries the live\n`ServerStatus` plus `last_error` — so the handler now reads the connection state\nback and classifies from it:\n\n- `Connected` -> `status: "connected"`, `tools` present, no `error`, and the\n `McpServerConnected` event still fires (including for zero tools, since the\n verdict comes from `ServerStatus`, never the count).\n- anything else, or a status that cannot be read back -> `status:\n "installed_disconnected"` with `error`, `tools` omitted, and **no**\n `McpServerConnected` event. `server_id` is still returned: the install\n succeeded, and it is what a caller needs to retry or remove the server.\n\nThis is the decided direction on #6110 — the schema is right, the handler was\nwrong — and it makes the two adjacent steps of one flow consistent, since the\nsibling `mcp_setup_test_connection` already reports a failed dial in band.\n\n`qualified_name` was emitted but undeclared. Declared rather than removed: it is\nadditive, it makes the catalog truthful, and dropping a field the setup agent may\nalready read would trade one drift for another.\n\nClassification and payload assembly are split into two pure functions so both\narms are testable without a registry or a reachable MCP server — the same shape\nused for `split_manifest_trust` in #6093.\n\nCloses #6110\n
M3gA-Mind1591a837447b
diff --git a/src/openhuman/mcp/registry/schemas_part_02.rs b/src/openhuman/mcp/registry/schemas_part_02.rsindex 6f2d4029a2..4af57de06c 100644--- a/src/openhuman/mcp/registry/schemas_part_02.rs+++ b/src/openhuman/mcp/registry/schemas_part_02.rs@@ -1,4 +1,3 @@-// ── Handler implementations ──────────────────────────────────────────────────fn handle_registry_search(params: Map<String, Value>) -> ControllerFuture {@@ -409,6 +408,12 @@ pub fn setup_schemas(function: &str) -> ControllerSchema {comment: "Freshly-minted server UUID.",required: true,},+ FieldSchema {+ name: "qualified_name",+ ty: TypeSchema::String,+ comment: "Registry qualified name the install was made from — echoed back so a caller need not correlate on the request.",+ required: true,+ },FieldSchema {name: "status",ty: TypeSchema::String,diff --git a/src/openhuman/mcp/registry/setup_ops.rs b/src/openhuman/mcp/registry/setup_ops.rsindex 3eb969460a..20c7369ab0 100644--- a/src/openhuman/mcp/registry/setup_ops.rs+++ b/src/openhuman/mcp/registry/setup_ops.rs@@ -24,6 +24,7 @@ use crate::rpc::RpcOutcome;use tinymcp::SecretRef;use super::helpers::{encode, inject_required_env_keys, require, resolve};+use super::types::{ConnStatus, ServerStatus};/// Reads a map of credential names to handles.fn parse_handles(raw: HashMap<String, String>) -> Result<HashMap<String, SecretRef>, String> {@@ -206,6 +207,67 @@ pub async fn mcp_setup_test_connection(// ── install_and_connect ──────────────────────────────────────────────────────+/// The schema's `status` discriminator, and the `error` that accompanies a+/// non-connected result.+///+/// Split out as a pure function so both arms are testable without standing up a+/// registry and a reachable MCP server.+///+/// **Why the verdict comes from `ConnStatus` and not from the call's own+/// return.** `McpRegistry::setup_install_and_connect` turns a failed connect+/// into `Ok(ConnectOutcome { server_id, tools: vec![] })` — it logs the reason+/// and drops it. `ConnectOutcome` carries only `server_id` and `tools`, so a+/// failed connect is byte-identical to a server that connected and advertises+/// no tools, which is a legitimate state (a server exposing only resources or+/// prompts). Counting tools therefore cannot answer the question. The registry's+/// own `ConnStatus` can: it carries the live [`ServerStatus`] plus `last_error`.+///+/// A status we cannot read back is reported as `installed_disconnected` rather+/// than assumed connected: the install is confirmed either way, and claiming a+/// connection we did not observe is the failure mode this change exists to+/// remove (#6110).+fn classify_install_connect(status: Option<&ConnStatus>) -> (&'static str, Option<String>) {+ match status {+ Some(entry) if matches!(entry.status, ServerStatus::Connected) => ("connected", None),+ Some(entry) => (+ "installed_disconnected",+ Some(entry.last_error.clone().unwrap_or_else(|| {+ format!(+ "installed, but the server is `{}` rather than connected",+ entry.status.as_str()+ )+ })),+ ),+ None => (+ "installed_disconnected",+ Some("installed, but the server's connection state could not be read back".to_string()),+ ),+ }+}++/// Builds the reply for `install_and_connect`, honouring the two conditional+/// fields the controller schema declares: `tools` iff `status == connected`,+/// `error` iff it is not. Pure, so the shape is testable without a registry.+fn install_and_connect_payload(+ server_id: &str,+ qualified_name: &str,+ status: &str,+ error: Option<String>,+ tools: Vec<tinymcp_bus::McpTool>,+) -> Value {+ let mut payload = serde_json::Map::new();+ payload.insert("server_id".to_string(), json!(server_id));+ payload.insert("qualified_name".to_string(), json!(qualified_name));+ payload.insert("status".to_string(), json!(status));+ if status == "connected" {+ payload.insert("tools".to_string(), json!(tools));+ }+ if let Some(error) = error {+ payload.insert("error".to_string(), json!(error));+ }+ Value::Object(payload)+}+pub async fn mcp_setup_install_and_connect(config: &Config,qualified_name: String,@@ -214,38 +276,63 @@ pub async fn mcp_setup_install_and_connect(let qualified_name = require(&qualified_name, "qualified_name")?;let handles = parse_handles(env_refs)?;- let outcome = resolve(config)?+ let host = resolve(config)?;+ // Still `?`: this arm is reached only when the *install* failed, and there+ // is no server to report a status for. A failed *connect* does not come+ // through here — see `classify_install_connect`.+ let outcome = host.dynamic().setup_install_and_connect(&qualified_name, &handles, None).await.map_err(|error| error.to_string())?;- let tools = super::tools_safe_for_agent(&outcome.server_id, outcome.tools);+ let server_id = outcome.server_id.clone();+ let connection = host+ .dynamic()+ .status()+ .await+ .map_err(|error| {+ log::warn!(+ "[mcp_setup] install_and_connect could not read back status for \+ server_id={server_id}: {error}"+ );+ })+ .ok()+ .and_then(|all| all.into_iter().find(|entry| entry.server_id == server_id));+ let (status, error) = classify_install_connect(connection.as_ref());+ let connected = status == "connected";++ let tools = super::tools_safe_for_agent(&server_id, outcome.tools);let tool_count = u32::try_from(tools.len()).unwrap_or(u32::MAX);BUS.publish(DomainEvent::McpServerInstalled {- server_id: outcome.server_id.clone(),+ server_id: server_id.clone(),qualified_name: qualified_name.clone(),});- // Unconditional, like the `connect` handler's. The call returning `Ok` is- // what says the connection succeeded; a server exposing only resources or- // prompts connects with zero tools, and gating on the count would leave- // anything tracking connection state believing it never came up.- BUS.publish(DomainEvent::McpServerConnected {- server_id: outcome.server_id.clone(),- tool_count,- });+ // Only when the server is actually connected. This used to fire+ // unconditionally, so an install whose connect failed announced+ // `McpServerConnected { tool_count: 0 }` to every subscriber — the same+ // false claim the `status` field now avoids making to the caller (#6110).+ // A connected server with zero tools still publishes: `connected` is read+ // from `ServerStatus`, never from the tool count.+ if connected {+ BUS.publish(DomainEvent::McpServerConnected {+ server_id: server_id.clone(),+ tool_count,+ });+ }+ let log = if connected {+ format!("installed and connected server_id={server_id} tools={tool_count}")+ } else {+ format!(+ "installed server_id={server_id}, but connecting did not succeed: {}",+ error.as_deref().unwrap_or("no reason reported")+ )+ };Ok(RpcOutcome::new(- json!({- "server_id": outcome.server_id,- "qualified_name": qualified_name,- "tools": tools,- }),- vec![format!(- "installed and connected server_id={} tools={tool_count}",- outcome.server_id- )],+ install_and_connect_payload(&server_id, &qualified_name, status, error, tools),+ vec![log],))}diff --git a/src/openhuman/mcp/registry/setup_ops_tests.rs b/src/openhuman/mcp/registry/setup_ops_tests.rsindex eb81877404..7a784f67ca 100644--- a/src/openhuman/mcp/registry/setup_ops_tests.rs+++ b/src/openhuman/mcp/registry/setup_ops_tests.rs@@ -44,3 +44,173 @@ fn an_invented_handle_is_refused_and_named() {fn an_empty_handle_map_parses_to_nothing() {assert!(parse_handles(HashMap::new()).unwrap().is_empty());}++// ── install_and_connect status reporting (#6110) ─────────────────────────────+//+// `mcp_setup_install_and_connect` declared a `status` discriminator it never+// emitted, and the `installed_disconnected` half of it was unobservable: the+// registry's `setup_install_and_connect` turns a failed connect into+// `Ok(ConnectOutcome { server_id, tools: vec![] })`, so the handler reported+// success — and published `McpServerConnected` — for a server that never came+// up. These pin the classification and the reply shape; the two functions are+// pure so neither needs a registry or a reachable MCP server.++use super::super::types::{ConnStatus, ServerStatus};++fn conn_status(status: ServerStatus, last_error: Option<&str>) -> ConnStatus {+ ConnStatus {+ server_id: "srv-1".to_string(),+ qualified_name: "acme/thing".to_string(),+ display_name: "Thing".to_string(),+ status,+ tool_count: 0,+ last_error: last_error.map(str::to_string),+ auth_hint: None,+ }+}++#[test]+fn a_connected_server_classifies_as_connected_with_no_error() {+ let entry = conn_status(ServerStatus::Connected, None);+ assert_eq!(+ super::classify_install_connect(Some(&entry)),+ ("connected", None)+ );+}++#[test]+fn a_connected_server_with_no_tools_is_still_connected() {+ // The state the old unconditional-success path existed to protect: a+ // server exposing only resources or prompts connects with zero tools.+ // `connected` reads from `ServerStatus`, never from the tool count.+ let mut entry = conn_status(ServerStatus::Connected, None);+ entry.tool_count = 0;+ assert_eq!(super::classify_install_connect(Some(&entry)).0, "connected");+}++#[test]+fn a_failed_connect_reports_installed_disconnected_and_carries_the_reason() {+ let entry = conn_status(ServerStatus::Error, Some("dial tcp: connection refused"));+ let (status, error) = super::classify_install_connect(Some(&entry));+ assert_eq!(status, "installed_disconnected");+ assert_eq!(error.as_deref(), Some("dial tcp: connection refused"));+}++#[test]+fn a_401_reports_installed_disconnected_rather_than_connected() {+ // `Unauthorized` is reachable, distinct from `Error`, and is emphatically+ // not connected — a caller offering a sign-in path needs to see that.+ let entry = conn_status(ServerStatus::Unauthorized, Some("server answered 401"));+ let (status, error) = super::classify_install_connect(Some(&entry));+ assert_eq!(status, "installed_disconnected");+ assert_eq!(error.as_deref(), Some("server answered 401"));+}++#[test]+fn a_non_connected_status_without_a_reason_still_names_the_state() {+ // `last_error` is `Option`; the schema's `error` is documented as present+ // whenever `status != connected`, so it must not go missing here.+ let entry = conn_status(ServerStatus::Disconnected, None);+ let (status, error) = super::classify_install_connect(Some(&entry));+ assert_eq!(status, "installed_disconnected");+ assert!(+ error.as_deref().is_some_and(|e| e.contains("disconnected")),+ "the reason must name the state it saw, got: {error:?}"+ );+}++#[test]+fn an_unreadable_status_is_not_assumed_connected() {+ let (status, error) = super::classify_install_connect(None);+ assert_eq!(+ status, "installed_disconnected",+ "a status we could not read back must never be reported as connected"+ );+ assert!(error.is_some(), "and it must say why");+}++#[test]+fn the_connected_payload_carries_tools_and_no_error() {+ let payload =+ super::install_and_connect_payload("srv-1", "acme/thing", "connected", None, Vec::new());+ assert_eq!(+ payload.get("server_id").and_then(|v| v.as_str()),+ Some("srv-1")+ );+ assert_eq!(+ payload.get("qualified_name").and_then(|v| v.as_str()),+ Some("acme/thing")+ );+ assert_eq!(+ payload.get("status").and_then(|v| v.as_str()),+ Some("connected")+ );+ assert!(+ payload.get("tools").is_some(),+ "schema declares `tools` iff status == connected: {payload}"+ );+ assert!(+ payload.get("error").is_none(),+ "schema declares `error` iff status != connected: {payload}"+ );+}++#[test]+fn the_disconnected_payload_carries_the_error_and_omits_tools() {+ let payload = super::install_and_connect_payload(+ "srv-1",+ "acme/thing",+ "installed_disconnected",+ Some("connection refused".to_string()),+ Vec::new(),+ );+ assert_eq!(+ payload.get("status").and_then(|v| v.as_str()),+ Some("installed_disconnected")+ );+ assert_eq!(+ payload.get("error").and_then(|v| v.as_str()),+ Some("connection refused")+ );+ assert!(+ payload.get("tools").is_none(),+ "`tools` must be absent when the server did not connect: {payload}"+ );+ // `server_id` stays required in both arms — the install did happen, and it+ // is what a caller needs to retry or remove the half-finished server.+ assert_eq!(+ payload.get("server_id").and_then(|v| v.as_str()),+ Some("srv-1")+ );+}++#[test]+fn every_declared_output_name_is_one_the_handler_can_emit() {+ // The drift #6110 is about: the catalog promised four fields, the handler+ // emitted three others. Walk the declared set against both reply arms.+ let declared: Vec<&str> = super::super::schemas::setup_schemas("install_and_connect")+ .outputs+ .iter()+ .map(|field| field.name)+ .collect();+ let connected = super::install_and_connect_payload("s", "q", "connected", None, Vec::new());+ let disconnected = super::install_and_connect_payload(+ "s",+ "q",+ "installed_disconnected",+ Some("boom".to_string()),+ Vec::new(),+ );+ for name in ["server_id", "qualified_name", "status", "tools", "error"] {+ assert!(+ declared.contains(&name),+ "`{name}` is emitted but not declared: {declared:?}"+ );+ }+ for name in &declared {+ assert!(+ connected.get(*name).is_some() || disconnected.get(*name).is_some(),+ "`{name}` is declared but neither reply arm emits it"+ );+ }+}