entropic_mcp.cpp

src/facade/entropic_mcp.cpp

@file entropic_mcp.cpp @brief C API implementation for external MCP server management.

Owners: @tvanfossen

apply_workspace_app_context

void entropic::apply_workspace_app_context(entropic_handle_t h, const std::string &workspace, const std::optional< std::string > &app_context)

Give a workspace's sessions prompts built on its own app_context (gh#179), or return them to the handle's.

src/facade/entropic_mcp.cpp:209

Source · 24 lines
void entropic::apply_workspace_app_context(
    entropic_handle_t h, const std::string& workspace,
    const std::optional<std::string>& app_context) {
    if (!app_context) {
        h->engine->clear_workspace_prompts(workspace);
        return;
    }
    const auto data_dir = entropic::config::resolve_data_dir(h->config);
    std::string constitution, handle_ctx;
    entropic::prompts::load_shared_prompt_sources(h->config, data_dir,
                                                  constitution, handle_ctx);
    std::string prefix;
    if (!constitution.empty()) { prefix += constitution + "\n\n"; }
    if (!app_context->empty()) { prefix += *app_context + "\n\n"; }
    entropic::WorkspacePrompts prompts;
    prompts.default_prompt = prefix;
    for (const auto& [name, tier] : h->config.models.tiers) {
        prompts.tier_prompts[name] = prefix
            + entropic::prompts::resolve_tier_identity_full(tier, name, data_dir).body;
    }
    auto def = prompts.tier_prompts.find(h->config.models.default_tier);
    if (def != prompts.tier_prompts.end()) { prompts.default_prompt = def->second; }
    h->engine->set_workspace_prompts(workspace, std::move(prompts));
}
Activity · 19 steps
lines 212–212◇ if (!app_context)lines 213–213h->engine->clear_workspace_prompts(workspace);lines 214–214return;lines 216–216const auto data_dir = entropic::config::resolve_data_dir(h->config);lines 217–217std::string constitution, handle_ctx;lines 218–219entropic::prompts::load_shared_prompt_sources(h->config, data_dir, constitution, handle_ctx);lines 220–220std::string prefix;lines 221–221◇ if (!constitution.empty())lines 221–221prefix += constitution + "\n\n";lines 222–222◇ if (!app_context->empty())lines 222–222prefix += *app_context + "\n\n";lines 223–223entropic::WorkspacePrompts prompts;lines 224–224prompts.default_prompt = prefix;lines 225–225◇ for (const auto& [name, tier] : h->config.models.tiers)lines 226–227prompts.tier_prompts[name] = prefix + entropic::prompts::resolve_tier_identity_full(tier, name, data_dir).body;lines 229–229auto def = prompts.tier_prompts.find(h->config.models.default_tier);lines 230–230◇ if (def != prompts.tier_prompts.end())lines 230–230prompts.default_prompt = def->second;lines 231–231h->engine->set_workspace_prompts(workspace, std::move(prompts));

Requirements

REQ-MCP-027

bridge_project_dir

std::filesystem::path entropic::bridge_project_dir(entropic_handle_t h)

The project dir the external bridge derives its socket from.

src/facade/entropic_mcp.cpp:179

Source · 4 lines
std::filesystem::path entropic::bridge_project_dir(entropic_handle_t h) {
    return h->config.config_dir.empty() ? std::filesystem::current_path()
                                        : h->config.config_dir;
}
Activity · 1 steps
lines 180–181return h->config.config_dir.empty() ? std::filesystem::current_path() : h->config.config_dir;

Requirements

REQ-BRIDGE-001

build_workspace

static std::unique_ptr< EntropicWorkspace > build_workspace(entropic_handle_t h, const std::string &name, const std::filesystem::path &dir)

Build a workspace's own server instances rooted at dir .

src/facade/entropic_mcp.cpp:380

Source · 30 lines
static std::unique_ptr<EntropicWorkspace> build_workspace(
    entropic_handle_t h, const std::string& name,
    const std::filesystem::path& dir) {
    auto ws = std::make_unique<EntropicWorkspace>();
    ws->name = name;
    ws->root = dir;
    ws->servers = std::make_unique<entropic::ServerManager>(
        h->config.permissions, dir);
    std::vector<std::string> tier_names;
    std::vector<std::string> require_context;
    for (const auto& [tier, cfg] : h->config.models.tiers) {
        if (tier != h->config.models.default_tier) {
            tier_names.push_back(tier);
        }
        if (cfg.requires_context) { require_context.push_back(tier); }
    }
    auto data_dir = entropic::config::resolve_data_dir(h->config);
    const auto mcp = confined_mcp_config(h);
    ws->servers->init_builtins(mcp, tier_names,
                               data_dir.string(), require_context);
    ws->servers->load_plugins(mcp);
    // gh#199: the workspace inherits the handle's enablement policy, so its
    // root's .mcp.json launches nothing the operator did not enable.
    // v2.14.1: and it launches the operator's DECLARED servers itself,
    // rooted here — a bound session dispatches only to this set, so a
    // declared server left on the base set was invisible to it (decision
    // #87, revising #83).
    entropic::wire_external_server_policy(h, *ws->servers, true);
    return ws;
}
Activity · 17 steps
lines 383–383auto ws = std::make_unique<EntropicWorkspace>();lines 384–384ws->name = name;lines 385–385ws->root = dir;lines 386–387ws->servers = std::make_unique<entropic::ServerManager>( h->config.permissions, dir);lines 388–388std::vector<std::string> tier_names;lines 389–389std::vector<std::string> require_context;lines 390–390◇ for (const auto& [tier, cfg] : h->config.models.tiers)lines 391–391◇ if (tier != h->config.models.default_tier)lines 392–392tier_names.push_back(tier);lines 394–394◇ if (cfg.requires_context)lines 394–394require_context.push_back(tier);lines 396–396auto data_dir = entropic::config::resolve_data_dir(h->config);lines 397–397const auto mcp = confined_mcp_config(h);lines 398–399ws->servers->init_builtins(mcp, tier_names, data_dir.string(), require_context);lines 400–400ws->servers->load_plugins(mcp);lines 407–407entropic::wire_external_server_policy(h, *ws->servers, true);lines 408–408return ws;

Requirements

REQ-MCP-027

check_server_mgr

static entropic_error_t check_server_mgr(entropic_handle_t h)

Check handle prerequisites for MCP server APIs.

src/facade/entropic_mcp.cpp:40

Source · 5 lines
static entropic_error_t check_server_mgr(entropic_handle_t h) {
    if (!h) { return ENTROPIC_ERROR_INVALID_HANDLE; }
    if (!h->server_manager) { return ENTROPIC_ERROR_INVALID_STATE; }
    return ENTROPIC_OK;
}
Activity · 5 steps
lines 41–41◇ if (!h)lines 41–41return ENTROPIC_ERROR_INVALID_HANDLE;lines 42–42◇ if (!h->server_manager)lines 42–42return ENTROPIC_ERROR_INVALID_STATE;lines 43–43return ENTROPIC_OK;

Requirements

REQ-API-005

confined_mcp_config

static entropic::MCPConfig confined_mcp_config(entropic_handle_t h)

The handle's MCP config, confined to a workspace root (gh#166).

src/facade/entropic_mcp.cpp:80

Source · 14 lines
static entropic::MCPConfig confined_mcp_config(entropic_handle_t h) {
    entropic::MCPConfig mcp = h->config.mcp;
    auto& fs_cfg = mcp.filesystem;
    if (fs_cfg.allow_outside_root != entropic::OutsideRootAccess::refuse
        || !fs_cfg.outside_root_allow.empty()) {
        logger->info("workspace servers confine to their root (host "
                     "mcp.filesystem.allow_outside_root, outside_root_allow "
                     "({} entries) and the path approver apply to the "
                     "default set only)", fs_cfg.outside_root_allow.size());
    }
    fs_cfg.allow_outside_root = entropic::OutsideRootAccess::refuse;
    fs_cfg.outside_root_allow.clear();
    return mcp;
}
Activity · 7 steps
lines 81–81entropic::MCPConfig mcp = h->config.mcp;lines 82–82auto& fs_cfg = mcp.filesystem;lines 83–84◇ if (fs_cfg.allow_outside_root != entropic::OutsideRootAccess::refuse || !fs_cfg.outside_root_allow.empty())lines 85–88logger->info("workspace servers confine to their root (host " "mcp.filesystem.allow_outside_root, outside_root_allow " "({} entries) and the path approver apply to the " "default set only)", fs_cfg.outside_root_allow.size());lines 90–90fs_cfg.allow_outside_root = entropic::OutsideRootAccess::refuse;lines 91–91fs_cfg.outside_root_allow.clear();lines 92–92return mcp;

Requirements

REQ-MCP-021 REQ-MCP-027

entropic_deregister_mcp_server

ENTROPIC_EXPORT entropic_error_t entropic_deregister_mcp_server(entropic_handle_t handle, const char *name)

Deregister an external MCP server.

src/facade/entropic_mcp.cpp:810

Show on the map →

Called by SCENARIO, TEST_CASE

Calls check_server_mgr

Source · 18 lines
entropic_deregister_mcp_server(
    entropic_handle_t handle,
    const char* name) {

    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK || !name) {
        return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }

    try {
        handle->server_manager->disconnect_external_server(name);
        logger->info("deregister_mcp_server: name='{}'", name);
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return ENTROPIC_ERROR_SERVER_NOT_FOUND;
    }
}
Activity · 4 steps
lines 814–814auto rc = check_server_mgr(handle);lines 815–815◇ if (rc != ENTROPIC_OK || !name)lines 816–816return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 819–826try { handle->server_manager->disconnect_external_server(name); logger->info("deregister_mcp_server: name='{}'", name); return ENTROPIC_OK; } catch (const std::exception& e) { handle->last_error = e.what(); return ENTROPIC_ERROR_SERVER_NOT_FOUND; }
ENTROPIC_EXPORT entropic_error_t entropic_deregister_mcp_server(entropic_handle_t handle, const char *name)

Deregister an external MCP server.

src/facade/entropic_mcp.cpp:810

Show on the map →

Called by SCENARIO

Calls check_server_mgr, disconnect_external_server

Source · 18 lines
entropic_deregister_mcp_server(
    entropic_handle_t handle,
    const char* name) {

    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK || !name) {
        return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }

    try {
        handle->server_manager->disconnect_external_server(name);
        logger->info("deregister_mcp_server: name='{}'", name);
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return ENTROPIC_ERROR_SERVER_NOT_FOUND;
    }
}
Activity · 4 steps
lines 814–814auto rc = check_server_mgr(handle);lines 815–815◇ if (rc != ENTROPIC_OK || !name)lines 816–816return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 819–826try { handle->server_manager->disconnect_external_server(name); logger->info("deregister_mcp_server: name='{}'", name); return ENTROPIC_OK; } catch (const std::exception& e) { handle->last_error = e.what(); return ENTROPIC_ERROR_SERVER_NOT_FOUND; }

Requirements

REQ-ABI-002 REQ-API-005 REQ-MCP-025

entropic_list_mcp_servers

ENTROPIC_EXPORT char * entropic_list_mcp_servers(entropic_handle_t handle)

List all MCP servers as JSON array.

src/facade/entropic_mcp.cpp:841

Show on the map →

Called by SCENARIO, SCENARIO, TEST_CASE

Calls none

Source · 21 lines
entropic_list_mcp_servers(entropic_handle_t handle) {
    if (!handle || !handle->configured.load()) {
        return nullptr;
    }
    try {
        nlohmann::json arr = nlohmann::json::array();
        if (handle->server_manager) {
            auto servers = handle->server_manager->list_server_info();
            for (const auto& [name, s] : servers) {
                arr.push_back({{"name", s.name},
                               {"transport", s.transport},
                               {"status", s.status},
                               {"source", s.source}});
            }
        }
        return strdup(arr.dump().c_str());
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return nullptr;
    }
}
Activity · 3 steps
lines 842–842◇ if (!handle || !handle->configured.load())lines 843–843return nullptr;lines 845–860try { nlohmann::json arr = nlohmann::json::array(); if (handle->server_manager) { auto servers = handle->server_manager->list_server_info(); for (const auto& [name, s] : servers) { arr.push_back({{"name", s.name}, {"transport", s.transport}, {"status", s.status}, {"source", s.source}}); } } return strdup(arr.dump().c_str()); } catch (const std::exception& e) { handle->last_error = e.what(); return nullptr; }
ENTROPIC_EXPORT char * entropic_list_mcp_servers(entropic_handle_t handle)

List all MCP servers with status information.

src/facade/entropic_mcp.cpp:841

Show on the map →

Called by SCENARIO, SCENARIO

Calls list_server_info

Source · 21 lines
entropic_list_mcp_servers(entropic_handle_t handle) {
    if (!handle || !handle->configured.load()) {
        return nullptr;
    }
    try {
        nlohmann::json arr = nlohmann::json::array();
        if (handle->server_manager) {
            auto servers = handle->server_manager->list_server_info();
            for (const auto& [name, s] : servers) {
                arr.push_back({{"name", s.name},
                               {"transport", s.transport},
                               {"status", s.status},
                               {"source", s.source}});
            }
        }
        return strdup(arr.dump().c_str());
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return nullptr;
    }
}
Activity · 3 steps
lines 842–842◇ if (!handle || !handle->configured.load())lines 843–843return nullptr;lines 845–860try { nlohmann::json arr = nlohmann::json::array(); if (handle->server_manager) { auto servers = handle->server_manager->list_server_info(); for (const auto& [name, s] : servers) { arr.push_back({{"name", s.name}, {"transport", s.transport}, {"status", s.status}, {"source", s.source}}); } } return strdup(arr.dump().c_str()); } catch (const std::exception& e) { handle->last_error = e.what(); return nullptr; }

Requirements

REQ-ABI-002 REQ-API-005 REQ-API-008 REQ-MCP-025

entropic_register_mcp_server

ENTROPIC_EXPORT entropic_error_t entropic_register_mcp_server(entropic_handle_t handle, const char *name, const char *config_json)

Register an external MCP server from JSON config (C ABI).

src/facade/entropic_mcp.cpp:764

Show on the map →

Called by SCENARIO, TEST_CASE, register_server, setup_engine, setup_engine

Calls check_server_mgr, parse_external_server_spec, resolve_registration_target

Source · 33 lines
entropic_register_mcp_server(
    entropic_handle_t handle,
    const char* name,
    const char* config_json) {

    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK || !name || !config_json) {
        return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }

    try {
        auto j = nlohmann::json::parse(config_json);
        auto spec = parse_external_server_spec(name, j);
        // gh#166 (v2.13.0): an optional "workspace" field registers the
        // server on that workspace's set instead of the handle's, and
        // spawns it with cwd = the workspace root — which is what a
        // repo-scoped server like `clew-mcp --repo` actually needs.
        auto ws_name = j.value("workspace", std::string{});
        auto* servers = resolve_registration_target(handle, ws_name, spec);
        if (servers == nullptr) {
            handle->last_error = "unknown workspace: " + ws_name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            servers->connect_external_server(spec);
            logger->info("register_mcp_server: name='{}' env_keys={} "
                         "workspace='{}'", name, spec.env.size(), ws_name);
        }
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        rc = ENTROPIC_ERROR_CONNECTION_FAILED;
    }
    return rc;
}
Activity · 5 steps
lines 769–769auto rc = check_server_mgr(handle);lines 770–770◇ if (rc != ENTROPIC_OK || !name || !config_json)lines 771–771return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 774–794try { auto j = nlohmann::json::parse(config_json); auto spec = parse_external_server_spec(name, j); // gh#166 (v2.13.0): an optional "workspace" field registers the // server on that workspace's set instead of the handle's, and // spawns it with cwd = the workspace root — which is what a // repo-scoped server like `clew-mcp --repo` actually needs. auto ws_name = j.value("workspace", std::string{}); auto* servers = resolve_registration_target(handle, ws_name, spec); if (servers == nullptr) { handle->last_error = "unknown workspace: " + ws_name; rc = ENTROPIC_ERROR_INVALID_ARGUMENT; } else { servers->connect_external_server(spec); logger->info("register_mcp_server: name='{}' env_keys={} " "workspace='{}'", name, spec.env.size(), ws_name); } } catch (const std::exception& e) { handle->last_error = e.what(); rc = ENTROPIC_ERROR_CONNECTION_FAILED; }lines 795–795return rc;
ENTROPIC_EXPORT entropic_error_t entropic_register_mcp_server(entropic_handle_t handle, const char *name, const char *config_json)

Register an external MCP server at runtime.

src/facade/entropic_mcp.cpp:764

Show on the map →

Called by none

Calls check_server_mgr, parse_external_server_spec, resolve_registration_target

Source · 33 lines
entropic_register_mcp_server(
    entropic_handle_t handle,
    const char* name,
    const char* config_json) {

    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK || !name || !config_json) {
        return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }

    try {
        auto j = nlohmann::json::parse(config_json);
        auto spec = parse_external_server_spec(name, j);
        // gh#166 (v2.13.0): an optional "workspace" field registers the
        // server on that workspace's set instead of the handle's, and
        // spawns it with cwd = the workspace root — which is what a
        // repo-scoped server like `clew-mcp --repo` actually needs.
        auto ws_name = j.value("workspace", std::string{});
        auto* servers = resolve_registration_target(handle, ws_name, spec);
        if (servers == nullptr) {
            handle->last_error = "unknown workspace: " + ws_name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            servers->connect_external_server(spec);
            logger->info("register_mcp_server: name='{}' env_keys={} "
                         "workspace='{}'", name, spec.env.size(), ws_name);
        }
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        rc = ENTROPIC_ERROR_CONNECTION_FAILED;
    }
    return rc;
}
Activity · 5 steps
lines 769–769auto rc = check_server_mgr(handle);lines 770–770◇ if (rc != ENTROPIC_OK || !name || !config_json)lines 771–771return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 774–794try { auto j = nlohmann::json::parse(config_json); auto spec = parse_external_server_spec(name, j); // gh#166 (v2.13.0): an optional "workspace" field registers the // server on that workspace's set instead of the handle's, and // spawns it with cwd = the workspace root — which is what a // repo-scoped server like `clew-mcp --repo` actually needs. auto ws_name = j.value("workspace", std::string{}); auto* servers = resolve_registration_target(handle, ws_name, spec); if (servers == nullptr) { handle->last_error = "unknown workspace: " + ws_name; rc = ENTROPIC_ERROR_INVALID_ARGUMENT; } else { servers->connect_external_server(spec); logger->info("register_mcp_server: name='{}' env_keys={} " "workspace='{}'", name, spec.env.size(), ws_name); } } catch (const std::exception& e) { handle->last_error = e.what(); rc = ENTROPIC_ERROR_CONNECTION_FAILED; }lines 795–795return rc;

Requirements

REQ-ABI-002 REQ-API-005 REQ-MCP-025

entropic_session_bind_workspace

ENTROPIC_EXPORT entropic_error_t entropic_session_bind_workspace(entropic_handle_t handle, const char *session_key, const char *name)

Bind a session to a workspace (gh#166) — see entropic.h .

src/facade/entropic_mcp.cpp:583

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, bind_session_workspace

Calls check_server_mgr

Source · 33 lines
entropic_session_bind_workspace(entropic_handle_t handle,
                                const char* session_key,
                                const char* name) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    if (name == nullptr || *name == '\0' || !handle->engine) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    entropic::HandleApiLock lock(handle);
    std::string key = session_key != nullptr ? session_key : "";
    // Single-exit accumulator (knots returns gate ≤ 3). A conversation
    // cites paths relative to the root it was built in, so re-rooting one
    // mid-life invalidates every citation in it with no error anywhere:
    // refuse rather than silently re-point.
    rc = ENTROPIC_OK;
    if (handle->engine->message_count_for(key) > 0) {
        handle->last_error =
            "session '" + key + "' already holds messages; bind a "
            "workspace before its first turn";
        rc = ENTROPIC_ERROR_INVALID_STATE;
    } else {
        std::lock_guard<std::mutex> guard(handle->workspace_mutex);
        if (handle->workspaces.count(name) == 0) {
            handle->last_error = std::string("unknown workspace: ") + name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            handle->session_workspace[key] = name;
            handle->engine->bind_session_workspace(key, name);  // gh#179
            logger->info("session '{}' bound to workspace '{}'", key, name);
        }
    }
    return rc;
}
Activity · 21 steps
lines 586–586auto rc = check_server_mgr(handle);lines 587–587◇ if (rc != ENTROPIC_OK)lines 587–587return rc;lines 588–588◇ if (name == nullptr || *name == '\0' || !handle->engine)lines 589–589return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 591–591entropic::HandleApiLock lock(handle);lines 592–592std::string key = session_key != nullptr ? session_key : "";lines 597–597rc = ENTROPIC_OK;lines 598–598◇ if (handle->engine->message_count_for(key) > 0)lines 599–601handle->last_error = "session '" + key + "' already holds messages; bind a " "workspace before its first turn";lines 602–602rc = ENTROPIC_ERROR_INVALID_STATE;lines 603–603elselines 604–604std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 605–605◇ if (handle->workspaces.count(name) == 0)lines 606–606handle->last_error = std::string("unknown workspace: ") + name;lines 607–607rc = ENTROPIC_ERROR_INVALID_ARGUMENT;lines 608–608elselines 609–609handle->session_workspace[key] = name;lines 610–610handle->engine->bind_session_workspace(key, name);lines 611–611logger->info("session '{}' bound to workspace '{}'", key, name);lines 614–614return rc;
ENTROPIC_EXPORT entropic_error_t entropic_session_bind_workspace(entropic_handle_t handle, const char *session_key, const char *name)

Bind a session to a workspace (gh#166).

src/facade/entropic_mcp.cpp:583

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, bind_session_workspace

Calls bind_session_workspace, check_server_mgr, message_count_for

Source · 33 lines
entropic_session_bind_workspace(entropic_handle_t handle,
                                const char* session_key,
                                const char* name) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    if (name == nullptr || *name == '\0' || !handle->engine) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    entropic::HandleApiLock lock(handle);
    std::string key = session_key != nullptr ? session_key : "";
    // Single-exit accumulator (knots returns gate ≤ 3). A conversation
    // cites paths relative to the root it was built in, so re-rooting one
    // mid-life invalidates every citation in it with no error anywhere:
    // refuse rather than silently re-point.
    rc = ENTROPIC_OK;
    if (handle->engine->message_count_for(key) > 0) {
        handle->last_error =
            "session '" + key + "' already holds messages; bind a "
            "workspace before its first turn";
        rc = ENTROPIC_ERROR_INVALID_STATE;
    } else {
        std::lock_guard<std::mutex> guard(handle->workspace_mutex);
        if (handle->workspaces.count(name) == 0) {
            handle->last_error = std::string("unknown workspace: ") + name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            handle->session_workspace[key] = name;
            handle->engine->bind_session_workspace(key, name);  // gh#179
            logger->info("session '{}' bound to workspace '{}'", key, name);
        }
    }
    return rc;
}
Activity · 21 steps
lines 586–586auto rc = check_server_mgr(handle);lines 587–587◇ if (rc != ENTROPIC_OK)lines 587–587return rc;lines 588–588◇ if (name == nullptr || *name == '\0' || !handle->engine)lines 589–589return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 591–591entropic::HandleApiLock lock(handle);lines 592–592std::string key = session_key != nullptr ? session_key : "";lines 597–597rc = ENTROPIC_OK;lines 598–598◇ if (handle->engine->message_count_for(key) > 0)lines 599–601handle->last_error = "session '" + key + "' already holds messages; bind a " "workspace before its first turn";lines 602–602rc = ENTROPIC_ERROR_INVALID_STATE;lines 603–603elselines 604–604std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 605–605◇ if (handle->workspaces.count(name) == 0)lines 606–606handle->last_error = std::string("unknown workspace: ") + name;lines 607–607rc = ENTROPIC_ERROR_INVALID_ARGUMENT;lines 608–608elselines 609–609handle->session_workspace[key] = name;lines 610–610handle->engine->bind_session_workspace(key, name);lines 611–611logger->info("session '{}' bound to workspace '{}'", key, name);lines 614–614return rc;

Requirements

REQ-ABI-002 REQ-API-005 REQ-MCP-027

entropic_set_path_approval_callback

ENTROPIC_EXPORT entropic_error_t entropic_set_path_approval_callback(entropic_handle_t handle, ent_path_approval_cb cb, void *user_data)

Register the outside-root path approver — see entropic.h .

src/facade/entropic_mcp.cpp:348

Show on the map →

Called by SCENARIO

Calls none

Source · 14 lines
entropic_set_path_approval_callback(entropic_handle_t handle,
                                    ent_path_approval_cb cb,
                                    void* user_data) {
    if (handle == nullptr) { return ENTROPIC_ERROR_INVALID_HANDLE; }
    entropic::log::HandleLogScope scope(handle->log_id);
    {
        std::lock_guard<std::mutex> lock(handle->path_approval_mutex);
        handle->path_approval_cb = cb;
        handle->path_approval_data = user_data;
    }
    logger->info("path approval callback {}",
                 cb != nullptr ? "registered" : "cleared");
    return ENTROPIC_OK;
}
Activity · 8 steps
lines 351–351◇ if (handle == nullptr)lines 351–351return ENTROPIC_ERROR_INVALID_HANDLE;lines 352–352entropic::log::HandleLogScope scope(handle->log_id);lines 354–354std::lock_guard<std::mutex> lock(handle->path_approval_mutex);lines 355–355handle->path_approval_cb = cb;lines 356–356handle->path_approval_data = user_data;lines 358–359logger->info("path approval callback {}", cb != nullptr ? "registered" : "cleared");lines 360–360return ENTROPIC_OK;
ENTROPIC_EXPORT entropic_error_t entropic_set_path_approval_callback(entropic_handle_t handle, ent_path_approval_cb cb, void *user_data)

Register the approver for filesystem access outside the root.

src/facade/entropic_mcp.cpp:348

Show on the map →

Called by SCENARIO

Calls none

Source · 14 lines
entropic_set_path_approval_callback(entropic_handle_t handle,
                                    ent_path_approval_cb cb,
                                    void* user_data) {
    if (handle == nullptr) { return ENTROPIC_ERROR_INVALID_HANDLE; }
    entropic::log::HandleLogScope scope(handle->log_id);
    {
        std::lock_guard<std::mutex> lock(handle->path_approval_mutex);
        handle->path_approval_cb = cb;
        handle->path_approval_data = user_data;
    }
    logger->info("path approval callback {}",
                 cb != nullptr ? "registered" : "cleared");
    return ENTROPIC_OK;
}
Activity · 8 steps
lines 351–351◇ if (handle == nullptr)lines 351–351return ENTROPIC_ERROR_INVALID_HANDLE;lines 352–352entropic::log::HandleLogScope scope(handle->log_id);lines 354–354std::lock_guard<std::mutex> lock(handle->path_approval_mutex);lines 355–355handle->path_approval_cb = cb;lines 356–356handle->path_approval_data = user_data;lines 358–359logger->info("path approval callback {}", cb != nullptr ? "registered" : "cleared");lines 360–360return ENTROPIC_OK;

Requirements

REQ-API-005 REQ-API-010 REQ-MCP-021

entropic_workspace_create

ENTROPIC_EXPORT entropic_error_t entropic_workspace_create(entropic_handle_t handle, const char *name, const char *dir)

Create a named workspace (gh#166) — see entropic.h .

src/facade/entropic_mcp.cpp:542

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, resolve_workspace

Calls apply_workspace_app_context, build_workspace, check_server_mgr, load_workspace_context_file, validate_workspace_args

Source · 28 lines
entropic_workspace_create(entropic_handle_t handle,
                          const char* name,
                          const char* dir) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    entropic::HandleApiLock lock(handle);
    std::filesystem::path root;
    std::optional<std::string> ctx;
    rc = validate_workspace_args(handle, name, dir, root);
    if (rc == ENTROPIC_OK) { rc = load_workspace_context_file(handle, root, ctx); }
    if (rc == ENTROPIC_OK) {
        try {
            auto ws = build_workspace(handle, name, root);
            ws->app_context = ctx;
            ws->servers->initialize();
            std::lock_guard<std::mutex> guard(handle->workspace_mutex);
            handle->workspaces[name] = std::move(ws);
            entropic::apply_workspace_app_context(handle, name, ctx);  // gh#179
            logger->info("workspace '{}' created at {} (app_context: {})",
                         name, root.string(), ctx ? "its own" : "the handle's");
        } catch (const std::exception& e) {
            // Design rule #5: exceptions never cross the .so boundary.
            handle->last_error = e.what();
            rc = ENTROPIC_ERROR_INTERNAL;
        }
    }
    return rc;
}
Activity · 12 steps
lines 545–545auto rc = check_server_mgr(handle);lines 546–546◇ if (rc != ENTROPIC_OK)lines 546–546return rc;lines 547–547entropic::HandleApiLock lock(handle);lines 548–548std::filesystem::path root;lines 549–549std::optional<std::string> ctx;lines 550–550rc = validate_workspace_args(handle, name, dir, root);lines 551–551◇ if (rc == ENTROPIC_OK)lines 551–551rc = load_workspace_context_file(handle, root, ctx);lines 552–552◇ if (rc == ENTROPIC_OK)lines 553–566try { auto ws = build_workspace(handle, name, root); ws->app_context = ctx; ws->servers->initialize(); std::lock_guard<std::mutex> guard(handle->workspace_mutex); handle->workspaces[name] = std::move(ws); entropic::apply_workspace_app_context(handle, name, ctx); // gh#179 logger->info("workspace '{}' created at {} (app_context: {})", name, root.string(), ctx ? "its own" : "the handle's"); } catch (const std::exception& e) { // Design rule #5: exceptions never cross the .so boundary. handle->last_error = e.what(); rc = ENTROPIC_ERROR_INTERNAL; }lines 568–568return rc;
ENTROPIC_EXPORT entropic_error_t entropic_workspace_create(entropic_handle_t handle, const char *name, const char *dir)

Create a named workspace rooted at a directory (gh#166).

src/facade/entropic_mcp.cpp:542

Show on the map →

Called by SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, SCENARIO, resolve_workspace

Calls apply_workspace_app_context, build_workspace, check_server_mgr, initialize, load_workspace_context_file, validate_workspace_args

Source · 28 lines
entropic_workspace_create(entropic_handle_t handle,
                          const char* name,
                          const char* dir) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    entropic::HandleApiLock lock(handle);
    std::filesystem::path root;
    std::optional<std::string> ctx;
    rc = validate_workspace_args(handle, name, dir, root);
    if (rc == ENTROPIC_OK) { rc = load_workspace_context_file(handle, root, ctx); }
    if (rc == ENTROPIC_OK) {
        try {
            auto ws = build_workspace(handle, name, root);
            ws->app_context = ctx;
            ws->servers->initialize();
            std::lock_guard<std::mutex> guard(handle->workspace_mutex);
            handle->workspaces[name] = std::move(ws);
            entropic::apply_workspace_app_context(handle, name, ctx);  // gh#179
            logger->info("workspace '{}' created at {} (app_context: {})",
                         name, root.string(), ctx ? "its own" : "the handle's");
        } catch (const std::exception& e) {
            // Design rule #5: exceptions never cross the .so boundary.
            handle->last_error = e.what();
            rc = ENTROPIC_ERROR_INTERNAL;
        }
    }
    return rc;
}
Activity · 12 steps
lines 545–545auto rc = check_server_mgr(handle);lines 546–546◇ if (rc != ENTROPIC_OK)lines 546–546return rc;lines 547–547entropic::HandleApiLock lock(handle);lines 548–548std::filesystem::path root;lines 549–549std::optional<std::string> ctx;lines 550–550rc = validate_workspace_args(handle, name, dir, root);lines 551–551◇ if (rc == ENTROPIC_OK)lines 551–551rc = load_workspace_context_file(handle, root, ctx);lines 552–552◇ if (rc == ENTROPIC_OK)lines 553–566try { auto ws = build_workspace(handle, name, root); ws->app_context = ctx; ws->servers->initialize(); std::lock_guard<std::mutex> guard(handle->workspace_mutex); handle->workspaces[name] = std::move(ws); entropic::apply_workspace_app_context(handle, name, ctx); // gh#179 logger->info("workspace '{}' created at {} (app_context: {})", name, root.string(), ctx ? "its own" : "the handle's"); } catch (const std::exception& e) { // Design rule #5: exceptions never cross the .so boundary. handle->last_error = e.what(); rc = ENTROPIC_ERROR_INTERNAL; }lines 568–568return rc;

Requirements

REQ-ABI-002 REQ-API-005 REQ-MCP-027

entropic_workspace_set_app_context

ENTROPIC_EXPORT entropic_error_t entropic_workspace_set_app_context(entropic_handle_t handle, const char *name, const char *app_context)

Give a workspace its own app_context (gh#179) — see entropic.h .

src/facade/entropic_mcp.cpp:629

Source · 33 lines
entropic_workspace_set_app_context(entropic_handle_t handle,
                                   const char* name,
                                   const char* app_context) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    if (name == nullptr || *name == '\0') { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    entropic::HandleApiLock lock(handle);
    std::optional<std::string> ctx;
    if (app_context != nullptr) { ctx = app_context; }
    {
        std::lock_guard<std::mutex> guard(handle->workspace_mutex);
        auto it = handle->workspaces.find(name);
        if (it == handle->workspaces.end()) {
            handle->last_error = std::string("unknown workspace: ") + name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            it->second->app_context = ctx;
        }
    }
    try {
        if (rc == ENTROPIC_OK) {
            entropic::apply_workspace_app_context(handle, name, ctx);
            logger->info("workspace '{}' app_context {}", name,
                         ctx ? "set (" + std::to_string(ctx->size()) + " bytes)"
                             : std::string("reset to the handle's"));
        }
    } catch (const std::exception& e) {
        // Design rule #5: exceptions never cross the .so boundary.
        handle->last_error = e.what();
        rc = ENTROPIC_ERROR_INTERNAL;
    }
    return rc;
}
Activity · 18 steps
lines 632–632auto rc = check_server_mgr(handle);lines 633–633◇ if (rc != ENTROPIC_OK)lines 633–633return rc;lines 634–634◇ if (name == nullptr || *name == '\0')lines 634–634return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 635–635entropic::HandleApiLock lock(handle);lines 636–636std::optional<std::string> ctx;lines 637–637◇ if (app_context != nullptr)lines 637–637ctx = app_context;lines 639–639std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 640–640auto it = handle->workspaces.find(name);lines 641–641◇ if (it == handle->workspaces.end())lines 642–642handle->last_error = std::string("unknown workspace: ") + name;lines 643–643rc = ENTROPIC_ERROR_INVALID_ARGUMENT;lines 644–644elselines 645–645it->second->app_context = ctx;lines 648–659try { if (rc == ENTROPIC_OK) { entropic::apply_workspace_app_context(handle, name, ctx); logger->info("workspace '{}' app_context {}", name, ctx ? "set (" + std::to_string(ctx->size()) + " bytes)" : std::string("reset to the handle's")); } } catch (const std::exception& e) { // Design rule #5: exceptions never cross the .so boundary. handle->last_error = e.what(); rc = ENTROPIC_ERROR_INTERNAL; }lines 660–660return rc;
ENTROPIC_EXPORT entropic_error_t entropic_workspace_set_app_context(entropic_handle_t handle, const char *name, const char *app_context)

Give a workspace its own app_context (gh#179).

src/facade/entropic_mcp.cpp:629

Source · 33 lines
entropic_workspace_set_app_context(entropic_handle_t handle,
                                   const char* name,
                                   const char* app_context) {
    auto rc = check_server_mgr(handle);
    if (rc != ENTROPIC_OK) { return rc; }
    if (name == nullptr || *name == '\0') { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    entropic::HandleApiLock lock(handle);
    std::optional<std::string> ctx;
    if (app_context != nullptr) { ctx = app_context; }
    {
        std::lock_guard<std::mutex> guard(handle->workspace_mutex);
        auto it = handle->workspaces.find(name);
        if (it == handle->workspaces.end()) {
            handle->last_error = std::string("unknown workspace: ") + name;
            rc = ENTROPIC_ERROR_INVALID_ARGUMENT;
        } else {
            it->second->app_context = ctx;
        }
    }
    try {
        if (rc == ENTROPIC_OK) {
            entropic::apply_workspace_app_context(handle, name, ctx);
            logger->info("workspace '{}' app_context {}", name,
                         ctx ? "set (" + std::to_string(ctx->size()) + " bytes)"
                             : std::string("reset to the handle's"));
        }
    } catch (const std::exception& e) {
        // Design rule #5: exceptions never cross the .so boundary.
        handle->last_error = e.what();
        rc = ENTROPIC_ERROR_INTERNAL;
    }
    return rc;
}
Activity · 18 steps
lines 632–632auto rc = check_server_mgr(handle);lines 633–633◇ if (rc != ENTROPIC_OK)lines 633–633return rc;lines 634–634◇ if (name == nullptr || *name == '\0')lines 634–634return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 635–635entropic::HandleApiLock lock(handle);lines 636–636std::optional<std::string> ctx;lines 637–637◇ if (app_context != nullptr)lines 637–637ctx = app_context;lines 639–639std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 640–640auto it = handle->workspaces.find(name);lines 641–641◇ if (it == handle->workspaces.end())lines 642–642handle->last_error = std::string("unknown workspace: ") + name;lines 643–643rc = ENTROPIC_ERROR_INVALID_ARGUMENT;lines 644–644elselines 645–645it->second->app_context = ctx;lines 648–659try { if (rc == ENTROPIC_OK) { entropic::apply_workspace_app_context(handle, name, ctx); logger->info("workspace '{}' app_context {}", name, ctx ? "set (" + std::to_string(ctx->size()) + " bytes)" : std::string("reset to the handle's")); } } catch (const std::exception& e) { // Design rule #5: exceptions never cross the .so boundary. handle->last_error = e.what(); rc = ENTROPIC_ERROR_INTERNAL; }lines 660–660return rc;

Requirements

REQ-ABI-002 REQ-API-005 REQ-MCP-027

expected_bridge_socket

std::filesystem::path entropic::expected_bridge_socket(entropic_handle_t h)

The socket this handle's external bridge binds, or empty when the handle runs no bridge (v2.14.0, gh#200).

src/facade/entropic_mcp.cpp:191

Source · 9 lines
std::filesystem::path entropic::expected_bridge_socket(entropic_handle_t h) {
    const auto& ext = h->config.mcp.external;
    std::filesystem::path sock;
    if (ext.enabled) {
        sock = ext.socket_path.has_value()
            ? *ext.socket_path : compute_socket_path(bridge_project_dir(h));
    }
    return sock;
}
Activity · 5 steps
lines 192–192const auto& ext = h->config.mcp.external;lines 193–193std::filesystem::path sock;lines 194–194◇ if (ext.enabled)lines 195–196sock = ext.socket_path.has_value() ? *ext.socket_path : compute_socket_path(bridge_project_dir(h));lines 198–198return sock;

Requirements

REQ-MCP-025

outside_root_thunk

static entropic::OutsideRootVerdict outside_root_thunk(const entropic::OutsideRootRequest &req, void *ud)

FilesystemServer → consumer bridge for outside-root approval.

src/facade/entropic_mcp.cpp:109

Source · 24 lines
static entropic::OutsideRootVerdict outside_root_thunk(
    const entropic::OutsideRootRequest& req, void* ud) {
    auto* h = static_cast<entropic_handle_t>(ud);
    ent_path_approval_cb cb = nullptr;
    void* cb_data = nullptr;
    {
        std::lock_guard<std::mutex> lock(h->path_approval_mutex);
        cb = h->path_approval_cb;
        cb_data = h->path_approval_data;
    }
    auto verdict = entropic::OutsideRootVerdict::no_approver;
    if (cb != nullptr) {
        const std::string session = entropic::current_run_session();
        ent_path_approval_request_t c_req{
            req.path.c_str(), req.root.c_str(), req.tool.c_str(),
            req.access == entropic::PathAccess::write
                ? ENT_PATH_ACCESS_WRITE : ENT_PATH_ACCESS_READ,
            session.c_str()};
        verdict = cb(&c_req, cb_data) == ENT_DECISION_ACCEPT
            ? entropic::OutsideRootVerdict::approved
            : entropic::OutsideRootVerdict::rejected;
    }
    return verdict;
}
Activity · 12 steps
lines 111–111auto* h = static_cast<entropic_handle_t>(ud);lines 112–112ent_path_approval_cb cb = nullptr;lines 113–113void* cb_data = nullptr;lines 115–115std::lock_guard<std::mutex> lock(h->path_approval_mutex);lines 116–116cb = h->path_approval_cb;lines 117–117cb_data = h->path_approval_data;lines 119–119auto verdict = entropic::OutsideRootVerdict::no_approver;lines 120–120◇ if (cb != nullptr)lines 121–121const std::string session = entropic::current_run_session();lines 122–126ent_path_approval_request_t c_req{ req.path.c_str(), req.root.c_str(), req.tool.c_str(), req.access == entropic::PathAccess::write ? ENT_PATH_ACCESS_WRITE : ENT_PATH_ACCESS_READ, session.c_str()};lines 127–129verdict = cb(&c_req, cb_data) == ENT_DECISION_ACCEPT ? entropic::OutsideRootVerdict::approved : entropic::OutsideRootVerdict::rejected;lines 131–131return verdict;

Requirements

REQ-MCP-021

release_session_tool_state

std::size_t entropic::release_session_tool_state(entropic_handle_t h, const std::string &key)

Release a session's per-session tool state on every server set (gh#158).

src/facade/entropic_mcp.cpp:315

Source · 15 lines
std::size_t entropic::release_session_tool_state(entropic_handle_t h,
                                                 const std::string& key) {
    std::size_t released = 0;
    if (h == nullptr) { return released; }
    if (h->server_manager) {
        released += h->server_manager->release_session(key);
    }
    std::lock_guard<std::mutex> lock(h->workspace_mutex);
    for (const auto& [name, ws] : h->workspaces) {
        if (ws && ws->servers) {
            released += ws->servers->release_session(key);
        }
    }
    return released;
}
Activity · 10 steps
lines 317–317std::size_t released = 0;lines 318–318◇ if (h == nullptr)lines 318–318return released;lines 319–319◇ if (h->server_manager)lines 320–320released += h->server_manager->release_session(key);lines 322–322std::lock_guard<std::mutex> lock(h->workspace_mutex);lines 323–323◇ for (const auto& [name, ws] : h->workspaces)lines 324–324◇ if (ws && ws->servers)lines 325–325released += ws->servers->release_session(key);lines 328–328return released;

Requirements

REQ-LOOP-009

resolve_registration_target

static entropic::ServerManager * resolve_registration_target(entropic_handle_t handle, const std::string &ws_name, entropic::ExternalServerConfig &spec)

Servers a registration targets, and the cwd it spawns in (gh#166).

src/facade/entropic_mcp.cpp:741

Source · 10 lines
static entropic::ServerManager* resolve_registration_target(
    entropic_handle_t handle, const std::string& ws_name,
    entropic::ExternalServerConfig& spec) {
    if (ws_name.empty()) { return handle->server_manager.get(); }
    std::lock_guard<std::mutex> guard(handle->workspace_mutex);
    auto it = handle->workspaces.find(ws_name);
    if (it == handle->workspaces.end()) { return nullptr; }
    spec.working_dir = it->second->root.string();
    return it->second->servers.get();
}
Activity · 8 steps
lines 744–744◇ if (ws_name.empty())lines 744–744return handle->server_manager.get();lines 745–745std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 746–746auto it = handle->workspaces.find(ws_name);lines 747–747◇ if (it == handle->workspaces.end())lines 747–747return nullptr;lines 748–748spec.working_dir = it->second->root.string();lines 749–749return it->second->servers.get();

Requirements

REQ-MCP-027

swap_session_tool_dir

void entropic::swap_session_tool_dir(const std::string &session_key, const std::filesystem::path &path, bool entering, void *ud)

The facade's gh#160 ScopedSandbox swap callback.

src/facade/entropic_mcp.cpp:283

Show on the map →

Called by SCENARIO, wire_session_roots

Calls workspace_servers

Source · 16 lines
void entropic::swap_session_tool_dir(
    const std::string& session_key,
    const std::filesystem::path& path,
    bool entering, void* ud) {
    auto* h = static_cast<entropic_handle_t>(ud);
    auto* servers = entropic::workspace_servers(h, session_key);
    if (servers == nullptr) { return; }
    logger->info("delegation dir swap: session='{}' -> {} ({})",
                 session_key, path.string(),
                 entering ? "enter" : "restore");
    if (entering) {
        servers->enter_working_dir(path);
    } else {
        servers->leave_working_dir(path);
    }
}
Activity · 9 steps
lines 287–287auto* h = static_cast<entropic_handle_t>(ud);lines 288–288auto* servers = entropic::workspace_servers(h, session_key);lines 289–289◇ if (servers == nullptr)lines 289–289return;lines 290–292logger->info("delegation dir swap: session='{}' -> {} ({})", session_key, path.string(), entering ? "enter" : "restore");lines 293–293◇ if (entering)lines 294–294servers->enter_working_dir(path);lines 295–295elselines 296–296servers->leave_working_dir(path);

Requirements

REQ-DELEG-005

validate_workspace_args

static entropic_error_t validate_workspace_args(entropic_handle_t handle, const char *name, const char *dir, std::filesystem::path &root)

Validate workspace-create arguments and resolve the root.

src/facade/entropic_mcp.cpp:456

Source · 28 lines
static entropic_error_t validate_workspace_args(
    entropic_handle_t handle, const char* name, const char* dir,
    std::filesystem::path& root) {
    if (name == nullptr || *name == '\0' || dir == nullptr
        || *dir == '\0') {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    std::error_code ec;
    root = std::filesystem::absolute(dir, ec);
    std::string err;
    if (ec || !std::filesystem::is_directory(root, ec)) {
        err = std::string("workspace dir is not a directory: ") + dir;
    } else {
        err = workspace_root_refusal(handle->config.mcp.workspace_roots, root);
    }
    if (err.empty()) {
        std::lock_guard<std::mutex> guard(handle->workspace_mutex);
        if (handle->workspaces.count(name) > 0) {
            err = std::string("workspace already exists: ") + name;
        }
    }
    if (!err.empty()) {
        logger->warn("workspace '{}' refused: {}", name, err);
        handle->last_error = err;
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    return ENTROPIC_OK;
}
Activity · 18 steps
lines 459–460◇ if (name == nullptr || *name == '\0' || dir == nullptr || *dir == '\0')lines 461–461return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 463–463std::error_code ec;lines 464–464root = std::filesystem::absolute(dir, ec);lines 465–465std::string err;lines 466–466◇ if (ec || !std::filesystem::is_directory(root, ec))lines 467–467err = std::string("workspace dir is not a directory: ") + dir;lines 468–468elselines 469–469err = workspace_root_refusal(handle->config.mcp.workspace_roots, root);lines 471–471◇ if (err.empty())lines 472–472std::lock_guard<std::mutex> guard(handle->workspace_mutex);lines 473–473◇ if (handle->workspaces.count(name) > 0)lines 474–474err = std::string("workspace already exists: ") + name;lines 477–477◇ if (!err.empty())lines 478–478logger->warn("workspace '{}' refused: {}", name, err);lines 479–479handle->last_error = err;lines 480–480return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 482–482return ENTROPIC_OK;

Requirements

REQ-MCP-027

wire_external_server_policy

void entropic::wire_external_server_policy(entropic_handle_t h, ServerManager &servers, bool with_declared)

Give a server set the handle's external-server policy (v2.14.0).

src/facade/entropic_mcp.cpp:242

Show on the map →

Called by build_workspace, init_mcp_servers

Calls discovered_server_thunk, expected_bridge_socket, set_discovered_server_approver, set_mcp_config, set_own_bridge_socket

Source · 9 lines
void entropic::wire_external_server_policy(entropic_handle_t h,
                                           ServerManager& servers,
                                           bool with_declared) {
    MCPConfig policy = h->config.mcp;
    if (!with_declared) { policy.external_servers.clear(); }
    servers.set_mcp_config(policy);
    servers.set_own_bridge_socket(expected_bridge_socket(h));
    servers.set_discovered_server_approver(discovered_server_thunk, h);
}
Activity · 6 steps
lines 245–245MCPConfig policy = h->config.mcp;lines 246–246◇ if (!with_declared)lines 246–246policy.external_servers.clear();lines 247–247servers.set_mcp_config(policy);lines 248–248servers.set_own_bridge_socket(expected_bridge_socket(h));lines 249–249servers.set_discovered_server_approver(discovered_server_thunk, h);

Requirements

REQ-MCP-025

wire_outside_root_approver

void entropic::wire_outside_root_approver(entropic_handle_t h)

Point the DEFAULT server set's filesystem server at the handle's path-approval slot (v2.13.0).

src/facade/entropic_mcp.cpp:140

Source · 5 lines
void entropic::wire_outside_root_approver(entropic_handle_t h) {
    if (h != nullptr && h->server_manager) {
        h->server_manager->set_outside_root_approver(outside_root_thunk, h);
    }
}
Activity · 2 steps
lines 141–141◇ if (h != nullptr && h->server_manager)lines 142–142h->server_manager->set_outside_root_approver(outside_root_thunk, h);

Requirements

REQ-MCP-021

workspace_root_refusal

static std::string workspace_root_refusal(const std::vector< std::filesystem::path > &roots, const std::filesystem::path &root)

Why root may not be a workspace under mcp.workspace_roots .

src/facade/entropic_mcp.cpp:423

Source · 16 lines
static std::string workspace_root_refusal(
    const std::vector<std::filesystem::path>& roots,
    const std::filesystem::path& root) {
    namespace fs = std::filesystem;
    std::error_code ec;
    const auto canon = fs::weakly_canonical(root, ec);
    bool inside = roots.empty();
    for (const auto& r : roots) {
        const auto base = fs::weakly_canonical(r, ec);
        const auto rel = canon.lexically_relative(base);
        inside = inside || (!rel.empty() && *rel.begin() != "..");
    }
    return inside ? std::string{}
        : "workspace dir " + canon.string()
          + " is outside every mcp.workspace_roots entry";
}
Activity · 9 steps
lines 426–426namespace fs = std::filesystem;lines 427–427std::error_code ec;lines 428–428const auto canon = fs::weakly_canonical(root, ec);lines 429–429bool inside = roots.empty();lines 430–430◇ for (const auto& r : roots)lines 431–431const auto base = fs::weakly_canonical(r, ec);lines 432–432const auto rel = canon.lexically_relative(base);lines 433–433inside = inside || (!rel.empty() && *rel.begin() != "..");lines 435–437return inside ? std::string{} : "workspace dir " + canon.string() + " is outside every mcp.workspace_roots entry";

Requirements

REQ-MCP-027