Skip to main content

Module mcp

Module mcp 

Source
Expand description

Model Context Protocol clients (feature mcp), built on [rmcp].

An McpClient reaches one server over stdio (McpTransport::stdio), streamable HTTP (McpClientConfig::url) or the legacy HTTP+SSE protocol (McpTransport::sse). Pass it to an agent with .tools([client]): the agent lists the server’s tools as McpTools when it initializes and follows the server’s list-changed notifications. McpClient::load_servers builds clients from an mcp.json-style config.

The raw MCP results (McpClient::list_prompts, McpClient::read_resource, …) are the rmcp model types; use them through the re-export strands::mcp::rmcp so the versions match. They are part of this crate’s public API: an rmcp major version bump is a breaking release of strands.

Re-exports§

pub use rmcp;

Structs§

ElicitationContext
What an ElicitationCallback receives besides the request (ElicitationContext).
McpCallToolOptions
Options for one tool call (McpCallToolOptions).
McpClient
A client for one MCP server (McpClient).
McpClientConfig
How to reach the server, plus the client’s behaviour (McpClientConfig).
McpClientCredentials
OAuth client credentials for machine-to-machine authentication (McpClientCredentials).
McpClientOptions
Behaviour shared by every MCP client configuration (McpClientOptions).
McpListOptions
Options for the paginated list methods (McpListOptions).
McpListToolsOptions
Per-call overrides for McpClient::list_tools_with (McpListToolsOptions).
McpLoadServersOptions
How McpClient::load_servers turns entries into clients (McpLoadServersOptions).
McpLogHandler
Receives the log messages an MCP server emits.
McpLogMessage
A log message an MCP server emits (LoggingMessageNotificationParams).
McpProgress
A progress update an MCP server reports during a tool call (McpProgress).
McpProgressCallback
Receives progress notifications during a tool call (McpProgressCallback). A failure is logged as a warning.
McpServerConfig
One server entry of a config file or map (McpServerConfig).
McpTool
A tool that proxies calls to an MCP server (McpTool).
McpToolConfig
What an McpTool is built from (McpToolConfig).
McpToolFilterCallback
Decides whether a tool matches a filter (McpToolFilterCallback). It receives the tool under its agent-facing name.
McpToolFilters
Filters controlling which MCP tools a client exposes (McpToolFilters).
McpTransport
How an McpClient reaches its server (McpTransport).
SerializableMcpToolFilters
Tool filters in a config file (SerializableMcpToolFilters): each pattern is a regex matched from the start of the server-side tool name.
StdioServerParameters
How to spawn a stdio MCP server (StdioServerParameters).
ToolsChangedCallback
Called when the server’s tool list changes, with the previously registered tool names and the refreshed tools.

Enums§

McpConnectionState
Connection state of an MCP client (McpConnectionState).
McpError
A failure of an MCP client operation.
McpLogLevel
The severity of an MCP server log message (LoggingLevel).
McpSdkErrorCode
Why an MCP SDK operation failed.
McpServerTransport
The transport of a config entry ('stdio' | 'sse' | 'streamable-http').
McpServersSource
Where McpClient::load_servers reads servers from: a JSON file (flat or under mcpServers, ~/ expanded), a typed map, or a JSON object of entries.
McpToolMatcher
Matches a tool for filtering (McpToolMatcher).

Constants§

DEFAULT_CLIENT_NAME
The client name sent in the MCP handshake unless application_name overrides it.
URL_ELICITATION_REQUIRED
The JSON-RPC code a server uses when a request needs URL elicitation first (ProtocolErrorCode.UrlElicitationRequired).

Traits§

ElicitationCallback
Handles a server’s request for user input during a tool call (ElicitationCallback).
McpAuthProvider
Supplies the bearer token for each request of a URL-configured client (authProvider).

Functions§

default_environment
The variables a stdio server inherits: only those deemed safe, and none whose value starts with () (an exported shell function).