Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
tool_registry.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
11
12#include <nlohmann/json.hpp>
13
14static auto logger = entropic::log::get("mcp.tool_registry");
15
16namespace entropic {
17
33 if (tool == nullptr) {
34 logger->warn("Attempted to register null tool");
35 return;
36 }
37 const auto& name = tool->name();
38 if (tools_.count(name) > 0) {
39 logger->warn("Tool '{}' already registered — replacing", name);
40 }
41 tools_[name] = tool;
42 logger->info("Registered tool: {}", name);
43}
44
53bool ToolRegistry::has_tool(const std::string& name) const {
54 return tools_.count(name) > 0;
55}
56
70std::string ToolRegistry::get_tools_json() const {
71 auto arr = nlohmann::json::array();
72 for (const auto& [name, tool] : tools_) {
73 nlohmann::json entry;
74 entry["name"] = tool->definition().name;
75 entry["description"] = tool->definition().description;
76 entry["inputSchema"] = nlohmann::json::parse(
77 tool->definition().input_schema);
78 arr.push_back(std::move(entry));
79 }
80 return arr.dump();
81}
82
91std::vector<const ToolDefinition*> ToolRegistry::get_definitions() const {
92 std::vector<const ToolDefinition*> defs;
93 defs.reserve(tools_.size());
94 for (const auto& [name, tool] : tools_) {
95 defs.push_back(&tool->definition());
96 }
97 return defs;
98}
99
116 const std::string& name,
117 const std::string& args_json) {
118 auto it = tools_.find(name);
119 if (it == tools_.end()) {
120 logger->warn("Unknown tool: {}", name);
121 ServerResponse resp;
122 resp.result = "Error: Unknown tool '" + name + "'";
123 return resp;
124 }
125 logger->info("Dispatch: tool='{}'", name);
126 return it->second->execute(args_json);
127}
128
137ToolBase* ToolRegistry::get_tool(const std::string& name) const {
138 auto it = tools_.find(name);
139 if (it == tools_.end()) {
140 return nullptr;
141 }
142 return it->second;
143}
144
145} // namespace entropic
Abstract base class for individual MCP tools.
Definition tool_base.h:45
const std::string & name() const
Get the tool name.
Definition tool_base.cpp:36
void register_tool(ToolBase *tool)
Register a tool instance.
ServerResponse dispatch(const std::string &name, const std::string &args_json)
Dispatch a tool call to the registered tool's execute().
std::string get_tools_json() const
Get all registered tool definitions as a JSON array string.
bool has_tool(const std::string &name) const
Check if a tool is registered by name.
ToolBase * get_tool(const std::string &name) const
Get a registered tool by name.
std::vector< const ToolDefinition * > get_definitions() const
Get all registered tool definitions.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
MCPServerBase concrete base class + ServerResponse.
Structured result from tool execution.
Definition server_base.h:33
std::string result
Human-readable result.
Definition server_base.h:34
Tool registration, lookup, and dispatch.