fix: use cfg-gated Send+Sync supertraits to avoid semver break (#757)
This commit is contained in:
parent
55b478b0f4
commit
d485249048
2 changed files with 248 additions and 213 deletions
|
|
@ -4,8 +4,7 @@ use crate::{
|
|||
error::ErrorData as McpError,
|
||||
model::{TaskSupport, *},
|
||||
service::{
|
||||
MaybeSend, MaybeSendFuture, NotificationContext, RequestContext, RoleServer, Service,
|
||||
ServiceRole,
|
||||
MaybeSendFuture, NotificationContext, RequestContext, RoleServer, Service, ServiceRole,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -161,12 +160,8 @@ impl<H: ServerHandler> Service<RoleServer> for H {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait ServerHandler: Sized + MaybeSend + 'static {
|
||||
macro_rules! server_handler_methods {
|
||||
() => {
|
||||
fn enqueue_task(
|
||||
&self,
|
||||
_request: CallToolRequestParams,
|
||||
|
|
@ -233,8 +228,9 @@ pub trait ServerHandler: Sized + MaybeSend + 'static {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + MaybeSendFuture + '_
|
||||
{
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>>
|
||||
+ MaybeSendFuture
|
||||
+ '_ {
|
||||
std::future::ready(Ok(ListResourceTemplatesResult::default()))
|
||||
}
|
||||
fn read_resource(
|
||||
|
|
@ -258,7 +254,9 @@ pub trait ServerHandler: Sized + MaybeSend + 'static {
|
|||
request: UnsubscribeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<UnsubscribeRequestMethod>()))
|
||||
std::future::ready(Err(
|
||||
McpError::method_not_found::<UnsubscribeRequestMethod>(),
|
||||
))
|
||||
}
|
||||
fn call_tool(
|
||||
&self,
|
||||
|
|
@ -369,6 +367,19 @@ pub trait ServerHandler: Sized + MaybeSend + 'static {
|
|||
let _ = (request, context);
|
||||
std::future::ready(Err(McpError::method_not_found::<CancelTaskMethod>()))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub trait ServerHandler: Sized + Send + Sync + 'static {
|
||||
server_handler_methods!();
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[cfg(feature = "local")]
|
||||
pub trait ServerHandler: Sized + 'static {
|
||||
server_handler_methods!();
|
||||
}
|
||||
|
||||
macro_rules! impl_server_handler_for_wrapper {
|
||||
|
|
|
|||
|
|
@ -128,11 +128,23 @@ pub type RxJsonRpcMessage<R> = JsonRpcMessage<
|
|||
<R as ServiceRole>::PeerNot,
|
||||
>;
|
||||
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait Service<R: ServiceRole>: MaybeSend + 'static {
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub trait Service<R: ServiceRole>: Send + Sync + 'static {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_;
|
||||
fn handle_notification(
|
||||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_;
|
||||
fn get_info(&self) -> R::Info;
|
||||
}
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
pub trait Service<R: ServiceRole>: 'static {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
|
|
@ -197,11 +209,23 @@ impl<R: ServiceRole> Service<R> for Box<dyn DynService<R>> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait DynService<R: ServiceRole>: MaybeSend {
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub trait DynService<R: ServiceRole>: Send + Sync {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> MaybeBoxFuture<'_, Result<R::Resp, McpError>>;
|
||||
fn handle_notification(
|
||||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> MaybeBoxFuture<'_, Result<(), McpError>>;
|
||||
fn get_info(&self) -> R::Info;
|
||||
}
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
pub trait DynService<R: ServiceRole> {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
|
|
|
|||
Loading…
Reference in a new issue