Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
server_manager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#pragma once
14
21
22#include <chrono>
23#include <filesystem>
24#include <map>
25#include <memory>
26#include <string>
27#include <vector>
28
29namespace entropic {
30
35struct ServerInfo {
36 std::string name;
37 std::string transport;
38 std::string url;
39 std::string command;
40 std::string status;
41 std::vector<std::string> tools;
42 std::string source;
43 std::chrono::system_clock::time_point connected_at;
45};
46
57public:
64 ServerManager(const PermissionsConfig& permissions,
65 const std::filesystem::path& project_dir);
66
72 void register_server(std::unique_ptr<MCPServerBase> server);
73
86 void init_builtins(const MCPConfig& mcp_config,
87 const std::vector<std::string>& tier_names,
88 const std::string& data_dir);
89
94 void initialize();
95
101 std::string list_tools() const;
102
113 std::string execute(const std::string& tool_name,
114 const std::string& args_json);
115
122 MCPServerBase* get_server(const std::string& name) const;
123
129 std::vector<std::string> server_names() const;
130
137 const std::filesystem::path& project_dir() const { return project_dir_; }
138
145 std::string get_tool_schema(const std::string& tool_name) const;
146
154 bool is_explicitly_allowed(const std::string& tool_name,
155 const std::string& args_json) const;
156
164 std::string get_permission_pattern(const std::string& tool_name,
165 const std::string& args_json) const;
166
173 bool skip_duplicate_check(const std::string& tool_name) const;
174
182 const std::string& tool_name) const;
183
190 void add_permission(const std::string& pattern, bool allow);
191
196 void shutdown();
197
198 /* ── v1.8.7: External server methods ───────────────── */
199
213 std::vector<std::string> connect_external_server(
214 const ExternalServerConfig& spec);
215
231 std::vector<std::string> connect_external_server(
232 const std::string& name,
233 const std::string& command = "",
234 const std::vector<std::string>& args = {},
235 const std::string& url = "");
236
242 void disconnect_external_server(const std::string& name);
243
249 std::map<std::string, ServerInfo> list_server_info() const;
250
256
262 void set_mcp_config(const MCPConfig& config);
263
275
276private:
283 static std::string extract_prefix(const std::string& tool_name);
284
291 static std::string extract_local_name(const std::string& tool_name);
292
299 static std::string args_to_pattern(const std::string& args_json);
300
301 PermissionManager permissions_;
302 std::filesystem::path project_dir_;
303 std::map<std::string, std::unique_ptr<MCPServerBase>> servers_;
304
305 /* ── v1.8.7: External server state ─────────────────── */
306 std::map<std::string, std::unique_ptr<ExternalMCPClient>> external_clients_;
307 std::map<std::string, ServerInfo> server_info_;
308 std::unique_ptr<HealthMonitor> health_monitor_;
309 std::unique_ptr<MCPJsonDiscovery> mcp_json_discovery_;
310 MCPConfig mcp_config_;
311
317 void initialize_external_servers();
318
327 std::string route_tool_call(const std::string& tool_name,
328 const std::string& args_json);
329
340 std::string route_external_call(
341 ExternalMCPClient* client,
342 const std::string& tool_name,
343 const std::string& local_name,
344 const std::string& args_json);
345
356 void connect_and_register_external(
357 const std::string& name,
358 std::unique_ptr<ExternalMCPClient> client,
359 const std::string& source,
360 const std::string& url,
361 const std::string& command);
362
371 std::unique_ptr<ExternalMCPClient> create_external_client(
372 const std::string& name,
373 const ExternalServerEntry& entry);
374
382 std::unique_ptr<ExternalMCPClient> create_external_client(
383 const ExternalServerConfig& config);
384
399 static std::unique_ptr<Transport> make_transport(
400 const ExternalServerConfig& spec);
401
410 static std::string disconnected_error(
411 const std::string& tool_name,
412 const std::string& server_name);
413};
414
415} // namespace entropic
Concrete base class for MCP servers (80% logic).
Definition server_base.h:66
Manages MCP server instances and routes tool calls.
std::vector< std::string > connect_external_server(const ExternalServerConfig &spec)
Connect to an external MCP server at runtime (canonical spec-based API).
MCPAccessLevel get_required_access_level(const std::string &tool_name) const
Get the required access level for a tool.
bool is_explicitly_allowed(const std::string &tool_name, const std::string &args_json) const
Check if tool is explicitly allowed (skip prompting).
std::map< std::string, ServerInfo > list_server_info() const
Get snapshot of all servers with current status.
std::vector< std::string > server_names() const
List registered server names (in-process + external).
void process_health_events()
Process pending health events (call from engine loop).
MCPServerBase * get_server(const std::string &name) const
Get a registered in-process server by name.
const std::filesystem::path & project_dir() const
Get the project root directory.
std::string list_tools() const
List all tools from all connected servers.
void register_server(std::unique_ptr< MCPServerBase > server)
Register a built-in server (in-process, ownership transferred).
void add_permission(const std::string &pattern, bool allow)
Add a runtime permission pattern.
bool skip_duplicate_check(const std::string &tool_name) const
Check if tool should skip duplicate detection.
void init_builtins(const MCPConfig &mcp_config, const std::vector< std::string > &tier_names, const std::string &data_dir)
Register built-in servers based on config flags.
std::string get_permission_pattern(const std::string &tool_name, const std::string &args_json) const
Generate permission pattern via server class delegation.
std::string get_tool_schema(const std::string &tool_name) const
Get the JSON Schema for a tool's input parameters.
void interrupt_external_tools()
Abort in-flight tool calls across every external MCP client.
std::string execute(const std::string &tool_name, const std::string &args_json)
Execute a tool call via the appropriate server.
void set_mcp_config(const MCPConfig &config)
Set MCP config for external server initialization.
void shutdown()
Shutdown all servers (in-process + external).
void disconnect_external_server(const std::string &name)
Disconnect and remove an external server.
void initialize()
Initialize all registered servers.
Configuration structs with defaults.
Client for communicating with external MCP servers.
Monitors external MCP server health and triggers reconnection.
Discovers external MCP servers from .mcp.json files.
Activate model on GPU (WARM → ACTIVE).
MCPAccessLevel
MCP tool access level for per-identity authorization.
Definition config.h:38
Permission manager for MCP tool access control.
MCPServerBase concrete base class + ServerResponse.
Parsed server entry from .mcp.json.
MCP server configuration.
Definition config.h:455
Tool permission configuration.
Definition config.h:400
Runtime state of a connected MCP server.
std::string url
SSE URL (empty otherwise)
std::string transport
"stdio" | "sse" | "in_process"
std::string source
"builtin" | "config" | "mcp_json" | "runtime"
std::vector< std::string > tools
Registered tool names (prefixed)
std::string name
Server name (unique key)
std::string command
Stdio command (empty otherwise)
int reconnect_attempts
Current reconnect attempt count.
std::chrono::system_clock::time_point connected_at
Connection timestamp.
std::string status
"connected" | "disconnected" | "error" | "reconnecting"