Skip to main content

ServerTransport

Trait ServerTransport 

Source
pub trait ServerTransport: Send + Sync {
    // Required methods
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_request_handler(&mut self, handler: ServerRequestHandler);
    fn send_notification<'life0, 'async_trait>(
        &'life0 mut self,
        notification: JsonRpcNotification,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn set_tool_schemas(
        &mut self,
        _schemas: HashMap<String, Value>,
    ) -> McpResult<()> { ... }
    fn set_server_capabilities(
        &mut self,
        _capabilities: ServerCapabilities,
    ) -> McpResult<()> { ... }
    fn set_task_notifications(
        &mut self,
        _receiver: Receiver<JsonRpcNotification>,
    ) -> McpResult<()> { ... }
    fn is_running(&self) -> bool { ... }
    fn server_info(&self) -> String { ... }
}
Expand description

Transport trait for MCP servers

Trait defines the interface for handling incoming requests and sending responses in a server-side MCP connection.

Required Methods§

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the server transport and begin listening for connections

§Returns

Result indicating success or an error

Source

fn set_request_handler(&mut self, handler: ServerRequestHandler)

Set the request handler that will process incoming requests

§Arguments
  • handler - The request handler function
Source

fn send_notification<'life0, 'async_trait>( &'life0 mut self, notification: JsonRpcNotification, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a JSON-RPC notification to the client

§Arguments
  • notification - The JSON-RPC notification to send
§Returns

Result indicating success or an error

Source

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the server transport

§Returns

Result indicating success or an error

Provided Methods§

Source

fn set_tool_schemas( &mut self, _schemas: HashMap<String, Value>, ) -> McpResult<()>

Provide registered tool input schemas to transports that mirror and validate MCP routing headers. Other transports may ignore them.

Source

fn set_server_capabilities( &mut self, _capabilities: ServerCapabilities, ) -> McpResult<()>

Provide the capabilities used to acknowledge subscription filters.

Source

fn set_task_notifications( &mut self, _receiver: Receiver<JsonRpcNotification>, ) -> McpResult<()>

Attach task-status notifications to the transport’s subscription hub.

Source

fn is_running(&self) -> bool

Check if the server is running

§Returns

True if the server is running and accepting connections

Source

fn server_info(&self) -> String

Get server information for debugging

§Returns

String describing the server state

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§