pub trait Transport: Send + Sync {
// Required methods
fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_resource<'life0, 'life1, 'async_trait>(
&'life0 self,
uri: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Transport is the core trait for communication with MCP servers.
This trait defines the interface for interacting with Model Context Protocol (MCP) servers through various transport mechanisms. Implementations of this trait handle the low-level communication details, allowing clients to focus on high-level interactions.
§Examples
Using a transport to list available tools:
use mcp_runner::transport::Transport;
use mcp_runner::error::Result;
use serde_json::Value;
async fn example<T: Transport>(transport: &T) -> Result<()> {
// Initialize the transport
transport.initialize().await?;
// List available tools
let tools = transport.list_tools().await?;
println!("Available tools: {:?}", tools);
Ok(())
}Required Methods§
Sourcefn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Initializes the transport connection to the MCP server.
This method should be called before any other methods to ensure the transport is ready for communication.
§Returns
A Result<()> that is:
Ok(())if initialization was successfulErr(Error)if initialization failed
Sourcefn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists all available tools provided by the MCP server.
§Returns
A Result<Vec<Value>> that is:
Ok(Vec<Value>)containing a list of tool definitions if successfulErr(Error)if the request failed
§Tool Definition Format
Each tool definition is a JSON object with at least:
name: A string identifier for the tooldescription: A human-readable description of the tool- Additional fields as specified by the MCP server
Sourcefn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists all available resources provided by the MCP server.
Resources can include model metadata, usage information, or other static or dynamic data exposed by the server.
§Returns
A Result<Vec<Value>> that is:
Ok(Vec<Value>)containing a list of resource definitions if successfulErr(Error)if the request failed