Skip to content

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

feat(mcp): pass config path and workspace dir to configured MCP server tools

Steven Enamakelbb4d5bdaf93f
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp_server_tools.rs b/crates/openhuman-core/src/tools/impl/network/mcp_server_tools.rs
index b3deff1e12..4c48ca7650 100644
--- a/crates/openhuman-core/src/tools/impl/network/mcp_server_tools.rs
+++ b/crates/openhuman-core/src/tools/impl/network/mcp_server_tools.rs
@@ -77,6 +77,8 @@ pub fn configured_server_tools(
tool,
Arc::clone(registry),
Arc::clone(security),
+ config.config_path.clone(),
+ config.workspace_dir.clone(),
)) as Box<dyn Tool>
})
.collect();
@@ -143,6 +145,8 @@ pub struct ConfiguredMcpServerTool {
registry: Arc<McpServerRegistry>,
security: Arc<SecurityPolicy>,
scrubber: SecretScrubber,
+ config_path: std::path::PathBuf,
+ workspace_dir: std::path::PathBuf,
}
impl ConfiguredMcpServerTool {
@@ -150,6 +154,8 @@ impl ConfiguredMcpServerTool {
inner: McpServerTool,
registry: Arc<McpServerRegistry>,
security: Arc<SecurityPolicy>,
+ config_path: std::path::PathBuf,
+ workspace_dir: std::path::PathBuf,
) -> Self {
let scrubber = SecretScrubber::for_server(&registry, inner.server_id());
Self {
@@ -157,6 +163,8 @@ impl ConfiguredMcpServerTool {
registry,
security,
scrubber,
+ config_path,
+ workspace_dir,
}
}
}
@@ -201,9 +209,10 @@ impl Tool for ConfiguredMcpServerTool {
.map_err(|err| anyhow::anyhow!(err))?;
let server = self.inner.server_id();
let tool = self.inner.remote_name();
- let config = crate::config::ops::load_config_with_timeout()
- .await
- .map_err(|error| anyhow::anyhow!("could not reload MCP configuration: {error}"))?;
+ let config =
+ crate::config::ops::reload_config_from_paths(&self.config_path, &self.workspace_dir)
+ .await
+ .map_err(|error| anyhow::anyhow!("could not reload MCP configuration: {error}"))?;
let current_registry = crate::mcp::host::static_registry(&config);
let Some(current_definition) = current_registry.get(server) else {
anyhow::bail!("MCP server is no longer configured: {server}");
@@ -212,7 +221,9 @@ impl Tool for ConfiguredMcpServerTool {
anyhow::bail!("MCP server is no longer configured: {server}");
};
if current_definition.fingerprint() != captured_definition.fingerprint() {
- anyhow::bail!("MCP server configuration changed; rebuild tools before calling {server}");
+ anyhow::bail!(
+ "MCP server configuration changed; rebuild tools before calling {server}"
+ );
}
let live = current_registry.list_tools(server).await?;
let safe = crate::mcp::registry::tools_safe_for_agent(
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp_server_tools_tests.rs b/crates/openhuman-core/src/tools/impl/network/mcp_server_tools_tests.rs
index d777780052..0837875ff9 100644
--- a/crates/openhuman-core/src/tools/impl/network/mcp_server_tools_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/network/mcp_server_tools_tests.rs
@@ -76,6 +76,15 @@ fn config(
}
async fn warmed(config: &Config) -> Arc<McpServerRegistry> {
+ tokio::fs::create_dir_all(config.config_path.parent().unwrap())
+ .await
+ .unwrap();
+ tokio::fs::write(
+ &config.config_path,
+ toml::to_string(config).expect("serialize config"),
+ )
+ .await
+ .unwrap();
let registry = Arc::new(crate::mcp::host::static_registry(config));
let host = crate::mcp::host::for_config(config).expect("host");
for (name, outcome) in registry.refresh_tool_cache(host.dynamic().store()).await {