# messageport intent & acp bridge

- Status: `experiment`
- Track: [agent discovery, auth & protocol bridges](https://aifoc.us/labs/agent-bridges-and-discovery/)
- Layer: 9. Agent Discovery, Auth & Protocol Bridges
- Updated: 2 December 2026
- Live demo: https://messageport-intent-acp-bridge.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/messageport-intent-acp-bridge

## Inspired by

- [webmcp is the new web intents ... maybe](https://aifoc.us/webmcp-is-the-new-web-intents/)
- [I think i've got it - Web Intents](https://aifoc.us/i-think-ive-got-it-web-intents/)
- [extensible web apps](https://aifoc.us/extensible-web-apps/)

## Why this matters

Web Intents stalled because cross-site handoffs lacked fine-grained capability scoping, and many browser-to-agent bridges today either pass raw bearer tokens in URLs or expose an entire host tool catalog to every page. Combining standard [`MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) transfers, a top-level Hub popup to navigate [Storage Partitioning](https://developer.mozilla.org/en-US/docs/Web/Privacy/State_Partitioning), [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) sanitization, binary framing, and origin-bound header auth tests how far built-in browser primitives carry cross-origin agent bridges.

## What this opens up

Replacing bespoke N×M website-to-agent integrations with browser-native `MessagePort` handoffs—letting a user-controlled Hub wire one exact tool to a page, gate local ACP permissions in one place, stream binary data cleanly over 15 KiB pipes, and connect live tabs with zero URL secrets.

## How the tests work

1. **Run Quickstart Probe #1 (1-Tool `MessagePort` Handoff)** to grant `catalog.search_books`, transfer a scoped `MessagePort` into the opaque `<iframe sandbox="allow-scripts" src="/tool-provider.html">`, invoke the granted tool, and verify that sibling `catalog.delete_inventory` calls fail with JSON-RPC `-32602`.
2. **Run Quickstart Probe #2 (Hostile ACP Payload & SSE Resume)** to send `cwd: "/etc"` and hostile `mcpServers` into `/acp-worker.js` and SQLite, verify both fields are stripped, block a site permission-approval forgery (`403`), approve in the Hub Owner box, and drop/resume SSE via `Last-Event-ID` with zero gaps or duplicates.
3. **Run Quickstart Probe #3 (`portwire` vs. `JSON.stringify`)** to send a 32 KiB `Uint8Array`, a nested `MessagePort`, and a 4-chunk `ReadableStream` across a 15 KiB byte pipe and compare byte-identical framing against naive JSON corruption.
4. **Test Storage Partitioning and Live-Tab SHA-256 Auth** in Bench 4 by opening the top-level `/hub-popup.html` picker, registering `SHA-256(origin:secret)` in SQLite, replaying a spoofed origin (`401`), and confirming URL-embedded secrets fail closed with `400 URL_SECRET_FORBIDDEN`.


## Hypothesis

- **Claim:** Pairing a top-level Hub picker with single-tool `MessagePort` handoffs, Hub-sanitized ACP permission gates (`X-Hub-Owner-Proof`), SQLite SSE `Last-Event-ID` resume, and 15 KiB binary `portwire` framing enables safe cross-origin tool and agent bridging without URL secrets or binary JSON bloat.
- **Confirms it:** An opaque `<iframe sandbox="allow-scripts">` runs only its single granted tool over the transferred `MessagePort`; the ACP broker strips hostile `cwd`/`mcpServers` fields and replays dropped SSE streams via `Last-Event-ID` without drops or duplicates; `portwire` round-trips 32 KiB buffers, nested ports, and streams byte-identically; and URL-embedded secrets reject with `400 URL_SECRET_FORBIDDEN`.
- **Bounds or disproves it:** Browser storage partitioning isolates embedded Hub iframes from top-level tool registrations unless a top-level popup (`/hub-popup.html`) mediates access, and tunneling binary data or streams across WebRTC-compatible byte pipes requires explicit <=16 KiB framing.


## Under the hood

[MessagePort Intent & ACP Bridge](https://messageport-intent-acp-bridge.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/messageport-intent-acp-bridge)) pairs a Cloudflare Worker and SQLite Durable Object (`BridgeRegistry`) with four browser test benches:

1. **Single-Tool `MessagePort` Intent Picker** — Queries `GET /api/hub/intents`, records grants via `POST /api/hub/handoff`, opens `/hub-popup.html` as a top-level context to navigate storage partitioning, and transfers a narrowed 1-tool `MessagePort` into an opaque `<iframe sandbox="allow-scripts" src="/tool-provider.html">` that allows only the granted tool and refuses sibling calls with `-32602`.
2. **Hub-Mediated ACP Broker & SSE Resume** — Runs `/acp-worker.js` behind `attachAcpHubBroker()`, strips hostile `cwd` and `mcpServers` fields on `POST /api/acp/rpc`, requires `X-Hub-Owner-Proof` on `POST /api/acp/permission` (blocking site forgery with `403`), and replays ordered SQLite frames over `GET /api/acp/stream` using the `Last-Event-ID` header.
3. **`portwire` Binary Framing vs. `JSON.stringify`** — Compares a 15 KiB-capped loopback byte pipe (`/lib/portwire.js`) against naive `JSON.stringify` DataChannel serialization across a 32 KiB `Uint8Array`, a transferred nested `MessagePort`, and a 4-chunk `ReadableStream` with pull back-pressure.
4. **Origin-Bound Live-Tab Auth & `bridge.mjs`** — Stores only `SHA-256(origin:secret)` digests in SQLite, verifies `Authorization: Bearer` + `X-Target-Origin` in constant time, rejects `?token=` and `/mcp/live/<channel>/<token>` URL secrets with `400 URL_SECRET_FORBIDDEN`, and ships a copyable zero-dependency Node 22+ `bridge.mjs` snippet using header/first-message auth.


## Key terms & further reading

- [MessageChannel & MessagePort](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel) — Browser messaging API creating a transferable two-ended pipe whose ports can be scoped to a single tool and handed across origins.
- [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) — JSON-RPC 2.0 protocol for driving local or remote AI agents with explicit `session/request_permission` pauses and streamed updates.
- [Storage Partitioning](https://developer.mozilla.org/en-US/docs/Web/Privacy/State_Partitioning) — Browser isolation model separating cross-site iframe storage from top-level origins, making a top-level Hub popup necessary to read shared registrations.
- [Server-Sent Events & Last-Event-ID](https://html.spec.whatwg.org/multipage/server-sent-events.html) — HTTP streaming standard where reconnecting clients send their last sequence ID so the Durable Object replays only missed frames.
- [RTCDataChannel Binary Limits](https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel) — Peer-to-peer byte transport whose ~16 KiB message cap requires chunked framing (like `portwire`) to carry binary arrays, nested ports, and streams.
- [JSON-RPC 2.0](https://www.jsonrpc.org/specification) — Stateless request/response format used here for single-tool port calls and Hub-mediated ACP messages.

## Open questions to iterate on

- How cleanly can a single `MessagePort` intent picker cover both human-clicked widgets and headless WebMCP tool dispatches?
- What binary framing header minimizes overhead when tunneling `ReadableStream` chunks and transferred `MessagePort` handles over WebRTC DataChannels?

## Iteration log

- **2026-12-02:** Deployed Cloudflare Worker + SQLite Durable Object (`BridgeRegistry`) and Browser Patch Bay featuring a 1-tool attenuated `MessagePort` intent picker + top-level `/hub-popup.html`, permission-gated Dedicated Worker ACP broker (`/acp-worker.js`) with SSE `Last-Event-ID` replay, `portwire` binary framing benchmark vs. `JSON.stringify`, and SHA-256 origin-bound live-tab auth rejecting URL secrets (`400 URL_SECRET_FORBIDDEN`).

## Primitives tested

- `MessagePort & MessageChannel`
- `Agent Client Protocol (ACP)`
- `portwire Binary Framing`
- `SSE Last-Event-ID Cursor Resume`
- `Top-Level Popup Storage Partitioning`
- `Durable Object SQLite (BridgeRegistry)`

## Connected labs in other tracks

- [acp context firewall lab](https://aifoc.us/labs/agent-bridges-and-discovery/acp-context-firewall-lab/) — Tests reverse-exfiltration defenses once a user's personal ACP agent is bridged into an untrusted site over `MessagePort`.
- [csp & iframe sandbox studio](https://aifoc.us/labs/browser-containment/csp-iframe-sandbox-studio/) — Benchmarks `hawser.js`-style narrowed/revocable `MessagePort` bridges across two live origins.
- [webmcp intent registry lab](https://aifoc.us/labs/agent-bridges-and-discovery/webmcp-intent-registry-lab/) — Tests BM25 cross-site WebMCP tool discovery and schema-drift rug-pull gates.

---
Canonical: https://aifoc.us/labs/agent-bridges-and-discovery/messageport-intent-acp-bridge/
