Crate rmcp
Expand description
§rmcp
The official Rust SDK for the Model Context Protocol. Build MCP servers that expose tools, resources, and prompts to AI assistants — or build clients that connect to them.
For getting started, usage guides, and full MCP feature documentation (resources, prompts, sampling, roots, logging, completions, subscriptions, etc.), see the main README.
§Feature Flags
§Transport features
| Feature | Description |
|---|---|
transport-io | Server-side stdio transport |
transport-child-process | Client-side stdio transport (spawns a child process) |
transport-async-rw | Generic async read/write transport |
transport-streamable-http-client | Streamable HTTP client (transport-agnostic) |
transport-streamable-http-client-reqwest | Streamable HTTP client with default reqwest backend |
transport-streamable-http-server | Streamable HTTP server transport |
§TLS backend options (for HTTP transports)
| Feature | Description |
|---|---|
reqwest | Uses rustls — pure Rust TLS (recommended default) |
reqwest-native-tls | Uses platform-native TLS (OpenSSL / Secure Transport / SChannel) |
reqwest-tls-no-provider | Uses rustls without a default crypto provider (bring your own) |
For enterprise-managed authorization, enable auth-enterprise-managed and a TLS
backend such as reqwest. See the EMA/XAA guide
for client authentication and an MCP connection example.
§Transports
The transport layer is pluggable. Two built-in pairs cover the most common cases:
Any type that implements the Transport trait can be used. The IntoTransport helper trait provides automatic conversions from:
(Sink, Stream)or a combinedSink + Stream(AsyncRead, AsyncWrite)or a combinedAsyncRead + AsyncWrite- A
Workerimplementation - A
Transportimplementation directly
§License
This project is licensed under the terms specified in the repository’s LICENSE file.
Re-exports§
pub use error::ErrorData;pub use error::RmcpError;pub use handler::client::ClientHandler;clientpub use handler::server::ServerHandler;serverpub use handler::server::wrapper::Json;serverpub use service::ClientCacheConfig;clientpub use service::ClientLifecycleMode;clientpub use service::ClientServiceExt;clientpub use service::MAX_CLIENT_CACHE_TTL;clientpub use service::RoleClient;clientpub use service::select_protocol_version;clientpub use service::serve_client;clientpub use service::serve_client_with_lifecycle;clientpub use service::Peer;clientorserverpub use service::Service;clientorserverpub use service::ServiceError;clientorserverpub use service::ServiceExt;clientorserverpub use service::RoleServer;serverpub use service::serve_server;serverpub use schemars;schemarspub use serde;macrospub use serde_json;macros
Modules§
- handler
- model
- Basic data types in MCP specification
- service
clientorserver - task_
manager server - Server-side runtime for the MCP Tasks extension (SEP-2663,
io.modelcontextprotocol/tasks). - transport
clientorserver - Transport
Macros§
- const_
string - elicit_
safe elicitationandserverand (clientorserver) - Macro to mark types as safe for elicitation by verifying they generate object schemas.
- object
- Use this macro just like
serde_json::json! - paste
macrosandserver
Enums§
- Rmcp
Error - This is an unified error type for the errors could be returned by the service.
Attribute Macros§
- prompt
macrosandserver - prompt
- prompt_
handler macrosandserver - prompt_handler
- prompt_
router macrosandserver - prompt_router
- tool
macrosandserver - tool
- tool_
handler macrosandserver - tool_handler
- tool_
router macrosandserver - tool_router
Notable traits for Vec<u8, A>
"," as Service>::Future":"Notable traits for Arc<R>
","Arc":"Notable traits for Arc<R>
","Arc, A>":"Notable traits for Arc<R>
","Arc>":"Notable traits for Arc<R>
","Arc":"Notable traits for Arc<R>
","Arc":"Notable traits for Arc<R>
","Arc":"Notable traits for Arc<R>
","Arc":"Notable traits for Arc<R>
","ArrayChunks":"Notable traits for ArrayChunks<I, N>
","Bytes":"Notable traits for Bytes<R>
","Chain::IntoIter>":"Notable traits for Chain<A, B>
","Chain":"Notable traits for Chain<T, U>
","Cloned":"Notable traits for Cloned<I>
type Item = T;","Copied":"Notable traits for Copied<I>
type Item = T;","Cycle":"Notable traits for Cycle<I>
","Drain<'_>":"Notable traits for Drain<'_>
","Enumerate":"Notable traits for Enumerate<I>
","ExtractIf<'_, K, V, R, F, A>":"Notable traits for ExtractIf<'_, K, V, R, F, A>
","Filter":"Notable traits for Filter<I, P>
","FilterMap":"Notable traits for FilterMap<I, F>
type Item = B;","FlatMap":"Notable traits for FlatMap<I, U, F>
","Flatten":"Notable traits for Flatten<I>
","Fuse":"Notable traits for Fuse<I>
","Inspect":"Notable traits for Inspect<I, F>
","Intersperse":"Notable traits for Intersperse<I>
","IntersperseWith":"Notable traits for IntersperseWith<I, G>
impl<I, G> Iterator for IntersperseWith<I, G>","IntoChars":"Notable traits for IntoChars
","IntoIter":"Notable traits for IntoIter<K, V, A>
","IntoKeys":"Notable traits for IntoKeys<K, V, A>
type Item = K;","IntoValues":"Notable traits for IntoValues
impl Iterator for IntoValues","IntoValues":"Notable traits for IntoValues<K, V, A>
type Item = V;","Iter<'_, K, V>":"Notable traits for Iter<'a, K, V>
","Iter<'_>":"Notable traits for Iter<'a>
","IterMut<'_, K, V>":"Notable traits for IterMut<'a, K, V>
","IterMut<'_>":"Notable traits for IterMut<'a>
","Keys<'_, K, V>":"Notable traits for Keys<'a, K, V>
","Keys<'_>":"Notable traits for Keys<'a>
","Lines":"Notable traits for Lines<B>
","Map":"Notable traits for Map<I, F>
type Item = B;","MapWhile":"Notable traits for MapWhile<I, P>
type Item = B;","MapWindows":"Notable traits for MapWindows<I, F, N>
type Item = R;","Peekable":"Notable traits for Peekable<I>
","Range<'_, K, V>":"Notable traits for Range<'a, K, V>
","RangeMut<'_, K, V>":"Notable traits for RangeMut<'a, K, V>
","Reader":"Notable traits for Reader<B>
","Rev":"Notable traits for Rev<I>
","Scan":"Notable traits for Scan<I, St, F>
type Item = B;","Skip":"Notable traits for Skip<I>
","SkipWhile":"Notable traits for SkipWhile<I, P>
","Split":"Notable traits for Split<B>
","StepBy":"Notable traits for StepBy<I>
","Take":"Notable traits for Take<T>
","TakeWhile":"Notable traits for TakeWhile<I, P>
","Values<'_, K, V>":"Notable traits for Values<'a, K, V>
","Values<'_>":"Notable traits for Values<'a>
","ValuesMut<'_, K, V>":"Notable traits for ValuesMut<'a, K, V>
","ValuesMut<'_>":"Notable traits for ValuesMut<'a>
","Vec":"Notable traits for Vec<u8, A>
","Writer":"Notable traits for Writer<B>
","Zip::IntoIter>":"Notable traits for Zip<A, B>
"}
