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:
4t145 2025-05-19 18:49:18 +08:00 • committed by GitHub
commit 076dc2c2cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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()
}