51 std::unique_ptr<Transport> transport);
89 std::string
execute(
const std::string& tool_name,
97 std::pair<std::vector<std::string>, std::vector<std::string>>
113 const std::string&
name()
const {
return name_; }
124 void interrupt() {
if (transport_) { transport_->interrupt(); } }
140 return transport_ && transport_->is_interrupted();
145 std::unique_ptr<Transport> transport_;
146 std::string cached_tools_json_;
147 std::vector<std::string> cached_tool_names_;
148 mutable std::mutex tools_mutex_;
157 std::atomic<int> next_id_{1};
159 static constexpr uint32_t DEFAULT_TIMEOUT_MS = 30000;
160 static constexpr uint32_t INIT_TIMEOUT_MS = 10000;
162 uint32_t init_timeout_ms_ = INIT_TIMEOUT_MS;
172 std::string build_request(
const std::string&
method,
173 const std::string&
params =
"{}");
184 std::string build_request_id(
const std::string&
method,
185 const std::string&
params,
216 static bool response_matches(
const std::string&
response_json,
225 bool send_initialize();
234 bool validate_init_response(
const std::string&
response);
251 static std::string extract_tool_result(
268 std::string empty_response_envelope(
269 const std::string& tool_name)
const;
279 std::string mismatched_response_envelope(
280 const std::string& tool_name,
int expected_id)
const;
290 std::string response_problem(
const std::string& tool_name,
294 static std::string build_response(
const std::string&
result_text,
295 bool is_error =
false);
Client for an external MCP server (stdio or SSE).
std::string list_tools() const
List tools as JSON array string (cached).
const std::string & name() const
Get server name.
std::pair< std::vector< std::string >, std::vector< std::string > > refresh_tools()
Re-query tools/list and diff against cache.
void set_init_timeout_ms(uint32_t ms)
Bound for bringing the server up: initialize + tools/list (gh#175, v2.14.0).
bool is_interrupted() const
Whether this client's transport is currently interrupted.
bool is_connected() const
Check connection state.
void clear_interrupt()
Release an interrupt so this client's transport works again.
void interrupt()
Abort any pending execute() by interrupting the transport.
bool connect()
Connect: open transport + MCP initialize + tools/list.
std::string execute(const std::string &tool_name, const std::string &args_json)
Execute a tool call via the external server.
void disconnect()
Disconnect: close transport.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
Abstract transport for external MCP server communication.