|
| 1 | +use std::sync::Arc; |
| 2 | + |
1 | 3 | use crate::{ |
2 | 4 | error::ErrorData as McpError, |
3 | 5 | model::*, |
@@ -327,3 +329,206 @@ pub trait ServerHandler: Sized + Send + Sync + 'static { |
327 | 329 | std::future::ready(Err(McpError::method_not_found::<CancelTaskMethod>())) |
328 | 330 | } |
329 | 331 | } |
| 332 | + |
| 333 | +macro_rules! impl_server_handler_for_wrapper { |
| 334 | + ($wrapper:ident) => { |
| 335 | + impl<T: ServerHandler> ServerHandler for $wrapper<T> { |
| 336 | + fn enqueue_task( |
| 337 | + &self, |
| 338 | + request: CallToolRequestParam, |
| 339 | + context: RequestContext<RoleServer>, |
| 340 | + ) -> impl Future<Output = Result<CreateTaskResult, McpError>> + Send + '_ { |
| 341 | + (**self).enqueue_task(request, context) |
| 342 | + } |
| 343 | + |
| 344 | + fn ping( |
| 345 | + &self, |
| 346 | + context: RequestContext<RoleServer>, |
| 347 | + ) -> impl Future<Output = Result<(), McpError>> + Send + '_ { |
| 348 | + (**self).ping(context) |
| 349 | + } |
| 350 | + |
| 351 | + fn initialize( |
| 352 | + &self, |
| 353 | + request: InitializeRequestParam, |
| 354 | + context: RequestContext<RoleServer>, |
| 355 | + ) -> impl Future<Output = Result<InitializeResult, McpError>> + Send + '_ { |
| 356 | + (**self).initialize(request, context) |
| 357 | + } |
| 358 | + |
| 359 | + fn complete( |
| 360 | + &self, |
| 361 | + request: CompleteRequestParam, |
| 362 | + context: RequestContext<RoleServer>, |
| 363 | + ) -> impl Future<Output = Result<CompleteResult, McpError>> + Send + '_ { |
| 364 | + (**self).complete(request, context) |
| 365 | + } |
| 366 | + |
| 367 | + fn set_level( |
| 368 | + &self, |
| 369 | + request: SetLevelRequestParam, |
| 370 | + context: RequestContext<RoleServer>, |
| 371 | + ) -> impl Future<Output = Result<(), McpError>> + Send + '_ { |
| 372 | + (**self).set_level(request, context) |
| 373 | + } |
| 374 | + |
| 375 | + fn get_prompt( |
| 376 | + &self, |
| 377 | + request: GetPromptRequestParam, |
| 378 | + context: RequestContext<RoleServer>, |
| 379 | + ) -> impl Future<Output = Result<GetPromptResult, McpError>> + Send + '_ { |
| 380 | + (**self).get_prompt(request, context) |
| 381 | + } |
| 382 | + |
| 383 | + fn list_prompts( |
| 384 | + &self, |
| 385 | + request: Option<PaginatedRequestParam>, |
| 386 | + context: RequestContext<RoleServer>, |
| 387 | + ) -> impl Future<Output = Result<ListPromptsResult, McpError>> + Send + '_ { |
| 388 | + (**self).list_prompts(request, context) |
| 389 | + } |
| 390 | + |
| 391 | + fn list_resources( |
| 392 | + &self, |
| 393 | + request: Option<PaginatedRequestParam>, |
| 394 | + context: RequestContext<RoleServer>, |
| 395 | + ) -> impl Future<Output = Result<ListResourcesResult, McpError>> + Send + '_ { |
| 396 | + (**self).list_resources(request, context) |
| 397 | + } |
| 398 | + |
| 399 | + fn list_resource_templates( |
| 400 | + &self, |
| 401 | + request: Option<PaginatedRequestParam>, |
| 402 | + context: RequestContext<RoleServer>, |
| 403 | + ) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + Send + '_ |
| 404 | + { |
| 405 | + (**self).list_resource_templates(request, context) |
| 406 | + } |
| 407 | + |
| 408 | + fn read_resource( |
| 409 | + &self, |
| 410 | + request: ReadResourceRequestParam, |
| 411 | + context: RequestContext<RoleServer>, |
| 412 | + ) -> impl Future<Output = Result<ReadResourceResult, McpError>> + Send + '_ { |
| 413 | + (**self).read_resource(request, context) |
| 414 | + } |
| 415 | + |
| 416 | + fn subscribe( |
| 417 | + &self, |
| 418 | + request: SubscribeRequestParam, |
| 419 | + context: RequestContext<RoleServer>, |
| 420 | + ) -> impl Future<Output = Result<(), McpError>> + Send + '_ { |
| 421 | + (**self).subscribe(request, context) |
| 422 | + } |
| 423 | + |
| 424 | + fn unsubscribe( |
| 425 | + &self, |
| 426 | + request: UnsubscribeRequestParam, |
| 427 | + context: RequestContext<RoleServer>, |
| 428 | + ) -> impl Future<Output = Result<(), McpError>> + Send + '_ { |
| 429 | + (**self).unsubscribe(request, context) |
| 430 | + } |
| 431 | + |
| 432 | + fn call_tool( |
| 433 | + &self, |
| 434 | + request: CallToolRequestParam, |
| 435 | + context: RequestContext<RoleServer>, |
| 436 | + ) -> impl Future<Output = Result<CallToolResult, McpError>> + Send + '_ { |
| 437 | + (**self).call_tool(request, context) |
| 438 | + } |
| 439 | + |
| 440 | + fn list_tools( |
| 441 | + &self, |
| 442 | + request: Option<PaginatedRequestParam>, |
| 443 | + context: RequestContext<RoleServer>, |
| 444 | + ) -> impl Future<Output = Result<ListToolsResult, McpError>> + Send + '_ { |
| 445 | + (**self).list_tools(request, context) |
| 446 | + } |
| 447 | + |
| 448 | + fn on_custom_request( |
| 449 | + &self, |
| 450 | + request: CustomRequest, |
| 451 | + context: RequestContext<RoleServer>, |
| 452 | + ) -> impl Future<Output = Result<CustomResult, McpError>> + Send + '_ { |
| 453 | + (**self).on_custom_request(request, context) |
| 454 | + } |
| 455 | + |
| 456 | + fn on_cancelled( |
| 457 | + &self, |
| 458 | + notification: CancelledNotificationParam, |
| 459 | + context: NotificationContext<RoleServer>, |
| 460 | + ) -> impl Future<Output = ()> + Send + '_ { |
| 461 | + (**self).on_cancelled(notification, context) |
| 462 | + } |
| 463 | + |
| 464 | + fn on_progress( |
| 465 | + &self, |
| 466 | + notification: ProgressNotificationParam, |
| 467 | + context: NotificationContext<RoleServer>, |
| 468 | + ) -> impl Future<Output = ()> + Send + '_ { |
| 469 | + (**self).on_progress(notification, context) |
| 470 | + } |
| 471 | + |
| 472 | + fn on_initialized( |
| 473 | + &self, |
| 474 | + context: NotificationContext<RoleServer>, |
| 475 | + ) -> impl Future<Output = ()> + Send + '_ { |
| 476 | + (**self).on_initialized(context) |
| 477 | + } |
| 478 | + |
| 479 | + fn on_roots_list_changed( |
| 480 | + &self, |
| 481 | + context: NotificationContext<RoleServer>, |
| 482 | + ) -> impl Future<Output = ()> + Send + '_ { |
| 483 | + (**self).on_roots_list_changed(context) |
| 484 | + } |
| 485 | + |
| 486 | + fn on_custom_notification( |
| 487 | + &self, |
| 488 | + notification: CustomNotification, |
| 489 | + context: NotificationContext<RoleServer>, |
| 490 | + ) -> impl Future<Output = ()> + Send + '_ { |
| 491 | + (**self).on_custom_notification(notification, context) |
| 492 | + } |
| 493 | + |
| 494 | + fn get_info(&self) -> ServerInfo { |
| 495 | + (**self).get_info() |
| 496 | + } |
| 497 | + |
| 498 | + fn list_tasks( |
| 499 | + &self, |
| 500 | + request: Option<PaginatedRequestParam>, |
| 501 | + context: RequestContext<RoleServer>, |
| 502 | + ) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send + '_ { |
| 503 | + (**self).list_tasks(request, context) |
| 504 | + } |
| 505 | + |
| 506 | + fn get_task_info( |
| 507 | + &self, |
| 508 | + request: GetTaskInfoParam, |
| 509 | + context: RequestContext<RoleServer>, |
| 510 | + ) -> impl Future<Output = Result<GetTaskInfoResult, McpError>> + Send + '_ { |
| 511 | + (**self).get_task_info(request, context) |
| 512 | + } |
| 513 | + |
| 514 | + fn get_task_result( |
| 515 | + &self, |
| 516 | + request: GetTaskResultParam, |
| 517 | + context: RequestContext<RoleServer>, |
| 518 | + ) -> impl Future<Output = Result<TaskResult, McpError>> + Send + '_ { |
| 519 | + (**self).get_task_result(request, context) |
| 520 | + } |
| 521 | + |
| 522 | + fn cancel_task( |
| 523 | + &self, |
| 524 | + request: CancelTaskParam, |
| 525 | + context: RequestContext<RoleServer>, |
| 526 | + ) -> impl Future<Output = Result<(), McpError>> + Send + '_ { |
| 527 | + (**self).cancel_task(request, context) |
| 528 | + } |
| 529 | + } |
| 530 | + }; |
| 531 | +} |
| 532 | + |
| 533 | +impl_server_handler_for_wrapper!(Box); |
| 534 | +impl_server_handler_for_wrapper!(Arc); |
0 commit comments