agenterra-rmcp: Rust Model Context Protocol
agenterra-rmcp is an Agenterra fork of the official Rust implementation of the Model Context Protocol (MCP), a protocol designed for AI assistants to communicate with other services. This library can be used to build both servers that expose capabilities to AI assistants and clients that interact with such servers.
Attribution
This crate is based on the official MCP Rust SDK. Original repository: https://github.com/modelcontextprotocol/rust-sdk
Quick Start
Server Implementation
Creating a server with tools is simple using the #[tool] macro:
use ;
use Arc;
use Mutex;
// Implement the server handler
// Run the server
async
Client Implementation
Creating a client to interact with a server:
use ;
use Command;
async
Transport Options
RMCP supports multiple transport mechanisms, each suited for different use cases:
transport-async-rw
Low-level interface for asynchronous read/write operations. This is the foundation for many other transports.
transport-io
For working directly with I/O streams (tokio::io::AsyncRead and tokio::io::AsyncWrite).
transport-child-process
Run MCP servers as child processes and communicate via standard I/O.
Example:
use TokioChildProcess;
use Command;
let transport = new?;
let service = client.serve.await?;
Access with peer interface when handling message
You can get the Peer struct from NotificationContext and RequestContext.
# use ;
# ;
Manage Multi Services
For many cases you need to manage several service in a collection, you can call into_dyn to convert services into the same type.
let service = service.into_dyn;
Feature Flags
agenterra-rmcp uses feature flags to control which components are included:
client: Enable client functionalityserver: Enable server functionality and the tool systemmacros: Enable the#[tool]macro (enabled by default)- Transport-specific features:
transport-async-rw: Async read/write supporttransport-io: I/O stream supporttransport-child-process: Child process supporttransport-sse-client/transport-sse-server: SSE supporttransport-streamable-http-client/transport-streamable-http-server: HTTP streaming
auth: OAuth2 authentication supportschemars: JSON Schema generation (for tool definitions)
Transports
transport-io: Server stdio transporttransport-sse-server: Server SSE transporttransport-child-process: Client stdio transporttransport-sse-client: Client sse transporttransport-streamable-http-serverstreamable http server transporttransport-streamable-http-clientstreamable http client transport
| transport | client | server |
|---|---|---|
| std IO | [child_process::TokioChildProcess] |
[io::stdio] |
| streamable http | [streamable_http_client::StreamableHttpClientTransport] |
[streamable_http_server::session::create_session] |
| sse | [sse_client::SseClientTransport] |
[sse_server::SseServer] |
IntoTransport trait
[IntoTransport] is a helper trait that implicitly convert a type into a transport type.
These types is automatically implemented [IntoTransport] trait
- A type that already implement both [
futures::Sink] and [futures::Stream] trait, or a tuple(Tx, Rx)whereTxis [futures::Sink] andRxis [futures::Stream]. - A type that implement both [
tokio::io::AsyncRead] and [tokio::io::AsyncWrite] trait. or a tuple(R, W)whereRis [tokio::io::AsyncRead] andWis [tokio::io::AsyncWrite]. - A type that implement Worker trait.
- A type that implement [
Transport] trait.
License
This project is licensed under the terms specified in the repository's LICENSE file.