server_manager.cpp

src/mcp/server_manager.cpp

@file server_manager.cpp @brief ServerManager implementation.

Owners: @tvanfossen

add_permission

void entropic::ServerManager::add_permission(const std::string &pattern, bool allow)

Add a runtime permission pattern.

src/mcp/server_manager.cpp:895

Show on the map →

Called by TEST_CASE

Calls add_permission

Source · 4 lines
void ServerManager::add_permission(
    const std::string& pattern, bool allow) {
    permissions_.add_permission(pattern, allow);
}
Activity · 1 steps
lines 897–897permissions_.add_permission(pattern, allow);

Requirements

REQ-MCP-009

append_external_tools

void entropic::ServerManager::append_external_tools(nlohmann::json &all) const

Collect tools from connected external clients into an array.

src/mcp/server_manager.cpp:237

Show on the map →

Called by list_tools

Calls external_snapshot, is_connected, list_tools

Source · 11 lines
void ServerManager::append_external_tools(nlohmann::json& all) const {
    for (const auto& [name, client] : external_snapshot()) {
        if (!client->is_connected()) {
            continue;
        }
        auto tools = nlohmann::json::parse(client->list_tools());
        for (auto& tool : tools) {
            all.push_back(std::move(tool));
        }
    }
}
Activity · 6 steps
lines 238–238◇ for (const auto& [name, client] : external_snapshot())lines 239–239◇ if (!client->is_connected())lines 240–240continue;lines 242–242auto tools = nlohmann::json::parse(client->list_tools());lines 243–243◇ for (auto& tool : tools)lines 244–244all.push_back(std::move(tool));

Requirements

REQ-MCP-007

append_plugin_tools

void entropic::ServerManager::append_plugin_tools(nlohmann::json &all) const

Collect tools from the dlopen plugins into an array (gh#133).

src/mcp/server_manager.cpp:215

Source · 11 lines
void ServerManager::append_plugin_tools(nlohmann::json& all) const {
    for (const auto& [name, plugin] : plugin_servers_) {
        try {
            append_prefixed_tools(plugin->list_tools(), name, all);
        } catch (const std::exception& e) {
            logger->error("Plugin '{}' returned an unusable tool list: {} — "
                          "its tools are unavailable this session", name,
                          e.what());
        }
    }
}
Activity · 2 steps
lines 216–216◇ for (const auto& [name, plugin] : plugin_servers_)lines 217–223try { append_prefixed_tools(plugin->list_tools(), name, all); } catch (const std::exception& e) { logger->error("Plugin '{}' returned an unusable tool list: {} — " "its tools are unavailable this session", name, e.what()); }

Requirements

REQ-MCP-007

append_prefixed_tools

static void entropic::append_prefixed_tools(const std::string &tools_json, const std::string &prefix, nlohmann::json &all)

Append a server's tools to an array, prefixing each name.

src/mcp/server_manager.cpp:192

Source · 10 lines
static void append_prefixed_tools(const std::string& tools_json,
                                  const std::string& prefix,
                                  nlohmann::json& all) {
    auto tools = nlohmann::json::parse(tools_json);
    for (auto& tool : tools) {
        std::string orig_name = tool.at("name");
        tool["name"] = prefix + "." + orig_name;
        all.push_back(std::move(tool));
    }
}
Activity · 5 steps
lines 195–195auto tools = nlohmann::json::parse(tools_json);lines 196–196◇ for (auto& tool : tools)lines 197–197std::string orig_name = tool.at("name");lines 198–198tool["name"] = prefix + "." + orig_name;lines 199–199all.push_back(std::move(tool));

Requirements

REQ-MCP-007

args_to_pattern

std::string entropic::ServerManager::args_to_pattern(const std::string &args_json)

Build args-to-pattern string for permission matching.

src/mcp/server_manager.cpp:989

Source · 18 lines
std::string ServerManager::args_to_pattern(
    const std::string& args_json) {
    if (args_json.empty() || args_json == "{}") {
        return "*";
    }
    try {
        auto j = nlohmann::json::parse(args_json);
        if (j.is_object() && !j.empty()) {
            auto first = j.begin();
            if (first->is_string()) {
                return first->get<std::string>();
            }
        }
    } catch (...) {
        // Parse failure — treat as wildcard
    }
    return "*";
}
Activity · 4 steps
lines 991–991◇ if (args_json.empty() || args_json == "{}")lines 992–992return "*";lines 994–1004try { auto j = nlohmann::json::parse(args_json); if (j.is_object() && !j.empty()) { auto first = j.begin(); if (first->is_string()) { return first->get<std::string>(); } } } catch (...) { // Parse failure — treat as wildcard }lines 1005–1005return "*";

Requirements

REQ-MCP-009

clear_external_tool_interrupts

void entropic::ServerManager::clear_external_tool_interrupts()

Release the interrupt on every external client (gh#150).

src/mcp/server_manager.cpp:1049

Show on the map →

Called by wire_external_interrupt

Calls clear_interrupt, external_snapshot

Source · 5 lines
void ServerManager::clear_external_tool_interrupts() {
    for (auto& [_, client] : external_snapshot()) {
        if (client) { client->clear_interrupt(); }
    }
}
Activity · 3 steps
lines 1050–1050◇ for (auto& [_, client] : external_snapshot())lines 1051–1051◇ if (client)lines 1051–1051client->clear_interrupt();

Requirements

REQ-MCP-025

connect_and_register_external

std::shared_ptr< ExternalMCPClient > entropic::ServerManager::connect_and_register_external(const std::string &name, std::unique_ptr< ExternalMCPClient > client, const std::string &source, const std::string &url, const std::string &command)

Connect an external client and register info.

src/mcp/server_manager.cpp:1209

Source · 41 lines
ServerManager::connect_and_register_external(
    const std::string& name,
    std::unique_ptr<ExternalMCPClient> client,
    const std::string& source,
    const std::string& url,
    const std::string& command) {

    ServerInfo info;
    info.name = name;
    info.transport = url.empty() ? "stdio" : "sse";
    info.url = url;
    info.command = command;
    info.source = source;
    info.status = "disconnected";

    bool ok = client->connect();
    if (ok) {
        info.status = "connected";
        info.connected_at = std::chrono::system_clock::now();
    } else {
        info.status = "error";
        logger->error("Failed to connect external server '{}'", name);
    }

    // gh#171: the connect above ran with no lock; registration re-checks the
    // name under it, because another thread may have registered it meanwhile.
    std::shared_ptr<ExternalMCPClient> shared = std::move(client);
    bool inserted = false;
    {
        std::unique_lock<std::shared_mutex> lock(*external_mutex_);
        inserted = external_clients_.emplace(name, shared).second;
        if (inserted) { server_info_[name] = info; }
    }
    if (!inserted) {
        logger->warn("External server '{}' was registered concurrently — "
                     "refusing the second connection", name);
        shared->disconnect();
        shared.reset();
    }
    return shared;
}
Activity · 25 steps
lines 1216–1216ServerInfo info;lines 1217–1217info.name = name;lines 1218–1218info.transport = url.empty() ? "stdio" : "sse";lines 1219–1219info.url = url;lines 1220–1220info.command = command;lines 1221–1221info.source = source;lines 1222–1222info.status = "disconnected";lines 1224–1224bool ok = client->connect();lines 1225–1225◇ if (ok)lines 1226–1226info.status = "connected";lines 1227–1227info.connected_at = std::chrono::system_clock::now();lines 1228–1228elselines 1229–1229info.status = "error";lines 1230–1230logger->error("Failed to connect external server '{}'", name);lines 1235–1235std::shared_ptr<ExternalMCPClient> shared = std::move(client);lines 1236–1236bool inserted = false;lines 1238–1238std::unique_lock<std::shared_mutex> lock(*external_mutex_);lines 1239–1239inserted = external_clients_.emplace(name, shared).second;lines 1240–1240◇ if (inserted)lines 1240–1240server_info_[name] = info;lines 1242–1242◇ if (!inserted)lines 1243–1244logger->warn("External server '{}' was registered concurrently — " "refusing the second connection", name);lines 1245–1245shared->disconnect();lines 1246–1246shared.reset();lines 1248–1248return shared;

Requirements

REQ-MCP-025

connect_declared_servers

void entropic::ServerManager::connect_declared_servers()

Connect every server the operator declared in config (v2.14.0).

src/mcp/server_manager.cpp:1092

Source · 18 lines
void ServerManager::connect_declared_servers() {
    for (const auto& [name, entry] : mcp_config_.external_servers) {
        ExternalServerConfig probe;
        probe.name = name;
        probe.transport = entry.command.empty() ? "sse" : "stdio";
        probe.command = entry.command;
        probe.args = entry.args;
        if (launches_own_bridge(probe, own_bridge_socket_, project_dir_)) {
            logger->warn("[mcp] declared server '{}' would connect to this "
                         "handle's own bridge ({}) — refused (gh#200)",
                         name, own_bridge_socket_.string());
            continue;
        }
        auto client = create_external_client(name, entry);
        connect_and_register_external(name, std::move(client),
                                      "config", entry.url, entry.command);
    }
}
Activity · 11 steps
lines 1093–1093◇ for (const auto& [name, entry] : mcp_config_.external_servers)lines 1094–1094ExternalServerConfig probe;lines 1095–1095probe.name = name;lines 1096–1096probe.transport = entry.command.empty() ? "sse" : "stdio";lines 1097–1097probe.command = entry.command;lines 1098–1098probe.args = entry.args;lines 1099–1099◇ if (launches_own_bridge(probe, own_bridge_socket_, project_dir_))lines 1100–1102logger->warn("[mcp] declared server '{}' would connect to this " "handle's own bridge ({}) — refused (gh#200)", name, own_bridge_socket_.string());lines 1103–1103continue;lines 1105–1105auto client = create_external_client(name, entry);lines 1106–1107connect_and_register_external(name, std::move(client), "config", entry.url, entry.command);

Requirements

REQ-MCP-025

connect_discovered_servers

void entropic::ServerManager::connect_discovered_servers()

Discover .mcp.json servers and connect the enabled ones.

src/mcp/server_manager.cpp:1116

Source · 13 lines
void ServerManager::connect_discovered_servers() {
    mcp_json_discovery_ = std::make_unique<MCPJsonDiscovery>(project_dir_);
    std::set<std::string> existing;
    for (const auto& [name, _] : servers_) { existing.insert(name); }
    for (const auto& [name, _] : external_clients_) { existing.insert(name); }

    for (const auto& cfg : mcp_json_discovery_->discover(existing)) {
        if (!admit_discovered(cfg)) { continue; }
        auto client = create_external_client(cfg);
        connect_and_register_external(cfg.name, std::move(client),
                                      "mcp_json", cfg.url, cfg.command);
    }
}
Activity · 11 steps
lines 1117–1117mcp_json_discovery_ = std::make_unique<MCPJsonDiscovery>(project_dir_);lines 1118–1118std::set<std::string> existing;lines 1119–1119◇ for (const auto& [name, _] : servers_)lines 1119–1119existing.insert(name);lines 1120–1120◇ for (const auto& [name, _] : external_clients_)lines 1120–1120existing.insert(name);lines 1122–1122◇ for (const auto& cfg : mcp_json_discovery_->discover(existing))lines 1123–1123◇ if (!admit_discovered(cfg))lines 1123–1123continue;lines 1124–1124auto client = create_external_client(cfg);lines 1125–1126connect_and_register_external(cfg.name, std::move(client), "mcp_json", cfg.url, cfg.command);

Requirements

REQ-MCP-025

connect_external_server

std::vector< std::string > entropic::ServerManager::connect_external_server(const ExternalServerConfig &spec)

Connect to an external MCP server at runtime (canonical spec-based API).

src/mcp/server_manager.cpp:1305

Source · 31 lines
std::vector<std::string> ServerManager::connect_external_server(
    const ExternalServerConfig& spec) {

    if (servers_.count(spec.name) > 0 || find_external(spec.name)) {
        logger->warn("Server '{}' already registered", spec.name);
        return {};
    }

    auto client = create_external_client(spec);  // gh#175: one factory

    // gh#171: the registered client comes back from registration rather than
    // being re-read with operator[], which INSERTED, unlocked, on a miss.
    auto registered = connect_and_register_external(
        spec.name, std::move(client), "runtime", spec.url, spec.command);
    if (!registered) { return {}; }
    if (health_monitor_) {
        health_monitor_->watch(spec.name, registered.get());
    }

    // Parse tool names from cached list
    std::vector<std::string> tool_names;
    auto tools_json = registered->list_tools();
    try {
        auto tools = nlohmann::json::parse(tools_json);
        for (const auto& t : tools) {
            tool_names.push_back(t["name"].get<std::string>());
        }
    } catch (...) {}

    return tool_names;
}
Activity · 13 steps
lines 1308–1308◇ if (servers_.count(spec.name) > 0 || find_external(spec.name))lines 1309–1309logger->warn("Server '{}' already registered", spec.name);lines 1310–1310return {};lines 1313–1313auto client = create_external_client(spec);lines 1317–1318auto registered = connect_and_register_external( spec.name, std::move(client), "runtime", spec.url, spec.command);lines 1319–1319◇ if (!registered)lines 1319–1319return {};lines 1320–1320◇ if (health_monitor_)lines 1321–1321health_monitor_->watch(spec.name, registered.get());lines 1325–1325std::vector<std::string> tool_names;lines 1326–1326auto tools_json = registered->list_tools();lines 1327–1332try { auto tools = nlohmann::json::parse(tools_json); for (const auto& t : tools) { tool_names.push_back(t["name"].get<std::string>()); } } catch (...) {}lines 1334–1334return tool_names;
std::vector< std::string > entropic::ServerManager::connect_external_server(const std::string &name, const std::string &command="", const std::vector< std::string > &args={}, const std::string &url="")

Connect by primitive parameters (legacy convenience).

src/mcp/server_manager.cpp:1346

Source · 12 lines
std::vector<std::string> ServerManager::connect_external_server(
    const std::string& name,
    const std::string& command,
    const std::vector<std::string>& args,
    const std::string& url) {
    ExternalServerConfig spec;
    spec.name = name;
    spec.command = command;
    spec.args = args;
    spec.url = url;
    return connect_external_server(spec);
}
Activity · 6 steps
lines 1351–1351ExternalServerConfig spec;lines 1352–1352spec.name = name;lines 1353–1353spec.command = command;lines 1354–1354spec.args = args;lines 1355–1355spec.url = url;lines 1356–1356return connect_external_server(spec);

Requirements

REQ-MCP-007 REQ-MCP-025

disconnected_error

std::string entropic::ServerManager::disconnected_error(const std::string &tool_name, const std::string &server_name)

Build error response JSON for disconnected server.

src/mcp/server_manager.cpp:1540

Source · 13 lines
std::string ServerManager::disconnected_error(
    const std::string& tool_name,
    const std::string& server_name) {

    nlohmann::json resp;
    resp["result"] = "Server '" + server_name +
                     "' is disconnected. Tool '" + tool_name +
                     "' is unavailable. Use a different approach "
                     "or try again later.";
    resp["directives"] = nlohmann::json::array();
    resp["is_error"] = true;
    return resp.dump();
}
Activity · 5 steps
lines 1544–1544nlohmann::json resp;lines 1545–1548resp["result"] = "Server '" + server_name + "' is disconnected. Tool '" + tool_name + "' is unavailable. Use a different approach " "or try again later.";lines 1549–1549resp["directives"] = nlohmann::json::array();lines 1550–1550resp["is_error"] = true;lines 1551–1551return resp.dump();

Requirements

REQ-MCP-002 REQ-MCP-025

enter_working_dir

size_t entropic::ServerManager::enter_working_dir(const std::filesystem::path &dir)

Re-root every in-process and plugin server for a sandboxed delegation, and KEEP the root lock (gh#158, gh#160).

src/mcp/server_manager.cpp:294

Source · 8 lines
size_t ServerManager::enter_working_dir(const std::filesystem::path& dir) {
    root_lock_->lock();
    auto moved = set_working_dir_all(dir);
    logger->info("Tool root lock HELD for sandbox {} — other sessions' "
                 "in-process dispatch on this server set waits until "
                 "restore", dir.string());
    return moved;
}
Activity · 4 steps
lines 295–295root_lock_->lock();lines 296–296auto moved = set_working_dir_all(dir);lines 297–299logger->info("Tool root lock HELD for sandbox {} — other sessions' " "in-process dispatch on this server set waits until " "restore", dir.string());lines 300–300return moved;

Requirements

REQ-DELEG-005 REQ-LOOP-009

execute

std::string entropic::ServerManager::execute(const std::string &tool_name, const std::string &args_json)

Execute a tool call via the appropriate server.

src/mcp/server_manager.cpp:435

Show on the map →

Called by SCENARIO, SCENARIO, TEST_CASE, TEST_CASE, read_via

Calls args_to_pattern, is_denied, route_tool_call

Source · 16 lines
std::string ServerManager::execute(
    const std::string& tool_name,
    const std::string& args_json) {

    // Check permissions first
    auto pattern = tool_name + ":" + args_to_pattern(args_json);
    if (permissions_.is_denied(tool_name, pattern)) {
        logger->warn("Permission denied: {}", tool_name);
        nlohmann::json resp;
        resp["result"] = "Error: Permission denied for " + tool_name;
        resp["directives"] = nlohmann::json::array();
        return resp.dump();
    }

    return route_tool_call(tool_name, args_json);
}
Activity · 8 steps
lines 440–440auto pattern = tool_name + ":" + args_to_pattern(args_json);lines 441–441◇ if (permissions_.is_denied(tool_name, pattern))lines 442–442logger->warn("Permission denied: {}", tool_name);lines 443–443nlohmann::json resp;lines 444–444resp["result"] = "Error: Permission denied for " + tool_name;lines 445–445resp["directives"] = nlohmann::json::array();lines 446–446return resp.dump();lines 449–449return route_tool_call(tool_name, args_json);

Requirements

REQ-MCP-002 REQ-MCP-007 REQ-MCP-009

external_tools_without_readonly_hint

std::vector< std::string > entropic::ServerManager::external_tools_without_readonly_hint(const std::vector< std::string > &allowed) const

External tools that do not declare readOnlyHint: true .

src/mcp/server_manager.cpp:374

Source · 11 lines
ServerManager::external_tools_without_readonly_hint(
        const std::vector<std::string>& allowed) const {
    std::vector<std::string> unsafe;
    for (const auto& [name, client] : external_snapshot()) {
        if (!client->is_connected()) { continue; }
        auto found = tools_without_readonly_hint(
            client->list_tools(), allowed);
        unsafe.insert(unsafe.end(), found.begin(), found.end());
    }
    return unsafe;
}
Activity · 7 steps
lines 376–376std::vector<std::string> unsafe;lines 377–377◇ for (const auto& [name, client] : external_snapshot())lines 378–378◇ if (!client->is_connected())lines 378–378continue;lines 379–380auto found = tools_without_readonly_hint( client->list_tools(), allowed);lines 381–381unsafe.insert(unsafe.end(), found.begin(), found.end());lines 383–383return unsafe;

Requirements

REQ-MCP-007

extract_local_name

std::string entropic::ServerManager::extract_local_name(const std::string &tool_name)

Extract local tool name from fully-qualified name.

src/mcp/server_manager.cpp:967

Source · 8 lines
std::string ServerManager::extract_local_name(
    const std::string& tool_name) {
    auto dot = tool_name.find('.');
    if (dot == std::string::npos) {
        return tool_name;
    }
    return tool_name.substr(dot + 1);
}
Activity · 4 steps
lines 969–969auto dot = tool_name.find('.');lines 970–970◇ if (dot == std::string::npos)lines 971–971return tool_name;lines 973–973return tool_name.substr(dot + 1);

Requirements

REQ-MCP-007

extract_prefix

std::string entropic::ServerManager::extract_prefix(const std::string &tool_name)

Extract server prefix from fully-qualified tool name.

src/mcp/server_manager.cpp:949

Source · 8 lines
std::string ServerManager::extract_prefix(
    const std::string& tool_name) {
    auto dot = tool_name.find('.');
    if (dot == std::string::npos) {
        return tool_name;
    }
    return tool_name.substr(0, dot);
}
Activity · 4 steps
lines 951–951auto dot = tool_name.find('.');lines 952–952◇ if (dot == std::string::npos)lines 953–953return tool_name;lines 955–955return tool_name.substr(0, dot);

Requirements

REQ-MCP-007

get_permission_pattern

std::string entropic::ServerManager::get_permission_pattern(const std::string &tool_name, const std::string &args_json) const

Generate permission pattern via server class delegation.

src/mcp/server_manager.cpp:805

Show on the map →

Called by TEST_CASE

Calls extract_prefix

Source · 11 lines
std::string ServerManager::get_permission_pattern(
    const std::string& tool_name,
    const std::string& args_json) const {
    auto prefix = extract_prefix(tool_name);
    auto it = servers_.find(prefix);
    if (it != servers_.end()) {
        return it->second->get_permission_pattern(
            tool_name, args_json);
    }
    return tool_name;
}
Activity · 5 steps
lines 808–808auto prefix = extract_prefix(tool_name);lines 809–809auto it = servers_.find(prefix);lines 810–810◇ if (it != servers_.end())lines 811–812return it->second->get_permission_pattern( tool_name, args_json);lines 814–814return tool_name;

Requirements

REQ-MCP-009

get_required_access_level

MCPAccessLevel entropic::ServerManager::get_required_access_level(const std::string &tool_name) const

Get the required access level for a tool.

src/mcp/server_manager.cpp:869

Source · 13 lines
MCPAccessLevel ServerManager::get_required_access_level(
    const std::string& tool_name) const {
    auto prefix = extract_prefix(tool_name);
    auto it = servers_.find(prefix);
    if (it != servers_.end()) {
        auto local = extract_local_name(tool_name);
        auto* tool = it->second->registry().get_tool(local);
        if (tool != nullptr) {
            return tool->required_access_level();
        }
    }
    return MCPAccessLevel::WRITE;  // Safe default
}
Activity · 8 steps
lines 871–871auto prefix = extract_prefix(tool_name);lines 872–872auto it = servers_.find(prefix);lines 873–873◇ if (it != servers_.end())lines 874–874auto local = extract_local_name(tool_name);lines 875–875auto* tool = it->second->registry().get_tool(local);lines 876–876◇ if (tool != nullptr)lines 877–877return tool->required_access_level();lines 880–880return MCPAccessLevel::WRITE;

Requirements

REQ-MCP-011

get_server

MCPServerBase * entropic::ServerManager::get_server(const std::string &name) const

Get a registered in-process server by name.

src/mcp/server_manager.cpp:461

Show on the map →

Called by TEST_CASE, bash_of, sessions_on, set_outside_root_approver, wire_state_provider

Calls none

Source · 4 lines
MCPServerBase* ServerManager::get_server(const std::string& name) const {
    auto it = servers_.find(name);
    return (it != servers_.end()) ? it->second.get() : nullptr;
}
Activity · 2 steps
lines 462–462auto it = servers_.find(name);lines 463–463return (it != servers_.end()) ? it->second.get() : nullptr;

Requirements

REQ-MCP-007

get_tool_schema

std::string entropic::ServerManager::get_tool_schema(const std::string &tool_name) const

Get the JSON Schema for a tool's input parameters.

src/mcp/server_manager.cpp:558

Source · 16 lines
std::string ServerManager::get_tool_schema(
    const std::string& tool_name) const {
    auto prefix = extract_prefix(tool_name);
    auto local_name = extract_local_name(tool_name);
    auto it = servers_.find(prefix);
    if (it != servers_.end()) {
        auto* tool = it->second->registry().get_tool(local_name);
        return (tool != nullptr) ? tool->definition().input_schema
                                 : std::string{};
    }
    // gh#133 (v2.10.1): without this a plugin's declared inputSchema would be
    // invisible to ToolExecutor::check_schema, which skips validation on an
    // empty schema — plugin tools would silently forgo the argument checking
    // every built-in server's tools get.
    return plugin_tool_schema(prefix, local_name);
}
Activity · 7 steps
lines 560–560auto prefix = extract_prefix(tool_name);lines 561–561auto local_name = extract_local_name(tool_name);lines 562–562auto it = servers_.find(prefix);lines 563–563◇ if (it != servers_.end())lines 564–564auto* tool = it->second->registry().get_tool(local_name);lines 565–566return (tool != nullptr) ? tool->definition().input_schema : std::string{};lines 572–572return plugin_tool_schema(prefix, local_name);

Requirements

REQ-MCP-008 REQ-MCP-013

init_builtins

void entropic::ServerManager::init_builtins(const MCPConfig &mcp_config, const std::vector< std::string > &tier_names, const std::string &data_dir, const std::vector< std::string > &require_context_tiers={})

Register built-in servers based on config flags.

src/mcp/server_manager.cpp:64

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, build_workspace, init_mcp_servers

Calls BashServer, DiagnosticsServer, EntropicServer, FilesystemServer, GitServer, WebServer, register_server

Source · 29 lines
void ServerManager::init_builtins(
    const MCPConfig& mcp,
    const std::vector<std::string>& tier_names,
    const std::string& data_dir,
    const std::vector<std::string>& require_context_tiers) {
    if (mcp.enable_entropic) {
        register_server(std::make_unique<EntropicServer>(
            tier_names, data_dir, require_context_tiers));
    }
    if (mcp.enable_filesystem) {
        register_server(std::make_unique<FilesystemServer>(
            project_dir_, mcp.filesystem, data_dir));
    }
    if (mcp.enable_bash) {
        register_server(std::make_unique<BashServer>(
            project_dir_, data_dir, mcp.bash.timeout_seconds));
    }
    if (mcp.enable_git) {
        register_server(std::make_unique<GitServer>(
            project_dir_, data_dir));
    }
    if (mcp.enable_diagnostics) {
        register_server(std::make_unique<DiagnosticsServer>(
            project_dir_, data_dir));
    }
    if (mcp.enable_web) {
        register_server(std::make_unique<WebServer>(data_dir));
    }
}
Activity · 12 steps
lines 69–69◇ if (mcp.enable_entropic)lines 70–71register_server(std::make_unique<EntropicServer>( tier_names, data_dir, require_context_tiers));lines 73–73◇ if (mcp.enable_filesystem)lines 74–75register_server(std::make_unique<FilesystemServer>( project_dir_, mcp.filesystem, data_dir));lines 77–77◇ if (mcp.enable_bash)lines 78–79register_server(std::make_unique<BashServer>( project_dir_, data_dir, mcp.bash.timeout_seconds));lines 81–81◇ if (mcp.enable_git)lines 82–83register_server(std::make_unique<GitServer>( project_dir_, data_dir));lines 85–85◇ if (mcp.enable_diagnostics)lines 86–87register_server(std::make_unique<DiagnosticsServer>( project_dir_, data_dir));lines 89–89◇ if (mcp.enable_web)lines 90–90register_server(std::make_unique<WebServer>(data_dir));

Requirements

REQ-MCP-001 REQ-MCP-007 REQ-MCP-023

initialize_external_servers

void entropic::ServerManager::initialize_external_servers()

Initialize external servers from config + .mcp.json.

src/mcp/server_manager.cpp:1065

Source · 16 lines
void ServerManager::initialize_external_servers() {
    connect_declared_servers();
    connect_discovered_servers();

    health_monitor_ = std::make_unique<HealthMonitor>(
        ReconnectPolicy(mcp_config_.reconnect),
        mcp_config_.health_check_interval_ms);
    for (auto& [name, client] : external_clients_) {
        health_monitor_->watch(name, client.get());
    }
    if (!external_clients_.empty()) {
        health_monitor_->start();
    }
    logger->info("External MCP: {} servers connected",
                 external_clients_.size());
}
Activity · 8 steps
lines 1066–1066connect_declared_servers();lines 1067–1067connect_discovered_servers();lines 1069–1071health_monitor_ = std::make_unique<HealthMonitor>( ReconnectPolicy(mcp_config_.reconnect), mcp_config_.health_check_interval_ms);lines 1072–1072◇ for (auto& [name, client] : external_clients_)lines 1073–1073health_monitor_->watch(name, client.get());lines 1075–1075◇ if (!external_clients_.empty())lines 1076–1076health_monitor_->start();lines 1078–1079logger->info("External MCP: {} servers connected", external_clients_.size());

Requirements

REQ-MCP-025

interrupt_external_tools

void entropic::ServerManager::interrupt_external_tools()

Abort in-flight tool calls across every external MCP client.

src/mcp/server_manager.cpp:1030

Show on the map →

Called by TEST_CASE, wire_external_interrupt

Calls external_snapshot, interrupt

Source · 5 lines
void ServerManager::interrupt_external_tools() {
    for (auto& [_, client] : external_snapshot()) {
        if (client) { client->interrupt(); }
    }
}
Activity · 3 steps
lines 1031–1031◇ for (auto& [_, client] : external_snapshot())lines 1032–1032◇ if (client)lines 1032–1032client->interrupt();

Requirements

REQ-MCP-025

is_explicitly_allowed

bool entropic::ServerManager::is_explicitly_allowed(const std::string &tool_name, const std::string &args_json) const

Check if tool is explicitly allowed (skip prompting).

src/mcp/server_manager.cpp:783

Source · 6 lines
bool ServerManager::is_explicitly_allowed(
    const std::string& tool_name,
    const std::string& args_json) const {
    auto pattern = tool_name + ":" + args_to_pattern(args_json);
    return permissions_.is_allowed(tool_name, pattern);
}
Activity · 2 steps
lines 786–786auto pattern = tool_name + ":" + args_to_pattern(args_json);lines 787–787return permissions_.is_allowed(tool_name, pattern);

Requirements

REQ-MCP-009

leave_working_dir

size_t entropic::ServerManager::leave_working_dir(const std::filesystem::path &dir)

Restore after enter_working_dir() , then release one level of the root lock (gh#158, gh#160).

src/mcp/server_manager.cpp:311

Source · 12 lines
size_t ServerManager::leave_working_dir(const std::filesystem::path& dir) {
    if (!root_lock_->owned_by_this_thread()) {
        logger->error("leave_working_dir({}) from a thread that holds no "
                      "sandbox root lock — refusing, nothing moved",
                      dir.string());
        return 0;
    }
    auto moved = set_working_dir_all(dir);
    root_lock_->unlock();
    logger->info("Tool root lock released on restore to {}", dir.string());
    return moved;
}
Activity · 7 steps
lines 312–312◇ if (!root_lock_->owned_by_this_thread())lines 313–315logger->error("leave_working_dir({}) from a thread that holds no " "sandbox root lock — refusing, nothing moved", dir.string());lines 316–316return 0;lines 318–318auto moved = set_working_dir_all(dir);lines 319–319root_lock_->unlock();lines 320–320logger->info("Tool root lock released on restore to {}", dir.string());lines 321–321return moved;

Requirements

REQ-DELEG-005 REQ-LOOP-009

list_server_info

std::map< std::string, ServerInfo > entropic::ServerManager::list_server_info() const

Get snapshot of all servers with current status.

src/mcp/server_manager.cpp:1403

Show on the map →

Called by TEST_CASE, entropic_list_mcp_servers

Calls info

Source · 34 lines
ServerManager::list_server_info() const {
    std::map<std::string, ServerInfo> result;
    {
        std::shared_lock<std::shared_mutex> lock(*external_mutex_);
        result = server_info_;
    }

    // Add in-process servers
    for (const auto& [name, _] : servers_) {
        if (result.count(name) == 0) {
            ServerInfo info;
            info.name = name;
            info.transport = "in_process";
            info.status = "connected";
            info.source = "builtin";
            result[name] = info;
        }
    }

    // gh#133 (v2.10.1): plugins report their own transport so `entropic
    // inspect` distinguishes them from builtins and external processes.
    for (const auto& [name, plugin] : plugin_servers_) {
        if (result.count(name) == 0) {
            ServerInfo info;
            info.name = name;
            info.transport = "plugin";
            info.status = "connected";
            info.source = "plugin";
            info.command = plugin->path().string();
            result[name] = info;
        }
    }
    return result;
}
Activity · 21 steps
lines 1404–1404std::map<std::string, ServerInfo> result;lines 1406–1406std::shared_lock<std::shared_mutex> lock(*external_mutex_);lines 1407–1407result = server_info_;lines 1411–1411◇ for (const auto& [name, _] : servers_)lines 1412–1412◇ if (result.count(name) == 0)lines 1413–1413ServerInfo info;lines 1414–1414info.name = name;lines 1415–1415info.transport = "in_process";lines 1416–1416info.status = "connected";lines 1417–1417info.source = "builtin";lines 1418–1418result[name] = info;lines 1424–1424◇ for (const auto& [name, plugin] : plugin_servers_)lines 1425–1425◇ if (result.count(name) == 0)lines 1426–1426ServerInfo info;lines 1427–1427info.name = name;lines 1428–1428info.transport = "plugin";lines 1429–1429info.status = "connected";lines 1430–1430info.source = "plugin";lines 1431–1431info.command = plugin->path().string();lines 1432–1432result[name] = info;lines 1435–1435return result;

Requirements

REQ-MCP-007

list_tools

std::string entropic::ServerManager::list_tools() const

List all tools from all connected servers.

src/mcp/server_manager.cpp:399

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, SCENARIO, TEST_CASE, sp_get_tools

Calls append_external_tools, append_plugin_tools, append_prefixed_tools, external_snapshot

Source · 16 lines
std::string ServerManager::list_tools() const {
    auto all = nlohmann::json::array();

    // In-process servers
    for (const auto& [name, server] : servers_) {
        append_prefixed_tools(server->list_tools(), name, all);
    }

    append_plugin_tools(all);     // gh#133 (v2.10.1)
    append_external_tools(all);

    logger->info("Tool list: {} tools from {} server(s) + {} plugin(s) + "
                 "{} external", all.size(), servers_.size(),
                 plugin_servers_.size(), external_snapshot().size());
    return all.dump();
}
Activity · 7 steps
lines 400–400auto all = nlohmann::json::array();lines 403–403◇ for (const auto& [name, server] : servers_)lines 404–404append_prefixed_tools(server->list_tools(), name, all);lines 407–407append_plugin_tools(all);lines 408–408append_external_tools(all);lines 410–412logger->info("Tool list: {} tools from {} server(s) + {} plugin(s) + " "{} external", all.size(), servers_.size(), plugin_servers_.size(), external_snapshot().size());lines 413–413return all.dump();

Requirements

REQ-MCP-007

load_plugins

entropic_error_t entropic::ServerManager::load_plugins(const MCPConfig &mcp_config)

Load the dlopen plugins listed in mcp.plugins (gh#133).

src/mcp/server_manager.cpp:114

Show on the map →

Called by build_workspace, init_mcp_servers

Calls find_external, load, name, set_working_dir

Source · 32 lines
entropic_error_t ServerManager::load_plugins(const MCPConfig& mcp) {
    auto first_error = ENTROPIC_OK;

    for (const auto& path : mcp.plugins) {
        std::unique_ptr<PluginServer> plugin;
        auto rc = PluginServer::load(path, plugin);
        if (rc != ENTROPIC_OK) {
            // Keep going: attempting every path diagnoses a whole broken
            // config in one run instead of one entry per restart.
            first_error = (first_error == ENTROPIC_OK) ? rc : first_error;
            continue;
        }

        auto name = plugin->name();
        if (servers_.count(name) > 0 || find_external(name) ||
            plugin_servers_.count(name) > 0) {
            logger->error("Plugin '{}' from {} collides with an already "
                          "registered server of the same name — refusing to "
                          "shadow it", name, path.string());
            first_error = (first_error == ENTROPIC_OK)
                              ? ENTROPIC_ERROR_PLUGIN_LOAD_FAILED
                              : first_error;
            continue;
        }

        plugin->set_working_dir(project_dir_.string());
        plugin_servers_[name] = std::move(plugin);
        logger->info("Registered plugin server: {}", name);
    }

    return first_error;
}
Activity · 16 steps
lines 115–115auto first_error = ENTROPIC_OK;lines 117–117◇ for (const auto& path : mcp.plugins)lines 118–118std::unique_ptr<PluginServer> plugin;lines 119–119auto rc = PluginServer::load(path, plugin);lines 120–120◇ if (rc != ENTROPIC_OK)lines 123–123first_error = (first_error == ENTROPIC_OK) ? rc : first_error;lines 124–124continue;lines 127–127auto name = plugin->name();lines 128–129◇ if (servers_.count(name) > 0 || find_external(name) || plugin_servers_.count(name) > 0)lines 130–132logger->error("Plugin '{}' from {} collides with an already " "registered server of the same name — refusing to " "shadow it", name, path.string());lines 133–135first_error = (first_error == ENTROPIC_OK) ? ENTROPIC_ERROR_PLUGIN_LOAD_FAILED : first_error;lines 136–136continue;lines 139–139plugin->set_working_dir(project_dir_.string());lines 140–140plugin_servers_[name] = std::move(plugin);lines 141–141logger->info("Registered plugin server: {}", name);lines 144–144return first_error;

Requirements

REQ-MCP-005

make_transport

std::unique_ptr< Transport > entropic::ServerManager::make_transport(const ExternalServerConfig &spec) const

Construct a Transport from a spec (single source of truth).

src/mcp/server_manager.cpp:1267

Show on the map →

Called by create_external_client

Calls SSETransport, set_working_dir

Source · 22 lines
std::unique_ptr<Transport> ServerManager::make_transport(
    const ExternalServerConfig& spec) const {
    bool prefer_sse = (spec.transport == "sse")
        || (!spec.url.empty() && spec.command.empty());
    if (prefer_sse) {
        return std::make_unique<SSETransport>(spec.url);
    }
    // gh#19 (v2.1.5): pass the registered server name as the display
    // label so child stderr lines and lifecycle logs identify the
    // server, not the resolved spawn command (which collides when
    // multiple servers share an entrypoint like /usr/bin/env python).
    auto transport = std::make_unique<StdioTransport>(
        spec.name, spec.command, spec.args, spec.env,
        /*default_timeout_ms=*/30000U);
    // gh#166 (v2.13.0): spawn the child IN the repository its tools are
    // supposed to serve. An explicit spec value wins; otherwise the
    // manager's own root, which for a workspace is the workspace root.
    transport->set_working_dir(spec.working_dir.empty()
                                   ? project_dir_.string()
                                   : spec.working_dir);
    return transport;
}
Activity · 6 steps
lines 1269–1270bool prefer_sse = (spec.transport == "sse") || (!spec.url.empty() && spec.command.empty());lines 1271–1271◇ if (prefer_sse)lines 1272–1272return std::make_unique<SSETransport>(spec.url);lines 1278–1280auto transport = std::make_unique<StdioTransport>( spec.name, spec.command, spec.args, spec.env, /*default_timeout_ms=*/30000U);lines 1284–1286transport->set_working_dir(spec.working_dir.empty() ? project_dir_.string() : spec.working_dir);lines 1287–1287return transport;

Requirements

REQ-MCP-025

plugin_tool_schema

std::string entropic::ServerManager::plugin_tool_schema(const std::string &prefix, const std::string &local_name) const

Look up a plugin tool's inputSchema from its descriptor list.

src/mcp/server_manager.cpp:590

Source · 22 lines
std::string ServerManager::plugin_tool_schema(
    const std::string& prefix,
    const std::string& local_name) const {

    auto it = plugin_servers_.find(prefix);
    if (it == plugin_servers_.end()) {
        return "";
    }
    try {
        auto tools = nlohmann::json::parse(it->second->list_tools());
        for (const auto& tool : tools) {
            if (tool.value("name", std::string{}) == local_name) {
                return tool.value("inputSchema",
                                  nlohmann::json::object()).dump();
            }
        }
    } catch (const std::exception& e) {
        logger->error("Plugin '{}': cannot read schema for tool '{}': {}",
                      prefix, local_name, e.what());
    }
    return "";
}
Activity · 5 steps
lines 594–594auto it = plugin_servers_.find(prefix);lines 595–595◇ if (it == plugin_servers_.end())lines 596–596return "";lines 598–609try { auto tools = nlohmann::json::parse(it->second->list_tools()); for (const auto& tool : tools) { if (tool.value("name", std::string{}) == local_name) { return tool.value("inputSchema", nlohmann::json::object()).dump(); } } } catch (const std::exception& e) { logger->error("Plugin '{}': cannot read schema for tool '{}': {}", prefix, local_name, e.what()); }lines 610–610return "";

Requirements

REQ-MCP-008

process_health_events

void entropic::ServerManager::process_health_events()

Process pending health events (call from engine loop).

src/mcp/server_manager.cpp:1447

Source · 5 lines
void ServerManager::process_health_events() {
    if (health_monitor_) {
        health_monitor_->process_events();
    }
}
Activity · 2 steps
lines 1448–1448◇ if (health_monitor_)lines 1449–1449health_monitor_->process_events();

Requirements

REQ-MCP-025

release_session

std::size_t entropic::ServerManager::release_session(const std::string &key)

Release every in-process server's state for one session (gh#158).

src/mcp/server_manager.cpp:508

Source · 12 lines
std::size_t ServerManager::release_session(const std::string& key) {
    std::size_t released = 0;
    for (const auto& [name, server] : servers_) {
        auto* owner = dynamic_cast<SessionStateOwner*>(server.get());
        if (owner != nullptr && owner->release_session(key)) {
            ++released;
        }
    }
    logger->info("Released session '{}' tool state on {} server(s)",
                 key, released);
    return released;
}
Activity · 7 steps
lines 509–509std::size_t released = 0;lines 510–510◇ for (const auto& [name, server] : servers_)lines 511–511auto* owner = dynamic_cast<SessionStateOwner*>(server.get());lines 512–512◇ if (owner != nullptr && owner->release_session(key))lines 513–513++released;lines 516–517logger->info("Released session '{}' tool state on {} server(s)", key, released);lines 518–518return released;

Requirements

REQ-LOOP-009 REQ-MCP-021

requires_approval

bool entropic::ServerManager::requires_approval(const std::string &tool_name) const

Whether a tool call needs the host's approval.

src/mcp/server_manager.cpp:850

Source · 6 lines
bool ServerManager::requires_approval(
    const std::string& tool_name) const {
    auto it = servers_.find(extract_prefix(tool_name));
    return it == servers_.end()
        || it->second->requires_approval(extract_local_name(tool_name));
}
Activity · 2 steps
lines 852–852auto it = servers_.find(extract_prefix(tool_name));lines 853–854return it == servers_.end() || it->second->requires_approval(extract_local_name(tool_name));

Requirements

REQ-MCP-012

route_external_call

std::string entropic::ServerManager::route_external_call(ExternalMCPClient *client, const std::string &tool_name, const std::string &local_name, const std::string &args_json)

Route a tool call to an external client.

src/mcp/server_manager.cpp:713

Source · 12 lines
std::string ServerManager::route_external_call(
    ExternalMCPClient* client,
    const std::string& tool_name,
    const std::string& local_name,
    const std::string& args_json) {

    if (!client->is_connected()) {
        auto prefix = extract_prefix(tool_name);
        return disconnected_error(tool_name, prefix);
    }
    return client->execute(local_name, args_json);
}
Activity · 4 steps
lines 719–719◇ if (!client->is_connected())lines 720–720auto prefix = extract_prefix(tool_name);lines 721–721return disconnected_error(tool_name, prefix);lines 723–723return client->execute(local_name, args_json);

Requirements

REQ-MCP-007 REQ-MCP-025

route_external_or_unknown

std::string entropic::ServerManager::route_external_or_unknown(const std::string &prefix, const std::string &tool_name, const std::string &local_name, const std::string &args_json)

Route to an external client, or report an unknown prefix.

src/mcp/server_manager.cpp:680

Source · 19 lines
std::string ServerManager::route_external_or_unknown(
    const std::string& prefix,
    const std::string& tool_name,
    const std::string& local_name,
    const std::string& args_json) {

    // gh#171: our own reference keeps the client alive for the whole call,
    // even if a disconnect removes it from the registry meanwhile.
    if (auto client = find_external(prefix)) {
        return route_external_call(client.get(), tool_name, local_name,
                                   args_json);
    }

    logger->warn("Unknown server: {}", prefix);
    nlohmann::json resp;
    resp["result"] = "Error: Unknown server '" + prefix + "'";
    resp["directives"] = nlohmann::json::array();
    return resp.dump();
}
Activity · 7 steps
lines 688–688◇ if (auto client = find_external(prefix))lines 689–690return route_external_call(client.get(), tool_name, local_name, args_json);lines 693–693logger->warn("Unknown server: {}", prefix);lines 694–694nlohmann::json resp;lines 695–695resp["result"] = "Error: Unknown server '" + prefix + "'";lines 696–696resp["directives"] = nlohmann::json::array();lines 697–697return resp.dump();

Requirements

REQ-MCP-002 REQ-MCP-007

route_plugin_call

std::string entropic::ServerManager::route_plugin_call(PluginServer &plugin, const std::string &local_name, const std::string &args_json)

Route a tool call to a loaded plugin (gh#133).

src/mcp/server_manager.cpp:744

Source · 24 lines
std::string ServerManager::route_plugin_call(
    PluginServer& plugin,
    const std::string& local_name,
    const std::string& args_json) {

    std::string raw;
    try {
        raw = plugin.execute(local_name, args_json);
        auto parsed = nlohmann::json::parse(raw);
        if (!parsed.is_object() || !parsed.contains("result")) {
            throw std::runtime_error("missing 'result' field");
        }
        return raw;
    } catch (const std::exception& e) {
        logger->error("Plugin '{}' returned an invalid response for tool "
                      "'{}': {} — raw response: {}",
                      plugin.name(), local_name, e.what(), raw);
        nlohmann::json resp;
        resp["result"] = "Error: plugin '" + plugin.name() +
                         "' returned an invalid response: " + e.what();
        resp["directives"] = nlohmann::json::array();
        return resp.dump();
    }
}
Activity · 2 steps
lines 749–749std::string raw;lines 750–766try { raw = plugin.execute(local_name, args_json); auto parsed = nlohmann::json::parse(raw); if (!parsed.is_object() || !parsed.contains("result")) { throw std::runtime_error("missing 'result' field"); } return raw; } catch (const std::exception& e) { logger->error("Plugin '{}' returned an invalid response for tool " "'{}': {} — raw response: {}", plugin.name(), local_name, e.what(), raw); nlohmann::json resp; resp["result"] = "Error: plugin '" + plugin.name() + "' returned an invalid response: " + e.what(); resp["directives"] = nlohmann::json::array(); return resp.dump(); }

Requirements

REQ-MCP-002 REQ-MCP-007

route_tool_call

std::string entropic::ServerManager::route_tool_call(const std::string &tool_name, const std::string &args_json)

Route a tool call to the correct server.

src/mcp/server_manager.cpp:639

Source · 23 lines
std::string ServerManager::route_tool_call(
    const std::string& tool_name,
    const std::string& args_json) {

    auto prefix = extract_prefix(tool_name);
    auto local_name = extract_local_name(tool_name);

    // Try in-process server first
    auto it = servers_.find(prefix);
    if (it != servers_.end()) {
        ToolRootShared root(*root_lock_, tool_name);
        return it->second->execute(local_name, args_json);
    }

    // gh#133 (v2.10.1): try a loaded plugin
    auto plug_it = plugin_servers_.find(prefix);
    if (plug_it != plugin_servers_.end()) {
        ToolRootShared root(*root_lock_, tool_name);
        return route_plugin_call(*plug_it->second, local_name, args_json);
    }

    return route_external_or_unknown(prefix, tool_name, local_name, args_json);
}
Activity · 11 steps
lines 643–643auto prefix = extract_prefix(tool_name);lines 644–644auto local_name = extract_local_name(tool_name);lines 647–647auto it = servers_.find(prefix);lines 648–648◇ if (it != servers_.end())lines 649–649ToolRootShared root(*root_lock_, tool_name);lines 650–650return it->second->execute(local_name, args_json);lines 654–654auto plug_it = plugin_servers_.find(prefix);lines 655–655◇ if (plug_it != plugin_servers_.end())lines 656–656ToolRootShared root(*root_lock_, tool_name);lines 657–657return route_plugin_call(*plug_it->second, local_name, args_json);lines 660–660return route_external_or_unknown(prefix, tool_name, local_name, args_json);

Requirements

REQ-LOOP-009 REQ-MCP-007

server_names

std::vector< std::string > entropic::ServerManager::server_names() const

List registered server names (in-process + external).

src/mcp/server_manager.cpp:529

Show on the map →

Called by SCENARIO, TEST_CASE, sp_get_state

Calls external_snapshot

Source · 13 lines
std::vector<std::string> ServerManager::server_names() const {
    std::vector<std::string> names;
    for (const auto& [name, _] : servers_) {
        names.push_back(name);
    }
    for (const auto& [name, _] : plugin_servers_) {  // gh#133 (v2.10.1)
        names.push_back(name);
    }
    for (const auto& [name, _] : external_snapshot()) {
        names.push_back(name);
    }
    return names;
}
Activity · 8 steps
lines 530–530std::vector<std::string> names;lines 531–531◇ for (const auto& [name, _] : servers_)lines 532–532names.push_back(name);lines 534–534◇ for (const auto& [name, _] : plugin_servers_)lines 535–535names.push_back(name);lines 537–537◇ for (const auto& [name, _] : external_snapshot())lines 538–538names.push_back(name);lines 540–540return names;

Requirements

REQ-MCP-007

set_discovered_server_approver

void entropic::ServerManager::set_discovered_server_approver(DiscoveredServerApprover fn, void *user_data)

Install the discovered-server approver (v2.14.0, gh#199).

src/mcp/server_manager.cpp:1180

Source · 5 lines
void ServerManager::set_discovered_server_approver(
    DiscoveredServerApprover fn, void* user_data) {
    discovered_approver_ = fn;
    discovered_approver_ud_ = user_data;
}
Activity · 2 steps
lines 1182–1182discovered_approver_ = fn;lines 1183–1183discovered_approver_ud_ = user_data;

Requirements

REQ-MCP-025

set_outside_root_approver

bool entropic::ServerManager::set_outside_root_approver(OutsideRootApprover fn, void *user_data)

Install the outside-root approver on this set's filesystem server (v2.13.0).

src/mcp/server_manager.cpp:482

Source · 10 lines
bool ServerManager::set_outside_root_approver(OutsideRootApprover fn,
                                              void* user_data) {
    ToolRootShared root(*root_lock_, "set_outside_root_approver");
    auto* fs_server = dynamic_cast<FilesystemServer*>(
        get_server("filesystem"));
    if (fs_server != nullptr) {
        fs_server->set_outside_root_approver(fn, user_data);
    }
    return fs_server != nullptr;
}
Activity · 5 steps
lines 484–484ToolRootShared root(*root_lock_, "set_outside_root_approver");lines 485–486auto* fs_server = dynamic_cast<FilesystemServer*>( get_server("filesystem"));lines 487–487◇ if (fs_server != nullptr)lines 488–488fs_server->set_outside_root_approver(fn, user_data);lines 490–490return fs_server != nullptr;

Requirements

REQ-MCP-021

set_own_bridge_socket

void entropic::ServerManager::set_own_bridge_socket(const std::filesystem::path &socket)

The socket this handle's external bridge binds (v2.14.0, gh#200).

src/mcp/server_manager.cpp:1192

Source · 3 lines
void ServerManager::set_own_bridge_socket(const std::filesystem::path& socket) {
    own_bridge_socket_ = socket;
}
Activity · 1 steps
lines 1193–1193own_bridge_socket_ = socket;

Requirements

REQ-MCP-025

set_working_dir_all

size_t entropic::ServerManager::set_working_dir_all(const std::filesystem::path &dir)

Point every in-process and plugin server at dir (gh#160).

src/mcp/server_manager.cpp:264

Source · 16 lines
size_t ServerManager::set_working_dir_all(
        const std::filesystem::path& dir) {
    std::lock_guard<ToolRootLock> exclusive(*root_lock_);
    size_t moved = 0;
    for (const auto& [name, server] : servers_) {
        if (server->set_working_dir(dir.string())) { ++moved; }
    }
    for (const auto& [name, plugin] : plugin_servers_) {
        if (plugin->set_working_dir(dir.string()) == ENTROPIC_OK) {
            ++moved;
        }
    }
    logger->info("Tool working dir → {} ({} servers moved)",
                 dir.string(), moved);
    return moved;
}
Activity · 10 steps
lines 266–266std::lock_guard<ToolRootLock> exclusive(*root_lock_);lines 267–267size_t moved = 0;lines 268–268◇ for (const auto& [name, server] : servers_)lines 269–269◇ if (server->set_working_dir(dir.string()))lines 269–269++moved;lines 271–271◇ for (const auto& [name, plugin] : plugin_servers_)lines 272–272◇ if (plugin->set_working_dir(dir.string()) == ENTROPIC_OK)lines 273–273++moved;lines 276–277logger->info("Tool working dir → {} ({} servers moved)", dir.string(), moved);lines 278–278return moved;

Requirements

REQ-DELEG-005 REQ-LOOP-009 REQ-MCP-001

shutdown

void entropic::ServerManager::shutdown()

Shutdown all servers (in-process + external).

src/mcp/server_manager.cpp:912

Show on the map →

Called by SCENARIO, SCENARIO, TEST_CASE, TEST_CASE, entropic_destroy

Calls disconnect, stop

Source · 27 lines
void ServerManager::shutdown() {
    // Stop health monitor first
    if (health_monitor_) {
        health_monitor_->stop();
    }

    // Disconnect external clients — taken out under the lock, disconnected
    // after it (gh#171: never I/O while holding external_mutex_).
    std::map<std::string, std::shared_ptr<ExternalMCPClient>> clients;
    {
        std::unique_lock<std::shared_mutex> lock(*external_mutex_);
        clients.swap(external_clients_);
        server_info_.clear();
    }
    for (auto& [name, client] : clients) {
        client->disconnect();
    }

    // gh#133 (v2.10.1): destroy plugin instances and dlclose their libraries
    // before the in-process servers, so nothing can call into an unmapped .so.
    logger->info("Unloading {} MCP plugin(s)", plugin_servers_.size());
    plugin_servers_.clear();

    // Destroy in-process servers
    logger->info("Shutting down {} MCP servers", servers_.size());
    servers_.clear();
}
Activity · 12 steps
lines 914–914◇ if (health_monitor_)lines 915–915health_monitor_->stop();lines 920–920std::map<std::string, std::shared_ptr<ExternalMCPClient>> clients;lines 922–922std::unique_lock<std::shared_mutex> lock(*external_mutex_);lines 923–923clients.swap(external_clients_);lines 924–924server_info_.clear();lines 926–926◇ for (auto& [name, client] : clients)lines 927–927client->disconnect();lines 932–932logger->info("Unloading {} MCP plugin(s)", plugin_servers_.size());lines 933–933plugin_servers_.clear();lines 936–936logger->info("Shutting down {} MCP servers", servers_.size());lines 937–937servers_.clear();

Requirements

REQ-MCP-006 REQ-MCP-025

Flows

skip_duplicate_check

bool entropic::ServerManager::skip_duplicate_check(const std::string &tool_name) const

Check if tool should skip duplicate detection.

src/mcp/server_manager.cpp:826

Source · 10 lines
bool ServerManager::skip_duplicate_check(
    const std::string& tool_name) const {
    auto prefix = extract_prefix(tool_name);
    auto it = servers_.find(prefix);
    if (it != servers_.end()) {
        auto local = extract_local_name(tool_name);
        return it->second->skip_duplicate_check(local);
    }
    return false;
}
Activity · 6 steps
lines 828–828auto prefix = extract_prefix(tool_name);lines 829–829auto it = servers_.find(prefix);lines 830–830◇ if (it != servers_.end())lines 831–831auto local = extract_local_name(tool_name);lines 832–832return it->second->skip_duplicate_check(local);lines 834–834return false;

Requirements

REQ-MCP-015

tools_without_readonly_hint

std::vector< std::string > entropic::ServerManager::tools_without_readonly_hint(const std::string &tools_json, const std::vector< std::string > &allowed)

The readOnlyHint filter itself, over one descriptor list.

src/mcp/server_manager.cpp:348

Show on the map →

Called by TEST_CASE, external_tools_without_readonly_hint

Calls tool_is_read_only

Source · 17 lines
std::vector<std::string> ServerManager::tools_without_readonly_hint(
        const std::string& tools_json,
        const std::vector<std::string>& allowed) {
    std::vector<std::string> unsafe;
    auto tools = nlohmann::json::parse(tools_json, nullptr, false);
    if (!tools.is_array()) { return unsafe; }
    for (const auto& tool : tools) {
        auto full = tool.value("name", std::string{});
        bool visible = allowed.empty()
            || std::find(allowed.begin(), allowed.end(), full)
                   != allowed.end();
        if (visible && !full.empty() && !tool_is_read_only(tool)) {
            unsafe.push_back(full);
        }
    }
    return unsafe;
}
Activity · 10 steps
lines 351–351std::vector<std::string> unsafe;lines 352–352auto tools = nlohmann::json::parse(tools_json, nullptr, false);lines 353–353◇ if (!tools.is_array())lines 353–353return unsafe;lines 354–354◇ for (const auto& tool : tools)lines 355–355auto full = tool.value("name", std::string{});lines 356–358bool visible = allowed.empty() || std::find(allowed.begin(), allowed.end(), full) != allowed.end();lines 359–359◇ if (visible && !full.empty() && !tool_is_read_only(tool))lines 360–360unsafe.push_back(full);lines 363–363return unsafe;

Requirements

REQ-DELEG-005 REQ-MCP-007