include/entropic/mcp/server_base.h

← API

include/entropic/mcp/server_base.h

entropic::MCPServerBase

Concrete base class for MCP servers (80% logic).

Derived by entropic::BashServer, entropic::DiagnosticsServer, entropic::EntropicServer, entropic::FilesystemServer, entropic::GitServer, entropic::WebServer.

virtual entropic::MCPServerBase::~MCPServerBase()=default

entropic::MCPServerBase::MCPServerBase(std::string name)

Construct with server name.

Parameters
  • name — Server name (e.g., "filesystem", "bash", "git").
  • name — Server name.

const std::string & entropic::MCPServerBase::name() const

Get the server name.

Returns
  • Server name string.
  • Server name.

void entropic::MCPServerBase::register_tool(ToolBase *tool)

Register a tool with this server.

Registration is the one thing every concrete server does in its constructor; the base owns the registry so a subclass cannot lose dispatch, envelope shape, or anchoring by forgetting to wire them.

Parameters
  • tool — Non-owning pointer. Server does NOT take ownership.
  • tool — Tool pointer (non-owning; the server retains ownership of the tool objects themselves).

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

List all registered tools as a JSON array string.

List all registered tools as JSON array. Non-virtual: ServerManager concatenates this across every in-process server so the model sees one flat tool list.

Returns
  • JSON array of tool definitions.
  • JSON array string — one object per registered tool carrying name, description and inputSchema; "[]" when nothing is registered.

std::string entropic::MCPServerBase::execute(const std::string &tool_name, const std::string &raw_args_json)

Execute a tool and wrap result in ServerResponse JSON.

Execute a tool and return ServerResponse JSON. Flow: Normalise non-object arguments to {} (gh#143) Dispatch to registered ToolBase::execute() If tool declares anchor_key(): auto-inject ContextAnchor directive Serialize to JSON ServerResponse envelope Steps 2-3 run under an exception barrier, so a throwing tool neither escapes nor gets its arguments anchored into context. The base owns the whole dispatch path — registry lookup, automatic ContextAnchor injection for any tool declaring an anchor_key, and envelope serialisation — so a concrete server that overrides nothing still produces the exact shape the DirectiveProcessor parses. gh#143 (v2.12.0): a tool that THROWS is answered the same way as an unknown one — the exception becomes error text in result. This is the in-process counterpart of gh#133's ServerManager::route_plugin_call, which already guarantees that a misbehaving PLUGIN server "becomes a normal tool error rather than an exception unwinding through the loop". In-process servers had no equivalent, so an unhandled throw — a .value() on a non-object (type_error.306), a missing .at() key (out_of_range.403) — escaped four uncaught hops up to run_as_inner and aborted the entire turn. The model never saw the failure and could not correct it. The barrier is HERE rather than in ToolRegistry::dispatch so that a throwing tool also skips inject_anchor_if_needed. A tool that failed must not have its arguments recorded as a ContextAnchor: for FilesystemServer a rejected path traversal would otherwise be anchored into context as though it had been legitimately read.

Parameters
  • tool_name — Tool name (without server prefix).
  • raw_args_json — JSON string of arguments, as supplied.
  • args_json — JSON arguments.
Returns
  • ServerResponse JSON envelope string. An unknown tool, or one that throws, yields the envelope with error text in result and no directives — never a throw (gh#143).
  • ServerResponse JSON envelope: a string result plus a directives array (empty when the tool has no side effects). An unknown tool, or one that throws, yields the same envelope with error text in result rather than a throw — and with no directives, anchor included.

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

Generate permission pattern for 'Always Allow/Deny'.

Default permission pattern: tool-level. Default: returns tool_name (tool-level granularity). Override in subclasses for finer granularity. One of the four extension points with a safe default. A server that wants coarser or finer "always allow" granularity (BashServer keys on the base command) overrides this; everyone else inherits tool-level.

Parameters
  • tool_name — Fully-qualified tool name (e.g., "filesystem.read_file").
  • args_json — Tool call arguments as JSON string.
  • tool_name — Fully-qualified tool name.
  • args_json — Tool arguments (unused in the default — the default granularity is deliberately argument-independent).
Returns
  • Permission pattern string.
  • tool_name as-is, i.e. tool-level permission granularity.

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

Check if a tool should skip duplicate detection.

Default: do not skip duplicate check. Override for tools with side effects that must always execute (e.g., read_file updates FileAccessTracker). Extension point with a safe default — a server opts an individual tool out only when the tool must always run for its side effect (filesystem.read_file updates the read tracker; entropic.delegate and entropic.pipeline are legitimately repeatable).

Parameters
  • tool_name — Local tool name (without server prefix).
  • tool_name — Tool name (unused in the default).
Returns
  • true if duplicate check should be skipped.
  • false — every tool is duplicate-checked unless a subclass says otherwise.

bool entropic::MCPServerBase::configure(const std::string &config_json)

Configure the server after creation.

Default configure: no-op. Default: no-op, returns true. Override for server-specific init. Extension point with a safe default so a server needing no configuration is not forced to implement one.

Parameters
  • config_json — JSON configuration string.
  • config_json — Configuration JSON (unused in the default).
Returns
  • true on success.
  • true — the no-op default always succeeds.

bool entropic::MCPServerBase::set_working_dir(const std::string &path)

Set the working directory.

Default set_working_dir: no-op. Default: no-op, returns true. Override in directory-aware servers. Extension point with a safe default — only directory-aware servers (filesystem, bash, git) need to re-root.

Parameters
  • path — New working directory path.
  • path — Working directory (unused in the default).
Returns
  • true on success.
  • true — the no-op default always succeeds.

bool entropic::MCPServerBase::requires_approval(const std::string &tool_name) const

Whether a call to this tool needs the host's approval.

Default approval requirement: every tool is gated. Default: true. Only an in-process server is consulted, so a plugin or external server can never exempt its own tools. Declared after every other virtual so existing vtable slots keep their positions. Safe default: a server must opt a tool OUT of the host's approval gate.

Parameters
  • tool_name — Local tool name (without server prefix).
  • tool_name — Local tool name (unused in the default).
Returns
  • true when the approval gate applies (the default); false for a tool that is the engine directing itself rather than an action on the user's system.
  • true — the approval gate applies.

const ToolRegistry & entropic::MCPServerBase::registry() const

Get the tool registry (const).

Returns
Reference to this server's tool registry.

entropic::ServerResponse

Structured result from tool execution.

std::string entropic::ServerResponse::result

Human-readable result.

std::vector<Directive> entropic::ServerResponse::directives

Engine-level side effects.