11#include <nlohmann/json.hpp>
109std::string MCPServerBase::normalize_args(
110 const std::string& tool_name,
111 const std::string&
raw)
const {
112 const auto first =
raw.find_first_not_of(
" \t\r\n");
113 if (
first == std::string::npos) {
118 const auto parsed = nlohmann::json::parse(
raw,
nullptr,
false);
123 "[{}.{}] arguments arrived as JSON null — reading as \"no "
124 "arguments\" and dispatching with {{}}",
166 const std::string& tool_name,
168 logger->info(
"[EXECUTE] {}.{}",
name_, tool_name);
177 if (tool !=
nullptr) {
180 }
catch (
const std::exception&
e) {
183 logger->error(
"Tool '{}.{}' threw: {} — args: {}",
187 "Error: tool '" +
name_ +
"." + tool_name +
"' failed: "
191 return serialize_response(
response);
210 const std::string& tool_name,
211 const std::string& )
const {
231 const std::string& )
const {
311 auto idx =
static_cast<int>(type);
333std::string MCPServerBase::serialize_response(
338 auto directives = nlohmann::json::array();
339 for (
const auto&
d :
response.directives) {
342 directives.push_back(std::move(
dj));
344 j[
"directives"] = std::move(directives);
362void MCPServerBase::inject_anchor_if_needed(
363 const ToolBase& tool,
373 logger->info(
"Auto-injected ContextAnchor: {}", key);
std::string list_tools() const
List all registered tools as a JSON array string.
const std::string & name() const
Get the server name.
std::string name_
Server name.
virtual bool skip_duplicate_check(const std::string &tool_name) const
Check if a tool should skip duplicate detection.
void register_tool(ToolBase *tool)
Register a tool with this server.
MCPServerBase(std::string name)
Construct with server name.
virtual std::string get_permission_pattern(const std::string &tool_name, const std::string &args_json) const
Generate permission pattern for 'Always Allow/Deny'.
ToolRegistry registry_
Tool registry.
virtual bool set_working_dir(const std::string &path)
Set the working directory.
virtual bool configure(const std::string &config_json)
Configure the server after creation.
std::string execute(const std::string &tool_name, const std::string &raw_args_json)
Execute a tool and wrap result in ServerResponse JSON.
entropic_directive_type_t
Directive types emitted by MCP tool results.
@ ENTROPIC_DIRECTIVE_CONTEXT_ANCHOR
Replace context anchor.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
static const char * directive_type_name(entropic_directive_type_t type)
Map directive type enum to wire-format string.
@ optional
optional: every escape asks the host's path approver
@ count
Sentinel — MUST remain last.
static const char *const DIRECTIVE_NAMES[]
Serialize ServerResponse to JSON envelope.
MCPServerBase concrete base class + ServerResponse.
Structured result from tool execution.