Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
discovery_policy.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
31#pragma once
32
35
36#include <algorithm>
37#include <filesystem>
38#include <string>
39#include <vector>
40
41#include <nlohmann/json.hpp>
42
43namespace entropic {
44
50 disabled,
51 enabled,
52 ask
53};
54
63inline McpJsonConfigVerdict mcpjson_config_verdict(const std::string& name,
64 const MCPConfig& cfg) {
65 auto named = [&name](const std::vector<std::string>& list) {
66 return std::find(list.begin(), list.end(), name) != list.end();
67 };
68 if (named(cfg.disabled_mcpjson_servers)) {
70 }
71 const bool on = cfg.enable_all_project_mcp_servers
72 || named(cfg.enabled_mcpjson_servers);
74}
75
84inline std::string arg_after(const std::vector<std::string>& args,
85 const std::string& flag) {
86 auto it = std::find(args.begin(), args.end(), flag);
87 return (it == args.end() || it + 1 == args.end()) ? std::string{} : *(it + 1);
88}
89
98 const bool cmd = std::filesystem::path(cfg.command).filename() == "entropic";
99 const bool sub = std::find(cfg.args.begin(), cfg.args.end(), "mcp-bridge")
100 != cfg.args.end();
101 return cfg.transport == "stdio" && cmd && sub;
102}
103
119 const std::filesystem::path& own_socket,
120 const std::filesystem::path& spawn_root) {
121 namespace fs = std::filesystem;
122 bool self = false;
123 if (!own_socket.empty() && is_entropic_bridge(cfg)) {
124 const auto sock = arg_after(cfg.args, "--socket");
125 auto dir = arg_after(cfg.args, "--project-dir");
126 if (dir.empty()) {
127 dir = cfg.working_dir.empty() ? spawn_root.string() : cfg.working_dir;
128 }
129 const fs::path target = !sock.empty()
130 ? fs::path(sock) : compute_socket_path(fs::weakly_canonical(dir));
131 self = fs::weakly_canonical(target) == fs::weakly_canonical(own_socket);
132 }
133 return self;
134}
135
145 const std::filesystem::path& root) {
146 nlohmann::json j;
147 j["name"] = cfg.name;
148 j["transport"] = cfg.transport;
149 j["command"] = cfg.command;
150 j["args"] = cfg.args;
151 j["url"] = cfg.url;
152 j["root"] = cfg.working_dir.empty() ? root.string() : cfg.working_dir;
153 return j.dump();
154}
155
156} // namespace entropic
Configuration structs with defaults.
Discovers external MCP servers from .mcp.json files.
Activate model on GPU (WARM → ACTIVE).
McpJsonConfigVerdict
What configuration alone says about a discovered server.
@ disabled
Named in disabled_mcpjson_servers — never connect.
@ ask
Config is silent; the pre-connect hook decides.
@ enabled
Named in enabled_mcpjson_servers, or enable-all is set.
std::filesystem::path compute_socket_path(const std::filesystem::path &project_dir)
Compute project-unique Unix socket path for self-detection.
bool launches_own_bridge(const ExternalServerConfig &cfg, const std::filesystem::path &own_socket, const std::filesystem::path &spawn_root)
Whether launching cfg would connect this handle to itself.
@ optional
optional: every escape asks the host's path approver
McpJsonConfigVerdict mcpjson_config_verdict(const std::string &name, const MCPConfig &cfg)
Config's verdict on one discovered server.
std::string arg_after(const std::vector< std::string > &args, const std::string &flag)
The value following flag in args, or "".
bool is_entropic_bridge(const ExternalServerConfig &cfg)
Whether a stdio entry runs entropic mcp-bridge.
std::string discovered_server_json(const ExternalServerConfig &cfg, const std::filesystem::path &root)
The pre-connect hook's context JSON for one discovered server.
Parsed server entry from .mcp.json.
MCP server configuration.
Definition config.h:953