ACP Worker: Booting… Provider Frame: Loading… DO SQLite: Ready

Track 9 · Agent Bridges & Discovery · MessagePort + ACP + Binary Framing

MessagePort Intent & ACP Bridge

Connecting web apps and external AI agents today usually means wiring custom OAuth apps, copying raw API keys into URLs, or handing one page access to every tool you own. This browser patch bay tests a cleaner pattern built on standard MessageChannel / MessagePort pipes, the Agent Client Protocol (ACP) over JSON-RPC 2.0, binary framing, and Server-Sent Events (SSE) cursor resume.

Why this matters

Early cross-site tool ideas like Web Intents stalled on scoped permissions, and modern browser-to-agent bridges often leak bearer tokens in query strings or let untrusted sites set working directories (cwd) and auto-approve actions. Browser Storage Partitioning also isolates embedded iframes from a user's top-level tool registry.

What this opens up

Replacing bespoke N×M agent integrations with browser-native MessagePort handoffs: a single user-controlled Hub grants a website access to one exact tool (such as a WebMCP catalog search), gates local ACP agent permissions in one place, streams binary files cleanly over 15 KiB pipes, and authenticates live tabs via origin-bound SHA-256 headers.

How the tests work

Run the 3 Quickstart Probes below to execute four live benches backed by a Dedicated Worker (/acp-worker.js), an opaque sandboxed iframe (/tool-provider.html), and a Cloudflare SQLite Durable Object (BridgeRegistry).

Architecture How a Hub Broker isolates site tools, local ACP workers, and live browser tabs
Browser Runtime · Separate Origins & Execution Contexts
Untrusted Site Requesting Website pick(intent) / acp.prompt()
  • Receives a MessagePort scoped to 1 tool only
  • Cannot read provider cookies or page DOM
  • Cannot choose local cwd or approve its own permissions
User-Controlled Hub Hub Broker & Consent UI top-level popup · window.top === window
  1. Checks event.origin & event.source before wiring ports
  2. Strips untrusted cwd & mcpServers fields from ACP calls
  3. Routes session/request_permission only to Hub Owner controls
  4. Splits binary buffers & streams into 15 KiB portwire chunks
Isolated Provider Opaque Tool Frame /tool-provider.html sandbox="allow-scripts" · origin="null"

Runs only the granted tool; rejects sibling tools with -32602.

Worker Agent Dedicated Worker /acp-worker.js cwd="/sandbox/hub-workspace"

Pauses execution until the Hub Owner clicks Approve or Deny.

Cloudflare Worker + BridgeRegistry SQLite Durable Object Header Auth · Zero URL Secrets

Stores registered tool intents (/api/hub/intents), ordered ACP stream events for Last-Event-ID SSE resume (/api/acp/stream), and SHA-256(origin:secret) tab hashes (/api/live-bridge/register). Rejects query or path tokens with 400 URL_SECRET_FORBIDDEN.

Every cross-origin boundary is narrowed at the transport layer: 1-tool MessagePort handoffs for site tools, Hub-sanitized ACP sessions for agents, 15 KiB binary frames for byte pipes, and SHA-256 header authentication for live tabs.

3 Quickstart Probes

1. Grant One Tool Over a MessagePort

Grants catalog.search_books, hands a narrowed MessagePort to the sandboxed provider iframe, calls the allowed tool, and verifies that calling catalog.delete_inventory is blocked with -32602.

2. Strip Hostile ACP Fields & Gate Approval

Sends malicious cwd: "/etc" and mcpServers into /acp-worker.js and SQLite, confirms both are stripped, blocks a site forgery attempt, and pauses the agent for Hub Owner approval.

3. Compare Binary portwire vs. JSON.stringify

Sends a 32 KiB Uint8Array, a nested MessagePort, and a 4-chunk ReadableStream through a 15 KiB byte pipe vs. JSON.stringify to compare lossless framing against silent data loss.

1. Single-Tool MessagePort Intent Picker (Site ↔ Hub ↔ Opaque Provider)

Searches registered providers, records a 1-tool grant in SQLite, and hands a direct MessagePort to a sandboxed iframe with event.origin checks.

No active port

Hub Registry & Intent Discovery

Tool Provider Origin Score Handoff

Site Consumer (Holds Only Transferred MessagePort)

Click "Grant 1-Tool Port" on any row above or run Quickstart Probe #1.

Live Opaque Tool Provider Frame (sandbox="allow-scripts")

Zero cookies, zero localStorage, zero parent DOM access. Enforces single-tool attenuation directly on the transferred MessagePort.

Handoff & Isolation Verification Record

No handoff recorded yet.

2. Permission-Gated Worker ACP Agent & Streamable SSE Last-Event-ID Resume

Runs real ACP JSON-RPC over /acp-worker.js + Cloudflare DO SQLite (/api/acp/rpc, /api/acp/permission, /api/acp/stream). Strips hostile cwd/mcpServers and gates session/request_permission exclusively in the Hub Owner panel.

ACP: Idle

Hostile Client Payload Controls

Hub Owner Permission Queue (Exclusive to Hub UI) 0 pending

No pending session/request_permission requests. Send a prompt to pause the Worker agent here.

Worker + Hub Broker Sanitization Audit

Run step 1 to observe hostile cwd/mcpServers stripping in both /acp-worker.js and DO SQLite.

Durable Object SSE Stream & Last-Event-ID Drop/Resume Test

Connects via fetch("/api/acp/stream") with Acp-Connection-Id header (never query strings), simulates a mid-stream drop after 2 frames (maxEvents=2), then reconnects with Last-Event-ID: 2 to verify zero duplicates and zero dropped frames.

Chunk 1 (before drop) —
Chunk 2 (Last-Event-ID) —
Integrity Check —
Initialize an ACP session and send a prompt, then click "Run Drop-at-Frame-2 & Last-Event-ID Resume".

3. portwire Binary Framing vs. Naive JSON.stringify DataChannel Check

Executes real payloads across a 15 KiB-framed loopback byte pipe (/lib/portwire.js) side-by-side with naive JSON.stringify/JSON.parse DataChannel transport.

Ready
Payload Type portwire Binary Frames (<= 15 KiB) Naive JSON.stringify DataChannel Verdict
Run any framing check above to inspect SHA-256 digests, wire frame counts, and naive JSON corruption output.

4. Storage Partitioning, Live-Tab Origin-Bound Hash Bridge & bridge.mjs Quickstart

Compares embedded/opaque iframe storage isolation against a top-level Hub popup, verifies SHA-256(origin:secret) Live-Tab registration with zero URL secrets, and provides a copyable header-authenticated bridge.mjs snippet.

Live Tab: Unregistered

Live-Tab SHA-256 Origin-Bound Bridge (Zero URL Secrets)

Browser generates a 256-bit local secret, hashes SHA-256(origin + ":" + secret) locally, and registers only the digest in DO SQLite.

Click "1. Register Origin-Bound Hash" to test SHA-256 origin-bound header auth vs. forbidden URL token paths.

Storage Partitioning vs. Top-Level Hub Check

Click "Run Storage Partitioning Snapshot" to compare top-level vs. opaque embedded contexts.

Copyable bridge.mjs Quickstart (Header / First-Message Auth)

Node 22+ zero-dependency bridge for piping a local stdio ACP agent to a remote Hub without putting bearer secrets in WebSocket or HTTP URLs.

Key terms & further reading
MessageChannel & MessagePort ↗
Browser API for creating a private two-ended messaging pipe whose ports can be transferred between origins, iframes, and Workers.
Agent Client Protocol (ACP) ↗
JSON-RPC 2.0 session protocol for driving local or remote AI agents with explicit permission requests and streamed updates.
Storage Partitioning ↗
Browser defense that isolates storage inside cross-site iframes, requiring a top-level Hub popup to read a user's shared tool registry.
SSE & Last-Event-ID ↗
Server-Sent Events streaming mechanism that sends the last received sequence number on reconnect so missed frames replay in order.
RTCDataChannel & Binary Framing ↗
Peer-to-peer byte transport whose ~16 KiB message limit requires chunked framing (like portwire) for binary arrays and streams.
JSON-RPC 2.0 ↗
Lightweight request/response message format used here for single-tool port calls and ACP broker RPC methods.