Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
external_bridge.cpp File Reference

Unix socket MCP bridge implementation. More...

#include <entropic/mcp/external_bridge.h>
#include <entropic/entropic.h>
#include <entropic/types/logging.h>
#include "engine_handle.h"
#include <nlohmann/json.hpp>
#include <atomic>
#include <cerrno>
#include <chrono>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <functional>
#include <mutex>
#include <sstream>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <poll.h>
Include dependency graph for external_bridge.cpp:

Go to the source code of this file.

Classes

struct  entropic::AsyncFinalState
 Handle entropic.context_clear. More...
 

Namespaces

namespace  entropic
 Activate model on GPU (WARM → ACTIVE).
 

Typedefs

using json = nlohmann::json
 

Functions

std::filesystem::path entropic::compute_socket_path (const std::filesystem::path &project_dir)
 Compute project-unique Unix socket path for self-detection.
 
static std::string entropic::rpc_ok (const json &id, const json &result)
 Build a JSON-RPC success response.
 
static std::string entropic::rpc_err (const json &id, int code, const std::string &msg)
 Build a JSON-RPC error response.
 
static json entropic::tool_text (const std::string &text)
 Wrap text in MCP tool result shape.
 
static json entropic::tool_definitions ()
 MCP tool definitions exposed by the bridge.
 
static std::string entropic::extract_final_text (const char *result_json)
 Extract the last assistant message from a run result JSON.
 
static void entropic::write_json_line (int fd, const json &msg)
 Write a JSON-RPC line to a socket fd.
 
static void entropic::send_progress (int fd, const std::string &token_text, const std::string &progress_token)
 Send an MCP progress notification with a text token.
 
static json entropic::handle_ask (entropic_handle_t handle, const json &args, int client_fd, const std::string &call_id)
 Handle entropic.ask — stream tokens then return final text.
 
static json entropic::handle_status (entropic_handle_t handle)
 Handle entropic.status.
 
static AsyncFinalState entropic::derive_async_final_state (entropic_handle_t handle, entropic_error_t err, char *result_json)
 Translate entropic_run's return code into a final task state.
 
static bool entropic::mark_tasks_cancelling (ExternalBridge *bridge)
 Mark every queued/running task as cancelling.
 
static bool entropic::any_cancelling_left (ExternalBridge *bridge)
 True while any task is still phase=cancelling.
 
static void entropic::cancel_inflight_async_tasks (entropic_handle_t handle, ExternalBridge *bridge)
 Cancel any async tasks currently running on the bridge.
 
static json entropic::handle_clear (entropic_handle_t handle, ExternalBridge *bridge)
 entropic.context_clear MCP tool handler.
 
static json entropic::handle_count (entropic_handle_t handle)
 Handle entropic.context_count.
 
static std::string entropic::generate_task_id ()
 Generate a simple UUID-like task ID.
 
static json entropic::dispatch_ask (entropic_handle_t handle, ExternalBridge *bridge, const json &args, int client_fd, const std::string &call_id)
 Route entropic.ask — sync (streaming) or async.
 
static json entropic::dispatch_tool (entropic_handle_t handle, ExternalBridge *bridge, const json &params, int client_fd, const std::string &call_id)
 Dispatch a tools/call to the appropriate handler.
 
static void entropic::prepare_socket_dir (const std::filesystem::path &parent)
 Prepare the socket containing directory with 0700 perms.
 
static bool entropic::socket_path_safe (const std::filesystem::path &path)
 Reject a pre-existing path that is a symlink or non-socket.
 
static bool entropic::bind_and_listen (int fd, const std::filesystem::path &path)
 Bind+listen on an AF_UNIX socket, applying 0600 perms.
 
static int entropic::create_listen_socket (const std::filesystem::path &path)
 Create, bind, and listen on a unix domain socket.
 
static bool entropic::peer_uid_matches (int client_fd)
 Validate that the connecting peer shares the engine's UID.
 
static std::string entropic::read_line (int fd)
 Read one newline-delimited line from a socket fd.
 
static json entropic::initialize_result ()
 Build the MCP initialize response payload.
 
static void entropic::phase_observer_cb (int state, void *ud)
 State observer that projects VERIFYING onto task phase.
 
static const char * entropic::sentinel_suffix_for_status (const std::string &status)
 Map a terminal status string to a sentinel filename suffix.
 

Variables

static auto entropic::logger = entropic::log::get("mcp.external_bridge")
 
static std::mutex entropic::s_bound_sockets_mu
 
static std::unordered_set< std::string > entropic::s_bound_sockets
 

Detailed Description

Unix socket MCP bridge implementation.

Listens on a unix domain socket, accepts one client at a time, and serves JSON-RPC 2.0 (MCP) dispatching to the engine handle.

Version
2.0.8

Definition in file external_bridge.cpp.

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 38 of file external_bridge.cpp.