Skip to content

Commit cefeb83

Browse files
committed
docs: add document for getting peer from context
1 parent 588c39c commit cefeb83

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

crates/rmcp/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,39 @@ let service = client.serve(transport).await?;
146146

147147

148148

149+
## Access with peer interface when handling message
150+
151+
You can get the [`Peer`](crate::service::Peer) struct from [`NotificationContext`](crate::service::NotificationContext) and [`RequestContext`](crate::service::RequestContext).
152+
153+
```rust, ignore
154+
# use rmcp::{
155+
# ServerHandler,
156+
# model::{LoggingLevel, LoggingMessageNotificationParam, ProgressNotificationParam},
157+
# service::{NotificationContext, RoleServer},
158+
# };
159+
# pub struct Handler;
160+
161+
impl ServerHandler for Handler {
162+
async fn on_progress(
163+
&self,
164+
notification: ProgressNotificationParam,
165+
context: NotificationContext<RoleServer>,
166+
) {
167+
let peer = context.peer;
168+
let _ = peer
169+
.notify_logging_message(LoggingMessageNotificationParam {
170+
level: LoggingLevel::Info,
171+
logger: None,
172+
data: serde_json::json!({
173+
"message": format!("Progress: {}", notification.progress),
174+
}),
175+
})
176+
.await;
177+
}
178+
}
179+
```
180+
181+
149182
## Manage Multi Services
150183

151184
For many cases you need to manage several service in a collection, you can call `into_dyn` to convert services into the same type.

0 commit comments

Comments
 (0)