include/entropic/mcp/tool_registry.h¶
include/entropic/mcp/tool_registry.h
entropic::ToolRegistry
Manages a collection of ToolBase instances.
void entropic::ToolRegistry::register_tool(ToolBase *tool)
Register a tool instance.
Defensive by design: registration runs inside server constructors, where a failed load_tool_definition or a copy-paste name collision would otherwise surface as a crash at the model's first tool call. A nullptr is a logged no-op (never a stored null entry) and a duplicate name logs a warning before replacing the entry.
- Parameters
tool— Non-owning pointer to a ToolBase. Caller retains ownership.tool— Non-owning pointer to a ToolBase; the server retains ownership. NULL is tolerated and logged.
bool entropic::ToolRegistry::has_tool(const std::string &name) const
Check if a tool is registered by name.
- Parameters
name— Tool name.name— Tool name (without server prefix).
- Returns
- true if registered.
- true when a tool of that name is registered, false for any unknown name.
std::string entropic::ToolRegistry::get_tools_json() const
Get all registered tool definitions as a JSON array string.
Get all registered tool definitions as JSON array. Emits inputSchema (camelCase), matching both the bundled data/tools/*/*.json descriptors and the plugin C ABI, so the schema lookup path is uniform across server kinds.
- Returns
- JSON array of tool definitions. Caller-owned string.
- JSON array string with one {name, description, inputSchema} object per registered tool; "[]" for an empty registry.
std::vector< const ToolDefinition * > entropic::ToolRegistry::get_definitions() const
Get all registered tool definitions.
- Returns
- Vector of ToolDefinition references.
- Exactly one non-owning ToolDefinition pointer per registered tool; an empty vector for an empty registry. Pointers stay valid for as long as the owning server holds its tools.
ServerResponse entropic::ToolRegistry::dispatch(const std::string &name, const std::string &args_json)
Dispatch a tool call to the registered tool's execute().
Dispatch a tool call to the registered tool. An unregistered name is answered with an error ServerResponse — the missing tool is never dereferenced. A throwing tool is NOT handled here — the barrier sits one level up in MCPServerBase::execute (gh#143), because a throw must also skip the automatic ContextAnchor injection that follows this call.
- Parameters
name— Tool name.args_json— JSON arguments string.name— Tool name (without server prefix).
- Returns
- ServerResponse from the tool, or error response if unknown.
- The tool's own ServerResponse when the name resolves; otherwise a response whose result is "Error: Unknown tool '<name>'" and whose directives are empty.
ToolBase * entropic::ToolRegistry::get_tool(const std::string &name) const
Get a registered tool by name.
- Parameters
name— Tool name.name— Tool name (without server prefix).
- Returns
- Tool pointer, or nullptr if not found.
- Non-owning tool pointer, or nullptr when the name is not registered — callers must null-check before use.