|
Entropic 2.14.3
Local-first agentic inference engine
|
Concrete base class for MCP servers (80% logic). More...
#include <entropic/mcp/server_base.h>


Public Member Functions | |
| MCPServerBase (std::string name) | |
| Construct with server name. | |
| const std::string & | name () const |
| Get the server name. | |
| void | register_tool (ToolBase *tool) |
| Register a tool with this server. | |
| std::string | list_tools () const |
| List all registered tools as a JSON array string. | |
| std::string | execute (const std::string &tool_name, const std::string &raw_args_json) |
| Execute a tool and wrap result in ServerResponse JSON. | |
| virtual std::string | get_permission_pattern (const std::string &tool_name, const std::string &args_json) const |
| Generate permission pattern for 'Always Allow/Deny'. | |
| virtual bool | skip_duplicate_check (const std::string &tool_name) const |
| Check if a tool should skip duplicate detection. | |
| virtual bool | configure (const std::string &config_json) |
| Configure the server after creation. | |
| virtual bool | set_working_dir (const std::string &path) |
| Set the working directory. | |
| const ToolRegistry & | registry () const |
| Get the tool registry (const). | |
Protected Attributes | |
| std::string | name_ |
| Server name. | |
| ToolRegistry | registry_ |
| Tool registry. | |
Concrete base class for MCP servers (80% logic).
Owns a ToolRegistry. Provides:
Concrete servers (FilesystemServer, BashServer, etc.) subclass and:
Definition at line 66 of file server_base.h.
|
explicit |
Construct with server name.
| name | Server name (e.g., "filesystem", "bash", "git"). |
| name | Server name. @dg_internal |
Definition at line 25 of file server_base.cpp.
Configure the server after creation.
Default configure: no-op.
| config_json | JSON configuration string. |
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.
| config_json | Configuration JSON (unused in the default). |
Definition at line 246 of file server_base.cpp.
| 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.
| tool_name | Tool name (without server prefix). |
| raw_args_json | JSON string of arguments, as supplied. |
result and no directives — never a throw (gh#143). Flow:
{} (gh#143)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.
| tool_name | Tool name (without server prefix). |
| args_json | JSON arguments. |
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. @req REQ-MCP-001 @req REQ-MCP-002 Definition at line 165 of file server_base.cpp.
|
virtual |
Generate permission pattern for 'Always Allow/Deny'.
Default permission pattern: tool-level.
| tool_name | Fully-qualified tool name (e.g., "filesystem.read_file"). |
| args_json | Tool call arguments as JSON string. |
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.
| tool_name | Fully-qualified tool name. |
| args_json | Tool arguments (unused in the default — the default granularity is deliberately argument-independent). |
Reimplemented in entropic::BashServer.
Definition at line 209 of file server_base.cpp.
| 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.
Definition at line 68 of file server_base.cpp.
| const std::string & entropic::MCPServerBase::name | ( | ) | const |
Get the server name.
Definition at line 34 of file server_base.cpp.
Register a tool with this server.
| tool | Non-owning pointer. Server does NOT take ownership. |
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.
| tool | Tool pointer (non-owning; the server retains ownership of the tool objects themselves). @req REQ-MCP-001 @req REQ-MCP-003 |
Definition at line 51 of file server_base.cpp.
|
inline |
Get the tool registry (const).
Definition at line 171 of file server_base.h.
Set the working directory.
Default set_working_dir: no-op.
| path | New working directory path. |
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.
| path | Working directory (unused in the default). |
Reimplemented in entropic::BashServer, entropic::FilesystemServer, and entropic::GitServer.
Definition at line 261 of file server_base.cpp.
Check if a tool should skip duplicate detection.
Default: do not skip duplicate check.
| tool_name | Local tool name (without server prefix). |
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).
| tool_name | Tool name (unused in the default). |
Reimplemented in entropic::EntropicServer, and entropic::FilesystemServer.
Definition at line 230 of file server_base.cpp.
|
protected |
Server name.
Definition at line 174 of file server_base.h.
|
protected |
Tool registry.
Definition at line 175 of file server_base.h.