//! MCP Tool Wrapper — bridges MCP server tools into the ToolRegistry //! //! Wraps `McpToolAdapter` (from zclaw-protocols) as a `Tool` trait object //! so the LLM can discover and call MCP tools during conversations. use async_trait::async_trait; use serde_json::Value; use std::sync::Arc; use zclaw_types::Result; use crate::tool::{Tool, ToolContext}; /// Wraps an MCP tool adapter into the `Tool` trait. /// /// The wrapper holds an `Arc` and delegates execution /// to the adapter, ignoring the `ToolContext` (MCP tools don't need /// agent_id, workspace, etc.). pub struct McpToolWrapper { adapter: Arc, /// Cached qualified name (service.tool) for Tool::name() qualified_name: String, } impl McpToolWrapper { pub fn new(adapter: Arc) -> Self { let qualified_name = adapter.qualified_name(); Self { adapter, qualified_name } } } #[async_trait] impl Tool for McpToolWrapper { fn name(&self) -> &str { &self.qualified_name } fn description(&self) -> &str { self.adapter.description() } fn input_schema(&self) -> Value { self.adapter.input_schema().clone() } async fn execute(&self, input: Value, _context: &ToolContext) -> Result { self.adapter.execute(input).await } }