|
cxxmcp 1.3.0
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< 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. | |
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.
|
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.
|
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.
|
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.
| id | Request id of the outstanding outbound request. |
Reimplemented in mcp::transport::StreamableHttpServerTransport.
|
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.