rmcp - Rust
Skip to main content

Crate rmcp

Crate rmcp 

Source
Expand description

§rmcp

Crates.io Documentation

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

FeatureDescriptionDefault
serverServer functionality and the tool system✅
clientClient functionality
macros#[tool] / #[prompt] macros (re-exports rmcp-macros)✅
schemarsJSON Schema generation for tool definitions
authOAuth 2.0 authentication support
auth-enterprise-managedEMA/XAA refresh-token and ID-JAG exchanges for registered public and confidential clients (includes auth)
elicitationElicitation support

§Transport features

FeatureDescription
transport-ioServer-side stdio transport
transport-child-processClient-side stdio transport (spawns a child process)
transport-async-rwGeneric async read/write transport
transport-streamable-http-clientStreamable HTTP client (transport-agnostic)
transport-streamable-http-client-reqwestStreamable HTTP client with default reqwest backend
transport-streamable-http-serverStreamable HTTP server transport

§TLS backend options (for HTTP transports)

FeatureDescription
reqwestUses rustls — pure Rust TLS (recommended default)
reqwest-native-tlsUses platform-native TLS (OpenSSL / Secure Transport / SChannel)
reqwest-tls-no-providerUses 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:

ClientServer
stdioTokioChildProcessstdio
Streamable HTTPStreamableHttpClientTransportStreamableHttpService

Any type that implements the Transport trait can be used. The IntoTransport helper trait provides automatic conversions from:

  1. (Sink, Stream) or a combined Sink + Stream
  2. (AsyncRead, AsyncWrite) or a combined AsyncRead + AsyncWrite
  3. A Worker implementation
  4. A Transport implementation 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;client
pub use handler::server::ServerHandler;server
pub use handler::server::wrapper::Json;server
pub use service::ClientCacheConfig;client
pub use service::ClientLifecycleMode;client
pub use service::ClientServiceExt;client
pub use service::MAX_CLIENT_CACHE_TTL;client
pub use service::RoleClient;client
pub use service::select_protocol_version;client
pub use service::serve_client;client
pub use service::serve_client_with_lifecycle;client
pub use service::Peer;client or server
pub use service::Service;client or server
pub use service::ServiceError;client or server
pub use service::ServiceExt;client or server
pub use service::RoleServer;server
pub use service::serve_server;server
pub use schemars;schemars
pub use serde;macros
pub use serde_json;macros

Modules§

handler
model
Basic data types in MCP specification
serviceclient or server
task_managerserver
Server-side runtime for the MCP Tasks extension (SEP-2663, io.modelcontextprotocol/tasks).
transportclient or server
Transport

Macros§

const_string
elicit_safeelicitation and server and (client or server)
Macro to mark types as safe for elicitation by verifying they generate object schemas.
object
Use this macro just like serde_json::json!
pastemacros and server

Enums§

RmcpError
This is an unified error type for the errors could be returned by the service.

Attribute Macros§

promptmacros and server
prompt
prompt_handlermacros and server
prompt_handler
prompt_routermacros and server
prompt_router
toolmacros and server
tool
tool_handlermacros and server
tool_handler
tool_routermacros and server
tool_router
","&mut Vec":"

Notable traits for Vec<u8, A>

impl<A> Write for Vec<u8, A>
where\n A: Allocator,
"," as Service>::Future":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc, A>":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc>":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","Arc":"

Notable traits for Arc<R>

impl<R> Read for Arc<R>
where\n R: Read + IoHandle + ?Sized,\n &'a R: for<'a> Read,
impl<W> Write for Arc<W>
where\n W: Write + IoHandle + ?Sized,\n &'a W: for<'a> Write,
","ArrayChunks":"

Notable traits for ArrayChunks<I, N>

impl<I, const N: usize> Iterator for ArrayChunks<I, N>
where\n I: Iterator,
type Item = [<I as Iterator>::Item; N];
","Bytes":"

Notable traits for Bytes<R>

impl<R> Iterator for Bytes<R>
where\n R: Read,
type Item = Result<u8, Error>;
","Chain::IntoIter>":"

Notable traits for Chain<A, B>

impl<A, B> Iterator for Chain<A, B>
where\n A: Iterator,\n B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
","Chain":"

Notable traits for Chain<T, U>

impl<T, U> Read for Chain<T, U>
where\n T: Read,\n U: Read,
","Cloned":"

Notable traits for Cloned<I>

impl<'a, I, T> Iterator for Cloned<I>
where\n T: 'a + Clone,\n I: Iterator<Item = &'a T>,
type Item = T;
","Copied":"

Notable traits for Copied<I>

impl<'a, I, T> Iterator for Copied<I>
where\n T: 'a + Copy,\n I: Iterator<Item = &'a T>,
type Item = T;
","Cycle":"

Notable traits for Cycle<I>

impl<I> Iterator for Cycle<I>
where\n I: Clone + Iterator,
type Item = <I as Iterator>::Item;
","Drain<'_>":"

Notable traits for Drain<'_>

impl Iterator for Drain<'_>
type Item = char;
","Enumerate":"

Notable traits for Enumerate<I>

impl<I> Iterator for Enumerate<I>
where\n I: Iterator,
type Item = (usize, <I as Iterator>::Item);
","ExtractIf<'_, K, V, R, F, A>":"

Notable traits for ExtractIf<'_, K, V, R, F, A>

impl<K, V, R, F, A> Iterator for ExtractIf<'_, K, V, R, F, A>
where\n A: AllocatorClone,\n K: PartialOrd,\n R: RangeBounds<K>,\n F: FnMut(&K, &mut V) -> bool,
type Item = (K, V);
","Filter":"

Notable traits for Filter<I, P>

impl<I, P> Iterator for Filter<I, P>
where\n I: Iterator,\n P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
","FilterMap":"

Notable traits for FilterMap<I, F>

impl<B, I, F> Iterator for FilterMap<I, F>
where\n I: Iterator,\n F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
","FlatMap":"

Notable traits for FlatMap<I, U, F>

impl<I, U, F> Iterator for FlatMap<I, U, F>
where\n I: Iterator,\n U: IntoIterator,\n F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
","Flatten":"

Notable traits for Flatten<I>

impl<I, U> Iterator for Flatten<I>
where\n I: Iterator,\n <I as Iterator>::Item: IntoIterator<IntoIter = U, Item = <U as Iterator>::Item>,\n U: Iterator,
type Item = <U as Iterator>::Item;
","Fuse":"

Notable traits for Fuse<I>

impl<I> Iterator for Fuse<I>
where\n I: Iterator,
type Item = <I as Iterator>::Item;
","Inspect":"

Notable traits for Inspect<I, F>

impl<I, F> Iterator for Inspect<I, F>
where\n I: Iterator,\n F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
","Intersperse":"

Notable traits for Intersperse<I>

impl<I> Iterator for Intersperse<I>
where\n I: Iterator,\n <I as Iterator>::Item: Clone,
type Item = <I as Iterator>::Item;
","IntersperseWith":"

Notable traits for IntersperseWith<I, G>

impl<I, G> Iterator for IntersperseWith<I, G>
where\n I: Iterator,\n G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
","IntoChars":"

Notable traits for IntoChars

type Item = char;
","IntoIter":"

Notable traits for IntoIter<K, V, A>

impl<K, V, A> Iterator for IntoIter<K, V, A>
where\n A: AllocatorClone,
type Item = (K, V);
","IntoKeys":"

Notable traits for IntoKeys<K, V, A>

impl<K, V, A> Iterator for IntoKeys<K, V, A>
where\n A: AllocatorClone,
type Item = K;
","IntoValues":"

Notable traits for IntoValues

type Item = Value;
","IntoValues":"

Notable traits for IntoValues<K, V, A>

impl<K, V, A> Iterator for IntoValues<K, V, A>
where\n A: AllocatorClone,
type Item = V;
","Iter<'_, K, V>":"

Notable traits for Iter<'a, K, V>

impl<'a, K, V> Iterator for Iter<'a, K, V>
where\n K: 'a,\n V: 'a,
type Item = (&'a K, &'a V);
","Iter<'_>":"

Notable traits for Iter<'a>

impl<'a> Iterator for Iter<'a>
type Item = (&'a String, &'a Value);
","IterMut<'_, K, V>":"

Notable traits for IterMut<'a, K, V>

impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
","IterMut<'_>":"

Notable traits for IterMut<'a>

impl<'a> Iterator for IterMut<'a>
type Item = (&'a String, &'a mut Value);
","Keys<'_, K, V>":"

Notable traits for Keys<'a, K, V>

impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
","Keys<'_>":"

Notable traits for Keys<'a>

impl<'a> Iterator for Keys<'a>
type Item = &'a String;
","Lines":"

Notable traits for Lines<B>

impl<B> Iterator for Lines<B>
where\n B: BufRead,
type Item = Result<String, Error>;
","Map":"

Notable traits for Map<I, F>

impl<B, I, F> Iterator for Map<I, F>
where\n I: Iterator,\n F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
","MapWhile":"

Notable traits for MapWhile<I, P>

impl<B, I, P> Iterator for MapWhile<I, P>
where\n I: Iterator,\n P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
","MapWindows":"

Notable traits for MapWindows<I, F, N>

impl<I, F, R, const N: usize> Iterator for MapWindows<I, F, N>
where\n I: Iterator,\n F: FnMut(&[<I as Iterator>::Item; N]) -> R,
type Item = R;
","Peekable":"

Notable traits for Peekable<I>

impl<I> Iterator for Peekable<I>
where\n I: Iterator,
type Item = <I as Iterator>::Item;
","Range<'_, K, V>":"

Notable traits for Range<'a, K, V>

impl<'a, K, V> Iterator for Range<'a, K, V>
type Item = (&'a K, &'a V);
","RangeMut<'_, K, V>":"

Notable traits for RangeMut<'a, K, V>

impl<'a, K, V> Iterator for RangeMut<'a, K, V>
type Item = (&'a K, &'a mut V);
","Reader":"

Notable traits for Reader<B>

impl<B> Read for Reader<B>
where\n B: Buf,
","Rev":"

Notable traits for Rev<I>

impl<I> Iterator for Rev<I>
type Item = <I as Iterator>::Item;
","Scan":"

Notable traits for Scan<I, St, F>

impl<B, I, St, F> Iterator for Scan<I, St, F>
where\n I: Iterator,\n F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
","Skip":"

Notable traits for Skip<I>

impl<I> Iterator for Skip<I>
where\n I: Iterator,
type Item = <I as Iterator>::Item;
","SkipWhile":"

Notable traits for SkipWhile<I, P>

impl<I, P> Iterator for SkipWhile<I, P>
where\n I: Iterator,\n P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
","Split":"

Notable traits for Split<B>

impl<B> Iterator for Split<B>
where\n B: BufRead,
type Item = Result<Vec<u8>, Error>;
","StepBy":"

Notable traits for StepBy<I>

impl<I> Iterator for StepBy<I>
where\n I: Iterator,
type Item = <I as Iterator>::Item;
","Take":"

Notable traits for Take<T>

impl<T> Read for Take<T>
where\n T: Read,
","TakeWhile":"

Notable traits for TakeWhile<I, P>

impl<I, P> Iterator for TakeWhile<I, P>
where\n I: Iterator,\n P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
","Values<'_, K, V>":"

Notable traits for Values<'a, K, V>

impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
","Values<'_>":"

Notable traits for Values<'a>

impl<'a> Iterator for Values<'a>
type Item = &'a Value;
","ValuesMut<'_, K, V>":"

Notable traits for ValuesMut<'a, K, V>

impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
type Item = &'a mut V;
","ValuesMut<'_>":"

Notable traits for ValuesMut<'a>

impl<'a> Iterator for ValuesMut<'a>
type Item = &'a mut Value;
","Vec":"

Notable traits for Vec<u8, A>

impl<A> Write for Vec<u8, A>
where\n A: Allocator,
","Writer":"

Notable traits for Writer<B>

impl<B> Write for Writer<B>
where\n B: BufMut,
","Zip::IntoIter>":"

Notable traits for Zip<A, B>

impl<A, B> Iterator for Zip<A, B>
where\n A: Iterator,\n B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
"}