Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
web.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
16
17#include <nlohmann/json.hpp>
18
19#include <algorithm>
20#include <string>
21
22static auto logger = entropic::log::get("mcp.web");
23
24namespace entropic {
25
26// ── WebFetchTool ────────────────────────────────────────────────
27
33class WebFetchTool : public ToolBase {
34public:
43
53 }
54
62 ServerResponse execute(const std::string& args_json) override;
63};
64
73 auto args = nlohmann::json::parse(args_json);
74 std::string url = args.at("url").get<std::string>();
75
76 static constexpr int default_max = 20000;
77 static constexpr int cap_max = 50000;
78 int max_length = args.value("max_length", default_max);
79 max_length = std::min(max_length, cap_max);
80
81 logger->info("[web_fetch] url='{}' max_length={}", url, max_length);
82
83 // v2.14.0 (gh#174/#203): a declared error, not placeholder prose a
84 // model could mistake for a fetched page or a result list.
85 return {
86 tool_error_json("not_implemented", "Web fetch is not implemented in this build; "
87 "the web server is a placeholder (mcp.enable_web)."),
88 {}
89 };
90}
91
92// ── WebSearchTool ───────────────────────────────────────────────
93
99class WebSearchTool : public ToolBase {
100public:
109
119 }
120
128 ServerResponse execute(const std::string& args_json) override;
129};
130
139 auto args = nlohmann::json::parse(args_json);
140 std::string query = args.at("query").get<std::string>();
141
142 static constexpr int default_max = 5;
143 static constexpr int cap_max = 10;
144 int max_results = args.value("max_results", default_max);
145 max_results = std::min(max_results, cap_max);
146
147 logger->info("[web_search] query='{}' max_results={}",
149
150 // v2.14.0 (gh#174/#203): a declared error, not placeholder prose a
151 // model could mistake for a fetched page or a result list.
152 return {
153 tool_error_json("not_implemented", "Web search is not implemented in this build; "
154 "the web server is a placeholder (mcp.enable_web)."),
155 {}
156 };
157}
158
159// ── WebServer ───────────────────────────────────────────────────
160
173 : MCPServerBase("web") {
174
175 std::string tools_dir = data_dir + "/tools";
176
178 "web_fetch", "web", tools_dir);
179 web_fetch_ = std::make_unique<WebFetchTool>(
180 std::move(fetch_def));
181
183 "web_search", "web", tools_dir);
184 web_search_ = std::make_unique<WebSearchTool>(
185 std::move(search_def));
186
187 register_tool(web_fetch_.get());
188 register_tool(web_search_.get());
189
190 logger->info("WebServer initialized with 2 tools");
191}
192
198WebServer::~WebServer() = default;
199
200} // namespace entropic
Concrete base class for MCP servers (80% logic).
Definition server_base.h:66
void register_tool(ToolBase *tool)
Register a tool with this server.
Abstract base class for individual MCP tools.
Definition tool_base.h:52
Tool for fetching web page content by URL.
Definition web.cpp:33
ServerResponse execute(const std::string &args_json) override
Fetch web page content (placeholder).
Definition web.cpp:72
MCPAccessLevel required_access_level() const override
Read-only tool — requires READ access.
Definition web.cpp:51
WebFetchTool(ToolDefinition def)
Construct from tool definition.
Definition web.cpp:41
Tool for web search queries.
Definition web.cpp:99
MCPAccessLevel required_access_level() const override
Read-only tool — requires READ access.
Definition web.cpp:117
ServerResponse execute(const std::string &args_json) override
Execute web search (placeholder).
Definition web.cpp:138
WebSearchTool(ToolDefinition def)
Construct from tool definition.
Definition web.cpp:107
WebServer(const std::string &data_dir)
Construct with data dir.
Definition web.cpp:172
~WebServer() override
Destructor.
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.
@ optional
optional: every escape asks the host's path approver
std::string tool_error_json(const std::string &code, const std::string &message)
A declared tool error: {"error": code, "message": message}.
MCPAccessLevel
MCP tool access level for per-identity authorization.
Definition config.h:38
@ READ
Read-only operations (e.g., read_file, list_directory)
MCPServerBase concrete base class + ServerResponse.
Structured result from tool execution.
Definition server_base.h:33
Parsed tool definition from JSON schema file.
Definition tool_base.h:33
Abstract base class for individual MCP tools.
Web MCP server — web_fetch + web_search.