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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! 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)
//! - [`StreamableHttpTransport`] - Streamable-HTTP / SSE transport with OAuth /
//! bearer auth for remote (hosted) MCP servers
//! - [`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 negotiates a current MCP protocol revision during the
//! `initialize` handshake (advertising [`protocol::PREFERRED_PROTOCOL_VERSION`],
//! `2025-06-18`, and honouring whatever revision the server selects — including
//! legacy `2024-11-05` servers). It includes:
//!
//! - JSON-RPC 2.0 communication over stdio or streamable-HTTP / SSE
//! - Protocol-revision negotiation (no longer pinned to `2024-11-05`)
//! - Tool discovery (`tools/list`) and execution (`tools/call`)
//! - Resources surface: `resources/list`, `resources/read`
//! - Prompts surface: `prompts/list`, `prompts/get`
//! - Automatic initialization handshake
//!
//! # Connecting to a remote (HTTP) MCP server
//!
//! ```ignore
//! use agent_sdk::mcp::{McpAuth, McpClient, StreamableHttpTransport};
//! use std::sync::Arc;
//!
//! let transport = StreamableHttpTransport::new(
//! "https://example.com/mcp",
//! McpAuth::Bearer(std::env::var("MCP_TOKEN")?),
//! )?;
//! let client = Arc::new(McpClient::new(transport, "remote".to_string()).await?);
//! let tools = client.list_tools().await?;
//! ```
pub use McpClient;
pub use ;
pub use ;
pub use ;
pub use ;