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): add MCP server tool support and update vendor dependency
Steven Enamakeld9e646ca7380
diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rsindex d4735a788f..3be29c8936 100644--- a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs@@ -29,10 +29,23 @@ impl OpenHumanTurnPrelude {actions.extend(super::super::recorded_tools::recorded_search_tools(recorded.specs(),));- self.mutable+ let mut mutable = self+ .mutable.lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .recorded_integration_actions = actions;+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ mutable.recorded_integration_actions = actions;+ // MCP tools are rebuilt from the tool cache every turn; all a resumed+ // thread needs remembered is which names it was sent, so a tool it+ // knew under the pre-readable hashed name keeps resolving.+ #[cfg(feature = "mcp")]+ {+ mutable.recorded_mcp_tool_names = recorded+ .specs()+ .iter()+ .filter(|spec| spec.name.starts_with("mcp_"))+ .map(|spec| spec.name.clone())+ .collect();+ }}/// Executors for tool declarations the resumed thread was sent that the@@ -110,13 +123,16 @@ impl OpenHumanTurnPrelude {self.refresh_delegation_tool_surface();}- /// Snapshot the currently connected server actions for this workspace.- /// A disconnected server drops out of the next turn's search catalogue.+ /// Snapshot the installed servers' tools for this workspace, from the+ /// persistent tool cache when a server is not connected yet. A disabled or+ /// uninstalled server drops out of the next turn's search catalogue; a+ /// merely disconnected one stays listed and its calls report that it is+ /// not connected.#[cfg(feature = "mcp")]async fn refresh_connected_mcp_tools(&self) {let servers = match self.runtime_config.as_deref() {Some(config) => {- crate::mcp::registry::connections::connected_overview_for_config(config).await+ crate::mcp::registry::connections::cached_overview_for_config(config).await}None => Vec::new(),};@@ -146,13 +162,21 @@ impl OpenHumanTurnPrelude {let Some(config) = self.runtime_config.as_ref() else {return Vec::new();};- let servers = self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .connected_mcp_tools- .clone();- crate::mcp::registry::action_tool::deferred_connected_tools(Arc::clone(config), &servers)+ let (servers, recorded) = {+ let mutable = self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ (+ mutable.connected_mcp_tools.clone(),+ mutable.recorded_mcp_tool_names.clone(),+ )+ };+ crate::mcp::registry::action_tool::deferred_connected_tools_with_legacy(+ Arc::clone(config),+ &servers,+ &recorded,+ )}pub(super) async fn refresh_cold_integrations(&self) {diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 0d96fe4f6b..bad9d39cf0 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -148,6 +148,10 @@ struct OpenHumanTurnPreludeMutable {/// turn so disconnects remove their deferred executors immediately.#[cfg(feature = "mcp")]connected_mcp_tools: Vec<crate::mcp::registry::types::ConnectedServerOverview>,+ /// `mcp_*` tool names a resumed thread was sent, so a tool recorded under+ /// its pre-readable hashed name is restored under that name too.+ #[cfg(feature = "mcp")]+ recorded_mcp_tool_names: std::collections::HashSet<String>,announced_skills: std::collections::HashSet<String>,pending_skill_announcement: Vec<String>,pending_skill_retraction: Vec<String>,@@ -1537,6 +1541,8 @@ impl OpenHumanSessionHost {pending_mcp_announcement: self.pending_mcp_announcement.clone(),#[cfg(feature = "mcp")]connected_mcp_tools: Vec::new(),+ #[cfg(feature = "mcp")]+ recorded_mcp_tool_names: std::collections::HashSet::new(),announced_skills: self.announced_skills.clone(),pending_skill_announcement: self.pending_skill_announcement.clone(),pending_skill_retraction: self.pending_skill_retraction.clone(),diff --git a/crates/openhuman-core/src/mcp/registry/action_tool_tests.rs b/crates/openhuman-core/src/mcp/registry/action_tool_tests.rsindex 74a5b41c2f..7ca5926ec1 100644--- a/crates/openhuman-core/src/mcp/registry/action_tool_tests.rs+++ b/crates/openhuman-core/src/mcp/registry/action_tool_tests.rs@@ -1,4 +1,7 @@use super::*;+use crate::mcp::registry::types::McpTool;+use serde_json::json;+use tinytools::{PermissionLevel, ToolExposure};fn server(server_id: &str, tool_name: &str) -> ConnectedServerOverview {ConnectedServerOverview {@@ -20,26 +23,58 @@ fn server(server_id: &str, tool_name: &str) -> ConnectedServerOverview {}#[test]-fn names_are_stable_distinct_and_provider_safe() {- let first = searchable_name("server-1", "weather.forecast/current");+fn names_read_as_server_then_tool_and_are_provider_safe() {+ let name = searchable_name("example/weather", "weather.forecast/current");+ assert_eq!(name, "mcp_weather_weather_forecast_current");assert_eq!(- first,- searchable_name("server-1", "weather.forecast/current")+ name,+ searchable_name("example/weather", "weather.forecast/current"));- assert_ne!(- first,- searchable_name("server-2", "weather.forecast/current")- );- assert_ne!(- first,- searchable_name("server-1", "weather_forecast_current")- );- assert!(first.len() <= 64);- assert!(first+ assert!(name.len() <= 64);+ assert!(name.chars().all(|ch| ch.is_ascii_lowercase() || ch.is_ascii_digit() || ch == '_'));}+#[test]+fn tools_are_named_mcp_server_tool() {+ let tools = deferred_connected_tools(+ Arc::new(Config::default()),+ &[server("server-1", "readGoals")],+ );+ assert_eq!(tools[0].name(), "mcp_weather_read_goals");+}++#[test]+fn equal_tool_names_on_two_servers_stay_distinct() {+ let tools = deferred_connected_tools(+ Arc::new(Config::default()),+ &[server("server-1", "forecast"), server("server-2", "forecast")],+ );+ assert_eq!(tools.len(), 2);+ assert_ne!(tools[0].name(), tools[1].name());+}++#[test]+fn a_recorded_legacy_name_is_restored_as_an_alias() {+ let legacy = tinymcp::tools::naming::legacy_tool_name("server-1", "forecast");+ let recorded: HashSet<String> = [legacy.clone()].into_iter().collect();+ let tools = deferred_connected_tools_with_legacy(+ Arc::new(Config::default()),+ &[server("server-1", "forecast")],+ &recorded,+ );+ let names: Vec<&str> = tools.iter().map(|tool| tool.name()).collect();+ assert_eq!(names, ["mcp_weather_forecast", legacy.as_str()]);++ let none = deferred_connected_tools_with_legacy(+ Arc::new(Config::default()),+ &[server("server-1", "forecast")],+ &HashSet::new(),+ );+ assert_eq!(none.len(), 1);+}+#[test]fn connected_tools_are_deferred_with_real_schemas() {let tools = deferred_connected_tools(@@ -95,7 +130,7 @@ fn nested_schema_lists_are_sanitized() {}#[tokio::test]-async fn action_refuses_a_server_that_is_no_longer_connected() {+async fn action_refuses_a_server_that_is_not_connected() {let source = server("not-connected", "forecast");let workspace = tempfile::tempdir().expect("temp workspace");let config = Config {@@ -104,8 +139,8 @@ async fn action_refuses_a_server_that_is_no_longer_connected() {config_path: workspace.path().join("config.toml"),..Default::default()};- let tool = McpActionTool::new(Arc::new(config), &source, source.tools[0].clone());- let result = tool.execute(json!({ "city": "London" })).await.unwrap();+ let tools = deferred_connected_tools(Arc::new(config), &[source]);+ let result = tools[0].execute(json!({ "city": "London" })).await.unwrap();assert!(result.is_error);- assert!(result.text().contains("no longer connected"));+ assert!(result.text().contains("not connected"), "{}", result.text());}diff --git a/crates/openhuman-core/src/mcp/registry/mod.rs b/crates/openhuman-core/src/mcp/registry/mod.rsindex 1b3291f76f..1e46056da7 100644--- a/crates/openhuman-core/src/mcp/registry/mod.rs+++ b/crates/openhuman-core/src/mcp/registry/mod.rs@@ -122,6 +122,31 @@ pub mod connections {}}+ /// Every enabled installed server's identity and tools in `config`'s+ /// workspace, without dialling: live tools for a connected server, the+ /// persistent tool cache for one that is not (yet).+ ///+ /// What the agent's MCP tool surface is built from, so a server's tools+ /// are offered from the first turn after a restart rather than only once+ /// its connect finishes. Listing is not authorization — a call still+ /// needs a live connection.+ pub async fn cached_overview_for_config(config: &Config) -> Vec<ConnectedServerOverview> {+ let service = match host::for_config(config) {+ Ok(service) => service,+ Err(error) => {+ tracing::debug!(?error, "[mcp] no host for workspace; no cached tools");+ return Vec::new();+ }+ };+ match service.dynamic().cached_overview().await {+ Ok(overview) => overview,+ Err(error) => {+ tracing::debug!(%error, "[mcp] falling back to live servers only");+ service.dynamic().connected_overview().await+ }+ }+ }+/// Every tool on every connected server in `config`'s workspace.////// The counterpart to [`all_connected_tools`] for a caller that holds adiff --git a/crates/openhuman-core/src/tools/impl/network/mcp.rs b/crates/openhuman-core/src/tools/impl/network/mcp.rsindex 7e574776f6..427fb67517 100644--- a/crates/openhuman-core/src/tools/impl/network/mcp.rs+++ b/crates/openhuman-core/src/tools/impl/network/mcp.rs@@ -304,7 +304,7 @@ pub(super) struct SecretScrubber {}impl SecretScrubber {- fn for_server(registry: &McpServerRegistry, server: &str) -> Self {+ pub(super) fn for_server(registry: &McpServerRegistry, server: &str) -> Self {let Some(definition) = registry.get(server) else {return Self {secrets: Vec::new(),@@ -464,7 +464,7 @@ impl SecretScrubber {}}- fn scrub_result(&self, mut result: ToolResult) -> ToolResult {+ pub(super) fn scrub_result(&self, mut result: ToolResult) -> ToolResult {if self.secrets.is_empty() {return result;}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.rsnew file mode 100644index 0000000000..33253ca138--- /dev/null+++ b/crates/openhuman-core/src/tools/impl/network/mcp_server_tools.rs@@ -0,0 +1,204 @@+//! Every tool on a configured (`[[mcp_client.servers]]` / `AgentSpec::mcp`)+//! server as its own agent tool.+//!+//! The generic bridge (`mcp_list_tools` + `mcp_call_tool`) makes a model+//! discover a server's tools and route each call through one proxy. These+//! tools are the direct form: `mcp_<server>_<tool>`, with the remote schema,+//! deferred by default so `tool_search` finds them, or sent every turn when+//! the server says `expose = "direct"` / lists them in `direct_tools`.+//!+//! They are built from tinymcp's persistent tool cache, never from the+//! network, so assembling a tool list costs no round trip. A server with+//! nothing cached yet is listed in the background and its tools appear on the+//! next build; until then the generic bridge still reaches it.+//!+//! Policy stays here: the act gate, the prompt-injection scan on remote+//! definitions, and the secret scrubber on output, exactly as `mcp_call_tool`+//! applies them.++use std::collections::HashSet;+use std::sync::Arc;++use async_trait::async_trait;+use serde_json::Value;+use tinymcp::tools::{McpExposure, McpServerTool, McpToolInvoker, McpToolSource};+use tinytools::{PermissionLevel, Tool, ToolCategory, ToolExposure, ToolResult};++use super::mcp::SecretScrubber;+use crate::config::{Config, McpToolExposure};+use crate::mcp::config_servers::McpServerRegistry;+use crate::security::{SecurityPolicy, ToolOperation};++/// 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.+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,+ registry,+ Arc::clone(security),+ )) 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`.+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.+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.+pub struct ConfiguredMcpServerTool {+ inner: McpServerTool,+ security: Arc<SecurityPolicy>,+ scrubber: SecretScrubber,+}++impl ConfiguredMcpServerTool {+ fn new(+ inner: McpServerTool,+ registry: &McpServerRegistry,+ security: Arc<SecurityPolicy>,+ ) -> Self {+ let scrubber = SecretScrubber::for_server(registry, inner.server_id());+ Self {+ inner,+ security,+ scrubber,+ }+ }+}++#[async_trait]+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 result = self.inner.execute(args).await?;+ Ok(self.scrubber.scrub_result(result))+ }+}++#[cfg(test)]+#[path = "mcp_server_tools_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/tools/impl/network/mod.rs b/crates/openhuman-core/src/tools/impl/network/mod.rsindex 7d96ab001d..83d4cd7efc 100644--- a/crates/openhuman-core/src/tools/impl/network/mod.rs+++ b/crates/openhuman-core/src/tools/impl/network/mod.rs@@ -14,6 +14,8 @@ mod http_request;// facade.)#[cfg(feature = "mcp")]mod mcp;+#[cfg(feature = "mcp")]+mod mcp_server_tools;mod url_guard;mod web_fetch;@@ -23,6 +25,8 @@ pub use gmail_unsubscribe::GmailUnsubscribeTool;pub use http_request::HttpRequestTool;#[cfg(feature = "mcp")]pub use mcp::{McpCallTool, McpListServersTool, McpListToolsTool};+#[cfg(feature = "mcp")]+pub use mcp_server_tools::{configured_server_tools, ConfiguredMcpServerTool};/// The SSRF guard the network tools apply, so a host outside this crate can/// hold user-supplied URLs to the same rule rather than writing a second one.pub use url_guard::{diff --git a/vendor/tinymcp b/vendor/tinymcpindex 06776cd04a..32edd2e6f2 160000--- a/vendor/tinymcp+++ b/vendor/tinymcp@@ -1 +1 @@-Subproject commit 06776cd04a4e3668f15a2e089354e497184cbab1+Subproject commit 32edd2e6f2644b71a649d3b782fda7263665c15e