33![ Release status] ( https://github.202132.xyzmodelcontextprotocol/rust-sdk/actions/workflows/release.yml/badge.svg )
44[ ![ docs.rs] ( https://img.shields.io/docsrs/rmcp )] ( https://docs.rs/rmcp/latest/rmcp )
55
6- 一个干净且完整的 MCP SDK
6+ 一个基于tokio异步运行时的官方Model Context Protocol SDK实现。
77
88## 使用
99
@@ -15,7 +15,7 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
1515```
1616
1717### 快速上手
18- 你可以用一行代码,启动一个SSE客户端
18+ 一行代码启动客户端:
1919``` rust
2020use rmcp :: {ServiceExt , transport :: TokioChildProcess };
2121use tokio :: process :: Command ;
@@ -32,19 +32,19 @@ use tokio::io::{stdin, stdout};
3232let transport = (stdin(), stdout());
3333```
3434
35- 传输层类型只需要实现 [ ` IntoTransport ` ] ( crate::transport::IntoTransport ) trait, 这个特性允许你创建一个Sink和一个Stream
35+ 传输层类型必须实现 [ ` IntoTransport ` ] ( crate::transport::IntoTransport ) trait, 这个特性允许分割成一个sink和一个stream。
3636
3737对于客户端, Sink 的 Item 是 [ ` ClientJsonRpcMessage ` ] ( crate::model::ClientJsonRpcMessage ) , Stream 的 Item 是 [ ` ServerJsonRpcMessage ` ] ( crate::model::ServerJsonRpcMessage )
3838
3939对于服务端, Sink 的 Item 是 [ ` ServerJsonRpcMessage ` ] ( crate::model::ServerJsonRpcMessage ) , Stream 的 Item 是 [ ` ClientJsonRpcMessage ` ] ( crate::model::ClientJsonRpcMessage )
4040
4141##### 这些类型自动实现了 [ ` IntoTransport ` ] ( crate::transport::IntoTransport ) trait
42- 1 . 兼具 [ ` Sink ` ] ( futures::Sink ) 与 [ ` Stream ` ] ( futures::Stream ) 的
43- 2 . 一对 Sink ` Tx ` Stream ` Rx ` , 类型 ` (Tx, Rx) ` 自动实现 [ ` IntoTransport ` ] ( crate::transport::IntoTransport )
44- 3 . 兼具 [ ` tokio::io::AsyncRead ` ] 与 [ ` tokio::io::AsyncWrite ` ] 的
45- 4 . 一对 Sink [ ` tokio::io::AsyncRead ` ] ` R ` [ ` tokio::io::AsyncWrite ` ] ` W ` , 类型 ` (R, W) ` 自动实现 [ ` IntoTransport ` ] ( crate::transport::IntoTransport )
42+ 1 . 已经同时实现了 [ ` Sink ` ] ( futures::Sink ) 和 [ ` Stream ` ] ( futures::Stream ) trait的类型。
43+ 2 . 由sink ` Tx ` 和 stream ` Rx ` 组成的元组: ` (Tx, Rx) ` 。
44+ 3 . 同时实现了 [ ` tokio::io::AsyncRead ` ] 和 [ ` tokio::io::AsyncWrite ` ] trait的类型。
45+ 4 . 由 [ ` tokio::io::AsyncRead ` ] ` R ` 和 [ ` tokio::io::AsyncWrite ` ] ` W ` 组成的元组: ` (R, W) ` 。
4646
47- 示例,你可以轻松创建一个TCP流来作为传输层. [ examples] ( examples/README.md )
47+ 例如,你可以看到我们如何轻松地通过TCP流或http升级构建传输层。 [ examples] ( examples/README.md )
4848
4949#### 2. 构建服务
5050你可以通过 [ ` ServerHandler ` ] ( crates/rmcp/src/handler/server.rs ) 或 [ ` ClientHandler ` ] ( crates/rmcp/src/handler/client.rs ) 轻松构建服务
@@ -53,38 +53,34 @@ let transport = (stdin(), stdout());
5353let service = common::counter::Counter::new();
5454```
5555
56- 如果你想用 ` tower ` , 你也可以使用 [ ` TowerHandler ` ] 来作为tower服务的适配器.
57-
58- 请参考 [ 服务用例] ( examples/servers/src/common/counter.rs ) .
59-
6056#### 3. 把他们组装到一起
6157``` rust, ignore
6258// 这里会自动完成初始化流程
6359let server = service.serve(transport).await?;
6460```
6561
66- #### 4. 与服务端/客户端交互
67- 一旦你完成初始化,你可以发送请求或者发送通知
62+ #### 4. 与服务交互
63+ 一旦服务初始化完成,你可以发送请求或通知:
6864
6965``` rust, ignore
70- // request
66+ // 请求
7167let roots = server.list_roots().await?;
7268
73- // or send notification
69+ // 或发送通知
7470server.notify_cancelled(...).await?;
7571```
7672
77- #### 5. 等待服务结束
73+ #### 5. 等待服务关闭
7874``` rust, ignore
7975let quit_reason = server.waiting().await?;
80- // or cancel it
76+ // 或取消它
8177let quit_reason = server.cancel().await?;
8278```
8379
84- ### 使用宏来定义工具
85- 使用 ` tool ` 宏来快速创建工具
80+ ### 使用宏来声明工具
81+ 使用 ` toolbox ` 和 ` tool ` 宏来快速创建工具。
8682
87- 请看这个[ 文件] ( examples/servers/src/common/calculator.rs ) .
83+ 请看这个[ 文件] ( examples/servers/src/common/calculator.rs ) 。
8884``` rust, ignore
8985use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};
9086
@@ -137,28 +133,33 @@ impl ServerHandler for Calculator {
137133}
138134
139135```
140- 你要做的唯一事情就是保证函数的返回类型实现了 ` IntoCallToolResult ` .
136+ 你要做的唯一事情就是确保函数的返回类型实现了 ` IntoCallToolResult ` 。
141137
142- 你可以为返回类型实现 ` IntoContents ` , 那么返回内容会被自动标记为成功 。
138+ 你可以为返回类型实现 ` IntoContents ` ,那么返回值将自动标记为成功 。
143139
144- 如果返回类型是 ` Result<T, E> ` ,其中 ` T ` 与 ` E ` 都实现了 ` IntoContents ` , 那就会自动标记成功或者失败 。
140+ 如果返回类型是 ` Result<T, E> ` ,其中 ` T ` 与 ` E ` 都实现了 ` IntoContents ` ,那也是可以的 。
145141
146142### 管理多个服务
147- 在很多情况下你需要把不同类型的服务管理在一个集合当中 ,你可以调用 ` into_dyn ` 来把他们都转化成动态类型 。
143+ 在很多情况下你需要在一个集合中管理多个服务 ,你可以调用 ` into_dyn ` 来将服务转换为相同类型 。
148144``` rust, ignore
149145let service = service.into_dyn();
150146```
151147
152148
153- ### 用例
154- 查看 [ 用例文件夹 ] ( examples/README.md )
149+ ### 示例
150+ 查看 [ examples ] ( examples/README.md )
155151
156- ### Features
152+ ### 功能特性
157153- ` client ` : 使用客户端sdk
158154- ` server ` : 使用服务端sdk
159-
155+ - ` macros ` : 宏默认
156+ #### 传输层
157+ - ` transport-io ` : 服务端标准输入输出传输
158+ - ` transport-sse-server ` : 服务端SSE传输
159+ - ` transport-child-process ` : 客户端标准输入输出传输
160+ - ` transport-sse ` : 客户端SSE传输
160161
161162## 相关资源
162163- [ MCP Specification] ( https://spec.modelcontextprotocol.io/specification/2024-11-05/ )
163164
164- - [ Schema] ( https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts )
165+ - [ Schema] ( https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts )
0 commit comments