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
Called by entropic_workspace_create, entropic_workspace_set_app_context
Calls clear_workspace_prompts, load_shared_prompt_sources, resolve_data_dir, resolve_tier_identity_full, set_workspace_prompts
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
Requirements
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
Requirements
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
Called by entropic_workspace_create
Calls ServerManager, confined_mcp_config, init_builtins, load_plugins, resolve_data_dir, wire_external_server_policy
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
Requirements
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
Called by entropic_deregister_mcp_server, entropic_register_mcp_server, entropic_session_bind_workspace, entropic_workspace_create, entropic_workspace_set_app_context
Calls none
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
Requirements
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
Requirements
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
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
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
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
Requirements
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
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
ENTROPIC_EXPORT char * entropic_list_mcp_servers(entropic_handle_t handle)
List all MCP servers with status information.
src/facade/entropic_mcp.cpp:841
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
Requirements
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
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
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
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
Requirements
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
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
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
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
Requirements
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
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
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
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
Requirements
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
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
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
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
Requirements
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
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
Requirements
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
Requirements
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
Requirements
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
Called by entropic_context_clear, entropic_session_context_clear, entropic_session_drop, session_context_set_inner
Calls release_session
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
Requirements
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
Requirements
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
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
Requirements
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
Requirements
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
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
Requirements
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
Requirements
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";
}