Trait McpBackend

Source
pub trait McpBackend:
    Send
    + Sync
    + Clone {
    type Error: StdError + Send + Sync + Into<Error> + From<BackendError> + 'static;
    type Config: Clone + Send + Sync;

Show 20 methods // Required methods fn initialize<'async_trait>( config: Self::Config, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait; fn get_server_info(&self) -> ServerInfo; fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_tools<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListToolsResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn call_tool<'life0, 'async_trait>( &'life0 self, request: CallToolRequestParam, ) -> Pin<Box<dyn Future<Output = Result<CallToolResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_resources<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListResourcesResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_resource<'life0, 'async_trait>( &'life0 self, request: ReadResourceRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ReadResourceResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_prompts<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListPromptsResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_prompt<'life0, 'async_trait>( &'life0 self, request: GetPromptRequestParam, ) -> Pin<Box<dyn Future<Output = Result<GetPromptResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn list_resource_templates<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListResourceTemplatesResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn subscribe<'life0, 'async_trait>( &'life0 self, request: SubscribeRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn unsubscribe<'life0, 'async_trait>( &'life0 self, request: UnsubscribeRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn complete<'life0, 'async_trait>( &'life0 self, request: CompleteRequestParam, ) -> Pin<Box<dyn Future<Output = Result<CompleteResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn elicit<'life0, 'async_trait>( &'life0 self, request: ElicitationRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ElicitationResult, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn set_level<'life0, 'async_trait>( &'life0 self, request: SetLevelRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn on_startup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn on_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn on_client_connect<'life0, 'life1, 'async_trait>( &'life0 self, client_info: &'life1 Implementation, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn on_client_disconnect<'life0, 'life1, 'async_trait>( &'life0 self, client_info: &'life1 Implementation, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn handle_custom_method<'life0, 'life1, 'async_trait>( &'life0 self, method: &'life1 str, params: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

Main trait for MCP backend implementations

This trait defines the interface that backends must implement to provide domain-specific functionality (tools, resources, prompts) while the framework handles the MCP protocol, authentication, transport, and middleware.

Required Associated Types§

Source

type Error: StdError + Send + Sync + Into<Error> + From<BackendError> + 'static

Backend-specific error type

Source

type Config: Clone + Send + Sync

Backend configuration type

Required Methods§

Source

fn initialize<'async_trait>( config: Self::Config, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Initialize the backend with configuration

This is called once during server startup and should establish any necessary connections, load configuration, and prepare the backend for handling requests.

Source

fn get_server_info(&self) -> ServerInfo

Get server information and capabilities

This defines what the backend supports (tools, resources, prompts) and provides metadata about the implementation.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check for the backend

Should verify that all backend services are operational. Called regularly for monitoring and health endpoints.

Source

fn list_tools<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListToolsResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List available tools with pagination

Source

fn call_tool<'life0, 'async_trait>( &'life0 self, request: CallToolRequestParam, ) -> Pin<Box<dyn Future<Output = Result<CallToolResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute a tool with the given parameters

Source

fn list_resources<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListResourcesResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List available resources with pagination

Source

fn read_resource<'life0, 'async_trait>( &'life0 self, request: ReadResourceRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ReadResourceResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read a resource by URI

Source

fn list_prompts<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListPromptsResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List available prompts with pagination

Source

fn get_prompt<'life0, 'async_trait>( &'life0 self, request: GetPromptRequestParam, ) -> Pin<Box<dyn Future<Output = Result<GetPromptResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a specific prompt

Provided Methods§

Source

fn list_resource_templates<'life0, 'async_trait>( &'life0 self, request: PaginatedRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ListResourceTemplatesResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List resource templates (optional)

Source

fn subscribe<'life0, 'async_trait>( &'life0 self, request: SubscribeRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to resource updates

Source

fn unsubscribe<'life0, 'async_trait>( &'life0 self, request: UnsubscribeRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Unsubscribe from resource updates

Source

fn complete<'life0, 'async_trait>( &'life0 self, request: CompleteRequestParam, ) -> Pin<Box<dyn Future<Output = Result<CompleteResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Complete tool or resource names

Source

fn elicit<'life0, 'async_trait>( &'life0 self, request: ElicitationRequestParam, ) -> Pin<Box<dyn Future<Output = Result<ElicitationResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Request structured input from the user

Source

fn set_level<'life0, 'async_trait>( &'life0 self, request: SetLevelRequestParam, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set logging level

Source

fn on_startup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the server is starting up

Source

fn on_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the server is shutting down

Source

fn on_client_connect<'life0, 'life1, 'async_trait>( &'life0 self, client_info: &'life1 Implementation, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a client connects

Source

fn on_client_disconnect<'life0, 'life1, 'async_trait>( &'life0 self, client_info: &'life1 Implementation, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a client disconnects

Source

fn handle_custom_method<'life0, 'life1, 'async_trait>( &'life0 self, method: &'life1 str, params: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Handle custom methods not part of the standard MCP protocol

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> McpBackend for CommonBackendImpl<T>
where T: Send + Sync + Clone + Default + 'static,

Source§

impl<T> McpBackend for T
where T: SimpleBackend,

Blanket implementation to convert SimpleBackend to McpBackend