tool_base.cpp¶
src/mcp/tool_base.cpp
@file tool_base.cpp @brief ToolBase implementation, load_tool_definition, and the response-format renderer (gh#203).
Owners: @tvanfossen
anchor_key
std::string entropic::ToolBase::anchor_key(const std::string &args_json) const
Generate anchor key for this tool result.
src/mcp/tool_base.cpp:65
Source · 4 lines
std::string ToolBase::anchor_key(
const std::string& /*args_json*/) const {
return "";
}Activity · 1 steps
Requirements
load_tool_definition
ToolDefinition entropic::load_tool_definition(const std::string &tool_name, const std::string &server_prefix, const std::string &data_dir)
Load a tool definition from a JSON file.
src/mcp/tool_base.cpp:297
Called by BashServer, DiagnosticsServer, EditFileTool, GlobTool, GrepTool, ListDirectoryTool, ReadFileTool, SCENARIO, SCENARIO, TEST_CASE, WebServer, WriteFileTool 5 more
create_git_tools, output_schema, register_core_tools, register_delegation_tools, register_introspection_tools
Calls render_response_format
Source · 33 lines
ToolDefinition load_tool_definition(
const std::string& tool_name,
const std::string& server_prefix,
const std::string& data_dir) {
std::string path = data_dir;
if (!server_prefix.empty()) {
path += "/" + server_prefix;
}
path += "/" + tool_name + ".json";
std::ifstream file(path);
if (!file.is_open()) {
throw std::runtime_error(
"Tool definition not found: " + path);
}
// ordered: the rendered Response format keeps the authored key order.
auto json = nlohmann::ordered_json::parse(file);
ToolDefinition def;
def.name = json.at("name").get<std::string>();
def.description = json.value("description", "");
def.input_schema = json.at("inputSchema").dump();
if (json.contains("outputSchema")) {
def.output_schema = json["outputSchema"].dump();
def.description += render_response_format(def.output_schema);
}
logger->info("Loaded tool definition: {} from {}",
def.name, path);
return def;
}Activity · 17 steps
Requirements
render_response_format
std::string entropic::render_response_format(const std::string &output_schema_json)
Render an outputSchema as the compact "Response format" text a model reads (gh#203).
src/mcp/tool_base.cpp:244
Called by SCENARIO, SCENARIO, load_tool_definition, phase_change_definition
Calls collect_notes, render_variants
Source · 15 lines
std::string render_response_format(const std::string& output_schema_json) {
auto schema = ojson::parse(output_schema_json, nullptr, false);
std::string out;
if (schema.is_object()) {
out = "\n\n**Response format** (JSON):\n" + render_variants(schema);
std::vector<std::string> notes;
collect_notes(schema, notes);
for (const auto& note : notes) { out += note + "\n"; }
// Engine-wide, not per tool: a call refused before or thrown out of
// the handler (bad arguments, a refused path, an I/O fault) is
// reported by the server base as plain text (server_base.cpp).
out += "Other failures: plain text `Error: ...`.\n";
}
return out;
}Activity · 10 steps
Requirements
required_access_level
MCPAccessLevel entropic::ToolBase::required_access_level() const
Minimum access level required to execute this tool.
src/mcp/tool_base.cpp:80
Source · 3 lines
MCPAccessLevel ToolBase::required_access_level() const {
return MCPAccessLevel::WRITE;
}Activity · 1 steps
Requirements
tool_error_json
std::string entropic::tool_error_json(const std::string &code, const std::string &message)
A declared tool error: {"error": code, "message": message} .
src/mcp/tool_base.cpp:269
Called by apply_todo_action, dispatch_inspect, execute, execute, execute, filter_json_by_key, option_refusal, pipeline_rejection, todo_index_error
Calls none
Source · 6 lines
std::string tool_error_json(const std::string& code, const std::string& message) {
nlohmann::json err;
err["error"] = code;
err["message"] = message;
return err.dump();
}