|
cxxmcp 1.1.6
C++ MCP SDK
|
Minimal message-level transport contract shared by MCP roles. More...
#include <transport.hpp>
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< 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. | |
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.
|
pure virtual |
Closes the transport and unblocks receive() where possible.
Implemented in mcp::client::TransportContractAdapter, mcp::server::TransportContractAdapter, 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.
|
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.
|
pure virtualnoexcept |
Human-readable transport name for diagnostics.
Implemented in mcp::client::TransportContractAdapter, mcp::server::TransportContractAdapter, 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.
|
pure virtual |
Receives the next JSON-RPC message from the peer.
receive() is the sequential inbound side. A successful std::nullopt return is an orderly end-of-stream signal, not a parse or transport error.
Implemented in mcp::client::TransportContractAdapter, mcp::server::TransportContractAdapter, 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.
|
pure virtual |
Sends one JSON-RPC message to the peer.
Concurrency safety is implementation-specific and must be documented by the concrete transport.
Implemented 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.
|
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.