Cover image
Try Now
2025-03-28

BEST Rust SDK for MCP (Model Context Protocol)

3 years

Works with Finder

3

Github Watches

8

Github Forks

58

Github Stars

NOTICE

This crate was merged into official sdk. We will continue our development there.

RMCP

Crates.io Version Release status docs.rs

A better and clean rust Model Context Protocol SDK implementation with tokio async runtime.

Comparing to official SDK

The Official SDK has too much limit and it was originally built for goose rather than general using purpose.

All the features listed on specification would be implemented in this crate. And the first and most important thing is, this crate has the correct and intact data types. See it yourself.

Usage

Import

rmcp = { version = "0.1", features = ["server"] }
## or dev channel
rmcp = { git = "https://github.com/4t145/rmcp", branch = "dev" }

Quick start

Start a client in one line:

use rmcp::{ServiceExt, transport::TokioChildProcess};
use tokio::process::Command;

let client = ().serve(
    TokioChildProcess::new(Command::new("npx").arg("-y").arg("@modelcontextprotocol/server-everything"))?
).await?;

1. Build a transport

use tokio::io::{stdin, stdout};
let transport = (stdin(), stdout());

The transport type must implemented IntoTransport trait, which allow split into a sink and a stream.

For client, the sink item is ClientJsonRpcMessage and stream item is ServerJsonRpcMessage

For server, the sink item is ServerJsonRpcMessage and stream item is ClientJsonRpcMessage

These types is automatically implemented IntoTransport trait
  1. The types that already implement both Sink and Stream trait.
  2. A tuple of sink Tx and stream Rx: (Tx, Rx).
  3. The type that implement both [tokio::io::AsyncRead] and [tokio::io::AsyncWrite] trait.
  4. A tuple of [tokio::io::AsyncRead] R and [tokio::io::AsyncWrite] W: (R, W).

For example, you can see how we build a transport through TCP stream or http upgrade so easily. examples

2. Build a service

You can easily build a service by using ServerHandler or ClientHandler.

let service = common::counter::Counter::new();

3. Serve them together

// this call will finish the initialization process
let server = service.serve(transport).await?;

4. Interact with the server

Once the server is initialized, you can send requests or notifications:

// request 
let roots = server.list_roots().await?;

// or send notification
server.notify_cancelled(...).await?;

5. Waiting for service shutdown

let quit_reason = server.waiting().await?;
// or cancel it
let quit_reason = server.cancel().await?;

Use marcos to declaring tool

Use toolbox and tool macros to create tool quickly.

Check this file.

use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};

use super::counter::Counter;

#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
pub struct SumRequest {
    #[schemars(description = "the left hand side number")]
    pub a: i32,
    #[schemars(description = "the right hand side number")]
    pub b: i32,
}
#[derive(Debug, Clone)]
pub struct Calculator;

// create a static toolbox to store the tool attributes
#[tool(tool_box)]
impl Calculator {
    // async function
    #[tool(description = "Calculate the sum of two numbers")]
    async fn sum(&self, #[tool(aggr)] SumRequest { a, b }: SumRequest) -> String {
        (a + b).to_string()
    }

    // sync function
    #[tool(description = "Calculate the sum of two numbers")]
    fn sub(
        &self,
        #[tool(param)]
        // this macro will transfer the schemars and serde's attributes
        #[schemars(description = "the left hand side number")]
        a: i32,
        #[tool(param)]
        #[schemars(description = "the right hand side number")]
        b: i32,
    ) -> String {
        (a - b).to_string()
    }
}

// impl call_tool and list_tool by querying static toolbox
#[tool(tool_box)]
impl ServerHandler for Calculator {
    fn get_info(&self) -> ServerInfo {
        ServerInfo {
            instructions: Some("A simple calculator".into()),
            ..Default::default()
        }
    }
}

The only thing you should do is to make the function's return type implement IntoCallToolResult.

And you can just implement IntoContents, and the return value will be marked as success automatically.

If you return a type of Result<T, E> where T and E both implemented IntoContents, it's also OK.

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();

Examples

See examples

Features

  • client: use client side sdk
  • server: use server side sdk
  • macros: macros default

Transports

  • transport-io: Server stdio transport
  • transport-sse-server: Server SSE transport
  • transport-child-process: Client stdio transport
  • transport-sse: Client sse transport

Related Resources

相关推荐

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • 林乔安妮
  • A fashion stylist GPT offering outfit suggestions for various scenarios.

  • 1Panel-dev
  • 💬 MaxKB is a ready-to-use AI chatbot that integrates Retrieval-Augmented Generation (RAG) pipelines, supports robust workflows, and provides advanced MCP tool-use capabilities.

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • Dhravya
  • Collection of apple-native tools for the model context protocol.

  • GLips
  • MCP server to provide Figma layout information to AI coding agents like Cursor

  • open-webui
  • User-friendly AI Interface (Supports Ollama, OpenAI API, ...)

  • Mintplex-Labs
  • The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.

  • adafruit
  • Python code to use the MCP3008 analog to digital converter with a Raspberry Pi or BeagleBone black.

    Reviews

    1 (1)
    Avatar
    user_TBvsuAtu
    2025-04-18

    As a devoted MCP application user, I am thrilled with RMCP by 4t145. This tool is truly remarkable and efficient for my computational needs. The clear documentation and seamless integration have significantly enhanced my productivity. For any MCP enthusiast, RMCP is a game-changer and highly recommended. Check it out on GitHub: https://github.com/4t145/rmcp.