Edge Connector

Integrate with an agent

Connect an agent to the Edge Connector with the Python adapter, MCP proxy, LangChain, HTTP middleware, PicoClaw, the shared library or the Unix socket.

Preview. The Edge Connector works with any agent framework. Each integration sends a tool call to the engine and acts on the verdict. Install the engine first (Install).

Choose an integration

Your agentUse
Any Python agentGeneric Python adapter
An MCP client, such as Claude Desktop or Claude Code, calling an MCP serverMCP proxy
LangChain or LangGraphLangChain / LangGraph
An agent that runs tools through HTTP endpointsHTTP middleware
PicoClawPicoClaw
Another languageShared library (FFI) or Unix socket (JSON-RPC)

Every tool name must have a reviewed capability mapping in the C engine (Tool-to-capability mapping). Unknown tool names are blocked.

Put the adapter on your agent's import path:

  • From a source checkout, run your agent with PYTHONPATH=/path/to/defenseclaw/edge-connector/tools.
  • After sudo make install, use the installed adapter directory, normally /usr/local/lib/defenseclaw. CMake copies the Python files there but does not add the directory to Python's import path.
  • Set DCLAW_LIB_PATH if the shared library is not at /usr/local/lib/libdclaw_core.so.
from generic_hook import EdgeConnector

ec = EdgeConnector()  # uses the Unix socket or the shared library

verdict = ec.evaluate(
    tool_name="exec_shell",
    arguments={"command": "rm -rf /"},
)
if verdict.blocked:
    print(f"Blocked: {verdict.reason}")

The adapter uses the Unix socket (DCLAW_SOCKET_PATH) when the daemon runs, and the shared library (ctypes) when it does not. It fails closed when the engine is unavailable. In production, DCLAW_FAIL_OPEN=1 also needs an authorized DCLAW_FAIL_OPEN_TOKEN tied to DCLAW_AUDIT_KEY; the flag alone does not enable fail-open.

MCP proxy (Model Context Protocol)

The MCP proxy sits between an LLM client and a real MCP server. It checks every tools/call request through the engine's local checks, verdict cache and optional Fleet request. Every other MCP message passes through unchanged.

LLM Client (Claude, Codex)
    | MCP (stdio / HTTP)
    v
Edge Connector MCP Proxy
    | evaluates via EdgeConnector.evaluate()
    | MCP (stdio / HTTP)
    v
Real MCP Server (ESP-Claw, HA-MCP, etc.)

From the edge-connector/ source directory, start it with a local stdio MCP server, or with a config file:

DCLAW_MCP_UPSTREAM='["python3", "-m", "esp_claw.mcp_server"]' \
  python3 tools/mcp_proxy.py

python3 tools/mcp_proxy.py --config tools/mcp_proxy_config.yaml

Use stdio for a local MCP server: the proxy rejects private and loopback HTTP upstream addresses. For a remote upstream, use a reviewed public HTTPS endpoint and check what network traffic it makes downstream.

To use it from Claude Desktop or Claude Code, add the proxy to the MCP client config:

{
  "mcpServers": {
    "esp-claw-secured": {
      "command": "python3",
      "args": ["/usr/local/lib/defenseclaw/mcp_proxy.py"],
      "env": {
        "DCLAW_MCP_UPSTREAM": "[\"python3\", \"-m\", \"esp_claw.mcp_server\"]",
        "DCLAW_LIB_PATH": "/usr/local/lib/libdclaw_core.so"
      }
    }
  }
}

Replace /usr/local/lib if CMake installed into another library directory. esp_claw.mcp_server is an example: install your own stdio MCP server and put its command there.

MCP methodActionWhat happens
tools/callEvaluateLocal checks, verdict cache and optional Fleet request. A blocked call returns an MCP error with the reason.
tools/list, resources/*, prompts/*, initialize and the restPass throughForwarded unchanged to the real server.

The proxy reads DCLAW_MCP_UPSTREAM, DCLAW_MCP_TRANSPORT and DCLAW_MCP_PORT (adapter variables) and passes every other Edge Connector variable through.

LangChain / LangGraph

Wrap LangChain tools so every call passes through the Edge Connector:

from langchain_hook import wrap_tools

tools = wrap_tools(my_tools)
agent = create_react_agent(llm, tools)

Or add it as a LangGraph node:

from langchain_hook import edge_connector_node

graph.add_node("security_gate", edge_connector_node)
graph.add_edge("agent", "security_gate")
graph.add_edge("security_gate", "tools")

HTTP middleware (FastAPI / Flask)

For agents that run tools through HTTP APIs:

# FastAPI
from http_middleware import EdgeConnectorMiddleware
app.add_middleware(EdgeConnectorMiddleware)

# Flask
from http_middleware import flask_edge_connector
flask_edge_connector(app)

The middleware checks POST requests to tool-execution endpoints and returns 403 for a blocked call.

PicoClaw

PicoClaw runs the Edge Connector through its process hooks.

Copy the hook

mkdir -p ~/.picoclaw/hooks
cp /usr/local/lib/defenseclaw/picoclaw_hook.py ~/.picoclaw/hooks/defenseclaw_gate.py
picoclaw config edit

Add it to hooks.processes

{
  "defenseclaw_gate": {
    "enabled": true,
    "priority": 5,
    "transport": "stdio",
    "command": ["python3", "/home/USERNAME/.picoclaw/hooks/defenseclaw_gate.py"],
    "env": {
      "DCLAW_LIB_PATH": "/usr/local/lib/libdclaw_core.so",
      "DCLAW_LOG_PATH": "/home/USERNAME/edge-connector.log"
    },
    "intercept": ["before_tool", "before_llm", "after_llm"]
  }
}

Replace USERNAME with the real home directory. Process launchers do not always expand ~ in JSON values.

Check it

# Check that the hook protocol responds (this does not evaluate a tool)
echo '{"jsonrpc":"2.0","id":1,"method":"hook.hello","params":{}}' | \
  DCLAW_LIB_PATH=/usr/local/lib/libdclaw_core.so \
  python3 ~/.picoclaw/hooks/defenseclaw_gate.py

# Observe a sensor-read decision; production waits for a Fleet verdict
picoclaw agent -m "check battery status"

# Observe a shell decision; inspect the actual tool call and audit result
picoclaw agent -m "run whoami in the shell"

# Watch decisions
tail -f ~/edge-connector.log
HookWhat happensActions
before_toolInput validation, rate limit, content scan, destination and SSRF checks, sequence correlation, cache lookup, then optional Fleet requestdeny_tool or continue
before_llmPrompt injection detection (a fixed list of patterns)abort_turn or continue
after_llmPII and credential leak scanDetection and logging

Low-level: shared library (FFI)

Load libdclaw_core.so from any language with C FFI:

import ctypes
lib = ctypes.CDLL("/usr/local/lib/libdclaw_core.so")
# Call dclaw_evaluate() — see defenseclaw.h for struct definitions

Low-level: Unix socket (JSON-RPC)

Query the running daemon from any process. This probe needs socat:

tool_hash="$(printf exec_shell | sha256sum | cut -d' ' -f1)"
printf '{"jsonrpc":"2.0","id":1,"method":"evaluate","params":{'\
'"tool_name":"exec_shell","tool_hash":"%s","capabilities":4,'\
'"destination":"","session_id":1}}\n' "$tool_hash" | \
  socat - UNIX-CONNECT:/run/defenseclaw/defenseclaw.sock

The daemon derives the capability flags from the tool name. The capabilities value the caller sends does not grant anything.

IPC schema

A full evaluate request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "evaluate",
  "params": {
    "tool_name": "call_api",
    "tool_hash": "515c7731d6367104f1431af261488829f178f87e0930fb7ca77785ba3ef19129",
    "capabilities": 8,
    "destination": "1.1.1.1",
    "session_id": 1,
    "direction": 0,
    "content": "Authorization: Bearer sk-proj-abc123..."
  }
}
FieldTypeRequiredDescription
tool_namestringyesName of the tool being called
tool_hashstringyes64-character hex SHA-256 of tool_name (either case). The engine checks that it matches the name.
capabilitiesintyesCapability bitmask
destinationstringnoTarget. Network capabilities must send an approved public numeric IP literal.
session_idintyesSession ID for sequence correlation
directionintno0 (request) or 1 (response). Selects the content scope and severity threshold.
contentstringnoText to inspect. Without it, only the rule-based checks run.

Tool-to-capability mapping

The C engine maps each tool to one capability, which decides how the call is handled.

CapabilityFlagFleet requestBehavior
SENSOR_READ0x40Optional speculative modeContent, rate and sequence checks
READ_FS0x01Optional speculative modeContent, rate and sequence checks
NET_FETCH0x08Optional speculative modeDestination allowlist and SSRF checks first
SEND_MSG0x10Optional speculative modeDestination allowlist and SSRF checks first
ACTUATE0x20Always synchronousPhysical action; blocks without a Fleet verdict
EXEC_SHELL0x04Always synchronousCode execution; blocks without a Fleet verdict
WRITE_FS0x02Always synchronousFile change; blocks without a Fleet verdict

By default (strict mode), an uncached undecided call waits for a Fleet verdict and is blocked when the gateway is unavailable, read-only tools included. DCLAW_STRICT_MODE=0 allows speculative execution for the first four capabilities, on builds that support it. A destination allowlist entry does not by itself approve a tool call.

Adapter environment variables

The eight Python adapter variables (DCLAW_LIB_PATH, DCLAW_SOCKET_PATH, DCLAW_LOG_PATH, DCLAW_FAIL_OPEN, DCLAW_FAIL_OPEN_TOKEN, DCLAW_MCP_UPSTREAM, DCLAW_MCP_TRANSPORT, DCLAW_MCP_PORT) are read only by the adapters and are listed only on this page. The gateway and device variables are in Fleet operations.

VariableWhat it does
DCLAW_LIB_PATHPath to libdclaw_core.so. Default /usr/local/lib/libdclaw_core.so.
DCLAW_SOCKET_PATHSocket the adapters connect to. Default /run/defenseclaw/defenseclaw.sock.
DCLAW_LOG_PATHAdapter audit log. Default ~/edge-connector.log.
DCLAW_FAIL_OPEN, DCLAW_FAIL_OPEN_TOKENDCLAW_FAIL_OPEN=1 allows calls when the engine is unavailable, but in production only with a DCLAW_FAIL_OPEN_TOKEN tied to DCLAW_AUDIT_KEY.
DCLAW_MCP_UPSTREAM, DCLAW_MCP_TRANSPORT, DCLAW_MCP_PORTMCP proxy upstream command or URL, stdio or http, and port (default 8089).

Troubleshooting