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
feat(mcp): finish the per-config connection lookups (#5701)\n\n`connections::connect` resolves per-config via `host::for_config`, while the\nby-server-id lookups read the process-global `host::try_service`. A host that\nconnects through the facade could never see the connection it just made.\n\n`main` is already midway through the answer: `all_connected_tools_for_config`\nand `disconnect_for_config` both exist, and `disconnect_for_config`'s own docs\ndescribe this exact trap. Neither was present at `ac6454177`, the revision the\nissue was written against, which is why the issue reads it as one odd function\nout of eight rather than as a migration with two of seven done.\n\nThis finishes it — the same shape, next to each ambient counterpart:\n\n connected_overview_for_config\n server_tools_for_config\n is_connected_for_config\n auth_hint_for_config\n last_error_for_config\n\nAdditive, so nothing existing changes signature and no caller has to move.\n\nEach `Err` arm logs the workspace-resolution failure instead of folding it\nsilently into `false` / `None` / `Vec::new()`, which is the issue's second ask:\n"the service is not up" and "the server is not connected" should not be\nindistinguishable.\n\n`server_tools_for_config` breaks the mechanical `_for_config` suffix on purpose:\n`tools_for_config` would sit directly below `all_connected_tools_for_config` and\nread as its every-server sibling.\n\nTest: `per_config_lookups_see_a_per_config_connection` opens two workspaces so\n`try_service` has no honest answer, connects through the facade in one, and\nasserts the per-config lookups see it and that the other workspace does not.\nVerified discriminating — reimplementing one variant over `try_service` turns it\nred.\n\n`cargo test --features mcp --test mcp_registry_e2e` 17 passed.\n`cargo check --lib --features mcp` and `--no-default-features` both clean.\n
Nguyen Thanh Datd92f197db826
diff --git a/src/openhuman/mcp/registry/mod.rs b/src/openhuman/mcp/registry/mod.rsindex 8ca955faa4..ec199c5fd7 100644--- a/src/openhuman/mcp/registry/mod.rs+++ b/src/openhuman/mcp/registry/mod.rs@@ -89,6 +89,26 @@ pub mod connections {}}+ /// Every connected server's identity and advertised tools in `config`'s+ /// workspace.+ ///+ /// The counterpart to [`connected_overview`] for a caller that holds a+ /// `Config`, for the same reason [`all_connected_tools_for_config`] and+ /// [`disconnect_for_config`] exist: the ambient form resolves through the+ /// process default, which stops answering once a second workspace is open.+ pub async fn connected_overview_for_config(config: &Config) -> Vec<ConnectedServerOverview> {+ match host::for_config(config) {+ Ok(service) => service.dynamic().connected_overview().await,+ Err(error) => {+ tracing::debug!(+ ?error,+ "[mcp] no host for workspace; reporting no connections"+ );+ Vec::new()+ }+ }+ }+/// Every tool on every connected server in `config`'s workspace.////// The counterpart to [`all_connected_tools`] for a caller that holds a@@ -136,6 +156,29 @@ pub mod connections {.await}+ /// The tools one connected server advertises in `config`'s workspace.+ ///+ /// Named `server_tools_*` rather than `tools_for_config` so it cannot be+ /// misread as [`all_connected_tools_for_config`], which is the every-server+ /// form sitting a few lines above.+ ///+ /// `None` means "not connected". A workspace with no host at all logs and+ /// also yields `None`, because a server cannot be connected in a workspace+ /// that has no host — but the log is there so the two are distinguishable+ /// when this is the answer a caller did not expect.+ pub async fn server_tools_for_config(+ config: &Config,+ server_id: &str,+ ) -> Option<Vec<tinymcp_bus::McpTool>> {+ match host::for_config(config) {+ Ok(service) => service.dynamic().connections().tools_for(server_id).await,+ Err(error) => {+ tracing::debug!(?error, server_id, "[mcp] no host for workspace; no tools");+ None+ }+ }+ }+/// Whether a server has a live entry.pub async fn is_connected(server_id: &str) -> bool {match host::try_service() {@@ -150,6 +193,27 @@ pub mod connections {}}+ /// Whether a server has a live entry in `config`'s workspace.+ pub async fn is_connected_for_config(config: &Config, server_id: &str) -> bool {+ match host::for_config(config) {+ Ok(service) => {+ service+ .dynamic()+ .connections()+ .is_connected(server_id)+ .await+ }+ Err(error) => {+ tracing::debug!(+ ?error,+ server_id,+ "[mcp] no host for workspace; reporting not connected"+ );+ false+ }+ }+ }+/// Why a server's most recent attempt hit a 401, as a stable code.pub async fn auth_hint_for(server_id: &str) -> Option<&'static str> {Some(@@ -162,6 +226,28 @@ pub mod connections {)}+ /// Why a server's most recent attempt in `config`'s workspace hit a 401.+ pub async fn auth_hint_for_config(config: &Config, server_id: &str) -> Option<&'static str> {+ match host::for_config(config) {+ Ok(service) => Some(+ service+ .dynamic()+ .connections()+ .auth_hint(server_id)+ .await?+ .as_code(),+ ),+ Err(error) => {+ tracing::debug!(+ ?error,+ server_id,+ "[mcp] no host for workspace; no auth hint"+ );+ None+ }+ }+ }+/// Connects one server and returns the tools it advertised.////// # Errors@@ -227,6 +313,21 @@ pub mod connections {.last_error(server_id).await}++ /// The most recent failure message for a server in `config`'s workspace.+ pub async fn last_error_for_config(config: &Config, server_id: &str) -> Option<String> {+ match host::for_config(config) {+ Ok(service) => service.dynamic().connections().last_error(server_id).await,+ Err(error) => {+ tracing::debug!(+ ?error,+ server_id,+ "[mcp] no host for workspace; no last error"+ );+ None+ }+ }+ }}/// The registry's own store, for the callers that reach it directly.diff --git a/tests/mcp_registry_e2e.rs b/tests/mcp_registry_e2e.rsindex a28fbe2a70..3e92cc6d73 100644--- a/tests/mcp_registry_e2e.rs+++ b/tests/mcp_registry_e2e.rs@@ -680,3 +680,76 @@ async fn supervisor_skips_a_disabled_server() {"supervisor does not connect disabled servers");}++/// The per-config connection lookups must answer about the workspace they were+/// handed (#5701).+///+/// `connections::connect` has always resolved per-config via `host::for_config`,+/// while the by-server-id lookups read the process-global `host::try_service`.+/// A host that connects through the facade could therefore never see the+/// connection it had just made.+///+/// The precondition below is what makes this test discriminate: with two+/// workspaces open and no default, `try_service` refuses to guess and answers+/// `None`, so anything routed through it degrades to "nothing is connected".+/// An embedder holding its own per-config service is in that state permanently.+#[tokio::test]+async fn per_config_lookups_see_a_per_config_connection() {+ use openhuman_core::openhuman::mcp::host;+ use openhuman_core::openhuman::mcp::registry::connections;++ let (_tmp_a, cfg_a) = fresh_workspace_config();+ let (_tmp_b, cfg_b) = fresh_workspace_config();+ let _host_b = host(&cfg_b);++ let h = host(&cfg_a);+ let server = make_installed_server();+ h.dynamic()+ .store()+ .insert_server(&server)+ .expect("insert installed server");++ let tools = connections::connect(&cfg_a, &server)+ .await+ .expect("connect succeeds");+ assert_eq!(tools.len(), 1, "stub advertises one tool");++ assert!(+ host::try_service().is_none(),+ "two workspaces open and no default: the ambient service must refuse to \+ guess, which is what makes the per-config forms the only correct ones here"+ );++ assert!(+ connections::is_connected_for_config(&cfg_a, &server.server_id).await,+ "the workspace that connected must see its own connection"+ );++ let listed = connections::server_tools_for_config(&cfg_a, &server.server_id)+ .await+ .expect("the connected server advertises its tools");+ assert_eq!(listed.len(), 1);+ assert_eq!(listed[0].name, "echo");++ let overview = connections::connected_overview_for_config(&cfg_a).await;+ assert!(+ overview.iter().any(|s| s.server_id == server.server_id),+ "the overview for this workspace must list the server it connected"+ );++ assert!(+ connections::last_error_for_config(&cfg_a, &server.server_id)+ .await+ .is_none(),+ "a successful connect leaves no error behind"+ );++ // A different workspace is a different connection map, not a shared one.+ assert!(+ !connections::is_connected_for_config(&cfg_b, &server.server_id).await,+ "a connection must not leak across workspaces"+ );++ assert!(connections::disconnect_for_config(&cfg_a, &server.server_id).await);+ assert!(!connections::is_connected_for_config(&cfg_a, &server.server_id).await);+}