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

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

#include <entropic/mcp/server_base.h>

Inheritance diagram for entropic::MCPServerBase:
Collaboration diagram for entropic::MCPServerBase:

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 &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 ToolRegistryregistry () const
 Get the tool registry (const).
 

Protected Attributes

std::string name_
 Server name.
 
ToolRegistry registry_
 Tool registry.
 

Detailed Description

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

Owns a ToolRegistry. Provides:

  • Tool registration via register_tool()
  • Tool listing via list_tools() → JSON array
  • Tool dispatch via execute()ServerResponse JSON envelope
  • Automatic ContextAnchor injection when a tool declares anchor_key()
  • Permission pattern generation (virtual, default: "server.tool_name")
  • Duplicate check skip (virtual, default: false)
  • Working directory management (virtual, default: no-op)
  • Configuration via configure() (virtual, default: no-op)

Concrete servers (FilesystemServer, BashServer, etc.) subclass and:

  1. Create ToolBase subclasses for each tool
  2. Register them in the constructor
  3. Override get_permission_pattern() / skip_duplicate_check() as needed
Lifecycle
auto server = std::make_unique<FilesystemServer>();
server->configure(config_json); // server-specific init
server->list_tools(); // JSON array of tool defs
auto result = server->execute("read_file", args_json);
Version
1.8.5

Definition at line 66 of file server_base.h.

Constructor & Destructor Documentation

◆ MCPServerBase()

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

Construct with server name.

Parameters
nameServer name (e.g., "filesystem", "bash", "git").
Version
1.8.5
Parameters
nameServer name.

Definition at line 23 of file server_base.cpp.

Member Function Documentation

◆ configure()

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

Configure the server after creation.

Default configure: no-op.

Parameters
config_jsonJSON configuration string.
Returns
true on success.
Version
1.8.5

Default: no-op, returns true. Override for server-specific init.

Parameters
config_jsonConfiguration JSON (unused in default).
Returns
true.

Definition at line 112 of file server_base.cpp.

◆ execute()

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

Execute a tool and wrap result in ServerResponse JSON.

Execute a tool and return ServerResponse JSON.

Parameters
tool_nameTool name (without server prefix).
args_jsonJSON string of arguments.
Returns
ServerResponse JSON envelope string.
Version
1.8.5

Flow:

  1. Dispatch to registered ToolBase::execute()
  2. If tool declares anchor_key(): auto-inject ContextAnchor directive
  3. Serialize to JSON ServerResponse envelope
Parameters
tool_nameTool name (without server prefix).
args_jsonJSON arguments.
Returns
ServerResponse JSON envelope.

Definition at line 64 of file server_base.cpp.

◆ get_permission_pattern()

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

Generate permission pattern for 'Always Allow/Deny'.

Default permission pattern: tool-level.

Parameters
tool_nameFully-qualified tool name (e.g., "filesystem.read_file").
args_jsonTool call arguments as JSON string.
Returns
Permission pattern string.
Version
1.8.5

Default: returns tool_name (tool-level granularity). Override in subclasses for finer granularity.

Parameters
tool_nameFully-qualified tool name.
args_jsonTool arguments (unused in default).
Returns
tool_name as-is.

Reimplemented in entropic::BashServer.

Definition at line 87 of file server_base.cpp.

◆ list_tools()

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

List all registered tools as a JSON array string.

List all registered tools as JSON array.

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

Definition at line 52 of file server_base.cpp.

◆ name()

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

Get the server name.

Returns
Server name string.
Version
1.8.5
Returns
Server name.

Definition at line 32 of file server_base.cpp.

◆ register_tool()

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

Register a tool with this server.

Parameters
toolNon-owning pointer. Server does NOT take ownership.
Version
1.8.5
Parameters
toolTool pointer (non-owning).

Definition at line 42 of file server_base.cpp.

◆ registry()

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

Get the tool registry (const).

Returns
Reference to this server's tool registry. @utility
Version
1.9.4

Definition at line 165 of file server_base.h.

◆ set_working_dir()

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

Set the working directory.

Default set_working_dir: no-op.

Parameters
pathNew working directory path.
Returns
true on success.
Version
1.8.5

Default: no-op, returns true. Override in directory-aware servers.

Parameters
pathWorking directory (unused in default).
Returns
true.

Reimplemented in entropic::BashServer, entropic::FilesystemServer, and entropic::GitServer.

Definition at line 123 of file server_base.cpp.

◆ skip_duplicate_check()

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

Check if a tool should skip duplicate detection.

Default: do not skip duplicate check.

Parameters
tool_nameLocal tool name (without server prefix).
Returns
true if duplicate check should be skipped.
Version
1.8.5

Override for tools with side effects that must always execute (e.g., read_file updates FileAccessTracker).

Parameters
tool_nameTool name (unused in default).
Returns
false.

Reimplemented in entropic::EntropicServer, and entropic::FilesystemServer.

Definition at line 100 of file server_base.cpp.

Member Data Documentation

◆ name_

std::string entropic::MCPServerBase::name_
protected

Server name.

Definition at line 168 of file server_base.h.

◆ registry_

ToolRegistry entropic::MCPServerBase::registry_
protected

Tool registry.

Definition at line 169 of file server_base.h.


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