tool_registry.cpp

src/mcp/tool_registry.cpp

@file tool_registry.cpp @brief ToolRegistry implementation.

Owners: @tvanfossen

dispatch

ServerResponse entropic::ToolRegistry::dispatch(const std::string &name, const std::string &args_json)

Dispatch a tool call to the registered tool's execute().

src/mcp/tool_registry.cpp:119

Show on the map →

Called by SCENARIO, TEST_CASE, execute

Calls none

Source · 13 lines
ServerResponse ToolRegistry::dispatch(
    const std::string& name,
    const std::string& args_json) {
    auto it = tools_.find(name);
    if (it == tools_.end()) {
        logger->warn("Unknown tool: {}", name);
        ServerResponse resp;
        resp.result = "Error: Unknown tool '" + name + "'";
        return resp;
    }
    logger->info("Dispatch: tool='{}'", name);
    return it->second->execute(args_json);
}
Activity · 8 steps
lines 122–122auto it = tools_.find(name);lines 123–123◇ if (it == tools_.end())lines 124–124logger->warn("Unknown tool: {}", name);lines 125–125ServerResponse resp;lines 126–126resp.result = "Error: Unknown tool '" + name + "'";lines 127–127return resp;lines 129–129logger->info("Dispatch: tool='{}'", name);lines 130–130return it->second->execute(args_json);

Requirements

REQ-MCP-002 REQ-MCP-003

get_definitions

std::vector< const ToolDefinition * > entropic::ToolRegistry::get_definitions() const

Get all registered tool definitions.

src/mcp/tool_registry.cpp:91

Show on the map →

Called by TEST_CASE

Calls none

Source · 8 lines
std::vector<const ToolDefinition*> ToolRegistry::get_definitions() const {
    std::vector<const ToolDefinition*> defs;
    defs.reserve(tools_.size());
    for (const auto& [name, tool] : tools_) {
        defs.push_back(&tool->definition());
    }
    return defs;
}
Activity · 5 steps
lines 92–92std::vector<const ToolDefinition*> defs;lines 93–93defs.reserve(tools_.size());lines 94–94◇ for (const auto& [name, tool] : tools_)lines 95–95defs.push_back(&tool->definition());lines 97–97return defs;

Requirements

REQ-MCP-003

get_tool

ToolBase * entropic::ToolRegistry::get_tool(const std::string &name) const

Get a registered tool by name.

src/mcp/tool_registry.cpp:141

Show on the map →

Called by TEST_CASE, execute

Calls none

Source · 7 lines
ToolBase* ToolRegistry::get_tool(const std::string& name) const {
    auto it = tools_.find(name);
    if (it == tools_.end()) {
        return nullptr;
    }
    return it->second;
}
Activity · 4 steps
lines 142–142auto it = tools_.find(name);lines 143–143◇ if (it == tools_.end())lines 144–144return nullptr;lines 146–146return it->second;

Requirements

REQ-MCP-003

get_tools_json

std::string entropic::ToolRegistry::get_tools_json() const

Get all registered tool definitions as a JSON array string.

src/mcp/tool_registry.cpp:70

Show on the map →

Called by TEST_CASE, list_tools

Calls none

Source · 12 lines
std::string ToolRegistry::get_tools_json() const {
    auto arr = nlohmann::json::array();
    for (const auto& [name, tool] : tools_) {
        nlohmann::json entry;
        entry["name"] = tool->definition().name;
        entry["description"] = tool->definition().description;
        entry["inputSchema"] = nlohmann::json::parse(
            tool->definition().input_schema);
        arr.push_back(std::move(entry));
    }
    return arr.dump();
}
Activity · 8 steps
lines 71–71auto arr = nlohmann::json::array();lines 72–72◇ for (const auto& [name, tool] : tools_)lines 73–73nlohmann::json entry;lines 74–74entry["name"] = tool->definition().name;lines 75–75entry["description"] = tool->definition().description;lines 76–77entry["inputSchema"] = nlohmann::json::parse( tool->definition().input_schema);lines 78–78arr.push_back(std::move(entry));lines 80–80return arr.dump();

Requirements

REQ-MCP-003 REQ-MCP-008

has_tool

bool entropic::ToolRegistry::has_tool(const std::string &name) const

Check if a tool is registered by name.

src/mcp/tool_registry.cpp:53

Show on the map →

Called by TEST_CASE

Calls none

Source · 3 lines
bool ToolRegistry::has_tool(const std::string& name) const {
    return tools_.count(name) > 0;
}
Activity · 1 steps
lines 54–54return tools_.count(name) > 0;

Requirements

REQ-MCP-003

register_tool

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

Register a tool instance.

src/mcp/tool_registry.cpp:32

Show on the map →

Called by SCENARIO, TEST_CASE, register_tool

Calls name

Source · 12 lines
void ToolRegistry::register_tool(ToolBase* tool) {
    if (tool == nullptr) {
        logger->warn("Attempted to register null tool");
        return;
    }
    const auto& name = tool->name();
    if (tools_.count(name) > 0) {
        logger->warn("Tool '{}' already registered — replacing", name);
    }
    tools_[name] = tool;
    logger->info("Registered tool: {}", name);
}
Activity · 8 steps
lines 33–33◇ if (tool == nullptr)lines 34–34logger->warn("Attempted to register null tool");lines 35–35return;lines 37–37const auto& name = tool->name();lines 38–38◇ if (tools_.count(name) > 0)lines 39–39logger->warn("Tool '{}' already registered — replacing", name);lines 41–41tools_[name] = tool;lines 42–42logger->info("Registered tool: {}", name);

Requirements

REQ-MCP-003