gemini_adk_rs/tools/mcp/session_manager.rs
1//! MCP session management — connection params, tool discovery, and tool invocation.
2
3use std::collections::HashMap;
4use std::time::Duration;
5
6/// Connection parameters for an MCP server.
7#[derive(Debug, Clone)]
8pub enum McpConnectionParams {
9 /// Connect via stdio (subprocess).
10 Stdio {
11 /// The command to execute.
12 command: String,
13 /// Arguments passed to the command.
14 args: Vec<String>,
15 /// Connection timeout.
16 timeout: Option<Duration>,
17 },
18 /// Connect via SSE/StreamableHTTP.
19 Sse {
20 /// The URL of the MCP server.
21 url: String,
22 /// Optional HTTP headers for authentication.
23 headers: Option<HashMap<String, String>>,
24 },
25}
26
27/// Manages the MCP client session lifecycle.
28pub struct McpSessionManager {
29 params: McpConnectionParams,
30}
31
32impl McpSessionManager {
33 /// Create a new MCP session manager with the given connection params.
34 pub fn new(params: McpConnectionParams) -> Self {
35 Self { params }
36 }
37
38 /// Get the connection parameters.
39 pub fn params(&self) -> &McpConnectionParams {
40 &self.params
41 }
42
43 /// List available tools from the MCP server.
44 /// Stub: returns empty list. Full implementation awaits MCP client integration.
45 pub async fn list_tools(&self) -> Result<Vec<McpToolInfo>, McpError> {
46 // TODO: Connect to MCP server and list tools
47 Ok(vec![])
48 }
49
50 /// Call a tool on the MCP server.
51 /// Stub: returns error. Full implementation awaits MCP client integration.
52 pub async fn call_tool(
53 &self,
54 name: &str,
55 _args: serde_json::Value,
56 ) -> Result<serde_json::Value, McpError> {
57 Err(McpError::NotConnected(format!(
58 "MCP session not connected — call_tool({}) requires MCP client integration",
59 name
60 )))
61 }
62}
63
64/// Information about an MCP tool.
65#[derive(Debug, Clone)]
66pub struct McpToolInfo {
67 /// Tool name.
68 pub name: String,
69 /// Human-readable tool description.
70 pub description: String,
71 /// JSON Schema for the tool's input parameters.
72 pub input_schema: serde_json::Value,
73}
74
75/// MCP-related errors.
76#[derive(Debug, thiserror::Error)]
77pub enum McpError {
78 /// Failed to connect to the MCP server.
79 #[error("Connection failed: {0}")]
80 ConnectionFailed(String),
81 /// The MCP session is not connected.
82 #[error("Not connected: {0}")]
83 NotConnected(String),
84 /// A tool call to the MCP server failed.
85 #[error("Tool call failed: {0}")]
86 ToolCallFailed(String),
87 /// A catch-all for other MCP errors.
88 #[error("{0}")]
89 Other(String),
90}