cxxmcp 1.3.0
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::Unit > send (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< std::optional< RxMessage > > receive_response (const protocol::RequestId &id)
 Waits for the response to one specific outbound request.
 
virtual void publish_subscription_notification (std::string_view method, protocol::Json params)
 Publishes a notification to active subscription listen streams.
 
virtual core::Result< core::Unit > close ()=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()

◆ publish_subscription_notification()

template<class Role >
virtual void mcp::transport::Transport< Role >::publish_subscription_notification ( std::string_view  method,
protocol::Json  params 
)
inlinevirtual

Publishes a notification to active subscription listen streams.

Transports that serve SEP-2575 stateless subscription channels override this to deliver the notification to matching subscribers. The default is a no-op.

Reimplemented in mcp::server::TransportContractAdapter, and mcp::transport::StreamableHttpServerTransport.

◆ receive()

◆ receive_response()

template<class Role >
virtual core::Result< std::optional< RxMessage > > mcp::transport::Transport< Role >::receive_response ( const protocol::RequestId &  id)
inlinevirtual

Waits for the response to one specific outbound request.

Server transports deliver client responses to server-initiated (reverse) requests through the same single-consumer receive() queue as inbound client traffic. A reverse-request caller that waits on receive() therefore competes with the transport's main receive loop, and the response can be consumed by the wrong side. Implementations that can route reverse responses to dedicated waiters override this method so reverse-request callers bypass the shared queue entirely.

The default implementation reports unsupported; callers fall back to the receive() loop.

Parameters
idRequest id of the outstanding outbound request.
Returns
The response message once it arrives, std::nullopt on orderly close, or an error when the transport does not support direct routing.

Reimplemented in mcp::transport::StreamableHttpServerTransport.

◆ 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: