cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
stdio_transport.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 [caomengxuan666]
2
3#pragma once
4
7
8#include <iosfwd>
9
11
12namespace mcp::client {
13
24class StdioTransport final : public Transport {
25 public:
28
33 StdioTransport(std::istream& input, std::ostream& output);
34
38 const protocol::JsonRpcRequest& request) override;
39
42 const protocol::JsonRpcNotification& notification) override;
43
49 TransportRequestHandler request_handler,
50 TransportNotificationHandler notification_handler = {}) override;
51
52 private:
53 std::istream* input_;
54 std::ostream* output_;
55 bool started_ = false;
56 TransportRequestHandler request_handler_;
57 TransportNotificationHandler notification_handler_;
58};
59
60} // namespace mcp::client
Client transport backed by std::istream and std::ostream.
Definition stdio_transport.hpp:24
StdioTransport(std::istream &input, std::ostream &output)
Creates a stdio transport using caller-owned streams.
core::Result< core::Unit > start(TransportRequestHandler request_handler, TransportNotificationHandler notification_handler={}) override
Starts receive-side dispatch for stream input.
core::Result< protocol::JsonRpcResponse > send(const protocol::JsonRpcRequest &request) override
Sends one JSON-RPC request over the output stream and waits for a response.
StdioTransport()
Creates a stdio transport using standard input and output streams.
core::Result< core::Unit > send_notification(const protocol::JsonRpcNotification &notification) override
Sends one JSON-RPC notification over the output stream.
Abstract client transport used by Client to exchange JSON-RPC messages.
Definition client.hpp:83
Core client compatibility API and transport interface for MCP clients.
std::function< core::Result< core::Unit >(const protocol::JsonRpcNotification &)> TransportNotificationHandler
Handles JSON-RPC notifications sent by the server to this client.
Definition client.hpp:75
std::function< core::Result< protocol::JsonRpcResponse >(const protocol::JsonRpcRequest &)> TransportRequestHandler
Handles JSON-RPC requests sent by the server to this client.
Definition client.hpp:68
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
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