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§
Sourcefn server_info(&self) -> ServerInfo
fn server_info(&self) -> ServerInfo
Get the server info.
Provided Methods§
Sourceasync fn route_notification(
&self,
_method: &str,
_params: Option<&Value>,
_ctx: &Context<'_>,
)
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.
Sourceasync fn tool_task_support(
&self,
_name: &str,
_ctx: &Context<'_>,
) -> TaskSupport
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
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.