Skip to content

Commit 387c36a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into revision-2025-03-26
2 parents 5cf8af8 + 4ca00c2 commit 387c36a

File tree

39 files changed

+733
-483
lines changed

39 files changed

+733
-483
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,7 @@ jobs:
5656
- name: Install Rust
5757
uses: dtolnay/rust-toolchain@stable
5858

59-
- name: Cache dependencies
60-
uses: actions/cache@v3
61-
with:
62-
path: |
63-
~/.cargo/registry
64-
~/.cargo/git
65-
target
66-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
67-
restore-keys: ${{ runner.os }}-cargo-
59+
- uses: Swatinem/rust-cache@v2
6860

6961
- name: Run clippy
7062
run: cargo clippy --all-targets --all-features -- -D warnings
@@ -93,19 +85,28 @@ jobs:
9385
- name: Create venv for python
9486
run: uv venv
9587

96-
- name: Cache dependencies
97-
uses: actions/cache@v3
98-
with:
99-
path: |
100-
~/.cargo/registry
101-
~/.cargo/git
102-
target
103-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
104-
restore-keys: ${{ runner.os }}-cargo-
88+
- uses: Swatinem/rust-cache@v2
10589

10690
- name: Run tests
10791
run: cargo test --all-features
10892

93+
doc:
94+
name: Generate Documentation
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@v3
98+
99+
- name: Install Rust
100+
uses: dtolnay/rust-toolchain@stable
101+
102+
- uses: Swatinem/rust-cache@v2
103+
104+
- name: Generate documentation
105+
run: |
106+
cargo doc --no-deps -p rmcp -p rmcp-macros
107+
env:
108+
RUSTDOCFLAGS: -Dwarnings
109+
109110
release:
110111
name: Release crates
111112
runs-on: ubuntu-latest
@@ -117,15 +118,7 @@ jobs:
117118
- name: Install Rust
118119
uses: dtolnay/rust-toolchain@stable
119120

120-
- name: Cache dependencies
121-
uses: actions/cache@v3
122-
with:
123-
path: |
124-
~/.cargo/registry
125-
~/.cargo/git
126-
target
127-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
128-
restore-keys: ${{ runner.os }}-cargo-
121+
- uses: Swatinem/rust-cache@v2
129122

130123
- name: Cargo login
131124
run: cargo login ${{ secrets.CRATES_TOKEN }}
@@ -146,4 +139,4 @@ jobs:
146139
- name: Publish rmcp
147140
if: ${{ startsWith(github.ref, 'refs/tags/release') }}
148141
continue-on-error: true
149-
run: cargo publish -p rmcp
142+
run: cargo publish -p rmcp

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[workspace]
44
members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"]

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
</div>
44

55
# RMCP
6+
67
[![Crates.io Version](https://img.shields.io/crates/v/rmcp)](https://crates.io/crates/rmcp)
78
![Release status](https://github.com/modelcontextprotocol/rust-sdk/actions/workflows/release.yml/badge.svg)
89
[![docs.rs](https://img.shields.io/docsrs/rmcp)](https://docs.rs/rmcp/latest/rmcp)
@@ -12,21 +13,28 @@ An official rust Model Context Protocol SDK implementation with tokio async runt
1213
## Usage
1314

1415
### Import
16+
1517
```toml
1618
rmcp = { version = "0.1", features = ["server"] }
1719
## or dev channel
1820
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "main" }
1921
```
2022

2123
### Quick start
24+
2225
Start a client in one line:
26+
2327
```rust
2428
use rmcp::{ServiceExt, transport::TokioChildProcess};
2529
use tokio::process::Command;
2630

27-
let client = ().serve(
28-
TokioChildProcess::new(Command::new("npx").arg("-y").arg("@modelcontextprotocol/server-everything"))?
29-
).await?;
31+
#[tokio::main]
32+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
33+
let client = ().serve(
34+
TokioChildProcess::new(Command::new("npx").arg("-y").arg("@modelcontextprotocol/server-everything"))?
35+
).await?;
36+
Ok(())
37+
}
3038
```
3139

3240
#### 1. Build a transport
@@ -43,48 +51,55 @@ For client, the sink item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRp
4351
For server, the sink item is [`ServerJsonRpcMessage`](crate::model::ServerJsonRpcMessage) and stream item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRpcMessage)
4452

4553
##### These types is automatically implemented [`IntoTransport`](crate::transport::IntoTransport) trait
54+
4655
1. The types that already implement both [`Sink`](futures::Sink) and [`Stream`](futures::Stream) trait.
4756
2. A tuple of sink `Tx` and stream `Rx`: `(Tx, Rx)`.
4857
3. The type that implement both [`tokio::io::AsyncRead`] and [`tokio::io::AsyncWrite`] trait.
49-
4. A tuple of [`tokio::io::AsyncRead`] `R `and [`tokio::io::AsyncWrite`] `W`: `(R, W)`.
58+
4. A tuple of [`tokio::io::AsyncRead`] `R `and [`tokio::io::AsyncWrite`] `W`: `(R, W)`.
5059

5160
For example, you can see how we build a transport through TCP stream or http upgrade so easily. [examples](examples/README.md)
5261

5362
#### 2. Build a service
63+
5464
You can easily build a service by using [`ServerHandler`](crates/rmcp/src/handler/server.rs) or [`ClientHandler`](crates/rmcp/src/handler/client.rs).
5565

5666
```rust, ignore
5767
let service = common::counter::Counter::new();
5868
```
5969

6070
#### 3. Serve them together
71+
6172
```rust, ignore
6273
// this call will finish the initialization process
6374
let server = service.serve(transport).await?;
6475
```
6576

6677
#### 4. Interact with the server
78+
6779
Once the server is initialized, you can send requests or notifications:
6880

6981
```rust, ignore
70-
// request
82+
// request
7183
let roots = server.list_roots().await?;
7284
7385
// or send notification
7486
server.notify_cancelled(...).await?;
7587
```
7688

7789
#### 5. Waiting for service shutdown
90+
7891
```rust, ignore
7992
let quit_reason = server.waiting().await?;
8093
// or cancel it
8194
let quit_reason = server.cancel().await?;
8295
```
8396

8497
### Use marcos to declaring tool
98+
8599
Use `toolbox` and `tool` macros to create tool quickly.
86100

87101
Check this [file](examples/servers/src/common/calculator.rs).
102+
88103
```rust, ignore
89104
use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};
90105
@@ -137,33 +152,39 @@ impl ServerHandler for Calculator {
137152
}
138153
139154
```
155+
140156
The only thing you should do is to make the function's return type implement `IntoCallToolResult`.
141157

142-
And you can just implement `IntoContents`, and the return value will be marked as success automatically.
158+
And you can just implement `IntoContents`, and the return value will be marked as success automatically.
143159

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

146162
### Manage Multi Services
163+
147164
For many cases you need to manage several service in a collection, you can call `into_dyn` to convert services into the same type.
165+
148166
```rust, ignore
149167
let service = service.into_dyn();
150168
```
151169

152-
153170
### Examples
171+
154172
See [examples](examples/README.md)
155173

156174
### Features
175+
157176
- `client`: use client side sdk
158177
- `server`: use server side sdk
159178
- `macros`: macros default
179+
160180
#### Transports
181+
161182
- `transport-io`: Server stdio transport
162183
- `transport-sse-server`: Server SSE transport
163184
- `transport-child-process`: Client stdio transport
164185
- `transport-sse`: Client sse transport
165186

166187
## Related Resources
167-
- [MCP Specification](https://spec.modelcontextprotocol.io/specification/2024-11-05/)
168188

189+
- [MCP Specification](https://spec.modelcontextprotocol.io/specification/2024-11-05/)
169190
- [Schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts)

crates/rmcp-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "rmcp-macros"

crates/rmcp-macros/src/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Resu
347347
#input_fn_vis fn #tool_attr_fn_ident() -> rmcp::model::Tool {
348348
rmcp::model::Tool {
349349
name: #name.into(),
350-
description: #description.into(),
350+
description: Some(#description.into()),
351351
input_schema: #schema.into(),
352352
annotations: None
353353
}

crates/rmcp/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "rmcp"
@@ -95,5 +95,11 @@ path = "tests/test_with_python.rs"
9595

9696
[[test]]
9797
name = "test_with_js"
98-
required-features = ["server", "transport-sse-server"]
99-
path = "tests/test_with_js.rs"
98+
required-features = ["server", "client", "transport-sse-server", "transport-child-process"]
99+
path = "tests/test_with_js.rs"
100+
101+
[[test]]
102+
name = "test_notification"
103+
required-features = ["server", "client"]
104+
path = "tests/test_notification.rs"
105+

0 commit comments

Comments
 (0)