Skip to main content

strands/mcp/
mod.rs

1//! Model Context Protocol clients (feature `mcp`), built on [`rmcp`].
2//!
3//! An [`McpClient`] reaches one server over stdio ([`McpTransport::stdio`]), streamable HTTP
4//! ([`McpClientConfig::url`]) or the legacy HTTP+SSE protocol ([`McpTransport::sse`]). Pass it
5//! to an agent with `.tools([client])`: the agent lists the server's tools as [`McpTool`]s when
6//! it initializes and follows the server's list-changed notifications.
7//! [`McpClient::load_servers`] builds clients from an `mcp.json`-style config.
8//!
9//! The raw MCP results ([`McpClient::list_prompts`], [`McpClient::read_resource`], ...) are the
10//! `rmcp` model types; use them through the re-export [`strands::mcp::rmcp`](rmcp) so the
11//! versions match. They are part of this crate's public API: an `rmcp` major version bump is a
12//! breaking release of `strands`.
13
14mod callbacks;
15mod client;
16mod config;
17mod error;
18mod filters;
19mod handler;
20mod http;
21mod mcp_tool;
22mod progress;
23mod sse;
24mod trace;
25mod transport;
26
27pub use callbacks::{
28    ElicitationCallback, ElicitationContext, McpLogHandler, McpLogLevel, McpLogMessage, McpProgress,
29    McpProgressCallback, ToolsChangedCallback,
30};
31pub use client::{
32    DEFAULT_CLIENT_NAME, McpCallToolOptions, McpClient, McpClientConfig, McpClientOptions, McpConnectionState,
33    McpListOptions, McpListToolsOptions,
34};
35pub use config::{
36    McpLoadServersOptions, McpServerConfig, McpServerTransport, McpServersSource, SerializableMcpToolFilters,
37};
38pub use error::{McpError, McpSdkErrorCode, URL_ELICITATION_REQUIRED};
39pub use filters::{McpToolFilterCallback, McpToolFilters, McpToolMatcher};
40pub use http::{McpAuthProvider, McpClientCredentials};
41pub(crate) use mcp_tool::tool_result;
42pub use mcp_tool::{McpTool, McpToolConfig};
43/// The `rmcp` crate, whose model types the raw MCP results use. An `rmcp` major version bump is
44/// a breaking release of `strands`.
45pub use rmcp;
46pub use transport::{McpTransport, StdioServerParameters, default_environment};
47
48#[cfg(test)]
49pub(crate) mod tests;