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 agent | Use |
|---|---|
| Any Python agent | Generic Python adapter |
| An MCP client, such as Claude Desktop or Claude Code, calling an MCP server | MCP proxy |
| LangChain or LangGraph | LangChain / LangGraph |
| An agent that runs tools through HTTP endpoints | HTTP middleware |
| PicoClaw | PicoClaw |
| Another language | Shared 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.
Generic Python adapter (recommended)
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_PATHif 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.yamlUse 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 method | Action | What happens |
|---|---|---|
tools/call | Evaluate | Local checks, verdict cache and optional Fleet request. A blocked call returns an MCP error with the reason. |
tools/list, resources/*, prompts/*, initialize and the rest | Pass through | Forwarded 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 editAdd 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| Hook | What happens | Actions |
|---|---|---|
before_tool | Input validation, rate limit, content scan, destination and SSRF checks, sequence correlation, cache lookup, then optional Fleet request | deny_tool or continue |
before_llm | Prompt injection detection (a fixed list of patterns) | abort_turn or continue |
after_llm | PII and credential leak scan | Detection 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 definitionsLow-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.sockThe 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..."
}
}| Field | Type | Required | Description |
|---|---|---|---|
tool_name | string | yes | Name of the tool being called |
tool_hash | string | yes | 64-character hex SHA-256 of tool_name (either case). The engine checks that it matches the name. |
capabilities | int | yes | Capability bitmask |
destination | string | no | Target. Network capabilities must send an approved public numeric IP literal. |
session_id | int | yes | Session ID for sequence correlation |
direction | int | no | 0 (request) or 1 (response). Selects the content scope and severity threshold. |
content | string | no | Text 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.
| Capability | Flag | Fleet request | Behavior |
|---|---|---|---|
SENSOR_READ | 0x40 | Optional speculative mode | Content, rate and sequence checks |
READ_FS | 0x01 | Optional speculative mode | Content, rate and sequence checks |
NET_FETCH | 0x08 | Optional speculative mode | Destination allowlist and SSRF checks first |
SEND_MSG | 0x10 | Optional speculative mode | Destination allowlist and SSRF checks first |
ACTUATE | 0x20 | Always synchronous | Physical action; blocks without a Fleet verdict |
EXEC_SHELL | 0x04 | Always synchronous | Code execution; blocks without a Fleet verdict |
WRITE_FS | 0x02 | Always synchronous | File 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.
| Variable | What it does |
|---|---|
DCLAW_LIB_PATH | Path to libdclaw_core.so. Default /usr/local/lib/libdclaw_core.so. |
DCLAW_SOCKET_PATH | Socket the adapters connect to. Default /run/defenseclaw/defenseclaw.sock. |
DCLAW_LOG_PATH | Adapter audit log. Default ~/edge-connector.log. |
DCLAW_FAIL_OPEN, DCLAW_FAIL_OPEN_TOKEN | DCLAW_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_PORT | MCP proxy upstream command or URL, stdio or http, and port (default 8089). |
Troubleshooting
Edge Connector install
Build the Edge Connector on a Linux device, run the local smoke test, then connect the device to a DefenseClaw Fleet gateway.
Fleet operations
Run an Edge Connector Fleet - the policy compiler, the MQTT broker, device keys, upgrades, build profiles, environment variables and the Grafana dashboard.