|
cxxmcp 1.1.6
C++ MCP SDK
|
Abstract server transport for receiving client JSON-RPC messages. More...
#include <transport.hpp>
Public Member Functions | |
| std::weak_ptr< void > | lifetime_token () const noexcept |
| Weak lifetime token for SessionContext and ClientPeer guards. | |
| virtual core::Result< core::Unit > | start (RequestHandler handler, NotificationHandler notification_handler={})=0 |
| Start accepting inbound messages and dispatch them to handlers. | |
| virtual core::Result< protocol::JsonRpcResponse > | send_request (const protocol::JsonRpcRequest &request) |
| Send a JSON-RPC request from the server to the connected client. | |
| virtual core::Result< protocol::JsonRpcResponse > | send_request_to_session (std::string_view session_id, const protocol::JsonRpcRequest &request) |
| Send a JSON-RPC request to a specific logical session. | |
| virtual std::optional< protocol::ClientCapabilities > | client_capabilities () const |
| Return capabilities learned from the client's initialize request. | |
| virtual std::optional< protocol::ClientCapabilities > | client_capabilities_for_session (std::string_view session_id) const |
| Return capabilities learned for a specific logical session. | |
| virtual core::Result< core::Unit > | send_notification (const protocol::JsonRpcNotification ¬ification)=0 |
| Send a JSON-RPC notification from the server to the client. | |
| virtual core::Result< core::Unit > | send_notification_to_session (std::string_view session_id, const protocol::JsonRpcNotification ¬ification) |
| Send a JSON-RPC notification to a specific logical session. | |
| virtual void | stop () noexcept=0 |
| Request transport shutdown. | |
| virtual std::string_view | name () const noexcept=0 |
| Human-readable transport name for diagnostics. | |
| virtual void | wait_until_ready () |
| Blocks until the transport is ready to process messages. | |
Abstract server transport for receiving client JSON-RPC messages.
A Transport is responsible for accepting inbound client messages, invoking the supplied handlers, serializing responses or errors, and sending server notifications back to the client. The server object owns or otherwise controls the transport lifetime; callbacks receive only borrowed references and must not store SessionContext::transport beyond the active session.
Implementations define their own threading model. StdioTransport runs its read loop inside start(), while HttpTransport serves callbacks from the HTTP server threads and uses an SSE stream for outbound traffic. Unless a derived transport documents stronger guarantees, callers should serialize calls that mutate shared server state from callbacks.
|
inlinevirtual |
Return capabilities learned from the client's initialize request.
Reimplemented in mcp::server::HttpTransport, mcp::server::StdioTransport, and mcp::server::ContractTransportAdapter.
|
inlinevirtual |
Return capabilities learned for a specific logical session.
| session_id | Transport-defined session identifier. |
Reimplemented in mcp::server::HttpTransport.
|
pure virtualnoexcept |
Human-readable transport name for diagnostics.
Implemented in mcp::server::HttpTransport, mcp::server::StdioTransport, and mcp::server::ContractTransportAdapter.
|
pure virtual |
Send a JSON-RPC notification from the server to the client.
| notification | Notification to serialize and deliver. |
Implemented in mcp::server::HttpTransport, mcp::server::StdioTransport, and mcp::server::ContractTransportAdapter.
|
inlinevirtual |
Send a JSON-RPC notification to a specific logical session.
| session_id | Transport-defined session identifier. |
| notification | Notification to serialize and deliver. |
Reimplemented in mcp::server::HttpTransport.
|
inlinevirtual |
Send a JSON-RPC request from the server to the connected client.
| request | Request to serialize and deliver. |
Reimplemented in mcp::server::HttpTransport, and mcp::server::ContractTransportAdapter.
|
inlinevirtual |
Send a JSON-RPC request to a specific logical session.
| session_id | Transport-defined session identifier. |
| request | Request to serialize and deliver. |
Reimplemented in mcp::server::HttpTransport.
|
pure virtual |
Start accepting inbound messages and dispatch them to handlers.
| handler | Required request handler. |
| notification_handler | Optional notification handler. |
Implemented in mcp::server::HttpTransport, mcp::server::StdioTransport, and mcp::server::ContractTransportAdapter.
|
pure virtualnoexcept |
Request transport shutdown.
stop() is best-effort and must not throw. Implementations should unblock any running start() call or pending outbound operation where possible.
Implemented in mcp::server::HttpTransport, mcp::server::StdioTransport, and mcp::server::ContractTransportAdapter.
|
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::server::HttpTransport.