1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Model Context Protocol (MCP) client support.
//!
//! This module provides a client for connecting to MCP servers,
//! allowing agents to use tools provided by external services.
//!
//! # Overview
//!
//! MCP (Model Context Protocol) is a protocol for connecting LLM applications
//! to external tools and services. This module provides:
//!
//! - [`McpClient`] - Client for communicating with MCP servers
//! - [`McpTransport`] - Trait for transport implementations
//! - [`StdioTransport`] - Stdio-based transport (subprocess communication)
//! - [`McpToolBridge`] - Wrapper to use MCP tools as SDK tools
//!
//! # Example
//!
//! ```ignore
//! use agent_sdk::mcp::{McpClient, StdioTransport, register_mcp_tools};
//! use agent_sdk::ToolRegistry;
//! use std::sync::Arc;
//!
//! // Spawn an MCP server process
//! let transport = StdioTransport::spawn("npx", &["-y", "@modelcontextprotocol/server-filesystem"]).await?;
//!
//! // Create client and initialize
//! let client = Arc::new(McpClient::new(transport, "filesystem".to_string()).await?);
//!
//! // Register all MCP tools with the agent
//! let mut registry = ToolRegistry::new();
//! register_mcp_tools(&mut registry, client).await?;
//! ```
//!
//! # MCP Protocol
//!
//! This implementation supports MCP protocol version 2024-11-05 and includes:
//!
//! - JSON-RPC 2.0 communication
//! - Tool discovery via `tools/list`
//! - Tool execution via `tools/call`
//! - Automatic initialization handshake
pub use McpClient;
pub use ;
pub use ;
pub use ;