feat: better http server support (#199)
* feat: better http server support 1. allow user get extensions in tool call. 2. allow user serve sse service without initialization. * fix: fix document test
This commit is contained in:
parent
c1c4c9a0c9
commit
076dc2c2cd
1 changed files with 95 additions and 96 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
error::Error as McpError,
|
||||
model::*,
|
||||
service::{Peer, RequestContext, RoleClient, Service, ServiceRole},
|
||||
service::{RequestContext, RoleClient, Service, ServiceRole},
|
||||
};
|
||||
|
||||
impl<H: ClientHandler> Service<RoleClient> for H {
|
||||
|
|
@ -118,47 +118,16 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
std::future::ready(())
|
||||
}
|
||||
|
||||
fn get_peer(&self) -> Option<Peer<RoleClient>>;
|
||||
|
||||
fn set_peer(&mut self, peer: Peer<RoleClient>);
|
||||
|
||||
fn get_info(&self) -> ClientInfo {
|
||||
ClientInfo::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Do nothing, just store the peer.
|
||||
impl ClientHandler for Option<Peer<RoleClient>> {
|
||||
fn get_peer(&self) -> Option<Peer<RoleClient>> {
|
||||
self.clone()
|
||||
}
|
||||
/// Do nothing, with default client info.
|
||||
impl ClientHandler for () {}
|
||||
|
||||
fn set_peer(&mut self, peer: Peer<RoleClient>) {
|
||||
*self = Some(peer);
|
||||
}
|
||||
}
|
||||
|
||||
/// Do nothing, even store the peer.
|
||||
impl ClientHandler for () {
|
||||
fn get_peer(&self) -> Option<Peer<RoleClient>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn set_peer(&mut self, peer: Peer<RoleClient>) {
|
||||
drop(peer);
|
||||
}
|
||||
}
|
||||
|
||||
/// Do nothing, even store the peer.
|
||||
/// Do nothing, with a specific client info.
|
||||
impl ClientHandler for ClientInfo {
|
||||
fn get_peer(&self) -> Option<Peer<RoleClient>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn set_peer(&mut self, peer: Peer<RoleClient>) {
|
||||
drop(peer);
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ClientInfo {
|
||||
self.clone()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue