Mirror of https://github.com/modelcontextprotocol/rust-sdk — The official Rust SDK for the Model Context Protocol
- Rust 99.2%
- Shell 0.5%
- JavaScript 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
This workflow sets up a new CI job to handle testing and building of example projects in the repository. It includes setting up Node.js, Rust, Python, and necessary caching to ensure proper environment preparation. Example directories are iterated to run tests and builds for each valid Cargo project. Co-authored-by: GCOV Github Badge <build@github.com> |
||
| .devcontainer | ||
| .github | ||
| crates | ||
| docs | ||
| examples | ||
| .gitignore | ||
| Cargo.toml | ||
| clippy.toml | ||
| LICENSE | ||
| README.md | ||
| rust-toolchain.toml | ||
| rustfmt.toml | ||
RMCP
Wait for the first release.
An official rust Model Context Protocol SDK implementation with tokio async runtime.
This repository contains the following crates:
- rmcp: The core crate providing the RMCP protocol implementation( If you want to get more information, please visit rmcp)
- rmcp-macros: A procedural macro crate for generating RMCP tool implementations(If you want to get more information, please visit rmcp-macros)
Usage
Import the crate
rmcp = { version = "0.1", features = ["server"] }
## or dev channel
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "main" }
Third Dependencies
Basic dependencies:
Build a Client
Start a client
use rmcp::{ServiceExt, transport::{TokioChildProcess, ConfigureCommandExt}};
use tokio::process::Command;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ().serve(TokioChildProcess::new(Command::new("npx").configure(|cmd| {
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
}))?).await?;
Ok(())
}
Build a Server
Build a transport
use tokio::io::{stdin, stdout};
let transport = (stdin(), stdout());
Build a service
You can easily build a service by using ServerHandler or ClientHandler.
let service = common::counter::Counter::new();
Start the server
// this call will finish the initialization process
let server = service.serve(transport).await?;
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?;
Waiting for service shutdown
let quit_reason = server.waiting().await?;
// or cancel it
let quit_reason = server.cancel().await?;
Examples
See examples
OAuth Support
See oauth_support for details.
Related Resources
Related Projects
- containerd-mcp-server - A containerd-based MCP server implementation
Development with Dev Container
See docs/DEVCONTAINER.md for instructions on using Dev Container for development.