caduceus
# Caduceus: Peer-to-Peer mTLS 1.3 Mesh for Autonomous AI Agents
[](go.mod)
[](LICENSE)
[](https://github.com/Uhm-why/caduceus/actions)
[](#quick-start)
[](go.mod)
**Caduceus** is a lightweight, zero-dependency peer-to-peer networking server for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). It enables autonomous AI agents—running in Claude Desktop, Zed, Hermes Agent, or headless scripts—to securely discover, communicate, consult, and delegate tasks to other agents across machines, local networks, or the internet.
Built 100% with the Go standard library, Caduceus compiles into a single 5.9MB static binary with zero external dependencies, zero cloud lock-in, and military-grade mutual TLS 1.3 encryption.
---
```
[Local Machine: Laptop/Desktop] [Remote Node: Server/Homelab/Pi]
Claude Desktop / Zed / Hermes Hermes / Headless Worker / LLM
│ ▲
(stdio MCP) (stdio MCP)
▼ │
┌──────────────────────────┐ Mutual TLS 1.3 Mesh ┌──────────────────────────┐
│ Caduceus Node A │ ◄──────────────────────────► │ Caduceus Node B │
│ - Ed25519 Root CA │ AES-128-GCM / ChaCha20 │ - Ed25519 Root CA │
│ - Maildir Message Spool │ Direct LAN / VPN / WAN │ - Maildir Message Spool │
│ - Context Compactor │ │ - Greylist OTP Engine │
└──────────────────────────┘ └──────────────────────────┘
```
---
## Why Caduceus?
Today's AI coding and task agents are isolated silos trapped on a single machine or within a single chat session. They cannot offload heavy workloads to dedicated hardware, cannot seek second opinions from specialized peer models, and cannot coordinate long-running jobs without fragile third-party cloud services.
Caduceus provides the decentralized nervous system for multi-agent workflows:
- **True Peer-to-Peer Symmetry**: Every node is functionally identical. Nodes can listen (`-listen`) or connect (`-ip`). No central coordinators, accounts, or telemetry.
- **Zero-Trust Cryptography (mTLS 1.3)**: Nodes communicate over mutual TLS 1.3 with hardware-grade Ed25519 keypairs. Untrusted certificates are rejected at the TLS handshake.
- **Human-in-the-Loop Defense (Greylist Engine)**: Prevent rogue or prompt-injected agents from performing unauthorized actions. Untrusted tasks trigger out-of-band One-Time Passwords (OTP) on the operator console before execution.
- **Crash-Proof Maildir Spooling**: Message exchange uses the Unix Maildir standard (`tmp/`, `new/`, `cur/`, `quarantine/`) with atomic filesystem renames and `fsync` durability. Zero dropped messages during sudden crashes or power loss.
- **Automatic Context Compactor**: Terminal output and large responses are automatically compacted (ANSI code stripping, run-length line deduplication, and head-tail windowing) to prevent context window bloat.
- **Zero External Dependencies**: Pure Go standard library. No bloated Node/Python runtimes, no CGo bindings, and no supply chain vulnerabilities.
---
## Real-World Use Cases
- **Heavy Task Offloading**: An agent running in Claude Desktop on a lightweight laptop delegates a 45-minute compilation, Docker build, or test suite to an agent on a dedicated server or Raspberry Pi.
- **Peer Code Review & Consultation**: An agent finishing a complex refactor automatically requests a second opinion from a peer agent running a different model architecture before committing.
- **Multi-Node Autonomous Swarms**: Link multiple specialized agent nodes across your local LAN or WireGuard mesh with mutual attestation.
- **Sandboxed Agent Workers**: Run autonomous worker agents in restricted Docker containers while maintaining operator oversight through the greylist authorization engine.
---
## Core Capabilities
- **Bidirectional mTLS 1.3 Transport**: Encrypted with Curve25519, Ed25519 certificates, and buffered zero-allocation wire framing.
- **12 Built-in MCP Tools**: Native tools exposed over stdio covering messaging, review, task delegation, status tracking, and capabilities.
- **Zero-Touch Initialization (`caduceus init`)**: Generates an Ed25519 Root CA, leaf certificate, config, and mailbox structure in one command.
- **Out-of-Band Trust Federation (`caduceus trust`)**: Add, list, or revoke peer CA fingerprints with strict RFC 5280 validation.
- **Policy Authorization Engine (`caduceus auth`)**: Define shell-style globbing rules (`allow`, `greylist`, `deny`) with brute-force lockout safeguards.
- **Deterministic Compactor**: Built-in 3-stage compaction pipeline keeping tool outputs compact and cost-effective.
---
## Quick Start
### 1. Build or Install
Compile a stripped, zero-dependency static binary:
```bash
make build
# Binary output: bin/caduceus (5.9MB)
```
### 2. Bootstrap Local Node Credentials
Initialize the node's local Ed25519 root CA, leaf certificates, and Maildir directories:
```bash
./bin/caduceus init
```
*Creates credentials and config in `~/.config/caduceus/` (mode `0700`).*
### 3. Run Caduceus
Start a listener node or connect to a peer:
```bash
# Node A: Listen for incoming peer connections
./bin/caduceus -listen :8443
# Node B: Connect to Node A across the network
./bin/caduceus -ip 192.168.1.50:8443
```
Configuration precedence: `CLI Flags > config.json > Hardcoded Defaults`.
---
## Multi-Node Trust Setup
Caduceus uses a decentralized trust model where nodes establish pairing by cross-importing each other's root CAs out-of-band:
1. **Bootstrap both machines**:
```bash
# Run on Laptop (Node A) and Server (Node B):
caduceus init
```
2. **Exchange public root certificates**:
Copy `ca.pem` from Node A to Node B, and vice versa (via `scp`, USB, or shared secret).
3. **Import trust**:
```bash
# On Node A: Trust Node B's root CA
caduceus trust add /path/to/node-b-ca.pem
# On Node B: Trust Node A's root CA
caduceus trust add /path/to/node-a-ca.pem
```
4. **Verify fingerprints**:
```bash
caduceus trust list
```
Both nodes will now mutually authenticate over mTLS 1.3. To revoke a peer at any time without affecting your local CA:
```bash
caduceus trust remove <fingerprint>
```
---
## Authorization & Human-in-the-Loop Security
Caduceus protects nodes against unauthorized task execution with a built-in authorization engine (`internal/auth`). When an agent delegates a task via `agent_peer_delegate`, the action is evaluated against three policy states:
- **Allow**: Executes immediately without operator intervention.
- **Greylist (Default)**: Suspends execution, generates an out-of-band One-Time Password (OTP), notifies the operator console, and holds the task pending authorization.
- **Deny**: Rejects the task dispatch immediately.
### Managing Policy Rules
```bash
# View active policy rules and default action
caduceus auth rules
# Explicitly allow safe read-only queries
caduceus auth allow "system.status" "allow status checks"
# Explicitly block destructive operations
caduceus auth deny "disk.format" "block disk format operations"
# Inspect active authorization challenges waiting for operator approval
caduceus auth pending
```
Pending challenges automatically lock out and fail closed after 3 incorrect verification attempts. Challenge tokens are displayed exclusively on the operator console and are never leaked to the disk spool.
---
## Connecting MCP Hosts to Caduceus
Caduceus communicates with Model Context Protocol (MCP) clients via standard I/O (`stdin`/`stdout`). When launched by an MCP client, Caduceus acts as a local MCP server while transparently managing the encrypted mTLS 1.3 tunnel to the remote peer (`-ip`).
### 1. Hermes Agent (`~/.hermes/config.yaml`)
```yaml
mcp_servers:
caduceus:
command: caduceus
args:
- -ip
- "192.168.1.50:8443"
```
### 2. Claude Desktop (`claude_desktop_config.json`)
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Linux**: `~/.config/Claude/claude_desktop_config.json`
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
**Native Binary:**
```json
{
"mcpServers": {
"caduceus": {
"command": "caduceus",
"args": ["-ip", "192.168.1.50:8443"]
}
}
}
```
**Sandboxed Container (Podman / Docker):**
```json
{
"mcpServers": {
"caduceus": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"caduceus-data:/home/caduceus/.config/caduceus",
"caduceus",
"-ip",
"192.168.1.50:8443"
]
}
}
}
```
### 3. Zed Editor (`~/.config/zed/settings.json`)
```json
{
"context_servers": {
"caduceus": {
"command": {
"path": "caduceus",
"args": ["-ip", "192.168.1.50:8443"]
}
}
}
}
```
---
## Running in a Container Sandbox
Caduceus includes a hardened, multi-stage `Dockerfile` creating an unprivileged, minimal Alpine runtime sandbox (~15MB total):
```bash
# 1. Build the container image
docker build -t caduceus .
# 2. Bootstrap node credentials in a persistent volume
docker run --rm -v caduceus-data:/home/caduceus/.config/caduceus caduceus init
# 3. Run listener node
docker run -d --name caduceus-node -p 8443:8443 \
-v caduceus-data:/home/caduceus/.config/caduceus \
caduceus -listen :8443
```
A pre-configured 2-node simulation is available via `docker-compose.yml`:
```bash
docker compose up
```
---
## Built-in MCP Tools
Caduceus exposes 12 Model Context Protocol tools to connected LLM hosts:
| Category | Tool | Description |
| :--- | :--- | :--- |
| **Direct Messaging** | `agent_peer_send` | Transmit an asynchronous message envelope directly to a peer agent's Maildir inbox. |
| | `agent_peer_inbox` | Drain and read pending messages, review requests, and task results from the local spool. |
| **Consultative Review** | `agent_peer_consult` | Request a second opinion or advisory analysis on an approach or architecture. |
| | `agent_peer_review` | Submit code, diffs, or text artifacts to a peer agent for formal review. |
| | `agent_peer_reply` | Transmit an advisory or review response back to the requesting agent's correlation ticket. |
| **Task Delegation** | `agent_peer_delegate` | Hand off an objective to a remote agent. Evaluated by the remote greylist policy engine. |
| | `agent_peer_task_status` | Query the real-time lifecycle status (`pending`, `running`, `completed`, `failed`) of a task. |
| | `agent_peer_task_cancel` | Signal cancellation for an active delegated task. |
| | `agent_peer_task_complete` | Terminal state handler recording completion and results into the requester's inbox. |
| | `agent_peer_task_progress` | Emit intermediate progress updates during long-running background tasks. |
| **Inspection** | `agent_peer_status` | Check physical connection state, latency, and SAN identity of the configured peer. |
| | `agent_peer_capabilities` | Inspect peer feature sets, supported protocol versions, and host system metadata. |
---
## Wire Protocol Specification (v1.0.0 Freeze)
Caduceus enforces a strict, zero-dependency wire protocol:
1. **Transport Layer**: Mutual TLS (mTLS) 1.3 exclusively (`tls.VersionTLS13`). Ed25519 signatures embedded in RFC 5280 compliant X.509 v3 certificates (`KeyUsageCertSign`).
2. **Framing**: Newline-delimited (`\n`) JSON-RPC 2.0 streaming envelopes over raw TLS sockets with buffered I/O.
3. **Handshake Sequence**:
- Client sends `caduceus/handshake` carrying version, supported features (`messaging`, `consultative`, `tasks`), and architecture metadata (`arch`, `host`, `os`).
- Server verifies major SemVer compatibility and required capabilities, replying with local capabilities.
- Both nodes transition to `StateActive` and start background keepalive ping monitors.
4. **Tool Schemas**: All 12 MCP tool interfaces and argument definitions are frozen under Semantic Versioning 1.0.0.
---
## Development & Quality Gates
Caduceus maintains a strict clean-code standard with zero external modules in `go.mod`.
```bash
# Run all unit and integration tests with race detection
make test
# Run Go static analysis
make vet
# Check code formatting
make fmt-check
# Compile production static stripped binary
make build
```
---
## License
Apache License 2.0. See [LICENSE](LICENSE) for full details.
TDQS
Scored across 12 tools
Each tool targets a distinct operation, and descriptions explicitly cross-reference alternatives (e.g., send vs delegate, status vs task_status, consult vs review). A few families (send/delegate/consult/review, and status/task_status) are inherently close, but the guidance keeps misselection unlikely.
All names use snake_case with a consistent agent_peer_ prefix and readable verb/noun structure. The task_* subfamily switches to a resource-prefixed style (task_status, task_cancel), which is a minor but predictable deviation.
Twelve tools is well within the ideal 3-15 range and each maps to a meaningful part of the peer-agent protocol: messaging, review/consult, and delegation lifecycle. No tool feels redundant or filler.
The surface covers connectivity, capability discovery, inbox drain, messaging, consult/review exchange, and the full delegate/status/progress/complete/cancel lifecycle. Minor gaps exist, such as listing active tasks or tickets and cancelling consult/review requests, but core workflows are covered.