Skip to main content

McpSession

Trait McpSession 

Source
pub trait McpSession: Send {
    // Required methods
    fn list_tools<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<McpToolInfo>, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn call_tool<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
        arguments: Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn name(&self) -> &str;

    // Provided method
    fn call_tool_with_timeout<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
        arguments: Value,
        _timeout: Option<Duration>,
    ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Transport-agnostic MCP client session.

The stdio McpServer (subprocess transport) implements this directly; the HTTP-streamable session in car-connectors (remote connectors) implements it too. McpToolExecutor holds sessions as dyn McpSession so it can route a tool call to either transport without knowing which one backs a given server. This is the seam that lets remote MCP connectors reuse the exact routing, fallback, and registration machinery the stdio path already has.

Required Methods§

Source

fn list_tools<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<McpToolInfo>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Discover the tools this server exposes.

Source

fn call_tool<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, arguments: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invoke a tool by its bare (server-side) name.

Source

fn name(&self) -> &str

The server’s registered name (the routing key).

Provided Methods§

Source

fn call_tool_with_timeout<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, arguments: Value, _timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invoke a tool, bounding the response await by timeout (else the session’s backstop). Default ignores timeout (back-compat for sessions where calls are short); the stdio McpServer honors it so a long-running run_command isn’t cut off mid-execution.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§