gemini_adk_rs/tools/mcp/
tool.rs

1//! Individual MCP tool — wraps an MCP session manager to implement ToolFunction.
2
3use std::sync::Arc;
4
5use async_trait::async_trait;
6
7use crate::error::ToolError;
8use crate::tool::ToolFunction;
9
10use super::session_manager::McpSessionManager;
11
12/// An individual MCP tool, wrapping an MCP session manager.
13pub struct McpTool {
14    name: String,
15    description: String,
16    input_schema: Option<serde_json::Value>,
17    session_manager: Arc<McpSessionManager>,
18}
19
20impl McpTool {
21    /// Create a new MCP tool proxy with the given name, description, and session.
22    pub fn new(
23        name: impl Into<String>,
24        description: impl Into<String>,
25        input_schema: Option<serde_json::Value>,
26        session_manager: Arc<McpSessionManager>,
27    ) -> Self {
28        Self {
29            name: name.into(),
30            description: description.into(),
31            input_schema,
32            session_manager,
33        }
34    }
35}
36
37#[async_trait]
38impl ToolFunction for McpTool {
39    fn name(&self) -> &str {
40        &self.name
41    }
42    fn description(&self) -> &str {
43        &self.description
44    }
45    fn parameters(&self) -> Option<serde_json::Value> {
46        self.input_schema.clone()
47    }
48    async fn call(&self, args: serde_json::Value) -> Result<serde_json::Value, ToolError> {
49        self.session_manager
50            .call_tool(&self.name, args)
51            .await
52            .map_err(|e| ToolError::ExecutionFailed(e.to_string()))
53    }
54}