cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::server::ContractTransportAdapter Class Referencefinal

Adapts a transport::ServerTransport to the existing server::Transport API. More...

#include <transport_adapter.hpp>

Inheritance diagram for mcp::server::ContractTransportAdapter:
mcp::server::Transport

Public Member Functions

 ContractTransportAdapter (transport::ServerTransport &transport)
 
 ContractTransportAdapter (std::unique_ptr< transport::ServerTransport > transport)
 
 ContractTransportAdapter (const ContractTransportAdapter &)=delete
 
ContractTransportAdapteroperator= (const ContractTransportAdapter &)=delete
 
 ContractTransportAdapter (ContractTransportAdapter &&other) noexcept
 
ContractTransportAdapteroperator= (ContractTransportAdapter &&other) noexcept
 
core::Result< core::Unitstart (RequestHandler handler, NotificationHandler notification_handler={}) override
 Start accepting inbound messages and dispatch them to handlers.
 
core::Result< protocol::JsonRpcResponsesend_request (const protocol::JsonRpcRequest &request) override
 Send a JSON-RPC request from the server to the connected client.
 
core::Result< core::Unitsend_notification (const protocol::JsonRpcNotification &notification) override
 Send a JSON-RPC notification from the server to the client.
 
std::optional< protocol::ClientCapabilitiesclient_capabilities () const override
 Return capabilities learned from the client's initialize request.
 
void stop () noexcept override
 Request transport shutdown.
 
std::string_view name () const noexcept override
 Human-readable transport name for diagnostics.
 
- Public Member Functions inherited from mcp::server::Transport
std::weak_ptr< void > lifetime_token () const noexcept
 Weak lifetime token for SessionContext and ClientPeer guards.
 
virtual core::Result< protocol::JsonRpcResponsesend_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::ClientCapabilitiesclient_capabilities_for_session (std::string_view session_id) const
 Return capabilities learned for a specific logical session.
 
virtual core::Result< core::Unitsend_notification_to_session (std::string_view session_id, const protocol::JsonRpcNotification &notification)
 Send a JSON-RPC notification to a specific logical session.
 
virtual void wait_until_ready ()
 Blocks until the transport is ready to process messages.
 

Detailed Description

Adapts a transport::ServerTransport to the existing server::Transport API.

start() drains inbound messages from the role-generic transport, dispatches requests and notifications through server handlers, and writes request responses back to the transport. send_request() and send_notification() provide the legacy server-side outbound API over the same message contract. send_request() calls must be serialized by the caller.

Member Function Documentation

◆ client_capabilities()

std::optional< protocol::ClientCapabilities > mcp::server::ContractTransportAdapter::client_capabilities ( ) const
inlineoverridevirtual

Return capabilities learned from the client's initialize request.

Returns
Client capabilities when known; std::nullopt before initialize or when the transport cannot provide them.

Reimplemented from mcp::server::Transport.

◆ name()

std::string_view mcp::server::ContractTransportAdapter::name ( ) const
inlineoverridevirtualnoexcept

Human-readable transport name for diagnostics.

Returns
A static string view owned by the transport implementation.

Implements mcp::server::Transport.

◆ send_notification()

core::Result< core::Unit > mcp::server::ContractTransportAdapter::send_notification ( const protocol::JsonRpcNotification notification)
inlineoverridevirtual

Send a JSON-RPC notification from the server to the client.

Parameters
notificationNotification to serialize and deliver.
Returns
core::Unit on success, or a core::Error for serialization, stopped-session, or I/O failures.

Implements mcp::server::Transport.

◆ send_request()

core::Result< protocol::JsonRpcResponse > mcp::server::ContractTransportAdapter::send_request ( const protocol::JsonRpcRequest request)
inlineoverridevirtual

Send a JSON-RPC request from the server to the connected client.

Parameters
requestRequest to serialize and deliver.
Returns
The client response, or an error if outbound requests are not supported or delivery fails.
Note
The base implementation returns MethodNotFound because not every transport can correlate outbound requests with client responses.

Reimplemented from mcp::server::Transport.

◆ start()

core::Result< core::Unit > mcp::server::ContractTransportAdapter::start ( RequestHandler  handler,
NotificationHandler  notification_handler = {} 
)
inlineoverridevirtual

Start accepting inbound messages and dispatch them to handlers.

Parameters
handlerRequired request handler.
notification_handlerOptional notification handler.
Returns
core::Unit when the transport stops cleanly, or a core::Error for setup, I/O, parse, serialization, or callback failures.
Note
Implementations may block until stop() is called or input ends.

Implements mcp::server::Transport.

◆ stop()

void mcp::server::ContractTransportAdapter::stop ( )
inlineoverridevirtualnoexcept

Request transport shutdown.

stop() is best-effort and must not throw. Implementations should unblock any running start() call or pending outbound operation where possible.

Implements mcp::server::Transport.


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