rust-sdk/crates/rmcp
Amey Pawar 4833ec7b63
fix(transport): make AsyncRwTransport::receive cancel-safe (#941) (#947)
`receive()` reads incoming lines with `read_until`, which is not
cancellation-safe, and it is polled inside the service loop's `select!`.
When another branch (e.g. an outgoing response) becomes ready while a
request line is only partially read, the `receive()` future is dropped
and the next call's `self.line_buf.clear()` discards the partial bytes,
so that incoming request is silently lost and never gets a response.
Under many concurrent large responses this intermittently drops requests.

Keep the partially-read bytes in `line_buf` across calls and clear it
only after a whole line has been consumed, so a cancelled read resumes
the same line instead of dropping it. The buffer is cleared (retaining
capacity) rather than reallocated per message.

Adds a regression test that fires 200 concurrent 64 KiB tool responses
over real stdio pipes and asserts no response id goes missing.

This also covers the child-process client transport, which reuses
`AsyncRwTransport`.
2026-07-02 09:08:24 -04:00
..
src fix(transport): make AsyncRwTransport::receive cancel-safe (#941) (#947) 2026-07-02 09:08:24 -04:00
tests fix(transport): make AsyncRwTransport::receive cancel-safe (#941) (#947) 2026-07-02 09:08:24 -04:00
build.rs chore: add pre-commit hook for conventional commit verification (#619) 2026-01-14 16:01:28 -05:00
Cargo.toml feat: add SEP-414 trace context meta accessors (#910) 2026-07-01 16:51:05 -04:00
CHANGELOG.md chore: release v2.0.0 (#920) 2026-06-29 08:24:11 -04:00
README.md feat: add local feature for !Send tool handler support (#740) 2026-03-11 17:22:56 -04:00

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

Feature Description Default
server Server functionality and the tool system
client Client functionality
macros #[tool] / #[prompt] macros (re-exports rmcp-macros)
schemars JSON Schema generation for tool definitions
auth OAuth 2.0 authentication support
elicitation Elicitation support

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)

Transports

The transport layer is pluggable. Two built-in pairs cover the most common cases:

Client Server
stdio TokioChildProcess stdio
Streamable HTTP StreamableHttpClientTransport StreamableHttpService

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.