modelcontextprotocol_server/transport/
mod.rs

1// mcp-server/src/transport/mod.rs
2pub mod stdio;
3
4use async_trait::async_trait;
5use anyhow::Result;
6use mcp_protocol::messages::JsonRpcMessage;
7use tokio::sync::mpsc;
8
9/// Transport trait for sending and receiving MCP messages
10#[async_trait]
11pub trait Transport: Send + Sync + 'static {
12    /// Start the transport (listening for incoming messages)
13    async fn start(&self, message_tx: mpsc::Sender<JsonRpcMessage>) -> Result<()>;
14    
15    /// Send a message to the client
16    async fn send(&self, message: JsonRpcMessage) -> Result<()>;
17    
18    /// Close the transport
19    async fn close(&self) -> Result<()>;
20    
21    /// Clone the transport
22    fn box_clone(&self) -> Box<dyn Transport>;
23}
24
25pub use stdio::StdioTransport;