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, RoleServer, Service, ServiceRole},
|
||||
service::{RequestContext, RoleServer, Service, ServiceRole},
|
||||
};
|
||||
|
||||
mod resource;
|
||||
|
|
@ -108,6 +108,10 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
request: InitializeRequestParam,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<InitializeResult, McpError>> + Send + '_ {
|
||||
if context.peer.peer_info().is_none() {
|
||||
context.peer.set_peer_info(request);
|
||||
}
|
||||
let info = self.get_info();
|
||||
std::future::ready(Ok(self.get_info()))
|
||||
}
|
||||
fn complete(
|
||||
|
|
@ -210,14 +214,6 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
std::future::ready(())
|
||||
}
|
||||
|
||||
fn get_peer(&self) -> Option<Peer<RoleServer>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn set_peer(&mut self, peer: Peer<RoleServer>) {
|
||||
drop(peer);
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::default()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue