Entropic 2.11.1
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
62 const std::string& /*args_json*/) const {
63 return "";
64}
65
79
100 const std::string& tool_name,
101 const std::string& server_prefix,
102 const std::string& data_dir) {
103
104 std::string path = data_dir;
105 if (!server_prefix.empty()) {
106 path += "/" + server_prefix;
107 }
108 path += "/" + tool_name + ".json";
109
110 std::ifstream file(path);
111 if (!file.is_open()) {
112 throw std::runtime_error(
113 "Tool definition not found: " + path);
114 }
115
116 auto json = nlohmann::json::parse(file);
117
118 ToolDefinition def;
119 def.name = json.at("name").get<std::string>();
120 def.description = json.value("description", "");
121 def.input_schema = json.at("inputSchema").dump();
122
123 logger->info("Loaded tool definition: {} from {}",
124 def.name, path);
125 return def;
126}
127
128} // 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:76
virtual std::string anchor_key(const std::string &args_json) const
Generate anchor key for this tool result.
Definition tool_base.cpp:61
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:99
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.