Skip to content

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

fix(registry): handle duplicate tool registrations gracefully

Steven Enamakel00cff9227163
diff --git a/crates/openhuman-core/src/mcp/registry/tools.rs b/crates/openhuman-core/src/mcp/registry/tools.rs
index eb3afb6fa1..b5a8670bea 100644
--- a/crates/openhuman-core/src/mcp/registry/tools.rs
+++ b/crates/openhuman-core/src/mcp/registry/tools.rs
@@ -5,6 +5,12 @@
//! status, connect/disconnect, and call a tool on a connected server. Thin
//! shims over [`crate::mcp::registry::ops`].
//!
+//! What each tool *is* — its name, description, schema, effect and whether it
+//! is deferred — is the contract's (`tinymcp_bus::agent_tools::RegistryTool`),
+//! so the identity a model and a cached prompt see is defined once. What is
+//! left here is host policy: the permission level an effect maps to, the
+//! exposure, and running the call against this workspace's registry.
+//!
//! Discovery/observe/connect/call tools are default-ON. The persistent
//! `mcp_registry_uninstall` mutator ships default-OFF via
//! `tools/user_filter.rs` (`mcp_manage` toggle). There is no install tool: a
@@ -18,13 +24,83 @@
use std::sync::Arc;
use async_trait::async_trait;
-use serde_json::{json, Value};
+use serde_json::{Value};
use crate::config::Config;
-use tinytools::{PermissionLevel, Tool, ToolResult};
+use tinymcp_bus::agent_tools::{
+ normalize_tool_arguments, AgentToolEffect, AgentToolSpec, RegistryTool,
+};
+use tinytools::{PermissionLevel, Tool, ToolExposure, ToolResult};
use super::ops;
+/// The permission level this host requires for a tool's effect.
+///
+/// An effect the contract adds later maps to the strictest level until this
+/// host decides otherwise.
+pub(crate) fn permission_for(effect: AgentToolEffect) -> PermissionLevel {
+ match effect {
+ AgentToolEffect::Read => PermissionLevel::ReadOnly,
+ AgentToolEffect::Execute => PermissionLevel::Execute,
+ _ => PermissionLevel::Write,
+ }
+}
+
+/// How this host exposes a spec: deferred specs are found by search.
+pub(crate) fn exposure_for(spec: &AgentToolSpec) -> ToolExposure {
+ if spec.deferred {
+ ToolExposure::Deferred
+ } else {
+ ToolExposure::Direct
+ }
+}
+
+/// The spec-derived half of a registry tool's `Tool` impl.
+macro_rules! spec_metadata {
+ () => {
+ fn name(&self) -> &str {
+ &self.spec.name
+ }
+ fn description(&self) -> &str {
+ &self.spec.description
+ }
+ fn parameters_schema(&self) -> Value {
+ self.spec.parameters.clone()
+ }
+ fn permission_level(&self) -> PermissionLevel {
+ permission_for(self.spec.effect)
+ }
+ fn exposure(&self) -> ToolExposure {
+ exposure_for(&self.spec)
+ }
+ // Observing is safe to run beside other calls; acting is not.
+ fn is_concurrency_safe(&self, _args: &Value) -> bool {
+ self.spec.effect == AgentToolEffect::Read
+ }
+ };
+}
+
+/// A registry tool struct holding its config and its contract spec.
+macro_rules! registry_tool {
+ ($(#[$doc:meta])* $ty:ident => $kind:ident) => {
+ $(#[$doc])*
+ pub struct $ty {
+ config: Arc<Config>,
+ spec: AgentToolSpec,
+ }
+ impl $ty {
+ /// Builds the tool over `config`.
+ #[must_use]
+ pub fn new(config: Arc<Config>) -> Self {
+ Self {
+ config,
+ spec: RegistryTool::$kind.spec(),
+ }
+ }
+ }
+ };
+}
+
macro_rules! emit {
($outcome:expr, $name:literal) => {{
let outcome = $outcome.map_err(|e| anyhow::anyhow!(concat!($name, ": {}"), e))?;
@@ -41,40 +117,15 @@ fn req_str(args: &serde_json::Value, key: &str) -> anyhow::Result<String> {
.ok_or_else(|| anyhow::anyhow!("missing required string argument `{key}`"))
}
-/// Search the MCP registry catalog.
-pub struct McpRegistrySearchTool {
- config: Arc<Config>,
-}
-impl McpRegistrySearchTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Search the MCP registry catalog.
+ McpRegistrySearchTool => Search
}
#[async_trait]
impl Tool for McpRegistrySearchTool {
- fn exposure(&self) -> tinytools::ToolExposure {
- tinytools::ToolExposure::Deferred
- }
+ spec_metadata!();
+
- fn name(&self) -> &str {
- "mcp_registry_search"
- }
- fn description(&self) -> &str {
- "Search the MCP server registry catalog by `query`, optionally filtered by \
- `transport` (\"stdio\" | \"hosted\" | \"all\"), paginated by `page` / \
- `page_size`. Use to discover installable MCP servers."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": {
- "query": { "type": "string" },
- "transport": { "type": "string", "enum": ["stdio", "hosted", "all"] },
- "page": { "type": "integer", "minimum": 1 },
- "page_size": { "type": "integer", "minimum": 1 }
- }
- })
- }
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let query = args
.get("query")
@@ -94,39 +145,17 @@ impl Tool for McpRegistrySearchTool {
"mcp_registry_search"
)
}
- fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
- true
- }
}
-/// Get one registry server by qualified name.
-pub struct McpRegistryGetTool {
- config: Arc<Config>,
-}
-impl McpRegistryGetTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Get one registry server by qualified name.
+ McpRegistryGetTool => Get
}
#[async_trait]
impl Tool for McpRegistryGetTool {
- fn exposure(&self) -> tinytools::ToolExposure {
- tinytools::ToolExposure::Deferred
- }
+ spec_metadata!();
+
- fn name(&self) -> &str {
- "mcp_registry_get"
- }
- fn description(&self) -> &str {
- "Get one MCP registry server's detail by `qualified_name`."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": { "qualified_name": { "type": "string" } },
- "required": ["qualified_name"]
- })
- }
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let qn = req_str(&args, "qualified_name")?;
emit!(
@@ -134,107 +163,49 @@ impl Tool for McpRegistryGetTool {
"mcp_registry_get"
)
}
- fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
- true
- }
}
-/// List installed MCP servers.
-pub struct McpRegistryInstalledListTool {
- config: Arc<Config>,
-}
-impl McpRegistryInstalledListTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// List installed MCP servers.
+ McpRegistryInstalledListTool => InstalledList
}
#[async_trait]
impl Tool for McpRegistryInstalledListTool {
- fn exposure(&self) -> tinytools::ToolExposure {
- tinytools::ToolExposure::Deferred
- }
+ spec_metadata!();
+
- fn name(&self) -> &str {
- "mcp_registry_installed_list"
- }
- fn description(&self) -> &str {
- "List the MCP servers currently installed for this user."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({ "type": "object", "properties": {} })
- }
async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
emit!(
ops::mcp_clients_installed_list(&self.config).await,
"mcp_registry_installed_list"
)
}
- fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
- true
- }
}
-/// Connection status of installed MCP servers.
-pub struct McpRegistryStatusTool {
- config: Arc<Config>,
-}
-impl McpRegistryStatusTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Connection status of installed MCP servers.
+ McpRegistryStatusTool => Status
}
#[async_trait]
impl Tool for McpRegistryStatusTool {
- fn name(&self) -> &str {
- "mcp_registry_status"
- }
- fn description(&self) -> &str {
- "Report the connection status of installed MCP servers."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({ "type": "object", "properties": {} })
- }
+ spec_metadata!();
+
async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
emit!(
ops::mcp_clients_status(&self.config).await,
"mcp_registry_status"
)
}
- fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
- true
- }
}
-/// List the tools advertised by a connected MCP server (discovery).
-pub struct McpRegistryListToolsTool {
- config: Arc<Config>,
-}
-impl McpRegistryListToolsTool {
- /// Builds the tool over `config`.
- #[must_use]
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// List the tools advertised by a connected MCP server (discovery).
+ McpRegistryListToolsTool => ListTools
}
#[async_trait]
impl Tool for McpRegistryListToolsTool {
- fn name(&self) -> &str {
- "mcp_registry_list_tools"
- }
- fn description(&self) -> &str {
- "List the tools (name, description, input schema) exposed by a \
- connected MCP server, given its `server_id`. Use this to discover \
- what a connected server can do before calling `mcp_registry_tool_call`. \
- The server must already be connected (see `mcp_registry_status` / \
- `mcp_registry_connect`)."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": { "server_id": { "type": "string" } },
- "required": ["server_id"]
- })
- }
+ spec_metadata!();
+
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let sid = req_str(&args, "server_id")?;
emit!(
@@ -242,39 +213,16 @@ impl Tool for McpRegistryListToolsTool {
"mcp_registry_list_tools"
)
}
- fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
- true
- }
}
-/// Connect an installed MCP server.
-pub struct McpRegistryConnectTool {
- config: Arc<Config>,
-}
-impl McpRegistryConnectTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Connect an installed MCP server.
+ McpRegistryConnectTool => Connect
}
#[async_trait]
impl Tool for McpRegistryConnectTool {
- fn name(&self) -> &str {
- "mcp_registry_connect"
- }
- fn description(&self) -> &str {
- "Connect (spawn + handshake) an installed MCP server by `server_id`, \
- returning its tools."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": { "server_id": { "type": "string" } },
- "required": ["server_id"]
- })
- }
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::Execute
- }
+ spec_metadata!();
+
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let sid = req_str(&args, "server_id")?;
emit!(
@@ -284,35 +232,14 @@ impl Tool for McpRegistryConnectTool {
}
}
-/// Disconnect an MCP server.
-pub struct McpRegistryDisconnectTool {
- config: Arc<Config>,
-}
-impl McpRegistryDisconnectTool {
- /// Builds the tool over `config`.
- #[must_use]
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Disconnect an MCP server.
+ McpRegistryDisconnectTool => Disconnect
}
#[async_trait]
impl Tool for McpRegistryDisconnectTool {
- fn name(&self) -> &str {
- "mcp_registry_disconnect"
- }
- fn description(&self) -> &str {
- "Disconnect (stop) a connected MCP server by `server_id`."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": { "server_id": { "type": "string" } },
- "required": ["server_id"]
- })
- }
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::Execute
- }
+ spec_metadata!();
+
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let sid = req_str(&args, "server_id")?;
emit!(
@@ -322,40 +249,14 @@ impl Tool for McpRegistryDisconnectTool {
}
}
-/// Call a tool on a connected MCP server.
-pub struct McpRegistryToolCallTool {
- config: Arc<Config>,
-}
-impl McpRegistryToolCallTool {
- /// Builds the tool over `config`.
- #[must_use]
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Call a tool on a connected MCP server.
+ McpRegistryToolCallTool => ToolCall
}
#[async_trait]
impl Tool for McpRegistryToolCallTool {
- fn name(&self) -> &str {
- "mcp_registry_tool_call"
- }
- fn description(&self) -> &str {
- "Invoke a tool on a connected MCP server: `server_id` + `tool_name` + \
- `arguments` object."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": {
- "server_id": { "type": "string" },
- "tool_name": { "type": "string" },
- "arguments": { "type": "object" }
- },
- "required": ["server_id", "tool_name"]
- })
- }
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::Execute
- }
+ spec_metadata!();
+
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let sid = req_str(&args, "server_id")?;
let tool_name = req_str(&args, "tool_name")?;
@@ -367,33 +268,14 @@ impl Tool for McpRegistryToolCallTool {
}
}
-/// Uninstall an MCP server. Default-OFF.
-pub struct McpRegistryUninstallTool {
- config: Arc<Config>,
-}
-impl McpRegistryUninstallTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
+registry_tool! {
+ /// Uninstall an MCP server. Default-OFF.
+ McpRegistryUninstallTool => Uninstall
}
#[async_trait]
impl Tool for McpRegistryUninstallTool {
- fn name(&self) -> &str {
- "mcp_registry_uninstall"
- }
- fn description(&self) -> &str {
- "Uninstall an installed MCP server by `server_id`. Default-OFF (opt-in)."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": { "server_id": { "type": "string" } },
- "required": ["server_id"]
- })
- }
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::Write
- }
+ spec_metadata!();
+
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let sid = req_str(&args, "server_id")?;
emit!(