cxxmcp 1.1.6
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/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.
 

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.