Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::ServerManager Class Reference

Manages MCP server instances and routes tool calls. More...

#include <entropic/mcp/server_manager.h>

Public Member Functions

 ServerManager (const PermissionsConfig &permissions, const std::filesystem::path &project_dir)
 Construct with permission config and project directory.
 
void register_server (std::unique_ptr< MCPServerBase > server)
 Register a built-in server (in-process, ownership transferred).
 
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.
 
void initialize ()
 Initialize all registered servers.
 
std::string list_tools () const
 List all tools from all connected servers.
 
std::string execute (const std::string &tool_name, const std::string &args_json)
 Execute a tool call via the appropriate server.
 
MCPServerBaseget_server (const std::string &name) const
 Get a registered in-process server by name.
 
std::vector< std::string > server_names () const
 List registered server names (in-process + external).
 
const std::filesystem::path & project_dir () const
 Get the project root directory.
 
std::string get_tool_schema (const std::string &tool_name) const
 Get the JSON Schema for a tool's input parameters.
 
bool is_explicitly_allowed (const std::string &tool_name, const std::string &args_json) const
 Check if tool is explicitly allowed (skip prompting).
 
std::string get_permission_pattern (const std::string &tool_name, const std::string &args_json) const
 Generate permission pattern via server class delegation.
 
bool skip_duplicate_check (const std::string &tool_name) const
 Check if tool should skip duplicate detection.
 
MCPAccessLevel get_required_access_level (const std::string &tool_name) const
 Get the required access level for a tool.
 
void add_permission (const std::string &pattern, bool allow)
 Add a runtime permission pattern.
 
void shutdown ()
 Shutdown all servers (in-process + external).
 
std::vector< std::string > connect_external_server (const ExternalServerConfig &spec)
 Connect to an external MCP server at runtime (canonical spec-based API).
 
std::vector< std::string > connect_external_server (const std::string &name, const std::string &command="", const std::vector< std::string > &args={}, const std::string &url="")
 Connect by primitive parameters (legacy convenience).
 
void disconnect_external_server (const std::string &name)
 Disconnect and remove an external server.
 
std::map< std::string, ServerInfolist_server_info () const
 Get snapshot of all servers with current status.
 
void process_health_events ()
 Process pending health events (call from engine loop).
 
void set_mcp_config (const MCPConfig &config)
 Set MCP config for external server initialization.
 
void interrupt_external_tools ()
 Abort in-flight tool calls across every external MCP client.
 

Detailed Description

Manages MCP server instances and routes tool calls.

Owns both in-process servers (v1.8.5) and external MCP clients (v1.8.7). Tool routing by server prefix is uniform across both. External servers discovered from .mcp.json and YAML config.

Version
1.8.7

Definition at line 56 of file server_manager.h.

Constructor & Destructor Documentation

◆ ServerManager()

entropic::ServerManager::ServerManager ( const PermissionsConfig permissions,
const std::filesystem::path &  project_dir 
)

Construct with permission config and project directory.

Parameters
permissionsPermission configuration.
project_dirProject root directory.
Version
1.8.5
Parameters
permissionsPermission configuration.
project_dirProject root directory.

Definition at line 32 of file server_manager.cpp.

Member Function Documentation

◆ add_permission()

void entropic::ServerManager::add_permission ( const std::string &  pattern,
bool  allow 
)

Add a runtime permission pattern.

Parameters
patternPermission pattern.
allowtrue for allow list, false for deny list.
Version
1.8.5
Parameters
patternPermission pattern.
allowtrue for allow list.

Definition at line 359 of file server_manager.cpp.

◆ connect_external_server() [1/2]

std::vector< std::string > entropic::ServerManager::connect_external_server ( const ExternalServerConfig spec)

Connect to an external MCP server at runtime (canonical spec-based API).

Connect (canonical spec-based) — Issue #9, v2.1.4.

Issue #9 (v2.1.4): unifies the runtime API and config-file paths. The full ExternalServerConfig is honored — including env, which pre-2.1.4 was silently dropped from the 4-arg path. The ServerConfig.name field is required.

Parameters
specFull server config (transport/command/args/env/url).
Returns
List of tool names registered from the server.
Version
2.1.4

The full ExternalServerConfig is honored. Replaces the pre-2.1.4 runtime path which silently dropped env (and any future spec field).

Definition at line 598 of file server_manager.cpp.

◆ connect_external_server() [2/2]

std::vector< std::string > entropic::ServerManager::connect_external_server ( const std::string &  name,
const std::string &  command = "",
const std::vector< std::string > &  args = {},
const std::string &  url = "" 
)

Connect by primitive parameters (legacy convenience).

Legacy primitive-args overload — forwards to spec-based API.

Forwards to the spec-based overload above; provided for backwards-compat with in-tree callers. Pre-2.1.4 callers that passed only command/args/url get default-empty env. Prefer the spec-based overload for new code. (#9, v2.1.4)

Parameters
nameUnique server name.
commandStdio command (mutually exclusive with url).
argsStdio command arguments.
urlSSE endpoint URL (mutually exclusive with command).
Returns
List of tool names registered from the server.
Version
2.1.4

Retained for in-tree callers that pre-date #9. New code should use the spec-based overload.

Definition at line 640 of file server_manager.cpp.

◆ disconnect_external_server()

void entropic::ServerManager::disconnect_external_server ( const std::string &  name)

Disconnect and remove an external server.

Parameters
nameServer name to disconnect.
Version
1.8.7
Parameters
nameServer name.

Definition at line 659 of file server_manager.cpp.

◆ execute()

std::string entropic::ServerManager::execute ( const std::string &  tool_name,
const std::string &  args_json 
)

Execute a tool call via the appropriate server.

Parameters
tool_nameFully-qualified name (e.g., "filesystem.read_file").
args_jsonJSON arguments string.
Returns
ServerResponse JSON envelope.
Version
1.8.5

Checks permissions before execution. Returns error JSON if denied or server not found.

Parameters
tool_nameFully-qualified name.
args_jsonJSON arguments.
Returns
ServerResponse JSON envelope.

Definition at line 153 of file server_manager.cpp.

◆ get_permission_pattern()

std::string entropic::ServerManager::get_permission_pattern ( const std::string &  tool_name,
const std::string &  args_json 
) const

Generate permission pattern via server class delegation.

Generate permission pattern via server delegation.

Parameters
tool_nameFully-qualified tool name.
args_jsonTool arguments as JSON.
Returns
Permission pattern string.
Version
1.8.5
Parameters
tool_nameFully-qualified tool name.
args_jsonTool arguments.
Returns
Permission pattern.

Definition at line 301 of file server_manager.cpp.

◆ get_required_access_level()

MCPAccessLevel entropic::ServerManager::get_required_access_level ( const std::string &  tool_name) const

Get the required access level for a tool.

Parameters
tool_nameFully-qualified tool name (e.g., "filesystem.read_file").
Returns
MCPAccessLevel required, or WRITE if tool not found.
Version
1.9.4
Parameters
tool_nameFully-qualified tool name.
Returns
MCPAccessLevel required, or WRITE if not found.

Definition at line 338 of file server_manager.cpp.

◆ get_server()

MCPServerBase * entropic::ServerManager::get_server ( const std::string &  name) const

Get a registered in-process server by name.

Parameters
nameServer name (e.g., "entropic", "filesystem").
Returns
Server pointer, or nullptr if not found.
Version
2.0.6
Parameters
nameServer name.
Returns
Server pointer, or nullptr if not found.

Definition at line 177 of file server_manager.cpp.

◆ get_tool_schema()

std::string entropic::ServerManager::get_tool_schema ( const std::string &  tool_name) const

Get the JSON Schema for a tool's input parameters.

Parameters
tool_nameFully-qualified tool name.
Returns
input_schema JSON string, or empty if tool not found.
Version
2.0.6
Parameters
tool_nameFully-qualified tool name.
Returns
input_schema JSON string, or empty if tool not found.

Definition at line 206 of file server_manager.cpp.

◆ init_builtins()

void entropic::ServerManager::init_builtins ( const MCPConfig mcp,
const std::vector< std::string > &  tier_names,
const std::string &  data_dir 
)

Register built-in servers based on config flags.

Creates and registers enabled built-in servers (entropic, filesystem, bash, git, diagnostics, web). Called by the facade after construction.

Parameters
mcp_configMCP config with enable flags.
tier_namesTier names for entropic server schemas.
data_dirBundled data directory path.
Version
2.0.1
Parameters
mcpMCP config with enable flags.
tier_namesTier names for entropic server.
data_dirBundled data directory.

Definition at line 46 of file server_manager.cpp.

◆ initialize()

void entropic::ServerManager::initialize ( )

Initialize all registered servers.

Initialize all registered servers + external connections.

Version
1.8.5

Definition at line 97 of file server_manager.cpp.

◆ interrupt_external_tools()

void entropic::ServerManager::interrupt_external_tools ( )

Abort in-flight tool calls across every external MCP client.

Signal every external client to cancel its in-flight tool.

Invoked from the engine's interrupt path so Ctrl+C unwinds docs_server.py / bash etc. within ~100ms instead of waiting out the transport timeout. (P1-10, 2.0.6-rc16)

@utility

Version
2.0.6-rc16

Called by AgentEngine::interrupt() via a facade-wired callback so tool dispatches to docs_server.py / bash / git unwind within ~100ms of Ctrl+C instead of running to completion. (P1-10, 2.0.6-rc16)

Definition at line 467 of file server_manager.cpp.

◆ is_explicitly_allowed()

bool entropic::ServerManager::is_explicitly_allowed ( const std::string &  tool_name,
const std::string &  args_json 
) const

Check if tool is explicitly allowed (skip prompting).

Check if tool is explicitly allowed.

Parameters
tool_nameFully-qualified tool name.
args_jsonTool arguments as JSON.
Returns
true if in allow list.
Version
1.8.5
Parameters
tool_nameFully-qualified tool name.
args_jsonTool arguments.
Returns
true if in allow list.

Definition at line 286 of file server_manager.cpp.

◆ list_server_info()

std::map< std::string, ServerInfo > entropic::ServerManager::list_server_info ( ) const

Get snapshot of all servers with current status.

Returns
Map of server name to ServerInfo.
Version
1.8.7
Returns
Map of name to ServerInfo.

Definition at line 686 of file server_manager.cpp.

◆ list_tools()

std::string entropic::ServerManager::list_tools ( ) const

List all tools from all connected servers.

List tools from all servers (in-process + external).

Returns
JSON array string of tool definitions.
Version
1.8.5
Returns
JSON array string.

Definition at line 113 of file server_manager.cpp.

◆ process_health_events()

void entropic::ServerManager::process_health_events ( )

Process pending health events (call from engine loop).

Process pending health events.

Version
1.8.7

Definition at line 708 of file server_manager.cpp.

◆ project_dir()

const std::filesystem::path & entropic::ServerManager::project_dir ( ) const
inline

Get the project root directory.

Returns
Project directory path. @utility
Version
2.0.6

Definition at line 137 of file server_manager.h.

◆ register_server()

void entropic::ServerManager::register_server ( std::unique_ptr< MCPServerBase server)

Register a built-in server (in-process, ownership transferred).

Register a built-in server.

Parameters
serverServer instance.
Version
1.8.5
Parameters
serverServer instance (ownership transferred).

Definition at line 81 of file server_manager.cpp.

◆ server_names()

std::vector< std::string > entropic::ServerManager::server_names ( ) const

List registered server names (in-process + external).

List all registered server names.

Returns
Server names.
Version
2.0.6
Returns
Server names (in-process + external).

Definition at line 188 of file server_manager.cpp.

◆ set_mcp_config()

void entropic::ServerManager::set_mcp_config ( const MCPConfig config)

Set MCP config for external server initialization.

Parameters
configMCP configuration with external_servers.
Version
1.8.7
Parameters
configMCP configuration.

Definition at line 453 of file server_manager.cpp.

◆ shutdown()

void entropic::ServerManager::shutdown ( )

Shutdown all servers (in-process + external).

Version
1.8.7

Definition at line 369 of file server_manager.cpp.

◆ skip_duplicate_check()

bool entropic::ServerManager::skip_duplicate_check ( const std::string &  tool_name) const

Check if tool should skip duplicate detection.

Parameters
tool_nameFully-qualified tool name.
Returns
true if duplicate check should be skipped.
Version
1.8.5
Parameters
tool_nameFully-qualified tool name.
Returns
true if skip.

Definition at line 320 of file server_manager.cpp.


The documentation for this class was generated from the following files: