feat: add local feature for !Send tool handler support (#740)
* feat: add local feature for !Send tool handler support * fix: gate streamable HTTP transport on not(local) feature
This commit is contained in:
parent
8700e5c920
commit
1a4a52a173
41 changed files with 362 additions and 222 deletions
|
|
@ -22,4 +22,6 @@ serde_json = "1.0"
|
|||
darling = { version = "0.23" }
|
||||
|
||||
[features]
|
||||
local = []
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -95,6 +95,9 @@ pub struct ToolAttribute {
|
|||
pub icons: Option<Expr>,
|
||||
/// Optional metadata for the tool
|
||||
pub meta: Option<Expr>,
|
||||
/// When true, the generated future will not require `Send`. Useful for `!Send` handlers
|
||||
/// (e.g. single-threaded database connections). Also enabled globally by the `local` crate feature.
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
#[derive(FromMeta, Debug, Default)]
|
||||
|
|
@ -333,7 +336,9 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
|
|||
if fn_item.sig.asyncness.is_some() {
|
||||
// 1. remove asyncness from sig
|
||||
// 2. make return type: `std::pin::Pin<Box<dyn std::future::Future<Output = #ReturnType> + Send + '_>>`
|
||||
// (omit `+ Send` when the `local` crate feature is active or `#[tool(local)]` is used)
|
||||
// 3. make body: { Box::pin(async move { #body }) }
|
||||
let omit_send = cfg!(feature = "local") || attribute.local;
|
||||
let new_output = syn::parse2::<ReturnType>({
|
||||
let mut lt = quote! { 'static };
|
||||
if let Some(receiver) = fn_item.sig.receiver() {
|
||||
|
|
@ -347,10 +352,18 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
|
|||
}
|
||||
match &fn_item.sig.output {
|
||||
syn::ReturnType::Default => {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = ()> + Send + #lt>> }
|
||||
if omit_send {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = ()> + #lt>> }
|
||||
} else {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = ()> + Send + #lt>> }
|
||||
}
|
||||
}
|
||||
syn::ReturnType::Type(_, ty) => {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = #ty> + Send + #lt>> }
|
||||
if omit_send {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = #ty> + #lt>> }
|
||||
} else {
|
||||
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = #ty> + Send + #lt>> }
|
||||
}
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ chrono = { version = "0.4.38", default-features = false, features = [
|
|||
|
||||
[features]
|
||||
default = ["base64", "macros", "server"]
|
||||
local = ["rmcp-macros?/local"]
|
||||
client = ["dep:tokio-stream"]
|
||||
server = ["transport-async-rw", "dep:schemars", "dep:pastey"]
|
||||
macros = ["dep:rmcp-macros", "dep:pastey"]
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ The transport layer is pluggable. Two built-in pairs cover the most common cases
|
|||
| | Client | Server |
|
||||
|:-:|:-:|:-:|
|
||||
| **stdio** | [`TokioChildProcess`](crate::transport::TokioChildProcess) | [`stdio`](crate::transport::stdio) |
|
||||
| **Streamable HTTP** | [`StreamableHttpClientTransport`](crate::transport::StreamableHttpClientTransport) | [`StreamableHttpService`](crate::transport::StreamableHttpService) |
|
||||
| **Streamable HTTP** | [`StreamableHttpClientTransport`](crate::transport::StreamableHttpClientTransport) | `StreamableHttpService` |
|
||||
|
||||
Any type that implements the [`Transport`](crate::transport::Transport) trait can be used. The [`IntoTransport`](crate::transport::IntoTransport) helper trait provides automatic conversions from:
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ use std::sync::Arc;
|
|||
use crate::{
|
||||
error::ErrorData as McpError,
|
||||
model::*,
|
||||
service::{NotificationContext, RequestContext, RoleClient, Service, ServiceRole},
|
||||
service::{
|
||||
MaybeSendFuture, NotificationContext, RequestContext, RoleClient, Service, ServiceRole,
|
||||
},
|
||||
};
|
||||
|
||||
impl<H: ClientHandler> Service<RoleClient> for H {
|
||||
|
|
@ -83,7 +85,7 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
fn ping(
|
||||
&self,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +93,7 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
params: CreateMessageRequestParams,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(
|
||||
McpError::method_not_found::<CreateMessageRequestMethod>(),
|
||||
))
|
||||
|
|
@ -100,7 +102,7 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
fn list_roots(
|
||||
&self,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<ListRootsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListRootsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(ListRootsResult::default()))
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +164,8 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: CreateElicitationRequestParams,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, McpError>> + MaybeSendFuture + '_
|
||||
{
|
||||
// Default implementation declines all requests - real clients should override this
|
||||
let _ = (request, context);
|
||||
std::future::ready(Ok(CreateElicitationResult {
|
||||
|
|
@ -175,7 +178,7 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: CustomRequest,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
|
||||
let CustomRequest { method, .. } = request;
|
||||
let _ = context;
|
||||
std::future::ready(Err(McpError::new(
|
||||
|
|
@ -189,46 +192,46 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
params: CancelledNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_progress(
|
||||
&self,
|
||||
params: ProgressNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_logging_message(
|
||||
&self,
|
||||
params: LoggingMessageNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_resource_updated(
|
||||
&self,
|
||||
params: ResourceUpdatedNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_resource_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_tool_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_prompt_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
|
||||
|
|
@ -236,14 +239,14 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
params: ElicitationResponseNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_custom_notification(
|
||||
&self,
|
||||
notification: CustomNotification,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
let _ = (notification, context);
|
||||
std::future::ready(())
|
||||
}
|
||||
|
|
@ -269,7 +272,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
fn ping(
|
||||
&self,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).ping(context)
|
||||
}
|
||||
|
||||
|
|
@ -277,14 +280,14 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
params: CreateMessageRequestParams,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).create_message(params, context)
|
||||
}
|
||||
|
||||
fn list_roots(
|
||||
&self,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<ListRootsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListRootsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).list_roots(context)
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +295,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
request: CreateElicitationRequestParams,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).create_elicitation(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +303,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
request: CustomRequest,
|
||||
context: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).on_custom_request(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -308,7 +311,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
params: CancelledNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_cancelled(params, context)
|
||||
}
|
||||
|
||||
|
|
@ -316,7 +319,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
params: ProgressNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_progress(params, context)
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +327,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
params: LoggingMessageNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_logging_message(params, context)
|
||||
}
|
||||
|
||||
|
|
@ -332,28 +335,28 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
params: ResourceUpdatedNotificationParam,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_resource_updated(params, context)
|
||||
}
|
||||
|
||||
fn on_resource_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_resource_list_changed(context)
|
||||
}
|
||||
|
||||
fn on_tool_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_tool_list_changed(context)
|
||||
}
|
||||
|
||||
fn on_prompt_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_prompt_list_changed(context)
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +364,7 @@ macro_rules! impl_client_handler_for_wrapper {
|
|||
&self,
|
||||
notification: CustomNotification,
|
||||
context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_custom_notification(notification, context)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ use std::sync::Arc;
|
|||
use crate::{
|
||||
error::ErrorData as McpError,
|
||||
model::{TaskSupport, *},
|
||||
service::{NotificationContext, RequestContext, RoleServer, Service, ServiceRole},
|
||||
service::{
|
||||
MaybeSend, MaybeSendFuture, NotificationContext, RequestContext, RoleServer, Service,
|
||||
ServiceRole,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod common;
|
||||
|
|
@ -159,12 +162,16 @@ impl<H: ServerHandler> Service<RoleServer> for H {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub trait ServerHandler: Sized + Send + Sync + 'static {
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait ServerHandler: Sized + MaybeSend + 'static {
|
||||
fn enqueue_task(
|
||||
&self,
|
||||
_request: CallToolRequestParams,
|
||||
_context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CreateTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::internal_error(
|
||||
"Task processing not implemented".to_string(),
|
||||
None,
|
||||
|
|
@ -173,7 +180,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
fn ping(
|
||||
&self,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
// handle requests
|
||||
|
|
@ -181,7 +188,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: InitializeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<InitializeResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<InitializeResult, McpError>> + MaybeSendFuture + '_ {
|
||||
if context.peer.peer_info().is_none() {
|
||||
context.peer.set_peer_info(request);
|
||||
}
|
||||
|
|
@ -191,49 +198,50 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: CompleteRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CompleteResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CompleteResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(CompleteResult::default()))
|
||||
}
|
||||
fn set_level(
|
||||
&self,
|
||||
request: SetLevelRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<SetLevelRequestMethod>()))
|
||||
}
|
||||
fn get_prompt(
|
||||
&self,
|
||||
request: GetPromptRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetPromptResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetPromptResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<GetPromptRequestMethod>()))
|
||||
}
|
||||
fn list_prompts(
|
||||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListPromptsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListPromptsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(ListPromptsResult::default()))
|
||||
}
|
||||
fn list_resources(
|
||||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourcesResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListResourcesResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(ListResourcesResult::default()))
|
||||
}
|
||||
fn list_resource_templates(
|
||||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + MaybeSendFuture + '_
|
||||
{
|
||||
std::future::ready(Ok(ListResourceTemplatesResult::default()))
|
||||
}
|
||||
fn read_resource(
|
||||
&self,
|
||||
request: ReadResourceRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ReadResourceResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ReadResourceResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(
|
||||
McpError::method_not_found::<ReadResourceRequestMethod>(),
|
||||
))
|
||||
|
|
@ -242,28 +250,28 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: SubscribeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<SubscribeRequestMethod>()))
|
||||
}
|
||||
fn unsubscribe(
|
||||
&self,
|
||||
request: UnsubscribeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<UnsubscribeRequestMethod>()))
|
||||
}
|
||||
fn call_tool(
|
||||
&self,
|
||||
request: CallToolRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CallToolResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CallToolResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<CallToolRequestMethod>()))
|
||||
}
|
||||
fn list_tools(
|
||||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListToolsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListToolsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(ListToolsResult::default()))
|
||||
}
|
||||
/// Get a tool definition by name.
|
||||
|
|
@ -277,7 +285,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: CustomRequest,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
|
||||
let CustomRequest { method, .. } = request;
|
||||
let _ = context;
|
||||
std::future::ready(Err(McpError::new(
|
||||
|
|
@ -291,34 +299,34 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
notification: CancelledNotificationParam,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_progress(
|
||||
&self,
|
||||
notification: ProgressNotificationParam,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_initialized(
|
||||
&self,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
tracing::info!("client initialized");
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_roots_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
std::future::ready(())
|
||||
}
|
||||
fn on_custom_notification(
|
||||
&self,
|
||||
notification: CustomNotification,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
let _ = (notification, context);
|
||||
std::future::ready(())
|
||||
}
|
||||
|
|
@ -331,7 +339,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListTasksResult, McpError>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Err(McpError::method_not_found::<ListTasksMethod>()))
|
||||
}
|
||||
|
||||
|
|
@ -339,7 +347,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: GetTaskInfoParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
let _ = (request, context);
|
||||
std::future::ready(Err(McpError::method_not_found::<GetTaskInfoMethod>()))
|
||||
}
|
||||
|
|
@ -348,7 +356,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: GetTaskResultParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetTaskPayloadResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetTaskPayloadResult, McpError>> + MaybeSendFuture + '_ {
|
||||
let _ = (request, context);
|
||||
std::future::ready(Err(McpError::method_not_found::<GetTaskResultMethod>()))
|
||||
}
|
||||
|
|
@ -357,7 +365,7 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
|
|||
&self,
|
||||
request: CancelTaskParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CancelTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CancelTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
let _ = (request, context);
|
||||
std::future::ready(Err(McpError::method_not_found::<CancelTaskMethod>()))
|
||||
}
|
||||
|
|
@ -370,14 +378,14 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: CallToolRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CreateTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CreateTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).enqueue_task(request, context)
|
||||
}
|
||||
|
||||
fn ping(
|
||||
&self,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).ping(context)
|
||||
}
|
||||
|
||||
|
|
@ -385,7 +393,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: InitializeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<InitializeResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<InitializeResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).initialize(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -393,7 +401,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: CompleteRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CompleteResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CompleteResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).complete(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +409,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: SetLevelRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).set_level(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +417,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: GetPromptRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetPromptResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetPromptResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).get_prompt(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -417,7 +425,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListPromptsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListPromptsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).list_prompts(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -425,7 +433,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourcesResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListResourcesResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).list_resources(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +441,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + Send + '_
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + MaybeSendFuture + '_
|
||||
{
|
||||
(**self).list_resource_templates(request, context)
|
||||
}
|
||||
|
|
@ -442,7 +450,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: ReadResourceRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ReadResourceResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ReadResourceResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).read_resource(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -450,7 +458,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: SubscribeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).subscribe(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +466,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: UnsubscribeRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).unsubscribe(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -466,7 +474,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: CallToolRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CallToolResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CallToolResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).call_tool(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -474,7 +482,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListToolsResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListToolsResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).list_tools(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -486,7 +494,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: CustomRequest,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).on_custom_request(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -494,7 +502,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
notification: CancelledNotificationParam,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_cancelled(notification, context)
|
||||
}
|
||||
|
||||
|
|
@ -502,21 +510,21 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
notification: ProgressNotificationParam,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_progress(notification, context)
|
||||
}
|
||||
|
||||
fn on_initialized(
|
||||
&self,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_initialized(context)
|
||||
}
|
||||
|
||||
fn on_roots_list_changed(
|
||||
&self,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_roots_list_changed(context)
|
||||
}
|
||||
|
||||
|
|
@ -524,7 +532,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
notification: CustomNotification,
|
||||
context: NotificationContext<RoleServer>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
(**self).on_custom_notification(notification, context)
|
||||
}
|
||||
|
||||
|
|
@ -536,7 +544,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: Option<PaginatedRequestParams>,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<ListTasksResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).list_tasks(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -544,7 +552,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: GetTaskInfoParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).get_task_info(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -552,7 +560,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: GetTaskResultParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetTaskPayloadResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<GetTaskPayloadResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).get_task_result(request, context)
|
||||
}
|
||||
|
||||
|
|
@ -560,7 +568,7 @@ macro_rules! impl_server_handler_for_wrapper {
|
|||
&self,
|
||||
request: CancelTaskParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CancelTaskResult, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<CancelTaskResult, McpError>> + MaybeSendFuture + '_ {
|
||||
(**self).cancel_task(request, context)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
|
||||
use futures::future::{BoxFuture, FutureExt};
|
||||
#[cfg(not(feature = "local"))]
|
||||
use futures::future::BoxFuture;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::common::{AsRequestContext, FromContextPart};
|
||||
|
|
@ -15,7 +16,7 @@ use crate::{
|
|||
RoleServer,
|
||||
handler::server::wrapper::Parameters,
|
||||
model::{GetPromptResult, PromptMessage},
|
||||
service::RequestContext,
|
||||
service::{MaybeBoxFuture, MaybeSend, MaybeSendFuture, RequestContext},
|
||||
};
|
||||
|
||||
/// Context for prompt retrieval operations
|
||||
|
|
@ -57,14 +58,23 @@ pub trait GetPromptHandler<S, A> {
|
|||
fn handle(
|
||||
self,
|
||||
context: PromptContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>;
|
||||
) -> MaybeBoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>;
|
||||
}
|
||||
|
||||
/// Type alias for dynamic prompt handlers
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub type DynGetPromptHandler<S> = dyn for<'a> Fn(PromptContext<'a, S>) -> BoxFuture<'a, Result<GetPromptResult, crate::ErrorData>>
|
||||
+ Send
|
||||
+ Sync;
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
pub type DynGetPromptHandler<S> = dyn for<'a> Fn(
|
||||
PromptContext<'a, S>,
|
||||
) -> futures::future::LocalBoxFuture<
|
||||
'a,
|
||||
Result<GetPromptResult, crate::ErrorData>,
|
||||
>;
|
||||
|
||||
/// Adapter type for async methods that return `Vec<PromptMessage>`
|
||||
pub struct AsyncMethodAdapter<T>(PhantomData<T>);
|
||||
|
||||
|
|
@ -191,31 +201,31 @@ macro_rules! impl_prompt_handler_for {
|
|||
impl<$($Tn,)* S, F, R> GetPromptHandler<S, ($($Tn,)*)> for F
|
||||
where
|
||||
$(
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + Send,
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + MaybeSendFuture,
|
||||
)*
|
||||
F: FnOnce(&S, $($Tn,)*) -> BoxFuture<'_, R> + Send,
|
||||
R: IntoGetPromptResult + Send + 'static,
|
||||
S: Send + Sync + 'static,
|
||||
F: FnOnce(&S, $($Tn,)*) -> MaybeBoxFuture<'_, R> + MaybeSendFuture,
|
||||
R: IntoGetPromptResult + MaybeSendFuture + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn handle(
|
||||
self,
|
||||
mut context: PromptContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
) -> MaybeBoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
{
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
let service = context.server;
|
||||
let fut = self(service, $($Tn,)*);
|
||||
async move {
|
||||
Box::pin(async move {
|
||||
let result = fut.await;
|
||||
result.into_get_prompt_result()
|
||||
}.boxed()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,28 +234,28 @@ macro_rules! impl_prompt_handler_for {
|
|||
impl<$($Tn,)* S, F, R> GetPromptHandler<S, SyncPromptMethodAdapter<($($Tn,)*), R>> for F
|
||||
where
|
||||
$(
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + Send,
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + MaybeSendFuture,
|
||||
)*
|
||||
F: FnOnce(&S, $($Tn,)*) -> R + Send,
|
||||
R: IntoGetPromptResult + Send,
|
||||
S: Send + Sync,
|
||||
F: FnOnce(&S, $($Tn,)*) -> R + MaybeSendFuture,
|
||||
R: IntoGetPromptResult + MaybeSendFuture,
|
||||
S: MaybeSend,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn handle(
|
||||
self,
|
||||
mut context: PromptContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
) -> MaybeBoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
{
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
let service = context.server;
|
||||
let result = self(service, $($Tn,)*);
|
||||
std::future::ready(result.into_get_prompt_result()).boxed()
|
||||
Box::pin(std::future::ready(result.into_get_prompt_result()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -254,25 +264,25 @@ macro_rules! impl_prompt_handler_for {
|
|||
impl<$($Tn,)* S, F, Fut, R> GetPromptHandler<S, AsyncPromptAdapter<($($Tn,)*), Fut, R>> for F
|
||||
where
|
||||
$(
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + Send + 'static,
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + MaybeSendFuture + 'static,
|
||||
)*
|
||||
F: FnOnce($($Tn,)*) -> Fut + Send + 'static,
|
||||
Fut: Future<Output = Result<R, crate::ErrorData>> + Send + 'static,
|
||||
R: IntoGetPromptResult + Send + 'static,
|
||||
S: Send + Sync + 'static,
|
||||
F: FnOnce($($Tn,)*) -> Fut + MaybeSendFuture + 'static,
|
||||
Fut: Future<Output = Result<R, crate::ErrorData>> + MaybeSendFuture + 'static,
|
||||
R: IntoGetPromptResult + MaybeSendFuture + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn handle(
|
||||
self,
|
||||
mut context: PromptContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
) -> MaybeBoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
{
|
||||
// Extract all parameters before moving into the async block
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
|
||||
|
|
@ -290,27 +300,27 @@ macro_rules! impl_prompt_handler_for {
|
|||
impl<$($Tn,)* S, F, R> GetPromptHandler<S, SyncPromptAdapter<($($Tn,)*), R>> for F
|
||||
where
|
||||
$(
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + Send + 'static,
|
||||
$Tn: for<'a> FromContextPart<PromptContext<'a, S>> + MaybeSendFuture + 'static,
|
||||
)*
|
||||
F: FnOnce($($Tn,)*) -> Result<R, crate::ErrorData> + Send + 'static,
|
||||
R: IntoGetPromptResult + Send + 'static,
|
||||
S: Send + Sync,
|
||||
F: FnOnce($($Tn,)*) -> Result<R, crate::ErrorData> + MaybeSendFuture + 'static,
|
||||
R: IntoGetPromptResult + MaybeSendFuture + 'static,
|
||||
S: MaybeSend,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn handle(
|
||||
self,
|
||||
mut context: PromptContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
) -> MaybeBoxFuture<'_, Result<GetPromptResult, crate::ErrorData>>
|
||||
{
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
let result = self($($Tn,)*);
|
||||
std::future::ready(result.and_then(|r| r.into_get_prompt_result())).boxed()
|
||||
Box::pin(std::future::ready(result.and_then(|r| r.into_get_prompt_result())))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use std::{borrow::Cow, sync::Arc};
|
||||
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
use crate::{
|
||||
handler::server::prompt::{DynGetPromptHandler, GetPromptHandler, PromptContext},
|
||||
model::{GetPromptResult, Prompt},
|
||||
service::{MaybeBoxFuture, MaybeSend},
|
||||
};
|
||||
|
||||
pub struct PromptRoute<S> {
|
||||
|
|
@ -32,10 +31,10 @@ impl<S> Clone for PromptRoute<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync + 'static> PromptRoute<S> {
|
||||
impl<S: MaybeSend + 'static> PromptRoute<S> {
|
||||
pub fn new<H, A: 'static>(attr: impl Into<Prompt>, handler: H) -> Self
|
||||
where
|
||||
H: GetPromptHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
H: GetPromptHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
Self {
|
||||
get: Arc::new(move |context: PromptContext<S>| {
|
||||
|
|
@ -50,9 +49,8 @@ impl<S: Send + Sync + 'static> PromptRoute<S> {
|
|||
where
|
||||
H: for<'a> Fn(
|
||||
PromptContext<'a, S>,
|
||||
) -> BoxFuture<'a, Result<GetPromptResult, crate::ErrorData>>
|
||||
+ Send
|
||||
+ Sync
|
||||
) -> MaybeBoxFuture<'a, Result<GetPromptResult, crate::ErrorData>>
|
||||
+ MaybeSend
|
||||
+ 'static,
|
||||
{
|
||||
Self {
|
||||
|
|
@ -72,9 +70,9 @@ pub trait IntoPromptRoute<S, A> {
|
|||
|
||||
impl<S, H, A, P> IntoPromptRoute<S, A> for (P, H)
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
A: 'static,
|
||||
H: GetPromptHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
H: GetPromptHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
P: Into<Prompt>,
|
||||
{
|
||||
fn into_prompt_route(self) -> PromptRoute<S> {
|
||||
|
|
@ -84,7 +82,7 @@ where
|
|||
|
||||
impl<S> IntoPromptRoute<S, ()> for PromptRoute<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
fn into_prompt_route(self) -> PromptRoute<S> {
|
||||
self
|
||||
|
|
@ -96,7 +94,7 @@ pub struct PromptAttrGenerateFunctionAdapter;
|
|||
|
||||
impl<S, F> IntoPromptRoute<S, PromptAttrGenerateFunctionAdapter> for F
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
F: Fn() -> PromptRoute<S>,
|
||||
{
|
||||
fn into_prompt_route(self) -> PromptRoute<S> {
|
||||
|
|
@ -137,7 +135,7 @@ impl<S> IntoIterator for PromptRouter<S> {
|
|||
|
||||
impl<S> PromptRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
@ -195,7 +193,7 @@ where
|
|||
|
||||
impl<S> std::ops::Add<PromptRouter<S>> for PromptRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
|
|
@ -207,7 +205,7 @@ where
|
|||
|
||||
impl<S> std::ops::AddAssign<PromptRouter<S>> for PromptRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
fn add_assign(&mut self, other: PromptRouter<S>) {
|
||||
self.merge(other);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ mod tool_traits;
|
|||
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
|
||||
use futures::{FutureExt, future::BoxFuture};
|
||||
use schemars::JsonSchema;
|
||||
pub use tool_traits::{AsyncTool, SyncTool, ToolBase};
|
||||
|
||||
|
|
@ -134,6 +133,7 @@ use crate::{
|
|||
tool_name_validation::validate_and_warn_tool_name,
|
||||
},
|
||||
model::{CallToolResult, Tool, ToolAnnotations},
|
||||
service::{MaybeBoxFuture, MaybeSend},
|
||||
};
|
||||
|
||||
pub struct ToolRoute<S> {
|
||||
|
|
@ -161,15 +161,15 @@ impl<S> Clone for ToolRoute<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync + 'static> ToolRoute<S> {
|
||||
impl<S: MaybeSend + 'static> ToolRoute<S> {
|
||||
pub fn new<C, A>(attr: impl Into<Tool>, call: C) -> Self
|
||||
where
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
Self {
|
||||
call: Arc::new(move |context: ToolCallContext<S>| {
|
||||
let call = call.clone();
|
||||
context.invoke(call).boxed()
|
||||
context.invoke(call)
|
||||
}),
|
||||
attr: attr.into(),
|
||||
}
|
||||
|
|
@ -178,9 +178,8 @@ impl<S: Send + Sync + 'static> ToolRoute<S> {
|
|||
where
|
||||
C: for<'a> Fn(
|
||||
ToolCallContext<'a, S>,
|
||||
) -> BoxFuture<'a, Result<CallToolResult, crate::ErrorData>>
|
||||
+ Send
|
||||
+ Sync
|
||||
) -> MaybeBoxFuture<'a, Result<CallToolResult, crate::ErrorData>>
|
||||
+ MaybeSend
|
||||
+ 'static,
|
||||
{
|
||||
Self {
|
||||
|
|
@ -199,8 +198,8 @@ pub trait IntoToolRoute<S, A> {
|
|||
|
||||
impl<S, C, A, T> IntoToolRoute<S, A> for (T, C)
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
T: Into<Tool>,
|
||||
{
|
||||
fn into_tool_route(self) -> ToolRoute<S> {
|
||||
|
|
@ -210,7 +209,7 @@ where
|
|||
|
||||
impl<S> IntoToolRoute<S, ()> for ToolRoute<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
fn into_tool_route(self) -> ToolRoute<S> {
|
||||
self
|
||||
|
|
@ -220,7 +219,7 @@ where
|
|||
pub struct ToolAttrGenerateFunctionAdapter;
|
||||
impl<S, F> IntoToolRoute<S, ToolAttrGenerateFunctionAdapter> for F
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
F: Fn() -> ToolRoute<S>,
|
||||
{
|
||||
fn into_tool_route(self) -> ToolRoute<S> {
|
||||
|
|
@ -230,14 +229,14 @@ where
|
|||
|
||||
pub trait CallToolHandlerExt<S, A>: Sized
|
||||
where
|
||||
Self: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
Self: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
fn name(self, name: impl Into<Cow<'static, str>>) -> WithToolAttr<Self, S, A>;
|
||||
}
|
||||
|
||||
impl<C, S, A> CallToolHandlerExt<S, A> for C
|
||||
where
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
fn name(self, name: impl Into<Cow<'static, str>>) -> WithToolAttr<Self, S, A> {
|
||||
WithToolAttr {
|
||||
|
|
@ -254,7 +253,7 @@ where
|
|||
|
||||
pub struct WithToolAttr<C, S, A>
|
||||
where
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
pub attr: crate::model::Tool,
|
||||
pub call: C,
|
||||
|
|
@ -263,8 +262,8 @@ where
|
|||
|
||||
impl<C, S, A> IntoToolRoute<S, A> for WithToolAttr<C, S, A>
|
||||
where
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
S: Send + Sync + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
fn into_tool_route(self) -> ToolRoute<S> {
|
||||
ToolRoute::new(self.attr, self.call)
|
||||
|
|
@ -273,7 +272,7 @@ where
|
|||
|
||||
impl<C, S, A> WithToolAttr<C, S, A>
|
||||
where
|
||||
C: CallToolHandler<S, A> + Send + Sync + Clone + 'static,
|
||||
C: CallToolHandler<S, A> + MaybeSend + Clone + 'static,
|
||||
{
|
||||
pub fn description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
|
||||
self.attr.description = Some(description.into());
|
||||
|
|
@ -328,7 +327,7 @@ impl<S> IntoIterator for ToolRouter<S> {
|
|||
|
||||
impl<S> ToolRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
@ -428,7 +427,7 @@ where
|
|||
|
||||
impl<S> std::ops::Add<ToolRouter<S>> for ToolRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
|
|
@ -440,7 +439,7 @@ where
|
|||
|
||||
impl<S> std::ops::AddAssign<ToolRouter<S>> for ToolRouter<S>
|
||||
where
|
||||
S: Send + Sync + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
fn add_assign(&mut self, other: ToolRouter<S>) {
|
||||
self.merge(other);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, pin::Pin, sync::Arc};
|
||||
use std::{borrow::Cow, future::Future, sync::Arc};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -11,6 +11,7 @@ use crate::{
|
|||
},
|
||||
model::{Icon, JsonObject, Meta, ToolAnnotations, ToolExecution},
|
||||
schemars::JsonSchema,
|
||||
service::{MaybeSend, MaybeSendFuture},
|
||||
};
|
||||
|
||||
/// Base trait to define attributes of a tool.
|
||||
|
|
@ -84,7 +85,8 @@ pub trait ToolBase {
|
|||
///
|
||||
/// Consider using [`AsyncTool`] if your workflow involves asynchronous operations.
|
||||
/// Examples are shown in [the module-level documentation][crate::handler::server::router::tool].
|
||||
pub trait SyncTool<S: Sync + Send + 'static>: ToolBase {
|
||||
#[allow(private_bounds)]
|
||||
pub trait SyncTool<S: MaybeSend + 'static>: ToolBase {
|
||||
fn invoke(service: &S, param: Self::Parameter) -> Result<Self::Output, Self::Error>;
|
||||
}
|
||||
|
||||
|
|
@ -92,11 +94,12 @@ pub trait SyncTool<S: Sync + Send + 'static>: ToolBase {
|
|||
///
|
||||
/// Consider using [`SyncTool`] if your workflow does not involve asynchronous operations.
|
||||
/// Examples are shown in [the module-level documentation][crate::handler::server::router::tool].
|
||||
pub trait AsyncTool<S: Sync + Send + 'static>: ToolBase {
|
||||
#[allow(private_bounds)]
|
||||
pub trait AsyncTool<S: MaybeSend + 'static>: ToolBase {
|
||||
fn invoke(
|
||||
service: &S,
|
||||
param: Self::Parameter,
|
||||
) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
|
||||
) -> impl Future<Output = Result<Self::Output, Self::Error>> + MaybeSendFuture;
|
||||
}
|
||||
|
||||
pub(crate) fn tool_attribute<T: ToolBase>() -> crate::model::Tool {
|
||||
|
|
@ -113,14 +116,14 @@ pub(crate) fn tool_attribute<T: ToolBase>() -> crate::model::Tool {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn sync_tool_wrapper<S: Sync + Send + 'static, T: SyncTool<S>>(
|
||||
pub(crate) fn sync_tool_wrapper<S: MaybeSend + 'static, T: SyncTool<S>>(
|
||||
service: &S,
|
||||
Parameters(params): Parameters<T::Parameter>,
|
||||
) -> Result<Json<T::Output>, ErrorData> {
|
||||
T::invoke(service, params).map(Json).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub(crate) fn sync_tool_wrapper_with_empty_params<S: Sync + Send + 'static, T: SyncTool<S>>(
|
||||
pub(crate) fn sync_tool_wrapper_with_empty_params<S: MaybeSend + 'static, T: SyncTool<S>>(
|
||||
service: &S,
|
||||
) -> Result<Json<T::Output>, ErrorData> {
|
||||
T::invoke(service, T::Parameter::default())
|
||||
|
|
@ -128,11 +131,10 @@ pub(crate) fn sync_tool_wrapper_with_empty_params<S: Sync + Send + 'static, T: S
|
|||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[expect(clippy::type_complexity)]
|
||||
pub(crate) fn async_tool_wrapper<S: Sync + Send + 'static, T: AsyncTool<S>>(
|
||||
pub(crate) fn async_tool_wrapper<S: MaybeSend + 'static, T: AsyncTool<S>>(
|
||||
service: &S,
|
||||
Parameters(params): Parameters<T::Parameter>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Json<T::Output>, ErrorData>> + Send + '_>> {
|
||||
) -> crate::service::MaybeBoxFuture<'_, Result<Json<T::Output>, ErrorData>> {
|
||||
Box::pin(async move {
|
||||
T::invoke(service, params)
|
||||
.await
|
||||
|
|
@ -141,10 +143,9 @@ pub(crate) fn async_tool_wrapper<S: Sync + Send + 'static, T: AsyncTool<S>>(
|
|||
})
|
||||
}
|
||||
|
||||
#[expect(clippy::type_complexity)]
|
||||
pub(crate) fn async_tool_wrapper_with_empty_params<S: Sync + Send + 'static, T: AsyncTool<S>>(
|
||||
pub(crate) fn async_tool_wrapper_with_empty_params<S: MaybeSend + 'static, T: AsyncTool<S>>(
|
||||
service: &S,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Json<T::Output>, ErrorData>> + Send + '_>> {
|
||||
) -> crate::service::MaybeBoxFuture<'_, Result<Json<T::Output>, ErrorData>> {
|
||||
Box::pin(async move {
|
||||
T::invoke(service, T::Parameter::default())
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ use std::{
|
|||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use futures::future::{BoxFuture, FutureExt};
|
||||
#[cfg(not(feature = "local"))]
|
||||
use futures::future::BoxFuture;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::common::{AsRequestContext, FromContextPart};
|
||||
|
|
@ -16,7 +17,7 @@ use crate::{
|
|||
RoleServer,
|
||||
handler::server::wrapper::Parameters,
|
||||
model::{CallToolRequestParams, CallToolResult, IntoContents, JsonObject},
|
||||
service::RequestContext,
|
||||
service::{MaybeBoxFuture, MaybeSend, MaybeSendFuture, RequestContext},
|
||||
};
|
||||
|
||||
/// Deserialize a JSON object into a type
|
||||
|
|
@ -146,13 +147,21 @@ pub trait CallToolHandler<S, A> {
|
|||
fn call(
|
||||
self,
|
||||
context: ToolCallContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<CallToolResult, crate::ErrorData>>;
|
||||
) -> MaybeBoxFuture<'_, Result<CallToolResult, crate::ErrorData>>;
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub type DynCallToolHandler<S> = dyn for<'s> Fn(ToolCallContext<'s, S>) -> BoxFuture<'s, Result<CallToolResult, crate::ErrorData>>
|
||||
+ Send
|
||||
+ Sync;
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
pub type DynCallToolHandler<S> =
|
||||
dyn for<'s> Fn(
|
||||
ToolCallContext<'s, S>,
|
||||
)
|
||||
-> futures::future::LocalBoxFuture<'s, Result<CallToolResult, crate::ErrorData>>;
|
||||
|
||||
// Tool-specific extractor for tool name
|
||||
pub struct ToolName(pub Cow<'static, str>);
|
||||
|
||||
|
|
@ -189,7 +198,7 @@ impl<S> FromContextPart<ToolCallContext<'_, S>> for JsonObject {
|
|||
}
|
||||
|
||||
impl<'s, S> ToolCallContext<'s, S> {
|
||||
pub fn invoke<H, A>(self, h: H) -> BoxFuture<'s, Result<CallToolResult, crate::ErrorData>>
|
||||
pub fn invoke<H, A>(self, h: H) -> MaybeBoxFuture<'s, Result<CallToolResult, crate::ErrorData>>
|
||||
where
|
||||
H: CallToolHandler<S, A>,
|
||||
{
|
||||
|
|
@ -221,31 +230,31 @@ macro_rules! impl_for {
|
|||
$(
|
||||
$Tn: for<'a> FromContextPart<ToolCallContext<'a, S>> ,
|
||||
)*
|
||||
F: FnOnce(&S, $($Tn,)*) -> BoxFuture<'_, R>,
|
||||
F: FnOnce(&S, $($Tn,)*) -> MaybeBoxFuture<'_, R>,
|
||||
|
||||
// Need RTN support here(I guess), https://github.com/rust-lang/rust/pull/138424
|
||||
// Fut: Future<Output = R> + Send + 'a,
|
||||
R: IntoCallToolResult + Send + 'static,
|
||||
S: Send + Sync + 'static,
|
||||
R: IntoCallToolResult + MaybeSendFuture + 'static,
|
||||
S: MaybeSend + 'static,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn call(
|
||||
self,
|
||||
mut context: ToolCallContext<'_, S>,
|
||||
) -> BoxFuture<'_, Result<CallToolResult, crate::ErrorData>>{
|
||||
) -> MaybeBoxFuture<'_, Result<CallToolResult, crate::ErrorData>>{
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
let service = context.service;
|
||||
let fut = self(service, $($Tn,)*);
|
||||
async move {
|
||||
Box::pin(async move {
|
||||
let result = fut.await;
|
||||
result.into_call_tool_result()
|
||||
}.boxed()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -254,28 +263,28 @@ macro_rules! impl_for {
|
|||
$(
|
||||
$Tn: for<'a> FromContextPart<ToolCallContext<'a, S>> ,
|
||||
)*
|
||||
F: FnOnce($($Tn,)*) -> Fut + Send + ,
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
R: IntoCallToolResult + Send + 'static,
|
||||
S: Send + Sync,
|
||||
F: FnOnce($($Tn,)*) -> Fut + MaybeSendFuture,
|
||||
Fut: Future<Output = R> + MaybeSendFuture + 'static,
|
||||
R: IntoCallToolResult + MaybeSendFuture + 'static,
|
||||
S: MaybeSend,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn call(
|
||||
self,
|
||||
mut context: ToolCallContext<S>,
|
||||
) -> BoxFuture<'static, Result<CallToolResult, crate::ErrorData>>{
|
||||
) -> MaybeBoxFuture<'static, Result<CallToolResult, crate::ErrorData>>{
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
let fut = self($($Tn,)*);
|
||||
async move {
|
||||
Box::pin(async move {
|
||||
let result = fut.await;
|
||||
result.into_call_tool_result()
|
||||
}.boxed()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -284,23 +293,23 @@ macro_rules! impl_for {
|
|||
$(
|
||||
$Tn: for<'a> FromContextPart<ToolCallContext<'a, S>> + ,
|
||||
)*
|
||||
F: FnOnce(&S, $($Tn,)*) -> R + Send + ,
|
||||
R: IntoCallToolResult + Send + ,
|
||||
S: Send + Sync,
|
||||
F: FnOnce(&S, $($Tn,)*) -> R + MaybeSendFuture,
|
||||
R: IntoCallToolResult + MaybeSendFuture,
|
||||
S: MaybeSend,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn call(
|
||||
self,
|
||||
mut context: ToolCallContext<S>,
|
||||
) -> BoxFuture<'static, Result<CallToolResult, crate::ErrorData>> {
|
||||
) -> MaybeBoxFuture<'static, Result<CallToolResult, crate::ErrorData>> {
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
std::future::ready(self(context.service, $($Tn,)*).into_call_tool_result()).boxed()
|
||||
Box::pin(std::future::ready(self(context.service, $($Tn,)*).into_call_tool_result()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -309,23 +318,23 @@ macro_rules! impl_for {
|
|||
$(
|
||||
$Tn: for<'a> FromContextPart<ToolCallContext<'a, S>> + ,
|
||||
)*
|
||||
F: FnOnce($($Tn,)*) -> R + Send + ,
|
||||
R: IntoCallToolResult + Send + ,
|
||||
S: Send + Sync,
|
||||
F: FnOnce($($Tn,)*) -> R + MaybeSendFuture,
|
||||
R: IntoCallToolResult + MaybeSendFuture,
|
||||
S: MaybeSend,
|
||||
{
|
||||
#[allow(unused_variables, non_snake_case, unused_mut)]
|
||||
fn call(
|
||||
self,
|
||||
mut context: ToolCallContext<S>,
|
||||
) -> BoxFuture<'static, Result<CallToolResult, crate::ErrorData>> {
|
||||
) -> MaybeBoxFuture<'static, Result<CallToolResult, crate::ErrorData>> {
|
||||
$(
|
||||
let result = $Tn::from_context_part(&mut context);
|
||||
let $Tn = match result {
|
||||
Ok(value) => value,
|
||||
Err(e) => return std::future::ready(Err(e)).boxed(),
|
||||
Err(e) => return Box::pin(std::future::ready(Err(e))),
|
||||
};
|
||||
)*
|
||||
std::future::ready(self($($Tn,)*).into_call_tool_result()).boxed()
|
||||
Box::pin(std::future::ready(self($($Tn,)*).into_call_tool_result()))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,47 @@
|
|||
use futures::{FutureExt, future::BoxFuture};
|
||||
use futures::FutureExt;
|
||||
#[cfg(not(feature = "local"))]
|
||||
use futures::future::BoxFuture;
|
||||
#[cfg(feature = "local")]
|
||||
use futures::future::LocalBoxFuture;
|
||||
use thiserror::Error;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Conditional Send helpers
|
||||
//
|
||||
// `MaybeSend` – supertrait alias: `Send + Sync` without `local`, empty with `local`
|
||||
// `MaybeSendFuture` – future bound alias: `Send` without `local`, empty with `local`
|
||||
// `MaybeBoxFuture` – boxed future type: `BoxFuture` without `local`, `LocalBoxFuture` with `local`
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(not(feature = "local"))]
|
||||
#[doc(hidden)]
|
||||
pub trait MaybeSend: Send + Sync {}
|
||||
#[cfg(not(feature = "local"))]
|
||||
impl<T: Send + Sync> MaybeSend for T {}
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
#[doc(hidden)]
|
||||
pub trait MaybeSend {}
|
||||
#[cfg(feature = "local")]
|
||||
impl<T> MaybeSend for T {}
|
||||
|
||||
#[cfg(not(feature = "local"))]
|
||||
#[doc(hidden)]
|
||||
pub trait MaybeSendFuture: Send {}
|
||||
#[cfg(not(feature = "local"))]
|
||||
impl<T: Send> MaybeSendFuture for T {}
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
#[doc(hidden)]
|
||||
pub trait MaybeSendFuture {}
|
||||
#[cfg(feature = "local")]
|
||||
impl<T> MaybeSendFuture for T {}
|
||||
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub(crate) type MaybeBoxFuture<'a, T> = BoxFuture<'a, T>;
|
||||
#[cfg(feature = "local")]
|
||||
pub(crate) type MaybeBoxFuture<'a, T> = LocalBoxFuture<'a, T>;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
use crate::model::ServerJsonRpcMessage;
|
||||
use crate::{
|
||||
|
|
@ -87,17 +128,21 @@ pub type RxJsonRpcMessage<R> = JsonRpcMessage<
|
|||
<R as ServiceRole>::PeerNot,
|
||||
>;
|
||||
|
||||
pub trait Service<R: ServiceRole>: Send + Sync + 'static {
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait Service<R: ServiceRole>: MaybeSend + 'static {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> impl Future<Output = Result<R::Resp, McpError>> + Send + '_;
|
||||
) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_;
|
||||
fn handle_notification(
|
||||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_;
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_;
|
||||
fn get_info(&self) -> R::Info;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +156,7 @@ pub trait ServiceExt<R: ServiceRole>: Service<R> + Sized {
|
|||
fn serve<T, E, A>(
|
||||
self,
|
||||
transport: T,
|
||||
) -> impl Future<Output = Result<RunningService<R, Self>, R::InitializeError>> + Send
|
||||
) -> impl Future<Output = Result<RunningService<R, Self>, R::InitializeError>> + MaybeSendFuture
|
||||
where
|
||||
T: IntoTransport<R, E, A>,
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
|
|
@ -123,7 +168,7 @@ pub trait ServiceExt<R: ServiceRole>: Service<R> + Sized {
|
|||
self,
|
||||
transport: T,
|
||||
ct: CancellationToken,
|
||||
) -> impl Future<Output = Result<RunningService<R, Self>, R::InitializeError>> + Send
|
||||
) -> impl Future<Output = Result<RunningService<R, Self>, R::InitializeError>> + MaybeSendFuture
|
||||
where
|
||||
T: IntoTransport<R, E, A>,
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
|
|
@ -135,7 +180,7 @@ impl<R: ServiceRole> Service<R> for Box<dyn DynService<R>> {
|
|||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> impl Future<Output = Result<R::Resp, McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_ {
|
||||
DynService::handle_request(self.as_ref(), request, context)
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +188,7 @@ impl<R: ServiceRole> Service<R> for Box<dyn DynService<R>> {
|
|||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
DynService::handle_notification(self.as_ref(), notification, context)
|
||||
}
|
||||
|
||||
|
|
@ -152,17 +197,21 @@ impl<R: ServiceRole> Service<R> for Box<dyn DynService<R>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait DynService<R: ServiceRole>: Send + Sync {
|
||||
#[allow(
|
||||
private_bounds,
|
||||
reason = "MaybeSend is a sealed conditional Send + Sync alias"
|
||||
)]
|
||||
pub trait DynService<R: ServiceRole>: MaybeSend {
|
||||
fn handle_request(
|
||||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> BoxFuture<'_, Result<R::Resp, McpError>>;
|
||||
) -> MaybeBoxFuture<'_, Result<R::Resp, McpError>>;
|
||||
fn handle_notification(
|
||||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> BoxFuture<'_, Result<(), McpError>>;
|
||||
) -> MaybeBoxFuture<'_, Result<(), McpError>>;
|
||||
fn get_info(&self) -> R::Info;
|
||||
}
|
||||
|
||||
|
|
@ -171,14 +220,14 @@ impl<R: ServiceRole, S: Service<R>> DynService<R> for S {
|
|||
&self,
|
||||
request: R::PeerReq,
|
||||
context: RequestContext<R>,
|
||||
) -> BoxFuture<'_, Result<R::Resp, McpError>> {
|
||||
) -> MaybeBoxFuture<'_, Result<R::Resp, McpError>> {
|
||||
Box::pin(self.handle_request(request, context))
|
||||
}
|
||||
fn handle_notification(
|
||||
&self,
|
||||
notification: R::PeerNot,
|
||||
context: NotificationContext<R>,
|
||||
) -> BoxFuture<'_, Result<(), McpError>> {
|
||||
) -> MaybeBoxFuture<'_, Result<(), McpError>> {
|
||||
Box::pin(self.handle_notification(notification, context))
|
||||
}
|
||||
fn get_info(&self) -> R::Info {
|
||||
|
|
@ -639,6 +688,28 @@ where
|
|||
serve_inner(service, transport.into_transport(), peer, peer_rx, ct)
|
||||
}
|
||||
|
||||
/// Spawn a task that may hold `!Send` state when the `local` feature is active.
|
||||
///
|
||||
/// Without the `local` feature this is `tokio::spawn` (requires `Future: Send + 'static`).
|
||||
/// With `local` it uses `tokio::task::spawn_local` (requires only `Future: 'static`).
|
||||
#[cfg(not(feature = "local"))]
|
||||
fn spawn_service_task<F>(future: F) -> tokio::task::JoinHandle<F::Output>
|
||||
where
|
||||
F: Future + Send + 'static,
|
||||
F::Output: Send + 'static,
|
||||
{
|
||||
tokio::spawn(future)
|
||||
}
|
||||
|
||||
#[cfg(feature = "local")]
|
||||
fn spawn_service_task<F>(future: F) -> tokio::task::JoinHandle<F::Output>
|
||||
where
|
||||
F: Future + 'static,
|
||||
F::Output: 'static,
|
||||
{
|
||||
tokio::task::spawn_local(future)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
fn serve_inner<R, S, T>(
|
||||
service: S,
|
||||
|
|
@ -674,7 +745,7 @@ where
|
|||
let serve_loop_ct = ct.child_token();
|
||||
let peer_return: Peer<R> = peer.clone();
|
||||
let current_span = tracing::Span::current();
|
||||
let handle = tokio::spawn(async move {
|
||||
let handle = spawn_service_task(async move {
|
||||
let mut transport = transport.into_transport();
|
||||
let mut batch_messages = VecDeque::<RxJsonRpcMessage<R>>::new();
|
||||
let mut send_task_set = tokio::task::JoinSet::<SendTaskResult>::new();
|
||||
|
|
@ -860,7 +931,7 @@ where
|
|||
extensions,
|
||||
};
|
||||
let current_span = tracing::Span::current();
|
||||
tokio::spawn(async move {
|
||||
spawn_service_task(async move {
|
||||
let result = service
|
||||
.handle_request(request, context)
|
||||
.await;
|
||||
|
|
@ -907,7 +978,7 @@ where
|
|||
extensions,
|
||||
};
|
||||
let current_span = tracing::Span::current();
|
||||
tokio::spawn(async move {
|
||||
spawn_service_task(async move {
|
||||
let result = service.handle_notification(notification, context).await;
|
||||
if let Err(error) = result {
|
||||
tracing::warn!(%error, "Error sending notification");
|
||||
|
|
|
|||
|
|
@ -162,7 +162,8 @@ impl<S: Service<RoleClient>> ServiceExt<RoleClient> for S {
|
|||
self,
|
||||
transport: T,
|
||||
ct: CancellationToken,
|
||||
) -> impl Future<Output = Result<RunningService<RoleClient, Self>, ClientInitializeError>> + Send
|
||||
) -> impl Future<Output = Result<RunningService<RoleClient, Self>, ClientInitializeError>>
|
||||
+ MaybeSendFuture
|
||||
where
|
||||
T: IntoTransport<RoleClient, E, A>,
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
|
|
|
|||
|
|
@ -95,7 +95,8 @@ impl<S: Service<RoleServer>> ServiceExt<RoleServer> for S {
|
|||
self,
|
||||
transport: T,
|
||||
ct: CancellationToken,
|
||||
) -> impl Future<Output = Result<RunningService<RoleServer, Self>, ServerInitializeError>> + Send
|
||||
) -> impl Future<Output = Result<RunningService<RoleServer, Self>, ServerInitializeError>>
|
||||
+ MaybeSendFuture
|
||||
where
|
||||
T: IntoTransport<RoleServer, E, A>,
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{future::poll_fn, marker::PhantomData};
|
|||
use tower_service::Service as TowerService;
|
||||
|
||||
use super::NotificationContext;
|
||||
use crate::service::{RequestContext, Service, ServiceRole};
|
||||
use crate::service::{MaybeSendFuture, RequestContext, Service, ServiceRole};
|
||||
|
||||
pub struct TowerHandler<S, R: ServiceRole> {
|
||||
pub service: S,
|
||||
|
|
@ -44,7 +44,7 @@ where
|
|||
&self,
|
||||
_notification: R::PeerNot,
|
||||
_context: NotificationContext<R>,
|
||||
) -> impl Future<Output = Result<(), crate::ErrorData>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), crate::ErrorData>> + MaybeSendFuture + '_ {
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
//! | transport | client | server |
|
||||
//! |:-: |:-: |:-: |
|
||||
//! | std IO | [`child_process::TokioChildProcess`] | [`io::stdio`] |
|
||||
//! | streamable http | [`streamable_http_client::StreamableHttpClientTransport`] | [`streamable_http_server::StreamableHttpService`] |
|
||||
//! | streamable http | [`streamable_http_client::StreamableHttpClientTransport`] | `streamable_http_server::StreamableHttpService` |
|
||||
//!
|
||||
//!## Helper Transport Types
|
||||
//! Thers are several helper transport types that can help you to create transport quickly.
|
||||
|
|
@ -107,7 +107,7 @@ pub use auth::{
|
|||
// pub mod ws;
|
||||
#[cfg(feature = "transport-streamable-http-server-session")]
|
||||
pub mod streamable_http_server;
|
||||
#[cfg(feature = "transport-streamable-http-server")]
|
||||
#[cfg(all(feature = "transport-streamable-http-server", not(feature = "local")))]
|
||||
pub use streamable_http_server::tower::{StreamableHttpServerConfig, StreamableHttpService};
|
||||
|
||||
#[cfg(feature = "transport-streamable-http-client")]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub mod session;
|
||||
#[cfg(feature = "transport-streamable-http-server")]
|
||||
#[cfg(all(feature = "transport-streamable-http-server", not(feature = "local")))]
|
||||
pub mod tower;
|
||||
pub use session::{SessionId, SessionManager};
|
||||
#[cfg(feature = "transport-streamable-http-server")]
|
||||
#[cfg(all(feature = "transport-streamable-http-server", not(feature = "local")))]
|
||||
pub use tower::{StreamableHttpServerConfig, StreamableHttpService};
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub mod never;
|
|||
|
||||
/// Controls how MCP sessions are created, validated, and closed.
|
||||
///
|
||||
/// The [`StreamableHttpService`](super::StreamableHttpService) calls into this
|
||||
/// The `StreamableHttpService` calls into this
|
||||
/// trait for every HTTP request that carries (or should carry) a session ID.
|
||||
///
|
||||
/// See the [module-level docs](self) for background on sessions.
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ impl<S, M> Clone for StreamableHttpService<S, M> {
|
|||
impl<RequestBody, S, M> tower_service::Service<Request<RequestBody>> for StreamableHttpService<S, M>
|
||||
where
|
||||
RequestBody: Body + Send + 'static,
|
||||
S: crate::Service<RoleServer>,
|
||||
S: crate::Service<RoleServer> + Send + 'static,
|
||||
M: SessionManager,
|
||||
RequestBody::Error: Display,
|
||||
RequestBody::Data: Send + 'static,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ use std::{
|
|||
use rmcp::service::NotificationContext;
|
||||
#[cfg(feature = "client")]
|
||||
use rmcp::{ClientHandler, RoleClient};
|
||||
use rmcp::{ErrorData as McpError, RoleServer, ServerHandler, model::*, service::RequestContext};
|
||||
use rmcp::{
|
||||
ErrorData as McpError, RoleServer, ServerHandler,
|
||||
model::*,
|
||||
service::{MaybeSendFuture, RequestContext},
|
||||
};
|
||||
#[cfg(feature = "client")]
|
||||
use serde_json::json;
|
||||
use tokio::sync::Notify;
|
||||
|
|
@ -85,7 +89,7 @@ impl ClientHandler for TestClientHandler {
|
|||
&self,
|
||||
params: LoggingMessageNotificationParam,
|
||||
_context: NotificationContext<RoleClient>,
|
||||
) -> impl Future<Output = ()> + Send + '_ {
|
||||
) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
|
||||
let receive_signal = self.receive_signal.clone();
|
||||
let received_messages = self.received_messages.clone();
|
||||
|
||||
|
|
@ -116,7 +120,7 @@ impl ServerHandler for TestServer {
|
|||
&self,
|
||||
request: SetLevelRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), McpError>> + Send + '_ {
|
||||
) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
|
||||
let peer = context.peer;
|
||||
async move {
|
||||
let (data, logger) = match request.level {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// cargo test --features "server client" --package rmcp test_client_initialization
|
||||
#![cfg(feature = "client")]
|
||||
#![cfg(all(feature = "client", not(feature = "local")))]
|
||||
|
||||
mod common;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
//cargo test --test test_close_connection --features "client server"
|
||||
|
||||
mod common;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use http::{HeaderName, HeaderValue};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::sync::Arc;
|
||||
|
||||
use rmcp::{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// cargo test --features "server client" --package rmcp test_logging
|
||||
#![cfg(not(feature = "local"))]
|
||||
mod common;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
//cargo test --test test_message_protocol --features "client server"
|
||||
#![cfg(not(feature = "local"))]
|
||||
|
||||
mod common;
|
||||
use common::handlers::{TestClientHandler, TestServer};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::sync::Arc;
|
||||
|
||||
use rmcp::{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use futures::StreamExt;
|
||||
use rmcp::{
|
||||
ClientHandler, Peer, RoleServer, ServerHandler, ServiceExt,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
//cargo test --test test_prompt_macros --features "client server"
|
||||
#![allow(dead_code)]
|
||||
use std::sync::Arc;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use futures::future::BoxFuture;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
mod common;
|
||||
|
||||
use anyhow::Result;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// cargo test --features "client" --package rmcp -- server_init
|
||||
#![cfg(feature = "client")]
|
||||
#![cfg(all(feature = "client", not(feature = "local")))]
|
||||
mod common;
|
||||
|
||||
use common::handlers::TestServer;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
/// Tests for concurrent SSE stream handling (shadow channels)
|
||||
///
|
||||
/// These tests verify that multiple GET SSE streams on the same session
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use rmcp::transport::streamable_http_server::{
|
||||
StreamableHttpServerConfig, StreamableHttpService, session::local::LocalSessionManager,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::time::Duration;
|
||||
|
||||
use rmcp::transport::streamable_http_server::{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#![cfg(all(
|
||||
feature = "transport-streamable-http-client",
|
||||
feature = "transport-streamable-http-client-reqwest",
|
||||
feature = "transport-streamable-http-server"
|
||||
feature = "transport-streamable-http-server",
|
||||
not(feature = "local")
|
||||
))]
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
//! Tests for task support validation in tool calls.
|
||||
//!
|
||||
//! Verifies that the server correctly validates `execution.taskSupport` settings
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
//! Test tool macros, including documentation for generated fns.
|
||||
|
||||
//cargo test --test test_tool_macros --features "client server"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use futures::future::BoxFuture;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use rmcp::{
|
||||
ServiceExt,
|
||||
service::QuitReason,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg(not(feature = "local"))]
|
||||
use std::process::Stdio;
|
||||
|
||||
use rmcp::{
|
||||
|
|
|
|||
Loading…
Reference in a new issue