plugin_server.cpp¶
src/mcp/plugin_server.cpp
@file plugin_server.cpp @brief dlopen-loaded MCP server plugin implementation (gh#133).
Owners: @tvanfossen
configure
entropic_error_t entropic::PluginServer::configure(const std::string &config_json)
Pass configuration to the plugin instance.
src/mcp/plugin_server.cpp:345
Source · 4 lines
entropic_error_t PluginServer::configure(const std::string& config_json) {
std::lock_guard<std::mutex> lock(call_mutex_);
return configure_fn_(instance_, config_json.c_str());
}Activity · 2 steps
Requirements
create_instance
entropic_error_t entropic::PluginServer::create_instance()
Create the plugin's server instance and read its name.
src/mcp/plugin_server.cpp:125
Source · 18 lines
entropic_error_t PluginServer::create_instance() {
instance_ = create_fn_();
if (instance_ == nullptr) {
logger->error("Plugin load failed: entropic_create_server() returned "
"NULL for {}", path_.string());
return ENTROPIC_ERROR_PLUGIN_LOAD_FAILED;
}
const char* raw_name = name_fn_(instance_);
name_ = (raw_name != nullptr) ? raw_name : "";
if (name_.empty()) {
logger->error("Plugin load failed: entropic_mcp_server_name() gave an "
"empty name for {} — the name is the tool-routing "
"prefix and cannot be blank", path_.string());
return ENTROPIC_ERROR_PLUGIN_LOAD_FAILED;
}
return ENTROPIC_OK;
}Activity · 10 steps
Requirements
execute
std::string entropic::PluginServer::execute(const std::string &tool_name, const std::string &args_json)
Execute one of the plugin's tools.
src/mcp/plugin_server.cpp:328
Source · 6 lines
std::string PluginServer::execute(const std::string& tool_name,
const std::string& args_json) {
std::lock_guard<std::mutex> lock(call_mutex_);
return take_string(
execute_fn_(instance_, tool_name.c_str(), args_json.c_str()));
}Activity · 2 steps
Requirements
list_tools
std::string entropic::PluginServer::list_tools() const
List the plugin's tools.
src/mcp/plugin_server.cpp:303
Source · 5 lines
std::string PluginServer::list_tools() const {
std::lock_guard<std::mutex> lock(call_mutex_);
auto tools = take_string(list_tools_fn_(instance_));
return tools.empty() ? "[]" : tools;
}Activity · 3 steps
Requirements
load
entropic_error_t entropic::PluginServer::load(const std::filesystem::path &path, std::unique_ptr< PluginServer > &out)
Load a plugin .so and construct its server instance.
src/mcp/plugin_server.cpp:70
Source · 25 lines
entropic_error_t PluginServer::load(const std::filesystem::path& path,
std::unique_ptr<PluginServer>& out) {
// RTLD_LOCAL keeps plugin symbols out of the global namespace so two
// plugins exporting the same entry-point names cannot collide.
dlerror(); // clear any stale error before the call
void* handle = dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
if (handle == nullptr) {
const char* err = dlerror();
logger->error("Plugin load failed: dlopen('{}'): {}", path.string(),
(err != nullptr) ? err : "unknown error");
return ENTROPIC_ERROR_PLUGIN_LOAD_FAILED;
}
// Adopt the handle immediately so every failure path below closes it.
std::unique_ptr<PluginServer> plugin(new PluginServer(handle, path));
auto rc = plugin->resolve_and_init();
if (rc != ENTROPIC_OK) {
return rc;
}
logger->info("Loaded MCP plugin '{}' from {}", plugin->name_,
path.string());
out = std::move(plugin);
return ENTROPIC_OK;
}Activity · 13 steps
Requirements
resolve_and_check_version
entropic_error_t entropic::PluginServer::resolve_and_check_version()
Resolve every entry point and verify the reported API version.
src/mcp/plugin_server.cpp:159
Source · 16 lines
entropic_error_t PluginServer::resolve_and_check_version() {
if (!resolve_symbols()) {
return ENTROPIC_ERROR_PLUGIN_LOAD_FAILED;
}
const int reported = version_fn_();
if (reported != ENTROPIC_MCP_PLUGIN_API_VERSION) {
logger->error("Plugin version mismatch for {}: plugin reports API "
"version {}, this engine implements {}. Rebuild the "
"plugin against matching entropic headers.",
path_.string(), reported,
ENTROPIC_MCP_PLUGIN_API_VERSION);
return ENTROPIC_ERROR_PLUGIN_VERSION_MISMATCH;
}
return ENTROPIC_OK;
}Activity · 7 steps
Requirements
resolve_and_init
entropic_error_t entropic::PluginServer::resolve_and_init()
Resolve entry points, check version, create the instance.
src/mcp/plugin_server.cpp:104
Source · 7 lines
entropic_error_t PluginServer::resolve_and_init() {
auto rc = resolve_and_check_version();
if (rc != ENTROPIC_OK) {
return rc;
}
return create_instance();
}Activity · 4 steps
Requirements
resolve_factory_symbols
bool entropic::PluginServer::resolve_factory_symbols()
Resolve the process-level entry points.
src/mcp/plugin_server.cpp:227
Source · 12 lines
bool PluginServer::resolve_factory_symbols() {
bool ok = true;
version_fn_ = reinterpret_cast<version_fn_t>(
resolve_one("entropic_plugin_api_version", ok));
create_fn_ = reinterpret_cast<create_fn_t>(
resolve_one("entropic_create_server", ok));
name_fn_ = reinterpret_cast<name_fn_t>(
resolve_one("entropic_mcp_server_name", ok));
free_fn_ = reinterpret_cast<free_fn_t>(
resolve_one("entropic_free", ok));
return ok;
}Activity · 6 steps
Requirements
resolve_instance_symbols
bool entropic::PluginServer::resolve_instance_symbols()
Resolve the per-instance entry points.
src/mcp/plugin_server.cpp:246
Source · 14 lines
bool PluginServer::resolve_instance_symbols() {
bool ok = true;
list_tools_fn_ = reinterpret_cast<list_tools_fn_t>(
resolve_one("entropic_mcp_server_list_tools", ok));
execute_fn_ = reinterpret_cast<execute_fn_t>(
resolve_one("entropic_mcp_server_execute", ok));
configure_fn_ = reinterpret_cast<configure_fn_t>(
resolve_one("entropic_mcp_server_configure", ok));
set_dir_fn_ = reinterpret_cast<set_dir_fn_t>(
resolve_one("entropic_mcp_server_set_working_dir", ok));
destroy_fn_ = reinterpret_cast<destroy_fn_t>(
resolve_one("entropic_mcp_server_destroy", ok));
return ok;
}Activity · 7 steps
Requirements
resolve_symbols
bool entropic::PluginServer::resolve_symbols()
dlsym all nine entry points, logging each one that is missing.
src/mcp/plugin_server.cpp:192
Called by resolve_and_check_version
Source · 7 lines
bool PluginServer::resolve_symbols() {
// Both halves run unconditionally: a plugin missing several entry points
// should be told about all of them in one build/run cycle.
const bool factory_ok = resolve_factory_symbols();
const bool instance_ok = resolve_instance_symbols();
return factory_ok && instance_ok;
}Activity · 3 steps
Requirements
set_working_dir
entropic_error_t entropic::PluginServer::set_working_dir(const std::string &dir)
Set the plugin's working directory.
src/mcp/plugin_server.cpp:360
Source · 4 lines
entropic_error_t PluginServer::set_working_dir(const std::string& dir) {
std::lock_guard<std::mutex> lock(call_mutex_);
return set_dir_fn_(instance_, dir.c_str());
}Activity · 2 steps
Requirements
take_string
std::string entropic::PluginServer::take_string(char *raw) const
Copy a plugin-allocated string and release it via the plugin.
src/mcp/plugin_server.cpp:274
Source · 14 lines
std::string PluginServer::take_string(char* raw) const {
if (raw == nullptr) {
return {};
}
std::string copy;
try {
copy.assign(raw);
} catch (...) {
free_fn_(raw);
throw;
}
free_fn_(raw);
return copy;
}Activity · 6 steps
Requirements
~PluginServer
entropic::PluginServer::~PluginServer()
Destroy the plugin instance, then close the library.
src/mcp/plugin_server.cpp:40
The index is older than this file: the lines it records no longer hold this function. Refresh the index to bundle its body.