Craftstead

Guide · Agent Bridge

Run local coding agents from Muse, with Agent Bridge

Muse is a cloud agent. Your code, your build tools, and your biggest machine are on your Mac. Agent Bridge connects the two: with its MCP server installed, Muse can open sessions on your Mac — hosted Pi and Claude Code sessions that work in your real project directories — and drive them the way you would from a browser, except the one giving instructions is your cloud agent.

This guide covers the whole path: the architecture, the data flow, a complete setup, and your first dispatched task. Everything below is the real, current behaviour of the open-source code in gowinder/agent-bridge (apps/mcp). Where the setup has sharp edges, they are called out, not smoothed over.

What this sets up

After setup, your cloud agent can:

  • Open a hosted session on your Mac (Pi or Claude Code), scoped to an allowlisted project directory
  • Send it work — a feature, a fix, a build — and read back progress and results
  • Answer its questions — when the local agent needs a decision, the question is forwarded to you through Muse, and your answer goes back into the session
  • Supervise several sessions over time, with an optional Listener that notices when a session finishes or needs you

What it does not do: it does not move your code anywhere. Sessions run on the Mac, in your directories, under your accounts. The relay between Muse and the Mac forwards ciphertext only.

Architecture

Five pieces, one encrypted hop:

  1. Muse (cloud agent) — plans the work, decides what to delegate, reviews results. It talks to the MCP server through MCP tool calls.
  2. Agent Bridge MCP server — a local stdio MCP server (apps/mcp/server/index.mjs) running wherever your agent's tools run. It holds this device's identity and the registry of sessions it owns, and exposes nine tools: bridge_status, session_list, session_open, session_send, session_read, session_wait, session_stop, session_archive, session_adopt.
  3. The relay — a Cloudflare Worker at agent-bridge.craftstead.app (self-hostable). It forwards end-to-end encrypted traffic between paired devices. Pairing and reconnects use Noise (XX for pairing, IK for reconnects); the relay should never see message bodies, project names, or model keys.
  4. Agent Bridge on the Mac — the bridge app. It receives instructions over its outbound WebSocket (no inbound ports, no port forwarding) and hosts the actual agent sessions.
  5. Hosted Pi / Claude Code sessions — the agents that do the work: reading and editing files, running builds and tests, inside the allowlisted directory, using the models and keys configured on the Mac.
Cloud agent Muse Plans the work, decides what to delegate, reviews results
MCP tool calls
MCP server stdio Holds this device's identity and the sessions it owns
Ciphertext
Relay Cloudflare Worker Forwards ciphertext — not message bodies, project names or model keys
Outbound WebSocket
Mac host Agent Bridge Receives instructions, hosts the sessions — no inbound ports
Spawns a session
Hosted session Pi / Claude Code Reads and edits local project files, runs builds and tests
Results and questions return the same path
Optional Listener Second paired device identity
Data flow — five pieces, one encrypted hop. The Mac dials out; the relay moves ciphertext. No inbound ports

One detail worth knowing: the bridge has no push subscription for MCP clients. An optional Listener — a second paired device identity — polls session state every 15 seconds and edge-detects three transitions (finished, needs-user, gone), so your cloud agent learns that a long task completed without polling in a tight loop itself.

Data flow, step by step

Pairing (once). On the Mac you mint a single-use invite link. On the calling machine, the pairing command generates a fresh device keypair and runs a Noise XX handshake with the invite as pre-shared key. Both sides derive the same six-digit confirmation code from the two public keys; you compare the code on the Mac with the code the command prints, and only then confirm. The device identity (key + reconnect token) is stored locally with 0600 permissions and is never printed.

Dispatch. When Muse calls session_open, the server resolves a session by engine + working directory + purpose: an existing matching session is reused, otherwise the bridge creates a new hosted session on the Mac. session_send delivers one task; a session runs one turn at a time, and a second send while it is busy is refused rather than queued silently.

Execution. The hosted session works locally — files, builds, tests, your model gateway. Progress and the final report come back over the encrypted channel and are read with session_read or awaited with session_wait.

Questions. If the local agent needs a decision, that surfaces as a needs-user state (the Listener notices it too). Muse passes the question to you verbatim and sends your answer back into the session. There is no separate approval protocol to configure; the conversation is the protocol.

Cleanup. Finished sessions can be stopped and archived from the same tool surface, and a device can be revoked from the Mac at any time — revocation takes effect immediately.

Setup

Prerequisites

  • Agent Bridge running on a Mac (menu bar app, or headless via the CLI), online on the relay
  • Pi or Claude Code installed on the Mac, with hosted sessions enabled in the bridge settings
  • Node 22 or newer on the machine that will run the MCP server (the relay connection uses Node's built-in WebSocket)
  • Your project directory allowlisted on the Mac — a paired device cannot add directories itself; if session_open returns cwd_not_allowlisted, the error lists the directories you can use

1. Install the MCP server

The MCP app lives in the Agent Bridge monorepo and imports its protocol and crypto packages from the workspace, so install from the repository root:

git clone https://github.com/gowinder/agent-bridge.git
cd agent-bridge
npm ci
npm run build:wasm -w @craftstead/crypto   # builds the Noise wasm module (needs a Rust toolchain with the wasm32 target)
npm run build

No Rust toolchain? If you already run the Agent Bridge app, copy the identical prebuilt module out of the app bundle instead:

cp "/Applications/AgentBridge.app/Contents/Resources/bridge/node_modules/@craftstead/crypto/wasm/noise.wasm" \
   packages/crypto/wasm/noise.wasm

Sanity-check the install without touching the network:

node apps/mcp/server/index.mjs < /dev/null
# [agent-bridge] Agent Bridge MCP v0.1.0 ready (stdio)
node apps/mcp/bin/client.mjs list-tools

2. Point your MCP host at the server

The server speaks MCP over stdio. Configure your host with the absolute path:

{
  "mcpServers": {
    "agent-bridge": {
      "command": "node",
      "args": ["/Users/you/code/agent-bridge/apps/mcp/server/index.mjs"]
    }
  }
}

If your agent runtime cannot hold a long-lived stdio session, the bundled CLI drives the same server one call at a time — this is how Muse itself uses it:

node apps/mcp/bin/client.mjs call-tool --name bridge_status --arguments-file /tmp/ab-args.json

3. Pair the device

On the Mac, mint an invite (menu bar app, or npm run bridge -- invite --ttl 600). On the calling machine, save the full invite link to a local file — treat it like a password, it is single-use — and run:

node apps/mcp/server/pair.mjs --invite-file ~/invite.txt

The command prints a six-digit confirmation code. Compare it with the code shown on the Mac (pairing screen, or the bridge log). If they match, confirm as the command instructs; the identity is written to ~/.agent-bridge/mcp/ (0700 directory, 0600 files).

4. Verify

echo '{}' > /tmp/ab-args.json
node apps/mcp/bin/client.mjs call-tool --name bridge_status --arguments-file /tmp/ab-args.json

You want "connected": true and "presentInDeviceList": true. Before pairing, the same call returns ok: false with error.code: "unpaired" — it doubles as the setup check.

Your first dispatched task

With pairing done, a complete round trip looks like this (shown with the CLI; an MCP host issues the same calls as tool invocations):

# open (or reuse) a Pi session in an allowlisted project directory
node apps/mcp/bin/client.mjs call-tool --name session_open \
  --arguments-file args-open.json        # {"purpose": "my-first-task", "cwd": "/Users/you/code/my-project"}

# send the task
node apps/mcp/bin/client.mjs call-tool --name session_send \
  --arguments-file args-send.json        # {"sessionId": "<from open>", "text": "Run the test suite and fix the first failure you find."}

# read the result when it finishes
node apps/mcp/bin/client.mjs call-tool --name session_read \
  --arguments-file args-read.json        # {"sessionId": "<same id>", "limit": 10}

Three habits worth adopting from day one:

  • Name sessions by purpose. Reuse is keyed by engine + directory + purpose, so a stable purpose string means follow-up instructions land in the same session with its context intact.
  • One turn at a time. If session_send answers session_busy, the previous task is still running — wait or read, don't resend.
  • Archive when done. Archived sessions keep the bridge's session list short and make audits easy.

Why the heavy work belongs on your Mac

This split — cloud agent plans, local agent executes — is not just about where files live. It is also about tokens.

A coding task burns most of its tokens in execution: reading files, iterating on builds, running test suites, recovering from errors. When a hosted Pi or Claude Code session on your Mac does that work, those tokens are spent by the local agent, on the model setup you configured on the Mac — your gateway, your keys, your rates. Your cloud agent's side of the conversation stays small: the task brief going out, progress checks, the final report coming back. Muse's context stays lean, and the expensive loop runs where you already pay for compute.

The local side can also run on a completely different cost model. Point the local agent at a flat-rate coding subscription — an OpenCode Go plan, for example — and let a fast, inexpensive model such as DeepSeek V4.1 Flash chew through the execution loop. The burn that would have been metered, per-token work for your cloud agent becomes a fixed subscription you already pay for, and the cloud agent only spends its own budget on planning, judgement, and review — the parts that actually need the stronger model. In the setup this guide was written from, that is exactly how it runs day to day: Muse plans and supervises; the local Pi executes on a subscription-backed DeepSeek model through a local gateway.

To be fair about the alternative: a cloud agent environment can often install Pi itself and execute in the cloud — Muse's own environment does this too, and for self-contained work in a cloned repository it is perfectly fine. The bridge earns its place for everything the cloud environment does not have: your uncommitted working tree, your local toolchain and services, the project that only exists on your disk, the machine with 64 GB of RAM and your full build cache. Some environments only exist in one place — your desk — and this is how your cloud agent reaches them.

Security model

  • End-to-end encryption. Pairing and reconnects run Noise handshakes between the paired devices; the relay forwards ciphertext and should not see chat bodies, project names, or model keys.
  • No open ports. The Mac dials out to the relay over a WebSocket. Nothing listens inbound.
  • Scoped access. Hosted sessions work inside allowlisted project directories. Remote file browsing and command execution stay off unless you enable them on the Mac.
  • Revocable. Devices can be expired or revoked from the Mac at any time; a revoked device fails immediately.
  • Local secrets stay local. The MCP device identity lives in ~/.agent-bridge/mcp/ with strict permissions and is never printed or committed (the repository gitignores every state path).

This is a design summary, not a security audit — the landing page says the same about the bridge itself.

Limits, honestly

  • The host is a Mac. Agent Bridge's host side is macOS only today.
  • The MCP server is stdio. Your agent (or its CLI driver) must be able to spawn a local process; a purely web-based agent with no local execution cannot use this yet.
  • Install is from the repository for now. The MCP app depends on workspace packages that are not yet published to npm, so the clone-and-build path above is the supported one.
  • Hosted vs mirrored sessions differ. Sessions the bridge hosts itself can be created remotely; sessions mirrored from desktop apps must be started in those apps first.
  • One turn per session. Parallel work means parallel sessions, not parallel sends.

FAQ

Is Agent Bridge free?

Yes — the bridge, the relay, and this MCP server are open source (MIT). You still pay your own model providers for the tokens your agents use.

Which agents can call the MCP server?

Any MCP host that can spawn a stdio process — and runtimes that can't hold a stdio session can use the bundled CLI, which is how Muse drives it.

Which agents can be driven on the Mac?

Hosted Pi and hosted Claude Code sessions can be created and driven end to end. The bridge also mirrors sessions from several desktop and CLI apps for reading and continuing; see the landing page for the per-app matrix.

Does the relay see my code?

No. Traffic between paired devices is end-to-end encrypted; the relay forwards ciphertext. Your code never leaves the Mac — the local session works on it in place.

What happens if the Mac is asleep or offline?

Calls fail with a connection error rather than queueing silently. Wake the Mac, and the same device identity reconnects — no re-pairing.

Can I self-host the relay?

Yes. Deploy the Worker from the same repository and point both the bridge and the MCP profile at your origin.