Skip to content

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

refactor(mcp): remove unused test-only mcp server tool bridge

Steven Enamakel2c74f0310186
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 d9b3849147..1366c3ff90 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
@@ -20,19 +20,9 @@ use std::sync::Arc;
use async_trait::async_trait;
use serde_json::Value;
-#[cfg(test)]
-use std::collections::HashSet;
-#[cfg(test)]
-use tinymcp::tools::{McpExposure, McpServerTool, McpToolInvoker, McpToolSource, SecretScrubber};
-#[cfg(test)]
-use tinymcp::McpRemoteToolExt;
use tinytools::{PermissionLevel, Tool, ToolCategory, ToolExposure, ToolResult};
use crate::config::Config;
-#[cfg(test)]
-use crate::config::McpToolExposure;
-#[cfg(test)]
-use crate::mcp::config_servers::McpServerRegistry;
use crate::security::{SecurityPolicy, ToolOperation};
/// Builds host adapters from TinyMCP-prepared declarations. Catalog retrieval,
@@ -182,234 +172,6 @@ impl Tool for ModuleConfiguredMcpServerTool {
}
}
-/// One tool per cached tool of every server in `registry`, for `config`.
-///
-/// `reserved` names are never produced — the generic bridge tools and
-/// anything else already registered keep their names.
-#[cfg(test)]
-pub fn configured_server_tools(
- config: &Config,
- registry: &Arc<McpServerRegistry>,
- security: &Arc<SecurityPolicy>,
- reserved: &HashSet<String>,
-) -> Vec<Box<dyn Tool>> {
- let host = match crate::mcp::host::for_config(config) {
- Ok(host) => host,
- Err(error) => {
- tracing::debug!(
- ?error,
- "[mcp_client] no host for workspace; no server tools"
- );
- return Vec::new();
- }
- };
-
- let mut sources = Vec::new();
- let mut uncached = Vec::new();
- for definition in registry.list() {
- match registry.cached_tools(&definition.name, host.dynamic().store()) {
- Some(tools) => {
- let tools = crate::mcp::registry::tools_safe_for_agent(&definition.name, tools);
- sources.push(
- McpToolSource::from_definition(definition, tools)
- .with_exposure(exposure_for(config, &definition.name)),
- );
- }
- None => uncached.push(definition.name.clone()),
- }
- }
- if !uncached.is_empty() {
- warm_in_background(Arc::clone(&host), Arc::clone(registry), uncached);
- }
-
- let invoker: Arc<dyn McpToolInvoker> = Arc::clone(registry) as Arc<dyn McpToolInvoker>;
- let tools: Vec<Box<dyn Tool>> = tinymcp::tools::tools_for(&sources, &invoker)
- .into_iter()
- .filter(|tool| !reserved.contains(tool.name()))
- .map(|tool| {
- Box::new(ConfiguredMcpServerTool::new(
- tool,
- Arc::clone(registry),
- Arc::clone(security),
- config.config_path.clone(),
- config.workspace_dir.clone(),
- )) as Box<dyn Tool>
- })
- .collect();
- tracing::debug!(
- servers = sources.len(),
- tools = tools.len(),
- "[mcp_client] registered per-tool MCP server tools"
- );
- tools
-}
-
-/// The exposure `config` asks for on the server named `server`.
-#[cfg(test)]
-fn exposure_for(config: &Config, server: &str) -> McpExposure {
- let Some(declared) = config
- .mcp_client
- .servers
- .iter()
- .find(|candidate| candidate.name.trim() == server)
- else {
- return McpExposure::deferred();
- };
- McpExposure {
- default: match declared.expose {
- McpToolExposure::Direct => ToolExposure::Direct,
- McpToolExposure::Deferred => ToolExposure::Deferred,
- },
- direct_tools: declared.direct_tools.clone(),
- }
-}
-
-/// Lists and caches `servers` off the tool-assembly path.
-#[cfg(test)]
-fn warm_in_background(
- host: Arc<crate::mcp::host::McpHost>,
- registry: Arc<McpServerRegistry>,
- servers: Vec<String>,
-) {
- let Ok(handle) = tokio::runtime::Handle::try_current() else {
- tracing::debug!("[mcp_client] no runtime; leaving the tool cache cold");
- return;
- };
- handle.spawn(async move {
- for server in servers {
- match registry
- .list_tools_caching(&server, host.dynamic().store())
- .await
- {
- Ok(tools) => tracing::debug!(
- server = %server,
- tools = tools.len(),
- "[mcp_client] warmed the tool cache"
- ),
- Err(error) => tracing::debug!(
- server = %server,
- "[mcp_client] could not warm the tool cache: {error}"
- ),
- }
- }
- });
-}
-
-/// A configured server's tool under this application's call policy.
-#[cfg(test)]
-pub struct ConfiguredMcpServerTool {
- inner: McpServerTool,
- registry: Arc<McpServerRegistry>,
- security: Arc<SecurityPolicy>,
- scrubber: SecretScrubber,
- config_path: std::path::PathBuf,
- workspace_dir: std::path::PathBuf,
-}
-
-#[cfg(test)]
-impl ConfiguredMcpServerTool {
- fn new(
- 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 {
- inner,
- registry,
- security,
- scrubber,
- config_path,
- workspace_dir,
- }
- }
-}
-
-#[async_trait]
-#[cfg(test)]
-impl Tool for ConfiguredMcpServerTool {
- fn name(&self) -> &str {
- self.inner.name()
- }
-
- fn description(&self) -> &str {
- self.inner.description()
- }
-
- fn parameters_schema(&self) -> Value {
- self.inner.parameters_schema()
- }
-
- fn permission_level(&self) -> PermissionLevel {
- self.inner.permission_level()
- }
-
- fn external_effect(&self) -> bool {
- self.inner.external_effect()
- }
-
- fn category(&self) -> ToolCategory {
- self.inner.category()
- }
-
- fn exposure(&self) -> ToolExposure {
- self.inner.exposure()
- }
-
- fn family(&self) -> Option<&str> {
- self.inner.family()
- }
-
- async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
- self.security
- .enforce_tool_operation(ToolOperation::Act, self.name())
- .map_err(|err| anyhow::anyhow!(err))?;
- let server = self.inner.server_id();
- let tool = self.inner.remote_name();
- 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}");
- };
- let Some(captured_definition) = self.registry.get(server) else {
- 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}"
- );
- }
- let live = current_registry.list_tools(server).await?;
- let safe = crate::mcp::registry::tools_safe_for_agent(
- server,
- live.into_iter()
- .map(|remote| {
- let description = remote.display_description();
- tinymcp_bus::McpTool {
- name: remote.name,
- description,
- input_schema: remote.input_schema,
- }
- })
- .collect(),
- );
- if !safe.iter().any(|candidate| candidate.name == tool) {
- anyhow::bail!("MCP tool is no longer available or safe: {server}/{tool}");
- }
- let result = self
- .inner
- .execute(args)
- .await
- .map_err(|error| anyhow::anyhow!(self.scrubber.scrub_error(&error)))?;
- Ok(self.scrubber.scrub_result(result))
- }
-}
-
#[cfg(test)]
#[path = "mcp_server_tools_tests.rs"]
mod tests;