Skip to main content

rmcp/handler/
server.rs

1// Sampling/Roots/Logging are SEP-2577-deprecated; internal references are expected.
2#![expect(deprecated)]
3use std::{borrow::Cow, sync::Arc};
4
5use crate::{
6    error::ErrorData as McpError,
7    model::*,
8    service::{
9        MaybeSendFuture, NotificationContext, RequestContext, RoleServer, Service, ServiceRole,
10        SubscriptionContext, negotiate_protocol_version, uses_legacy_lifecycle,
11    },
12};
13
14pub mod common;
15pub mod prompt;
16mod resource;
17pub mod router;
18pub mod tool;
19pub mod tool_name_validation;
20pub mod wrapper;
21
22/// SEP-2663: gate `tasks/*` methods on the client's declared tasks-extension
23/// capability.
24///
25/// - If the server does not advertise the tasks extension, the methods are
26///   simply unimplemented: `-32601` Method not found.
27/// - If the server advertises it but the client did not declare it (either in
28///   the request's `_meta` per-request capabilities or, for session-mode
29///   peers, at `initialize` time), the spec requires `-32021` Missing
30///   Required Client Capability with the required capability in `data`.
31fn validate_tasks_capability<M: ConstString, H: ServerHandler>(
32    handler: &H,
33    context: &RequestContext<RoleServer>,
34) -> Result<(), McpError> {
35    if !handler.get_info().capabilities.supports_tasks() {
36        return Err(McpError::method_not_found::<M>());
37    }
38    let client_declared = context
39        .client_capabilities()
40        .is_some_and(|caps| caps.supports_tasks());
41    if client_declared {
42        Ok(())
43    } else {
44        Err(McpError::missing_required_client_capability(
45            ClientCapabilities::builder().enable_tasks().build(),
46        ))
47    }
48}
49
50impl<H: ServerHandler> Service<RoleServer> for H {
51    async fn handle_request(
52        &self,
53        request: <RoleServer as ServiceRole>::PeerReq,
54        context: RequestContext<RoleServer>,
55    ) -> Result<<RoleServer as ServiceRole>::Resp, McpError> {
56        // `context` is moved into the dispatch below, so read the negotiated version first.
57        let protocol_version = context.protocol_version();
58        // SEP-2322 (`resultType` discriminator, MRTR) exists from 2026-07-28.
59        let sep_2322_supported = protocol_version
60            .as_ref()
61            .is_some_and(|v| v.as_str() >= ProtocolVersion::V_2026_07_28.as_str());
62        let requested_version = context.meta.protocol_version();
63        let uses_inline_negotiation = !matches!(&request, ClientRequest::InitializeRequest(_));
64        if uses_inline_negotiation && let Some(requested_version) = requested_version.as_ref() {
65            let supported_versions = self.supported_protocol_versions();
66            if !supported_versions.contains(requested_version) {
67                return Err(McpError::unsupported_protocol_version(
68                    requested_version.clone(),
69                    &supported_versions,
70                ));
71            }
72        }
73        // Self-contained metadata is required only when the request itself uses
74        // the inline lifecycle: a discover opener, a session that started without
75        // `initialize`, or a request that declares 2026-07-28+ in its own _meta.
76        // Sessions that negotiated via `initialize` (or `serve_directly`) keep the
77        // session model and may omit per-request metadata.
78        let requires_request_metadata = uses_inline_negotiation
79            && (matches!(&request, ClientRequest::DiscoverRequest(_))
80                || context.peer.request_metadata_required()
81                || requested_version.as_ref().is_some_and(|version| {
82                    version.as_str() >= ProtocolVersion::V_2026_07_28.as_str()
83                }));
84        if requires_request_metadata {
85            // Inline lifecycle requests are defined by the 2026-07-28 protocol.
86            // Validate that lifecycle contract even when a request selects an
87            // older application protocol version.
88            let missing = context
89                .meta
90                .missing_required_keys(&ProtocolVersion::V_2026_07_28);
91            if !missing.is_empty() {
92                return Err(McpError::invalid_params(
93                    format!(
94                        "request _meta is missing or has malformed required fields: {}",
95                        missing.join(", ")
96                    ),
97                    None,
98                ));
99            }
100        }
101        let legacy_request =
102            uses_legacy_lifecycle(protocol_version.as_ref(), requires_request_metadata);
103        let result = match request {
104            ClientRequest::InitializeRequest(request) => self
105                .initialize(request.params, context)
106                .await
107                .map(ServerResult::InitializeResult),
108            ClientRequest::DiscoverRequest(_request) => self
109                .discover(context)
110                .await
111                .map(ServerResult::DiscoverResult),
112            ClientRequest::PingRequest(_request) => {
113                if !legacy_request {
114                    Err(McpError::method_not_found::<PingRequestMethod>())
115                } else {
116                    self.ping(context).await.map(ServerResult::empty)
117                }
118            }
119            ClientRequest::CompleteRequest(request) => self
120                .complete(request.params, context)
121                .await
122                .map(ServerResult::CompleteResult),
123            ClientRequest::SetLevelRequest(request) => self
124                .set_level(request.params, context)
125                .await
126                .map(ServerResult::empty),
127            ClientRequest::GetPromptRequest(request) => self
128                .get_prompt(request.params, context)
129                .await
130                .map(ServerResult::from),
131            ClientRequest::ListPromptsRequest(request) => self
132                .list_prompts(request.params, context)
133                .await
134                .map(ServerResult::ListPromptsResult),
135            ClientRequest::ListResourcesRequest(request) => self
136                .list_resources(request.params, context)
137                .await
138                .map(ServerResult::ListResourcesResult),
139            ClientRequest::ListResourceTemplatesRequest(request) => self
140                .list_resource_templates(request.params, context)
141                .await
142                .map(ServerResult::ListResourceTemplatesResult),
143            ClientRequest::ReadResourceRequest(request) => self
144                .read_resource(request.params, context)
145                .await
146                .map(ServerResult::from),
147            ClientRequest::SubscriptionsListenRequest(request) => {
148                if legacy_request {
149                    Err(McpError::method_not_found::<SubscriptionsListenRequestMethod>())
150                } else {
151                    let requested = request.params.notifications;
152                    let Some(candidate) = self.accepted_subscription_filter(&requested) else {
153                        return Err(
154                            McpError::method_not_found::<SubscriptionsListenRequestMethod>(),
155                        );
156                    };
157                    let server_info = self.get_info();
158                    let advertised = requested.supported_by(&server_info.capabilities);
159                    let handler_accepted = requested.intersection(&candidate);
160                    let accepted = handler_accepted.intersection(&advertised);
161                    if accepted != handler_accepted {
162                        tracing::debug!(
163                            requested_resource_count = requested
164                                .resource_subscriptions
165                                .as_ref()
166                                .map_or(0, Vec::len),
167                            accepted_resource_count =
168                                accepted.resource_subscriptions.as_ref().map_or(0, Vec::len),
169                            "subscription filter reduced to advertised server capabilities"
170                        );
171                    }
172                    let server_implementation = server_info.server_info;
173                    let subscription_id = context.id.clone();
174                    let subscription =
175                        SubscriptionContext::establish(context, requested, accepted).await?;
176                    // The 2026-07-28 schema defines a final result for graceful
177                    // server teardown; explicit stdio cancellation remains a notification.
178                    self.listen(subscription).await.map(|()| {
179                        let mut result = SubscriptionsListenResult::complete(subscription_id);
180                        result.meta.set_server_info(server_implementation);
181                        ServerResult::SubscriptionsListenResult(result)
182                    })
183                }
184            }
185            ClientRequest::SubscribeRequest(request) => {
186                if !legacy_request {
187                    Err(McpError::method_not_found::<SubscribeRequestMethod>())
188                } else {
189                    self.subscribe(request.params, context)
190                        .await
191                        .map(ServerResult::empty)
192                }
193            }
194            ClientRequest::UnsubscribeRequest(request) => {
195                if !legacy_request {
196                    Err(McpError::method_not_found::<UnsubscribeRequestMethod>())
197                } else {
198                    self.unsubscribe(request.params, context)
199                        .await
200                        .map(ServerResult::empty)
201                }
202            }
203            ClientRequest::CallToolRequest(request) => {
204                let client_declared_tasks = context
205                    .client_capabilities()
206                    .is_some_and(|caps| caps.supports_tasks());
207                let response = self.call_tool(request.params, context).await?;
208                // SEP-2663: the server MUST NOT return CreateTaskResult unless
209                // the request declared the tasks extension capability. Guard
210                // against handlers that fail to check before materializing a
211                // task; such clients cannot parse a task handle.
212                if matches!(response, CallToolResponse::Task(_)) && !client_declared_tasks {
213                    return Err(McpError::missing_required_client_capability(
214                        ClientCapabilities::builder().enable_tasks().build(),
215                    ));
216                }
217                Ok(ServerResult::from(response))
218            }
219            ClientRequest::ListToolsRequest(request) => self
220                .list_tools(request.params, context)
221                .await
222                .map(ServerResult::ListToolsResult),
223            ClientRequest::CustomRequest(request) => self
224                .on_custom_request(request, context)
225                .await
226                .map(ServerResult::CustomResult),
227            ClientRequest::GetTaskRequest(request) => {
228                validate_tasks_capability::<GetTaskMethod, _>(self, &context)?;
229                self.get_task(request.params, context)
230                    .await
231                    .map(ServerResult::GetTaskResult)
232            }
233            ClientRequest::UpdateTaskRequest(request) => {
234                validate_tasks_capability::<UpdateTaskMethod, _>(self, &context)?;
235                self.update_task(request.params, context)
236                    .await
237                    .map(ServerResult::task_ack)
238            }
239            ClientRequest::CancelTaskRequest(request) => {
240                validate_tasks_capability::<CancelTaskMethod, _>(self, &context)?;
241                self.cancel_task(request.params, context)
242                    .await
243                    .map(ServerResult::task_ack)
244            }
245        };
246        let result = result.and_then(|mut result| {
247            if matches!(result, ServerResult::InputRequiredResult(_)) && !sep_2322_supported {
248                Err(McpError::invalid_request(
249                    "InputRequiredResult requires negotiated protocol version 2026-07-28 or newer",
250                    None,
251                ))
252            } else {
253                // Peers on protocol versions older than 2026-07-28 keep the
254                // legacy wire shape without `resultType: "complete"`.
255                if !sep_2322_supported {
256                    result.strip_result_type_for_legacy_peer();
257                }
258                Ok(result)
259            }
260        });
261
262        // SEP-2164: peers negotiating 2026-07-28+ get the standard INVALID_PARAMS code for
263        // resource-not-found; older peers keep RESOURCE_NOT_FOUND. ISO `YYYY-MM-DD` versions
264        // compare lexically the same as chronologically.
265        let use_invalid_params =
266            protocol_version.is_some_and(|v| v.as_str() >= ProtocolVersion::V_2026_07_28.as_str());
267        result.map_err(|mut error| {
268            if use_invalid_params && error.code == ErrorCode::RESOURCE_NOT_FOUND {
269                error.code = ErrorCode::INVALID_PARAMS;
270            }
271            error
272        })
273    }
274
275    async fn handle_notification(
276        &self,
277        notification: <RoleServer as ServiceRole>::PeerNot,
278        context: NotificationContext<RoleServer>,
279    ) -> Result<(), McpError> {
280        match notification {
281            ClientNotification::CancelledNotification(notification) => {
282                self.on_cancelled(notification.params, context).await
283            }
284            ClientNotification::ProgressNotification(notification) => {
285                self.on_progress(notification.params, context).await
286            }
287            ClientNotification::InitializedNotification(_notification) => {
288                self.on_initialized(context).await
289            }
290            ClientNotification::RootsListChangedNotification(_notification) => {
291                self.on_roots_list_changed(context).await
292            }
293            ClientNotification::CustomNotification(notification) => {
294                self.on_custom_notification(notification, context).await
295            }
296        };
297        Ok(())
298    }
299
300    fn get_info(&self) -> <RoleServer as ServiceRole>::Info {
301        self.get_info()
302    }
303}
304
305macro_rules! server_handler_methods {
306    () => {
307        fn ping(
308            &self,
309            context: RequestContext<RoleServer>,
310        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
311            std::future::ready(Ok(()))
312        }
313        // handle requests
314        fn initialize(
315            &self,
316            request: InitializeRequestParams,
317            context: RequestContext<RoleServer>,
318        ) -> impl Future<Output = Result<InitializeResult, McpError>> + MaybeSendFuture + '_ {
319            context.peer.set_peer_info(request.clone());
320            let mut info = self.get_info();
321            info.protocol_version = negotiate_protocol_version(
322                &request.protocol_version,
323                info.protocol_version,
324            );
325            std::future::ready(Ok(info))
326        }
327        /// Return the protocol versions supported by this server.
328        fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
329            Cow::Borrowed(ProtocolVersion::KNOWN_VERSIONS)
330        }
331        /// Return this server's discovery information.
332        fn discover(
333            &self,
334            context: RequestContext<RoleServer>,
335        ) -> impl Future<Output = Result<DiscoverResult, McpError>> + MaybeSendFuture + '_ {
336            std::future::ready(Ok(DiscoverResult::from_server_info(
337                self.supported_protocol_versions().into_owned(),
338                self.get_info(),
339            )))
340        }
341        fn complete(
342            &self,
343            request: CompleteRequestParams,
344            context: RequestContext<RoleServer>,
345        ) -> impl Future<Output = Result<CompleteResult, McpError>> + MaybeSendFuture + '_ {
346            std::future::ready(Ok(CompleteResult::default()))
347        }
348        fn set_level(
349            &self,
350            request: SetLevelRequestParams,
351            context: RequestContext<RoleServer>,
352        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
353            std::future::ready(Err(McpError::method_not_found::<SetLevelRequestMethod>()))
354        }
355        fn get_prompt(
356            &self,
357            request: GetPromptRequestParams,
358            context: RequestContext<RoleServer>,
359        ) -> impl Future<Output = Result<GetPromptResponse, McpError>> + MaybeSendFuture + '_ {
360            std::future::ready(Err(McpError::method_not_found::<GetPromptRequestMethod>()))
361        }
362        fn list_prompts(
363            &self,
364            request: Option<PaginatedRequestParams>,
365            context: RequestContext<RoleServer>,
366        ) -> impl Future<Output = Result<ListPromptsResult, McpError>> + MaybeSendFuture + '_ {
367            std::future::ready(Ok(ListPromptsResult::default()))
368        }
369        fn list_resources(
370            &self,
371            request: Option<PaginatedRequestParams>,
372            context: RequestContext<RoleServer>,
373        ) -> impl Future<Output = Result<ListResourcesResult, McpError>> + MaybeSendFuture + '_ {
374            std::future::ready(Ok(ListResourcesResult::default()))
375        }
376        fn list_resource_templates(
377            &self,
378            request: Option<PaginatedRequestParams>,
379            context: RequestContext<RoleServer>,
380        ) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>>
381               + MaybeSendFuture
382               + '_ {
383            std::future::ready(Ok(ListResourceTemplatesResult::default()))
384        }
385        fn read_resource(
386            &self,
387            request: ReadResourceRequestParams,
388            context: RequestContext<RoleServer>,
389        ) -> impl Future<Output = Result<ReadResourceResponse, McpError>> + MaybeSendFuture + '_ {
390            std::future::ready(Err(
391                McpError::method_not_found::<ReadResourceRequestMethod>(),
392            ))
393        }
394        /// Return the subset of a requested notification filter this server accepts.
395        ///
396        /// Returning `None` leaves `subscriptions/listen` unimplemented. The SDK
397        /// intersects the returned filter with both `requested` and the notification
398        /// capabilities advertised by [`Self::get_info`] before acknowledging it.
399        /// Categories that were not requested or advertised are always removed.
400        fn accepted_subscription_filter(
401            &self,
402            requested: &SubscriptionFilter,
403        ) -> Option<SubscriptionFilter> {
404            None
405        }
406        /// Run one established subscription until it is cancelled or closed gracefully.
407        ///
408        /// The SDK sends the acknowledgment before invoking this method. Returning
409        /// `Ok(())` sends the final [`SubscriptionsListenResult`] defined by the
410        /// 2026-07-28 schema, marking graceful server teardown. Explicit
411        /// stdio cancellation uses `notifications/cancelled` instead.
412        fn listen(
413            &self,
414            context: SubscriptionContext,
415        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
416            async move {
417                context.cancelled().await;
418                Ok(())
419            }
420        }
421        #[deprecated(
422            note = "resources/subscribe is legacy-only; implement accepted_subscription_filter and listen for protocol version 2026-07-28"
423        )]
424        fn subscribe(
425            &self,
426            request: SubscribeRequestParams,
427            context: RequestContext<RoleServer>,
428        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
429            std::future::ready(Err(McpError::method_not_found::<SubscribeRequestMethod>()))
430        }
431        #[deprecated(
432            note = "resources/unsubscribe is legacy-only; subscriptions/listen is cancelled through its request lifecycle"
433        )]
434        fn unsubscribe(
435            &self,
436            request: UnsubscribeRequestParams,
437            context: RequestContext<RoleServer>,
438        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
439            std::future::ready(Err(
440                McpError::method_not_found::<UnsubscribeRequestMethod>(),
441            ))
442        }
443        /// Handle a `tools/call` request from a client.
444        ///
445        /// # Choosing a return value
446        ///
447        /// MCP distinguishes two failure modes; the API forces you to pick
448        /// the right one explicitly because they reach the caller's UI very
449        /// differently:
450        ///
451        /// - `Ok(`[`CallToolResult::error`]`(...))` — the tool ran (or tried
452        ///   to) and produced a failure the caller should see. The
453        ///   `content` you supply is rendered in the caller's MCP client,
454        ///   so the user gets your message. **This is the right return
455        ///   value for almost every "the tool didn't work" path** — empty
456        ///   results, validation failures the user can fix, downstream
457        ///   service unavailability, etc.
458        ///
459        /// - `Err(`[`McpError`]`)` — a JSON-RPC protocol error. Use this
460        ///   only when the request itself is unroutable: unknown tool
461        ///   ([`ErrorCode::METHOD_NOT_FOUND`]), malformed request shape that
462        ///   cannot be treated as a valid `tools/call`, or a server-internal
463        ///   failure that means the server cannot serve any request right now
464        ///   ([`ErrorCode::INTERNAL_ERROR`], `-32603`). MCP clients
465        ///   typically render protocol errors opaquely; **the caller will
466        ///   not see your message** — they see something like "Tool result
467        ///   missing due to internal error". If you want the caller to read
468        ///   your error, use `Ok(CallToolResult::error(...))`.
469        ///
470        /// See [`CallToolResult::error`] for a worked example.
471        fn call_tool(
472            &self,
473            request: CallToolRequestParams,
474            context: RequestContext<RoleServer>,
475        ) -> impl Future<Output = Result<CallToolResponse, McpError>> + MaybeSendFuture + '_ {
476            std::future::ready(Err(McpError::method_not_found::<CallToolRequestMethod>()))
477        }
478        fn list_tools(
479            &self,
480            request: Option<PaginatedRequestParams>,
481            context: RequestContext<RoleServer>,
482        ) -> impl Future<Output = Result<ListToolsResult, McpError>> + MaybeSendFuture + '_ {
483            std::future::ready(Ok(ListToolsResult::default()))
484        }
485        /// Get a tool definition by name.
486        ///
487        /// The default implementation returns `None`, which bypasses validation.
488        /// When using `#[tool_handler]`, this method is automatically implemented.
489        fn get_tool(&self, _name: &str) -> Option<Tool> {
490            None
491        }
492        fn on_custom_request(
493            &self,
494            request: CustomRequest,
495            context: RequestContext<RoleServer>,
496        ) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
497            let CustomRequest { method, .. } = request;
498            let _ = context;
499            std::future::ready(Err(McpError::new(
500                ErrorCode::METHOD_NOT_FOUND,
501                method,
502                None,
503            )))
504        }
505
506        fn on_cancelled(
507            &self,
508            notification: CancelledNotificationParam,
509            context: NotificationContext<RoleServer>,
510        ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
511            std::future::ready(())
512        }
513        fn on_progress(
514            &self,
515            notification: ProgressNotificationParam,
516            context: NotificationContext<RoleServer>,
517        ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
518            std::future::ready(())
519        }
520        fn on_initialized(
521            &self,
522            context: NotificationContext<RoleServer>,
523        ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
524            tracing::info!("client initialized");
525            std::future::ready(())
526        }
527        fn on_roots_list_changed(
528            &self,
529            context: NotificationContext<RoleServer>,
530        ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
531            std::future::ready(())
532        }
533        fn on_custom_notification(
534            &self,
535            notification: CustomNotification,
536            context: NotificationContext<RoleServer>,
537        ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
538            let _ = (notification, context);
539            std::future::ready(())
540        }
541
542        fn get_info(&self) -> ServerInfo {
543            ServerInfo::default()
544        }
545
546        /// SEP-2663 `tasks/get`: return the current [`DetailedTask`] state.
547        fn get_task(
548            &self,
549            request: GetTaskParams,
550            context: RequestContext<RoleServer>,
551        ) -> impl Future<Output = Result<GetTaskResult, McpError>> + MaybeSendFuture + '_ {
552            let _ = (request, context);
553            std::future::ready(Err(McpError::method_not_found::<GetTaskMethod>()))
554        }
555
556        /// SEP-2663 `tasks/update`: accept responses to outstanding in-task
557        /// input requests. Returns an empty acknowledgement on success.
558        fn update_task(
559            &self,
560            request: UpdateTaskParams,
561            context: RequestContext<RoleServer>,
562        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
563            let _ = (request, context);
564            std::future::ready(Err(McpError::method_not_found::<UpdateTaskMethod>()))
565        }
566
567        /// SEP-2663 `tasks/cancel`: cooperative cancellation. Returns an empty
568        /// acknowledgement; the task's observable status may lag.
569        fn cancel_task(
570            &self,
571            request: CancelTaskParams,
572            context: RequestContext<RoleServer>,
573        ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
574            let _ = (request, context);
575            std::future::ready(Err(McpError::method_not_found::<CancelTaskMethod>()))
576        }
577    };
578}
579
580#[allow(unused_variables)]
581#[cfg(not(feature = "local"))]
582pub trait ServerHandler: Sized + Send + Sync + 'static {
583    server_handler_methods!();
584}
585
586#[allow(unused_variables)]
587#[cfg(feature = "local")]
588pub trait ServerHandler: Sized + 'static {
589    server_handler_methods!();
590}
591
592macro_rules! impl_server_handler_for_wrapper {
593    ($wrapper:ident) => {
594        impl<T: ServerHandler> ServerHandler for $wrapper<T> {
595            fn ping(
596                &self,
597                context: RequestContext<RoleServer>,
598            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
599                (**self).ping(context)
600            }
601
602            fn initialize(
603                &self,
604                request: InitializeRequestParams,
605                context: RequestContext<RoleServer>,
606            ) -> impl Future<Output = Result<InitializeResult, McpError>> + MaybeSendFuture + '_ {
607                (**self).initialize(request, context)
608            }
609
610            fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
611                (**self).supported_protocol_versions()
612            }
613
614            fn discover(
615                &self,
616                context: RequestContext<RoleServer>,
617            ) -> impl Future<Output = Result<DiscoverResult, McpError>> + MaybeSendFuture + '_ {
618                (**self).discover(context)
619            }
620
621            fn complete(
622                &self,
623                request: CompleteRequestParams,
624                context: RequestContext<RoleServer>,
625            ) -> impl Future<Output = Result<CompleteResult, McpError>> + MaybeSendFuture + '_ {
626                (**self).complete(request, context)
627            }
628
629            fn set_level(
630                &self,
631                request: SetLevelRequestParams,
632                context: RequestContext<RoleServer>,
633            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
634                (**self).set_level(request, context)
635            }
636
637            fn get_prompt(
638                &self,
639                request: GetPromptRequestParams,
640                context: RequestContext<RoleServer>,
641            ) -> impl Future<Output = Result<GetPromptResponse, McpError>> + MaybeSendFuture + '_ {
642                (**self).get_prompt(request, context)
643            }
644
645            fn list_prompts(
646                &self,
647                request: Option<PaginatedRequestParams>,
648                context: RequestContext<RoleServer>,
649            ) -> impl Future<Output = Result<ListPromptsResult, McpError>> + MaybeSendFuture + '_ {
650                (**self).list_prompts(request, context)
651            }
652
653            fn list_resources(
654                &self,
655                request: Option<PaginatedRequestParams>,
656                context: RequestContext<RoleServer>,
657            ) -> impl Future<Output = Result<ListResourcesResult, McpError>> + MaybeSendFuture + '_ {
658                (**self).list_resources(request, context)
659            }
660
661            fn list_resource_templates(
662                &self,
663                request: Option<PaginatedRequestParams>,
664                context: RequestContext<RoleServer>,
665            ) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + MaybeSendFuture + '_
666            {
667                (**self).list_resource_templates(request, context)
668            }
669
670            fn read_resource(
671                &self,
672                request: ReadResourceRequestParams,
673                context: RequestContext<RoleServer>,
674            ) -> impl Future<Output = Result<ReadResourceResponse, McpError>> + MaybeSendFuture + '_ {
675                (**self).read_resource(request, context)
676            }
677
678            fn accepted_subscription_filter(
679                &self,
680                requested: &SubscriptionFilter,
681            ) -> Option<SubscriptionFilter> {
682                (**self).accepted_subscription_filter(requested)
683            }
684
685            fn listen(
686                &self,
687                context: SubscriptionContext,
688            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
689                (**self).listen(context)
690            }
691
692            fn subscribe(
693                &self,
694                request: SubscribeRequestParams,
695                context: RequestContext<RoleServer>,
696            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
697                (**self).subscribe(request, context)
698            }
699
700            fn unsubscribe(
701                &self,
702                request: UnsubscribeRequestParams,
703                context: RequestContext<RoleServer>,
704            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
705                (**self).unsubscribe(request, context)
706            }
707
708            fn call_tool(
709                &self,
710                request: CallToolRequestParams,
711                context: RequestContext<RoleServer>,
712            ) -> impl Future<Output = Result<CallToolResponse, McpError>> + MaybeSendFuture + '_ {
713                (**self).call_tool(request, context)
714            }
715
716            fn list_tools(
717                &self,
718                request: Option<PaginatedRequestParams>,
719                context: RequestContext<RoleServer>,
720            ) -> impl Future<Output = Result<ListToolsResult, McpError>> + MaybeSendFuture + '_ {
721                (**self).list_tools(request, context)
722            }
723
724            fn get_tool(&self, name: &str) -> Option<Tool> {
725                (**self).get_tool(name)
726            }
727
728            fn on_custom_request(
729                &self,
730                request: CustomRequest,
731                context: RequestContext<RoleServer>,
732            ) -> impl Future<Output = Result<CustomResult, McpError>> + MaybeSendFuture + '_ {
733                (**self).on_custom_request(request, context)
734            }
735
736            fn on_cancelled(
737                &self,
738                notification: CancelledNotificationParam,
739                context: NotificationContext<RoleServer>,
740            ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
741                (**self).on_cancelled(notification, context)
742            }
743
744            fn on_progress(
745                &self,
746                notification: ProgressNotificationParam,
747                context: NotificationContext<RoleServer>,
748            ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
749                (**self).on_progress(notification, context)
750            }
751
752            fn on_initialized(
753                &self,
754                context: NotificationContext<RoleServer>,
755            ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
756                (**self).on_initialized(context)
757            }
758
759            fn on_roots_list_changed(
760                &self,
761                context: NotificationContext<RoleServer>,
762            ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
763                (**self).on_roots_list_changed(context)
764            }
765
766            fn on_custom_notification(
767                &self,
768                notification: CustomNotification,
769                context: NotificationContext<RoleServer>,
770            ) -> impl Future<Output = ()> + MaybeSendFuture + '_ {
771                (**self).on_custom_notification(notification, context)
772            }
773
774            fn get_info(&self) -> ServerInfo {
775                (**self).get_info()
776            }
777
778            fn get_task(
779                &self,
780                request: GetTaskParams,
781                context: RequestContext<RoleServer>,
782            ) -> impl Future<Output = Result<GetTaskResult, McpError>> + MaybeSendFuture + '_ {
783                (**self).get_task(request, context)
784            }
785
786            fn update_task(
787                &self,
788                request: UpdateTaskParams,
789                context: RequestContext<RoleServer>,
790            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
791                (**self).update_task(request, context)
792            }
793
794            fn cancel_task(
795                &self,
796                request: CancelTaskParams,
797                context: RequestContext<RoleServer>,
798            ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_ {
799                (**self).cancel_task(request, context)
800            }
801        }
802    };
803}
804
805impl_server_handler_for_wrapper!(Box);
806impl_server_handler_for_wrapper!(Arc);