cxxmcp 1.3.0
C++ MCP SDK
Loading...
Searching...
No Matches
transport.hpp File Reference

Server-side transport abstraction for MCP JSON-RPC traffic. More...

#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include "cxxmcp/core/result.hpp"
#include "cxxmcp/protocol/capabilities.hpp"
#include "cxxmcp/protocol/serialization.hpp"
#include "cxxmcp/protocol/types.hpp"
#include "cxxmcp/server/auth.hpp"

Go to the source code of this file.

Classes

struct  mcp::server::SessionContext
 Per-message connection metadata supplied to server handlers. More...
 
class  mcp::server::Transport
 Abstract server transport for receiving client JSON-RPC messages. More...
 

Typedefs

using mcp::server::SessionClient = ClientPeer
 Clearer alias for the session-bound client handle returned from server handler contexts.
 
using mcp::server::ClientHandle = ClientPeer
 Alias for applications that want to avoid colliding mentally with the top-level mcp::ClientPeer client-side peer.
 
using mcp::server::RequestHandler = std::function< core::Result< protocol::JsonRpcResponse >(const protocol::JsonRpcRequest &, const SessionContext &)>
 Callback used by transports to dispatch inbound JSON-RPC requests.
 
using mcp::server::NotificationHandler = std::function< core::Result< core::Unit >(const protocol::JsonRpcNotification &, const SessionContext &)>
 Callback used by transports to dispatch inbound JSON-RPC notifications.
 

Functions

std::string_view mcp::server::request_wire_version (const protocol::JsonRpcRequest &request, const SessionContext &context) noexcept
 Best-effort wire protocol version for the current request.
 
bool mcp::server::wire_version_requires_result_type (std::string_view version) noexcept
 True when the wire version requires resultType on result objects (SEP-2322 / MRTR, mandatory since the 2026-07-28 dated release).
 
bool mcp::server::method_requires_cache_hints (std::string_view method) noexcept
 True when a result for method must carry the SEP-2549 caching hints (ttlMs, cacheScope) on the stateless wire.
 

Detailed Description

Server-side transport abstraction for MCP JSON-RPC traffic.

Transports own the server-facing I/O loop and adapt protocol messages into request and notification callbacks. Implementations may be blocking or event-driven, but they all report transport and handler failures through core::Result rather than throwing.

Typedef Documentation

◆ NotificationHandler

using mcp::server::NotificationHandler = typedef std::function<core::Result<core::Unit>( const protocol::JsonRpcNotification&, const SessionContext&)>

Callback used by transports to dispatch inbound JSON-RPC notifications.

Parameters
notificationParsed JSON-RPC notification. The object is owned by the caller.
contextSession and connection metadata for this notification.
Returns
core::Unit on success, or a core::Error that stops or rejects the notification according to the transport implementation.

◆ RequestHandler

using mcp::server::RequestHandler = typedef std::function<core::Result<protocol::JsonRpcResponse>( const protocol::JsonRpcRequest&, const SessionContext&)>

Callback used by transports to dispatch inbound JSON-RPC requests.

Parameters
requestParsed JSON-RPC request. The object is owned by the caller.
contextSession and connection metadata for this request.
Returns
A JSON-RPC response on success, or a core::Error to be translated by the transport into a protocol error response.

Function Documentation

◆ request_wire_version()

std::string_view mcp::server::request_wire_version ( const protocol::JsonRpcRequest &  request,
const SessionContext &  context 
)
inlinenoexcept

Best-effort wire protocol version for the current request.

Checks the stateless version marker in _meta, then the MCP-Protocol-Version request header, then an explicit override, and falls back to the SDK's advertised default. Negotiation still happens in initialize; this is only for version-gated wire fields such as resultType (SEP-2322 / MRTR).