include/entropic/mcp/tool_base.h

← API

include/entropic/mcp/tool_base.h

entropic::ToolBase

Abstract base class for individual MCP tools.

Derived by entropic::CheckErrorsTool, entropic::CompleteTool, entropic::ContextInspectTool, entropic::DelegateTool, entropic::DiagnoseTool, entropic::DiagnosticsTool, entropic::EditFileTool, entropic::ExecuteTool, entropic::FollowupTool, entropic::GitAddTool, entropic::GitBranchTool, entropic::GitCheckoutTool, entropic::GitCommitTool, entropic::GitDiffTool, entropic::GitLogTool, entropic::GitResetTool, entropic::GitStatusTool, entropic::GlobTool, entropic::GrepTool, entropic::InspectTool, entropic::ListDirectoryTool, entropic::PhaseChangeTool, entropic::PipelineTool, entropic::PruneContextTool, entropic::ReadFileTool, entropic::ResumeDelegationTool, entropic::TodoTool, entropic::WebFetchTool, entropic::WebSearchTool, entropic::WriteFileTool.

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

entropic::ToolBase::ToolBase(ToolDefinition def)

Construct with a pre-built definition.

Parameters
  • def — Tool definition.

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

Get the tool name.

Returns
Tool name from definition.

const ToolDefinition & entropic::ToolBase::definition() const

Get the full tool definition.

Returns
Tool definition reference.

virtual ServerResponse entropic::ToolBase::execute(const std::string &args_json)=0

Execute this tool with the given arguments.

Parameters
  • args_json — JSON string of arguments.
Returns
ServerResponse with result text and optional directives.

std::string entropic::ToolBase::anchor_key(const std::string &args_json) const

Generate anchor key for this tool result.

Default anchor_key — no anchoring. Override in tools whose results should REPLACE previous results with the same key rather than accumulating in context. Default returns "" (no anchoring — results append normally). MCPServerBase injects a context_anchor directive only for a non-empty key, so the default leaves the envelope's directives array empty.

Parameters
  • args_json — Tool call arguments as JSON string.
  • args_json — Tool call arguments (unused in the default).
Returns
  • Anchor key string, or empty string for no anchor.
  • Empty string — no ContextAnchor is injected for this tool.

MCPAccessLevel entropic::ToolBase::required_access_level() const

Minimum access level required to execute this tool.

Default required access level — WRITE (safe default). Override in read-only tools (e.g., read_file, list_directory). The ToolExecutor checks this against the caller's MCPKeySet before executing. A newly added tool is treated as privileged until someone deliberately relaxes it; read-only tools override this to READ.

Returns
  • MCPAccessLevel::WRITE by default (safe default).
  • MCPAccessLevel::WRITE for every tool that does not override.

entropic::ToolDefinition

Parsed tool definition from JSON schema file.

std::string entropic::ToolDefinition::name

Tool name (e.g., "read_file")

std::string entropic::ToolDefinition::description

Human-readable description.

std::string entropic::ToolDefinition::input_schema

JSON Schema for arguments (raw JSON string)

std::string entropic::ToolDefinition::output_schema

JSON Schema for the result ("" = undeclared). v2.14.0.