feat: provide more context information (#236)

* feat: provide more context information

1. provide context for notification
2. allow extract more info from tool call
3. inject http request part for streamable http server

* docs: add document for getting peer from context
This commit is contained in:
4t145 2025-05-29 11:52:54 +08:00 • committed by GitHub
commit 969fad26cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 194 additions and 40 deletions

View file

@ -210,7 +210,12 @@ where
Some(ClientJsonRpcMessage::notification(notification)),
));
};
let _ = service.handle_notification(notification).await;
let context = NotificationContext {
meta: notification.get_meta().clone(),
extensions: notification.extensions().clone(),
peer: peer.clone(),
};
let _ = service.handle_notification(notification, context).await;
// Continue processing service
Ok(serve_inner(service, transport, peer, peer_rx, ct))
}

View file

@ -2,6 +2,7 @@ use std::{future::poll_fn, marker::PhantomData};
use tower_service::Service as TowerService;
use super::NotificationContext;
use crate::service::{RequestContext, Service, ServiceRole};
pub struct TowerHandler<S, R: ServiceRole> {
@ -42,6 +43,7 @@ where
fn handle_notification(
&self,
_notification: R::PeerNot,
_context: NotificationContext<R>,
) -> impl Future<Output = Result<(), crate::Error>> + Send + '_ {
std::future::ready(Ok(()))
}