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