agent_client_protocol/mcp_server/mod.rs
1//! Runtime-agnostic MCP server support.
2//!
3//! This module provides infrastructure for serving MCP directly without tying
4//! the core SDK to a particular MCP implementation or async runtime. With the
5//! `unstable_mcp_over_acp` feature, the same servers can be attached to ACP
6//! session setup requests through the `with_mcp_server` builder methods.
7//!
8//! ## Building MCP servers with tools
9//!
10//! The `agent-client-protocol-rmcp` crate provides the builder APIs for MCP
11//! tools backed by the `rmcp` crate.
12//!
13//! ## Custom MCP Server Implementations
14//!
15//! You can implement [`McpServerConnect`](`crate::mcp_server::McpServerConnect`) to create custom MCP servers:
16//!
17//! ```rust,ignore
18//! use agent_client_protocol::mcp_server::{McpConnectionTo, McpServer, McpServerConnect};
19//! use agent_client_protocol::{DynConnectTo, NullRun, Role, role};
20//!
21//! struct MyCustomServer;
22//!
23//! impl<R: Role> McpServerConnect<R> for MyCustomServer {
24//! fn name(&self) -> String {
25//! "my-custom-server".to_string()
26//! }
27//!
28//! fn connect(&self, cx: McpConnectionTo<R>) -> DynConnectTo<role::mcp::Client> {
29//! // Return a component that serves MCP requests
30//! DynConnectTo::new(my_mcp_component(cx))
31//! }
32//! }
33//!
34//! let server = McpServer::new(MyCustomServer, NullRun);
35//! ```
36
37#[cfg(feature = "unstable_mcp_over_acp")]
38mod active_session;
39mod connect;
40mod context;
41mod registry;
42mod server;
43mod tool;
44mod tool_fn;
45
46pub use connect::McpServerConnect;
47pub use context::{McpConnectionContext, McpConnectionTo};
48pub use registry::{
49 EnabledTools, McpToolMetadata, McpToolRegistry, McpToolSchema, RegisteredMcpTool,
50};
51pub use server::McpServer;
52pub use tool::McpTool;
53pub use tool_fn::{tool_fn, tool_fn_mut};