You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -47,48 +51,55 @@ For client, the sink item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRp
47
51
For server, the sink item is [`ServerJsonRpcMessage`](crate::model::ServerJsonRpcMessage) and stream item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRpcMessage)
48
52
49
53
##### These types is automatically implemented [`IntoTransport`](crate::transport::IntoTransport) trait
54
+
50
55
1. The types that already implement both [`Sink`](futures::Sink) and [`Stream`](futures::Stream) trait.
51
56
2. A tuple of sink `Tx` and stream `Rx`: `(Tx, Rx)`.
52
57
3. The type that implement both [`tokio::io::AsyncRead`] and [`tokio::io::AsyncWrite`] trait.
53
-
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)`.
54
59
55
60
For example, you can see how we build a transport through TCP stream or http upgrade so easily. [examples](examples/README.md)
56
61
57
62
#### 2. Build a service
63
+
58
64
You can easily build a service by using [`ServerHandler`](crates/rmcp/src/handler/server.rs) or [`ClientHandler`](crates/rmcp/src/handler/client.rs).
59
65
60
66
```rust, ignore
61
67
let service = common::counter::Counter::new();
62
68
```
63
69
64
70
#### 3. Serve them together
71
+
65
72
```rust, ignore
66
73
// this call will finish the initialization process
67
74
let server = service.serve(transport).await?;
68
75
```
69
76
70
77
#### 4. Interact with the server
78
+
71
79
Once the server is initialized, you can send requests or notifications:
72
80
73
81
```rust, ignore
74
-
// request
82
+
// request
75
83
let roots = server.list_roots().await?;
76
84
77
85
// or send notification
78
86
server.notify_cancelled(...).await?;
79
87
```
80
88
81
89
#### 5. Waiting for service shutdown
90
+
82
91
```rust, ignore
83
92
let quit_reason = server.waiting().await?;
84
93
// or cancel it
85
94
let quit_reason = server.cancel().await?;
86
95
```
87
96
88
97
### Use marcos to declaring tool
98
+
89
99
Use `toolbox` and `tool` macros to create tool quickly.
90
100
91
101
Check this [file](examples/servers/src/common/calculator.rs).
102
+
92
103
```rust, ignore
93
104
use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};
94
105
@@ -141,33 +152,39 @@ impl ServerHandler for Calculator {
141
152
}
142
153
143
154
```
155
+
144
156
The only thing you should do is to make the function's return type implement `IntoCallToolResult`.
145
157
146
-
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.
147
159
148
160
If you return a type of `Result<T, E>` where `T` and `E` both implemented `IntoContents`, it's also OK.
149
161
150
162
### Manage Multi Services
163
+
151
164
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
+
152
166
```rust, ignore
153
167
let service = service.into_dyn();
154
168
```
155
169
156
-
157
170
### Examples
171
+
158
172
See [examples](examples/README.md)
159
173
160
174
### Features
175
+
161
176
-`client`: use client side sdk
162
177
-`server`: use server side sdk
163
178
-`macros`: macros default
179
+
164
180
#### Transports
181
+
165
182
-`transport-io`: Server stdio transport
166
183
-`transport-sse-server`: Server SSE transport
167
184
-`transport-child-process`: Client stdio transport
0 commit comments