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
chore: files changed crates/openhuman-core/src/mcp/host.rs,crates/openhuman-core/src/mcp/mod.rs,crat
Steven Enamakelad30e3c42847
diff --git a/crates/openhuman-core/src/mcp/host.rs b/crates/openhuman-core/src/mcp/host.rsindex 16f416caca..5df314c3c3 100644--- a/crates/openhuman-core/src/mcp/host.rs+++ b/crates/openhuman-core/src/mcp/host.rs@@ -80,6 +80,7 @@ struct HostEntry {/// tools — are addressed by server id alone, because the connection map they/// read used to be a process global. They resolve through here.static DEFAULT_WORKSPACE: OnceLock<PathBuf> = OnceLock::new();+static DEFAULT_CONFIG: OnceLock<Config> = OnceLock::new();/// The three pieces of `tinymcp` this application drives.///@@ -275,6 +276,8 @@ pub fn lookup(config: &Config) -> anyhow::Result<Arc<McpHost>> {pub fn init(config: &Config) -> anyhow::Result<()> {for_config(config)?;+ set_default_config(config);+if DEFAULT_WORKSPACE.set(config.workspace_dir.clone()).is_err() {tracing::debug!("[mcp] a default workspace was already set; leaving it alone");return Ok(());@@ -284,6 +287,24 @@ pub fn init(config: &Config) -> anyhow::Result<()> {Ok(())}+/// Remembers the process config for ambient MCP calls without opening a+/// TinyMCP implementation in the host.+pub fn set_default_config(config: &Config) {+ let _ = DEFAULT_CONFIG.set(config.clone());+}++/// The config named by the current scoped dispatch, or the process default+/// outside a tenant scope. Ambient MCP helpers use this rather than resolving+/// an implementation-owned process registry.+pub fn ambient_config() -> Option<Config> {+ match crate::core::runtime::current_tenant() {+ Ok(tenant) if tenant.is_scoped() => {+ crate::core::runtime::CoreContext::with_current_embedder_config(Clone::clone)+ }+ _ => DEFAULT_CONFIG.get().cloned(),+ }+}+/// The service for the paths that have no `Config` to resolve by.////// Anything holding one should call [`for_config`] instead, which cannot answerdiff --git a/crates/openhuman-core/src/mcp/mod.rs b/crates/openhuman-core/src/mcp/mod.rsindex 72d75e0426..548a5bf3c6 100644--- a/crates/openhuman-core/src/mcp/mod.rs+++ b/crates/openhuman-core/src/mcp/mod.rs@@ -61,13 +61,10 @@#[cfg(feature = "mcp")]pub fn start(config: &crate::config::Config) {registry::bus::init();+ host::set_default_config(config);#[cfg(feature = "modules")]module_client::McpConfiguredClient::register_shutdown_hook();-- if let Err(error) = host::init(config) {- log::warn!("[mcp] the service could not be opened; continuing without it: {error}");- }}#[cfg(feature = "mcp")]diff --git a/crates/openhuman-core/src/mcp/registry/mod.rs b/crates/openhuman-core/src/mcp/registry/mod.rsindex 6014bd9504..100cd08c34 100644--- a/crates/openhuman-core/src/mcp/registry/mod.rs+++ b/crates/openhuman-core/src/mcp/registry/mod.rs@@ -104,10 +104,9 @@ pub mod connections {/// Sorted by qualified name, so a prompt built from this does not reshuffle/// between turns and cost its cached prefix.pub async fn connected_overview() -> Vec<ConnectedServerOverview> {- match host::try_service() {- Some(service) => service.dynamic().connected_overview().await,- None => Vec::new(),- }+ host::ambient_config().map_or_else(Vec::new, |config| async move {+ connected_overview_for_config(&config).await+ }.await)}/// Every connected server's identity and advertised tools in `config`'s@@ -187,20 +186,24 @@ pub mod connections {/// Every tool on every connected server, paired with its server.pub async fn all_connected_tools() -> Vec<(String, String, tinymcp_bus::McpTool)> {- match host::try_service() {- Some(service) => service.dynamic().connections().all_connected_tools().await,- None => Vec::new(),- }+ connected_overview()+ .await+ .into_iter()+ .flat_map(|server| {+ let server_id = server.server_id;+ let qualified_name = server.qualified_name;+ server.tools.into_iter().map(move |tool| {+ (server_id.clone(), qualified_name.clone(), tool)+ })+ })+ .collect()}/// The tools one connected server advertises, or `None` when it is not/// connected.pub async fn tools_for(server_id: &str) -> Option<Vec<tinymcp_bus::McpTool>> {- host::try_service()?- .dynamic()- .connections()- .tools_for(server_id)- .await+ let config = host::ambient_config()?;+ server_tools_for_config(&config, server_id).await}/// The tools one connected server advertises in `config`'s workspace.@@ -226,16 +229,10 @@ pub mod connections {/// Whether a server has a live entry.pub async fn is_connected(server_id: &str) -> bool {- match host::try_service() {- Some(service) => {- service- .dynamic()- .connections()- .is_connected(server_id)- .await- }- None => false,- }+ let Some(config) = host::ambient_config() else {+ return false;+ };+ is_connected_for_config(&config, server_id).await}/// Whether a server has a live entry in `config`'s workspace.@@ -288,10 +285,10 @@ pub mod connections {/// Answers `false` when the service is not up, which is the truth: nothing/// was holding a connection to drop.pub async fn disconnect(server_id: &str) -> bool {- match host::try_service() {- Some(service) => service.dynamic().connections().disconnect(server_id).await,- None => false,- }+ let Some(config) = host::ambient_config() else {+ return false;+ };+ disconnect_for_config(&config, server_id).await}/// Drop a connection held in `config`'s workspace.