McpMiddleware

Trait McpMiddleware 

Source
pub trait McpMiddleware: Send + Sync {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn priority(&self) -> i32 { ... }
    fn before_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 CallToolRequest,
        context: &'life2 mut MiddlewareContext,
    ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn after_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        request: &'life1 CallToolRequest,
        response: &'life2 mut CallToolResult,
        context: &'life3 mut MiddlewareContext,
    ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_error<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        request: &'life1 CallToolRequest,
        error: &'life2 McpError,
        context: &'life3 mut MiddlewareContext,
    ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
}
Expand description

MCP Middleware trait for intercepting and controlling server operations

Required Methods§

Source

fn name(&self) -> &str

Name of the middleware for identification

Provided Methods§

Source

fn priority(&self) -> i32

Priority/order of execution (lower numbers execute first)

Source

fn before_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 CallToolRequest, context: &'life2 mut MiddlewareContext, ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before the request is processed

Source

fn after_request<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, request: &'life1 CallToolRequest, response: &'life2 mut CallToolResult, context: &'life3 mut MiddlewareContext, ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called after the request is processed but before response is returned

Source

fn on_error<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, request: &'life1 CallToolRequest, error: &'life2 McpError, context: &'life3 mut MiddlewareContext, ) -> Pin<Box<dyn Future<Output = McpResult<MiddlewareResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called when an error occurs during request processing

Implementors§