11#include <nlohmann/json.hpp>
24 : name_(std::move(name)) {}
65 const std::string& tool_name,
66 const std::string& args_json) {
67 logger->info(
"[EXECUTE] {}.{}",
name_, tool_name);
72 if (tool !=
nullptr) {
73 inject_anchor_if_needed(*tool, args_json, response);
76 return serialize_response(response);
88 const std::string& tool_name,
89 const std::string& )
const {
101 const std::string& )
const {
169 auto idx =
static_cast<int>(type);
172 if (idx < 0 || idx >= count) {
185std::string MCPServerBase::serialize_response(
186 const ServerResponse& response) {
188 j[
"result"] = response.result;
190 auto directives = nlohmann::json::array();
191 for (
const auto& d : response.directives) {
194 directives.push_back(std::move(dj));
196 j[
"directives"] = std::move(directives);
209void MCPServerBase::inject_anchor_if_needed(
210 const ToolBase& tool,
211 const std::string& args_json,
212 ServerResponse& response) {
213 auto key = tool.anchor_key(args_json);
219 response.directives.push_back(std::move(anchor));
220 logger->info(
"Auto-injected ContextAnchor: {}", key);
std::string list_tools() const
List all registered tools as a JSON array string.
std::string execute(const std::string &tool_name, const std::string &args_json)
Execute a tool and wrap result in ServerResponse JSON.
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.
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.
static const char *const DIRECTIVE_NAMES[]
Serialize ServerResponse to JSON envelope.
MCPServerBase concrete base class + ServerResponse.