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§
Required Methods§
Sourcefn initialize<'async_trait>(
config: Self::Config,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
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.
Sourcefn get_server_info(&self) -> ServerInfo
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.
Sourcefn 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 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.
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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,
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§
Sourcefn 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 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)
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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 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
Sourcefn 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,
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>
impl<T> McpBackend for CommonBackendImpl<T>
Source§impl<T> McpBackend for Twhere
T: SimpleBackend,
Blanket implementation to convert SimpleBackend to McpBackend
impl<T> McpBackend for Twhere
T: SimpleBackend,
Blanket implementation to convert SimpleBackend to McpBackend