gemini_adk_rs/tools/mcp/
toolset.rs

1//! MCP toolset — discovers tools from an MCP server.
2
3use std::sync::Arc;
4
5use async_trait::async_trait;
6
7use crate::tool::ToolFunction;
8use crate::toolset::Toolset;
9
10use super::session_manager::McpSessionManager;
11
12/// A toolset that discovers tools from an MCP server.
13pub struct McpToolset {
14    session_manager: Arc<McpSessionManager>,
15    filter: Option<Vec<String>>,
16}
17
18impl McpToolset {
19    /// Create a new MCP toolset connected to the given session manager.
20    pub fn new(session_manager: Arc<McpSessionManager>) -> Self {
21        Self {
22            session_manager,
23            filter: None,
24        }
25    }
26
27    /// Only expose tools whose names match the filter.
28    pub fn with_filter(mut self, names: Vec<String>) -> Self {
29        self.filter = Some(names);
30        self
31    }
32
33    /// Returns the current filter, if any.
34    pub fn filter(&self) -> Option<&[String]> {
35        self.filter.as_deref()
36    }
37
38    /// Returns a reference to the underlying session manager.
39    pub fn session_manager(&self) -> &Arc<McpSessionManager> {
40        &self.session_manager
41    }
42}
43
44#[async_trait]
45impl Toolset for McpToolset {
46    fn get_tools(&self) -> Vec<Arc<dyn ToolFunction>> {
47        // Note: This is synchronous in the trait, but tool discovery is async.
48        // In practice, tools should be pre-loaded. For now, return empty.
49        // A more complete implementation would cache tools after async initialization.
50        vec![]
51    }
52
53    async fn close(&self) {
54        // Close MCP session if connected
55    }
56}