include/entropic/mcp/external_client.h¶
include/entropic/mcp/external_client.h
entropic::ExternalMCPClient
Client for an external MCP server (stdio or SSE).
entropic::ExternalMCPClient::ExternalMCPClient(std::string name, std::unique_ptr< Transport > transport)
Construct with name and transport.
- Parameters
name— Server name (unique key, used as tool prefix).transport— Ownership transferred.name— Server name.
bool entropic::ExternalMCPClient::connect()
Connect: open transport + MCP initialize + tools/list.
Connect: open transport, initialize, query tools. The MCP handshake in order — transport open, initialize, tools/list.
- Returns
- true on success.
- true when the transport opened and initialize succeeded; false otherwise. A failed tools/list is NOT fatal: the client stays connected with zero tools and a warning, so a server that is up but tool-less does not read as down.
void entropic::ExternalMCPClient::set_init_timeout_ms(uint32_t ms)
Bound for bringing the server up: initialize + tools/list (gh#175, v2.14.0).
Set the bring-up bound (gh#175). Applies to the first connect and to every HealthMonitor reconnect. Default INIT_TIMEOUT_MS.
- Parameters
ms— Milliseconds; 0 is ignored (the default stays).ms— Milliseconds; 0 keeps the current bound.
void entropic::ExternalMCPClient::disconnect()
Disconnect: close transport.
Disconnect: close transport, clear cache.
std::string entropic::ExternalMCPClient::list_tools() const
List tools as JSON array string (cached).
List tools as JSON array string (cached, prefixed).
- Returns
- JSON array of tool definitions with prefixed names.
- The cached tool descriptors with names already <server>.<tool>-prefixed, so ServerManager can concatenate them without re-prefixing; "[]" when disconnected.
std::string entropic::ExternalMCPClient::execute(const std::string &tool_name, const std::string &args_json)
Execute a tool call via the external server.
- Parameters
tool_name— Local name (without server prefix).args_json— JSON arguments string.args_json— JSON arguments; unparseable arguments degrade to an empty object rather than throwing.
- Returns
- ServerResponse JSON envelope (directives always empty).
- A ServerResponse JSON envelope whose directives array is ALWAYS empty — see build_response. A disconnected transport or an empty (timed-out) response yields an is_error envelope instead of a hang.
std::pair< std::vector< std::string >, std::vector< std::string > > entropic::ExternalMCPClient::refresh_tools()
Re-query tools/list and diff against cache.
Called after a successful reconnect so the model's tool list tracks a server that changed while it was down.
- Returns
- Pair of (added_names, removed_names).
- A pair of (added, removed) fully-qualified tool names; both empty when the server's surface is unchanged.
bool entropic::ExternalMCPClient::is_connected() const
Check connection state.
Check connection state via transport.
- Returns
- true if transport is connected.
- true if connected.
const std::string & entropic::ExternalMCPClient::name() const
Get server name.
- Returns
- Server name string.
void entropic::ExternalMCPClient::interrupt()
Abort any pending execute() by interrupting the transport.
Delegates to Transport::interrupt(). Safe to call concurrently from the engine's interrupt thread. (P1-10, 2.0.6-rc16)
void entropic::ExternalMCPClient::clear_interrupt()
Release an interrupt so this client's transport works again.
bool entropic::ExternalMCPClient::is_interrupted() const
Whether this client's transport is currently interrupted.
- Returns
- true while calls are being short-circuited by an interrupt.