cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
process_stdio_transport.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 [caomengxuan666]
2
3#pragma once
4
8
9#include <chrono>
10#include <memory>
11#include <optional>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
17
18namespace mcp::client {
19
23 std::string command;
24
26 std::vector<std::string> args;
27
29 std::string cwd;
30
32 std::unordered_map<std::string, std::string> env;
33
36 std::optional<std::chrono::milliseconds> request_timeout =
37 std::chrono::seconds(30);
38};
39
46class ProcessStdioTransport final : public Transport {
47 public:
51
52 ~ProcessStdioTransport() override;
53
55 ProcessStdioTransport& operator=(const ProcessStdioTransport&) = delete;
56
60 const protocol::JsonRpcRequest& request) override;
61
64 const protocol::JsonRpcNotification& notification) override;
65
70 TransportRequestHandler request_handler,
71 TransportNotificationHandler notification_handler = {}) override;
72
74 void stop() noexcept override;
75
76 private:
77 class Impl;
78
80 std::unique_ptr<Impl> impl_;
81};
82
83} // namespace mcp::client
Client transport that owns a child process and exchanges JSON-RPC over stdio.
Definition process_stdio_transport.hpp:46
ProcessStdioTransport(ProcessStdioTransportOptions options)
Creates a child-process stdio transport.
core::Result< protocol::JsonRpcResponse > send(const protocol::JsonRpcRequest &request) override
Sends one JSON-RPC request to the child process and waits for a response.
core::Result< core::Unit > start(TransportRequestHandler request_handler, TransportNotificationHandler notification_handler={}) override
Starts the child process and receive loop when needed.
void stop() noexcept override
Stops the child process and receive loop.
core::Result< core::Unit > send_notification(const protocol::JsonRpcNotification &notification) override
Sends one JSON-RPC notification to the child process.
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
Configuration for a child-process stdio transport.
Definition process_stdio_transport.hpp:21
std::string cwd
Optional working directory for the child process.
Definition process_stdio_transport.hpp:29
std::optional< std::chrono::milliseconds > request_timeout
Optional maximum time to wait for a JSON-RPC response from the child.
Definition process_stdio_transport.hpp:36
std::vector< std::string > args
Command-line arguments passed to the executable.
Definition process_stdio_transport.hpp:26
std::string command
Executable to launch.
Definition process_stdio_transport.hpp:23
std::unordered_map< std::string, std::string > env
Extra environment variables for the child process.
Definition process_stdio_transport.hpp:32
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