cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::transport::Transport< Role > Class Template Referenceabstract

Minimal message-level transport contract shared by MCP roles. More...

#include <transport.hpp>

Inheritance diagram for mcp::transport::Transport< Role >:
mcp::client::TransportContractAdapter mcp::server::TransportContractAdapter mcp::transport::FunctionTransport< Role > mcp::transport::JsonLineTransport< Role > mcp::transport::ProcessStdioClientTransport mcp::transport::QueueTransport< Role > mcp::transport::StdioTransport< Role > mcp::transport::StreamableHttpClientTransport mcp::transport::StreamableHttpServerTransport mcp::transport::WebSocketClientTransport mcp::transport::WebSocketServerTransport

Public Types

using TxMessage = typename MessageTraits< Role >::TxMessage
 
using RxMessage = typename MessageTraits< Role >::RxMessage
 

Public Member Functions

virtual std::string_view name () const noexcept=0
 Human-readable transport name for diagnostics.
 
virtual protocol::Json diagnostics () const
 Structured implementation diagnostics.
 
virtual core::Result< core::Unitsend (TxMessage message)=0
 Sends one JSON-RPC message to the peer.
 
virtual core::Result< std::optional< RxMessage > > receive ()=0
 Receives the next JSON-RPC message from the peer.
 
virtual core::Result< core::Unitclose ()=0
 Closes the transport and unblocks receive() where possible.
 
virtual void wait_until_ready ()
 Blocks until the transport is ready to process messages.
 

Detailed Description

template<class Role>
class mcp::transport::Transport< Role >

Minimal message-level transport contract shared by MCP roles.

This contract is intentionally limited to one outbound operation, one inbound operation, explicit close, and diagnostics. Higher-level session, retry, policy, and gateway behavior must live above this interface.

Implementations must document whether send() may be called concurrently. receive() is sequential: callers must not call receive() concurrently on the same transport unless a concrete implementation explicitly says otherwise. A successful receive() returning std::nullopt means the inbound stream ended cleanly or close() has completed. close() is best-effort, should be idempotent, and should unblock a blocked receive() where the underlying platform transport can do so.

Member Function Documentation

◆ close()

◆ diagnostics()

template<class Role >
virtual protocol::Json mcp::transport::Transport< Role >::diagnostics ( ) const
inlinevirtual

Structured implementation diagnostics.

The default keeps the core contract narrow. Transports with useful state may return keys such as "name", "closed", "inflight", or backend-specific counters. Diagnostics are not part of the wire protocol.

Reimplemented in mcp::transport::FunctionTransport< Role >, mcp::transport::JsonLineTransport< Role >, mcp::transport::QueueTransport< Role >, mcp::transport::StreamableHttpClientTransport, mcp::transport::StreamableHttpServerTransport, mcp::transport::ProcessStdioClientTransport, mcp::transport::StdioTransport< Role >, mcp::transport::WebSocketClientTransport, and mcp::transport::WebSocketServerTransport.

◆ name()

◆ receive()

◆ send()

◆ wait_until_ready()

template<class Role >
virtual void mcp::transport::Transport< Role >::wait_until_ready ( )
inlinevirtual

Blocks until the transport is ready to process messages.

The default is a no-op. Transports that need asynchronous startup (e.g. binding a socket) override this to block until the underlying resource is available.

Reimplemented in mcp::transport::StreamableHttpServerTransport, and mcp::transport::WebSocketServerTransport.


The documentation for this class was generated from the following file: