Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
tool_base.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
11
12#include <nlohmann/json.hpp>
13
14#include <fstream>
15#include <stdexcept>
16
17static auto logger = entropic::log::get("mcp.tool_base");
18
19namespace entropic {
20
28 : definition_(std::move(def)) {}
29
36const std::string& ToolBase::name() const {
37 return definition_.name;
38}
39
47 return definition_;
48}
49
58 const std::string& /*args_json*/) const {
59 return "";
60}
61
71
82 const std::string& tool_name,
83 const std::string& server_prefix,
84 const std::string& data_dir) {
85
86 std::string path = data_dir;
87 if (!server_prefix.empty()) {
88 path += "/" + server_prefix;
89 }
90 path += "/" + tool_name + ".json";
91
92 std::ifstream file(path);
93 if (!file.is_open()) {
94 throw std::runtime_error(
95 "Tool definition not found: " + path);
96 }
97
98 auto json = nlohmann::json::parse(file);
99
100 ToolDefinition def;
101 def.name = json.at("name").get<std::string>();
102 def.description = json.value("description", "");
103 def.input_schema = json.at("inputSchema").dump();
104
105 logger->info("Loaded tool definition: {} from {}",
106 def.name, path);
107 return def;
108}
109
110} // namespace entropic
ToolBase(ToolDefinition def)
Construct with a pre-built definition.
Definition tool_base.cpp:27
const std::string & name() const
Get the tool name.
Definition tool_base.cpp:36
ToolDefinition definition_
Tool definition.
Definition tool_base.h:102
virtual MCPAccessLevel required_access_level() const
Minimum access level required to execute this tool.
Definition tool_base.cpp:68
virtual std::string anchor_key(const std::string &args_json) const
Generate anchor key for this tool result.
Definition tool_base.cpp:57
const ToolDefinition & definition() const
Get the full tool definition.
Definition tool_base.cpp:46
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).
ToolDefinition 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.
Definition tool_base.cpp:81
MCPAccessLevel
MCP tool access level for per-identity authorization.
Definition config.h:38
@ WRITE
Read + write operations (e.g., write_file, execute)
MCPServerBase concrete base class + ServerResponse.
Parsed tool definition from JSON schema file.
Definition tool_base.h:27
std::string name
Tool name (e.g., "read_file")
Definition tool_base.h:28
std::string input_schema
JSON Schema for arguments (raw JSON string)
Definition tool_base.h:30
std::string description
Human-readable description.
Definition tool_base.h:29
Abstract base class for individual MCP tools.