@@ -24,7 +24,7 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
24
24
25
25
Start a client in one line:
26
26
27
- ``` rust
27
+ ``` rust, ignore
28
28
use rmcp::{ServiceExt, transport::TokioChildProcess};
29
29
use tokio::process::Command;
30
30
@@ -37,7 +37,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
37
37
}
38
38
```
39
39
40
- #### 1. Build a transport
40
+ <details >
41
+ <summary >1. Build a transport</summary >
41
42
42
43
``` rust, ignore
43
44
use tokio::io::{stdin, stdout};
@@ -58,48 +59,59 @@ For server, the sink item is [`ServerJsonRpcMessage`](crate::model::ServerJsonRp
58
59
4 . A tuple of [ ` tokio::io::AsyncRead ` ] ` R ` and [ ` tokio::io::AsyncWrite ` ] ` W ` : ` (R, W) ` .
59
60
60
61
For example, you can see how we build a transport through TCP stream or http upgrade so easily. [ examples] ( examples/README.md )
62
+ </details >
61
63
62
- #### 2. Build a service
64
+ <details >
65
+ <summary >2. Build a service</summary >
63
66
64
67
You can easily build a service by using [ ` ServerHandler ` ] ( crates/rmcp/src/handler/server.rs ) or [ ` ClientHandler ` ] ( crates/rmcp/src/handler/client.rs ) .
65
68
66
69
``` rust, ignore
67
70
let service = common::counter::Counter::new();
68
71
```
72
+ </details >
69
73
70
- #### 3. Serve them together
74
+ <details >
75
+ <summary >3. Serve them together</summary >
71
76
72
77
``` rust, ignore
73
78
// this call will finish the initialization process
74
79
let server = service.serve(transport).await?;
75
80
```
81
+ </details >
76
82
77
- #### 4. Interact with the server
83
+ <details >
84
+ <summary >4. Interact with the server</summary >
78
85
79
86
Once the server is initialized, you can send requests or notifications:
80
87
81
88
``` rust, ignore
82
- // request
89
+ // request
83
90
let roots = server.list_roots().await?;
84
91
85
92
// or send notification
86
93
server.notify_cancelled(...).await?;
87
94
```
95
+ </details >
88
96
89
- #### 5. Waiting for service shutdown
97
+ <details >
98
+ <summary >5. Waiting for service shutdown</summary >
90
99
91
100
``` rust, ignore
92
101
let quit_reason = server.waiting().await?;
93
102
// or cancel it
94
103
let quit_reason = server.cancel().await?;
95
104
```
105
+ </details >
96
106
97
107
### Use macros to declaring tool
98
108
99
109
Use ` toolbox ` and ` tool ` macros to create tool quickly.
100
110
101
- Check this [ file] ( examples/servers/src/common/calculator.rs ) .
111
+ <details >
112
+ <summary >Example: Calculator Tool</summary >
102
113
114
+ Check this [ file] ( examples/servers/src/common/calculator.rs ) .
103
115
``` rust, ignore
104
116
use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};
105
117
@@ -150,19 +162,19 @@ impl ServerHandler for Calculator {
150
162
}
151
163
}
152
164
}
153
-
154
165
```
155
166
167
+
156
168
The only thing you should do is to make the function's return type implement ` IntoCallToolResult ` .
157
169
158
170
And you can just implement ` IntoContents ` , and the return value will be marked as success automatically.
159
171
160
172
If you return a type of ` Result<T, E> ` where ` T ` and ` E ` both implemented ` IntoContents ` , it's also OK.
173
+ </details >
161
174
162
175
### Manage Multi Services
163
176
164
177
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
-
166
178
``` rust, ignore
167
179
let service = service.into_dyn();
168
180
```
@@ -177,7 +189,7 @@ See [examples](examples/README.md)
177
189
- ` server ` : use server side sdk
178
190
- ` macros ` : macros default
179
191
180
- #### Transports
192
+ ### Transports
181
193
182
194
- ` transport-io ` : Server stdio transport
183
195
- ` transport-sse-server ` : Server SSE transport
@@ -189,6 +201,8 @@ See [examples](examples/README.md)
189
201
- [ MCP Specification] ( https://spec.modelcontextprotocol.io/specification/2024-11-05/ )
190
202
- [ Schema] ( https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts )
191
203
192
- ## Development with Dev Container
204
+ ## Related Projects
205
+ - [ containerd-mcp-server] ( https://github.com/modelcontextprotocol/containerd-mcp-server ) - A containerd-based MCP server implementation
193
206
207
+ ## Development with Dev Container
194
208
See [ docs/DEVCONTAINER.md] ( docs/DEVCONTAINER.md ) for instructions on using Dev Container for development.
0 commit comments