Skip to content

Latest commit

 

History

History
123 lines (88 loc) · 3.13 KB

File metadata and controls

123 lines (88 loc) · 3.13 KB

RMCP

Crates.io Version Release status docs.rs

一个基于 tokio 异步运行时的官方 Model Context Protocol SDK 实现。

本项目使用了以下开源库:

使用

导入

rmcp = { version = "0.2.0", features = ["server"] }
## 或使用最新开发版本
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "main" }

第三方依赖库

基本依赖:

构建客户端

构建客户端
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(())
}

构建服务端

构建传输层
use tokio::io::{stdin, stdout};
let transport = (stdin(), stdout());
构建服务

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

let service = common::counter::Counter::new();
启动服务端
// this call will finish the initialization process
let server = service.serve(transport).await?;
与服务端交互

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?;
等待服务停止
let quit_reason = server.waiting().await?;
// 或将其取消
let quit_reason = server.cancel().await?;

示例

查看 examples

OAuth 支持

查看 oauth_support

相关资源

相关项目

开发

贡献指南

查看 docs/CONTRIBUTE.MD

使用 Dev Container

如果你想使用 Dev Container,查看 docs/DEVCONTAINER.md 获取开发指南。