Expand description
Runtime-agnostic MCP server support, including optional attachment to ACP sessions. Runtime-agnostic MCP server support.
This module provides infrastructure for serving MCP directly without tying
the core SDK to a particular MCP implementation or async runtime. With the
unstable_mcp_over_acp feature, the same servers can be attached to ACP
session setup requests through the with_mcp_server builder methods.
Stable protocol v1 and draft protocol v2 both support global proxy
attachment and per-session attachment. V2 uses
Proxy.v2().with_mcp_server(...) or
V2SessionBuilder::with_mcp_server(...) for new sessions and
V2ResumeSessionBuilder::with_mcp_server(...) for resumed sessions. With
unstable_session_fork, V2ForkSessionBuilder::with_mcp_server(...)
attaches a server to a forked session. V2 attachment additionally requires
unstable_protocol_v2.
§Building MCP servers with tools
The opt-in schemars feature provides McpTool, McpToolRegistry
and its metadata types, and the tool_fn / tool_fn_mut functions for
automatically generating JSON Schemas from Rust input and output types.
The agent-client-protocol-rmcp crate provides the builder APIs for MCP
tools backed by the rmcp crate and enables this feature.
Custom servers using crate::mcp_server::McpServerConnect,
crate::mcp_server::McpServer, and the connection types remain available
without schemars, including ACP attachment when
unstable_mcp_over_acp is enabled.
§Custom MCP Server Implementations
You can implement crate::mcp_server::McpServerConnect to create custom MCP
servers:
use agent_client_protocol::mcp_server::{McpConnectionTo, McpServer, McpServerConnect};
use agent_client_protocol::{DynConnectTo, NullRun, Role, role};
struct MyCustomServer;
impl<R: Role> McpServerConnect<R> for MyCustomServer {
fn name(&self) -> String {
"my-custom-server".to_string()
}
fn connect(&self, cx: McpConnectionTo<R>) -> DynConnectTo<role::mcp::Client> {
// Return a component that serves MCP requests
DynConnectTo::new(my_mcp_component(cx))
}
}
let server = McpServer::new(MyCustomServer, NullRun);Structs§
- McpConnection
To - Connection information available to an MCP server.
- McpOperation
Cancellation unstable_mcp_over_acp - Cancellation from the caller, provider removal, or connection shutdown.
- McpRequest
unstable_mcp_over_acp - One MCP invocation against a reusable service.
- McpRequest
Context unstable_mcp_over_acp - Authority for a single operation, not for the lifetime of its service.
- McpServer
- A runtime-agnostic MCP server.
- McpTool
Metadata schemars - Runtime-neutral metadata for an MCP tool.
- McpTool
Registry schemars - Runtime-neutral registry for MCP tools.
- Registered
McpTool schemars - A registered MCP tool that can be dispatched with erased JSON values.
Enums§
- Enabled
Tools schemars - Tracks which tools are enabled.
- McpConnection
Context - Describes how an MCP server connection was established.
- McpOutcome
unstable_mcp_over_acp - An MCP outcome, distinct from failure of the ACP binding.
Constants§
- MCP_
BACKEND_ FAILURE unstable_mcp_over_acp - The MCP backend failed independently of an MCP application error.
- MCP_
SERVER_ UNAVAILABLE unstable_mcp_over_acp - The declared MCP provider is no longer available.
Traits§
- McpServer
Connect - Trait for types that can create MCP server connections.
- McpService
unstable_mcp_over_acp - Reusable MCP application state with owned invocation futures.
- McpTool
schemars - Trait for defining MCP tools.
Functions§
- tool_fn
schemars - Create a stateless function-backed MCP tool and its concurrent runner.
- tool_
fn_ mut schemars - Create a “single-threaded” function-backed MCP tool and its runner.
Type Aliases§
- McpTool
Schema schemars - JSON Schema object used to describe MCP tool inputs and outputs.