Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
external_client.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
16#pragma once
17
19
20#include <atomic>
21#include <cstdint>
22#include <memory>
23#include <mutex>
24#include <string>
25#include <vector>
26
27namespace entropic {
28
43public:
50 ExternalMCPClient(std::string name,
51 std::unique_ptr<Transport> transport);
52
58 bool connect();
59
68
73 void disconnect();
74
80 std::string list_tools() const;
81
89 std::string execute(const std::string& tool_name,
90 const std::string& args_json);
91
97 std::pair<std::vector<std::string>, std::vector<std::string>>
99
105 bool is_connected() const;
106
113 const std::string& name() const { return name_; }
114
124 void interrupt() { if (transport_) { transport_->interrupt(); } }
125
131 void clear_interrupt() { if (transport_) { transport_->clear_interrupt(); } }
132
139 bool is_interrupted() const {
140 return transport_ && transport_->is_interrupted();
141 }
142
143private:
144 std::string name_;
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};
158
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;
163
172 std::string build_request(const std::string& method,
173 const std::string& params = "{}");
174
184 std::string build_request_id(const std::string& method,
185 const std::string& params,
186 int& id);
187
216 static bool response_matches(const std::string& response_json,
217 int expected_id);
218
225 bool send_initialize();
226
234 bool validate_init_response(const std::string& response);
235
242 bool query_tools();
243
251 static std::string extract_tool_result(
252 const std::string& response_json);
253
268 std::string empty_response_envelope(
269 const std::string& tool_name) const;
270
279 std::string mismatched_response_envelope(
280 const std::string& tool_name, int expected_id) const;
281
290 std::string response_problem(const std::string& tool_name,
291 const std::string& response,
292 int expected_id) const;
293
294 static std::string build_response(const std::string& result_text,
295 bool is_error = false);
296};
297
298} // namespace entropic
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.