Skip to main content

RequestRouter

Trait RequestRouter 

Source
pub trait RequestRouter: Send + Sync {
    // Required methods
    fn server_info(&self) -> ServerInfo;
    async fn route(
        &self,
        method: &str,
        params: Option<&Value>,
        ctx: &Context<'_>,
    ) -> Result<Value, McpError>;

    // Provided methods
    async fn route_notification(
        &self,
        _method: &str,
        _params: Option<&Value>,
        _ctx: &Context<'_>,
    ) { ... }
    async fn tool_task_support(
        &self,
        _name: &str,
        _ctx: &Context<'_>,
    ) -> TaskSupport { ... }
    async fn call_tool_json(
        &self,
        name: &str,
        _args: Object,
        _ctx: &Context<'_>,
    ) -> Result<Value, McpError> { ... }
}
Expand description

Trait for routing requests to handlers.

This trait is implemented by Server with different bounds depending on which handlers are registered.

Required Methods§

Source

fn server_info(&self) -> ServerInfo

Get the server info.

Source

async fn route( &self, method: &str, params: Option<&Value>, ctx: &Context<'_>, ) -> Result<Value, McpError>

Route a request and return the result.

Provided Methods§

Source

async fn route_notification( &self, _method: &str, _params: Option<&Value>, _ctx: &Context<'_>, )

Dispatch an inbound client notification (e.g. notifications/initialized or notifications/roots/list_changed) to the server’s lifecycle hooks. Analogous to route but for notifications — there is no reply. Defaults to a no-op.

Source

async fn tool_task_support( &self, _name: &str, _ctx: &Context<'_>, ) -> TaskSupport

The task-augmentation support a tool declares (Tool.execution.taskSupport), used to gate task-augmented tools/call. Defaults to Forbidden.

Source

async fn call_tool_json( &self, name: &str, _args: Object, _ctx: &Context<'_>, ) -> Result<Value, McpError>

Run a tool to completion for task-augmented execution, returning its CallToolResult as JSON (the tasks/result payload). Defaults to method-not-found.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<H, T, R, P, K> RequestRouter for Server<H, T, R, P, K>

Single RequestRouter implementation over the typestate handler slots.

Each capability is a slot (Registered<H> / NotRegistered) exposing an optional object-safe handler; routing checks each in turn. Adding a dispatched capability is one slot plus one arm here – there is no per-combination explosion. The shared per-method routing logic lives in crate::router.