10#include <unordered_map>
25namespace mcp::server {
48 std::unordered_map<std::string, std::string>
headers;
105 return lifetime_token_;
128 static_cast<int>(protocol::ErrorCode::MethodNotFound),
129 "transport does not support outbound requests",
143 return send_request(request);
159 virtual std::optional<protocol::ClientCapabilities>
162 return client_capabilities();
181 return send_notification(notification);
188 virtual void stop() noexcept = 0;
192 virtual std::string_view name() const noexcept = 0;
199 virtual
void wait_until_ready() {}
202 std::shared_ptr<void> lifetime_token_ = std::make_shared<int>(0);
MCP client and server capability declarations.
Non-owning handle for the client associated with a server session.
Definition peer.hpp:46
Abstract server transport for receiving client JSON-RPC messages.
Definition transport.hpp:99
std::weak_ptr< void > lifetime_token() const noexcept
Weak lifetime token for SessionContext and ClientPeer guards.
Definition transport.hpp:104
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.
Definition transport.hpp:177
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.
Definition transport.hpp:140
virtual core::Result< core::Unit > start(RequestHandler handler, NotificationHandler notification_handler={})=0
Start accepting inbound messages and dispatch them to handlers.
virtual void stop() noexcept=0
Request transport shutdown.
virtual core::Result< core::Unit > send_notification(const protocol::JsonRpcNotification ¬ification)=0
Send a JSON-RPC notification from the server to the client.
virtual std::optional< protocol::ClientCapabilities > client_capabilities_for_session(std::string_view session_id) const
Return capabilities learned for a specific logical session.
Definition transport.hpp:160
virtual core::Result< protocol::JsonRpcResponse > send_request(const protocol::JsonRpcRequest &request)
Send a JSON-RPC request from the server to the connected client.
Definition transport.hpp:124
virtual std::optional< protocol::ClientCapabilities > client_capabilities() const
Return capabilities learned from the client's initialize request.
Definition transport.hpp:149
Shared JSON, JSON-RPC, error, cancellation, and progress model types.
Shared result and error primitives used by the public cxxmcp SDK.
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
Authentication extension points for server transports.
std::function< core::Result< protocol::JsonRpcResponse >(const protocol::JsonRpcRequest &, const SessionContext &)> RequestHandler
Callback used by transports to dispatch inbound JSON-RPC requests.
Definition transport.hpp:74
std::function< core::Result< core::Unit >(const protocol::JsonRpcNotification &, const SessionContext &)> NotificationHandler
Callback used by transports to dispatch inbound JSON-RPC notifications.
Definition transport.hpp:84
Structured error returned by fallible SDK operations.
Definition result.hpp:35
JSON-RPC notification envelope for one-way MCP messages.
Definition types.hpp:137
JSON-RPC request envelope carrying an MCP method invocation.
Definition types.hpp:99
Per-message connection metadata supplied to server handlers.
Definition transport.hpp:42
std::optional< std::string > http_method
HTTP request method for HTTP-based transports.
Definition transport.hpp:50
std::optional< AuthIdentity > auth_identity
Authenticated principal produced by the configured AuthProvider.
Definition transport.hpp:54
std::optional< std::string > http_url
Absolute HTTP request URL for HTTP-based transports.
Definition transport.hpp:52
std::weak_ptr< void > transport_lifetime
Weak lifetime token supplied by the transport.
Definition transport.hpp:60
std::string remote_address
Best-effort remote endpoint description such as "stdio" or an address.
Definition transport.hpp:46
SessionClient client() const noexcept
Return a non-owning handle for the client on this session.
Definition peer.hpp:874
Transport * transport
Borrowed transport used to create a ClientPeer for outbound messages.
Definition transport.hpp:56
std::string session_id
Logical MCP session id when the transport has one.
Definition transport.hpp:44
std::unordered_map< std::string, std::string > headers
Transport-supplied request headers or metadata for this message.
Definition transport.hpp:48