1. What You're Testing
- Zero-guesswork discovery: Given arbitrary path-mounted URLs (
/habitats/research,/agents/demo/mcp,/.well-known/agent-card.json), doesdiscoverAgentEndpointreliably classifykind: "a2a" | "mcp"andauth: "open" | "bearer" | "oauth-required"? - **Protocol translation (
A2A -> MCP):** How cleanly can a remote A2A agent (long-running task + text +DataParttext/html+mcp) be wrapped as an MCP tool so any off-the-shelf MCP host (pi, Claude Desktop, Cursor) can call it and still receiveui://EmbeddedResources?
2. Visual Target (Architecture & Mockup)
Architecture & Flow Diagram
Mermaid
sequenceDiagram
participant MCPHost as "MCP Client (RemoteMcpClient)"
participant Bridge as "MCP <-> A2A Bridge (127.0.0.1:7458)"
participant Probe as "discoverAgentEndpoint"
participant A2AAgent as "Remote A2A DurableHabitat"
Bridge->>Probe: "Probe target URL"
Probe-->>Bridge: "EndpointCard(kind=a2a, skills=[research], streaming=true)"
Bridge->>Bridge: "Register MCP tool ask_research"
MCPHost->>Bridge: "callTool(ask_research, { prompt })"
Bridge->>A2AAgent: "sendText + waitForTask (Bearer token)"
A2AAgent-->>Bridge: "Completed Task (text + ui:// DataPart)"
Bridge-->>MCPHost: "CallToolResult (text + EmbeddedResource ui://)"
Target URL Probe & Bridge console / UI card:
Visual Target Wireframe
ASCII Layout
╔══════════════════════════════════════════════════════════════════════════════╗ ║ UNIVERSAL ENDPOINT PROBE & MCP-A2A BRIDGE · http://127.0.0.1:7458 ║ ╠══════════════════════════════════════════════════════════════════════════════╣ │ Paste URL: [ http://127.0.0.1:52910 ] [Probe] [Bridge] │ │ │ │ ┌─ PROBE RESULT ──────────────────────────────────────────────────────────┐ │ │ │ Kind: a2a Auth: bearer Streaming: true Version: 0.6.0 │ │ │ │ Endpoint URL: http://127.0.0.1:52910/a2a │ │ │ │ Capabilities (1 skill): │ │ │ │ • release-auditor — Audits diff & emits ui:// readiness card │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ ┌─ BRIDGED AS MCP SERVER ─────────────────────────────────────────────────┐ │ │ │ MCP URL: http://127.0.0.1:7458/mcp │ │ │ │ Exposed Tool: ask_release_auditor(message: string) │ │ │ │ Last Bridged Call: text=22 chars | _uiResources=1 (ui://audit/card) │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ ╚══════════════════════════════════════════════════════════════════════════════╝
3. Spin-Up & Prerequisites
Verify endpoint discovery tests pass first:
zsh
pnpm exec vitest run packages/protocols/src/discovery/discover.test.ts
4. Coding-Agent Prompt (Copy-Paste)
Coding-Agent Prompt · Ready to Paste
Build a self-contained lab prototype under `examples/lab-08-url-bridge/` that combines a universal URL protocol inspector (`discoverAgentEndpoint`) with a thin MCP-to-A2A bridge translating an A2A `DurableHabitat` (including `ui://` `DataPart` payloads) onto a local Streamable HTTP MCP server.
Read these repo files first:
- `packages/protocols/src/discovery/discover.ts`
- `packages/protocols/node_modules/@leocavalcante/pi-a2a/src/client.ts`
- `packages/habitat/src/ui-resources.ts` (`UI_OUTPUT_MODE`, `HabitatUIResource`)
- `packages/protocols/src/mcp/client/remote.ts`
Requirements:
1. Create `examples/lab-08-url-bridge/run.ts` (plus `README.md`) supporting:
- `--probe <url> [--token <bearer>]`: runs `discoverAgentEndpoint` and renders normalized `kind`, resolved endpoint `url`, `auth`, `streaming`, and capabilities.
- `--serve --port 7458`: runs a loopback Warm Paper web UI where you can paste any URL to probe it live AND click to mount an A2A endpoint onto the local bridge (`127.0.0.1:7458`).
- `--smoke` (and default): runs an end-to-end automated round-trip on ephemeral loopback ports (`127.0.0.1:0`).
2. Bridge mechanics (`A2A -> MCP`):
- Connect to the target A2A endpoint using `@leocavalcante/pi-a2a/client` (`connectAgent`, `sendText`, `isTask`, `waitForTask`).
- Expose one MCP tool per A2A skill (or `ask_<agent>`) via `@modelcontextprotocol/sdk`'s `McpServer` + `StreamableHTTPServerTransport` (do NOT roll a custom JSON-RPC MCP client!).
- When an A2A completed task contains both text parts and a `DataPart` tagged with `outputMode: "text/html+mcp"` (or a `HabitatUIResource`-shaped object), translate it back into a standard MCP `CallToolResult` containing the text block AND a `{ type: "resource", resource: uiResource }` block.
3. In automated `--smoke` mode:
- Start a mock `DurableHabitat` A2A server whose tool publishes a `ui://bridge/report` resource via `buildHabitatUIResource` / `publishUIResource`.
- Start an open mock MCP server as a second probe target.
- Probe both with `discoverAgentEndpoint` (asserting `kind === "a2a"` on one and `kind === "mcp"` on the other).
- Start the A2A->MCP bridge targeting the `DurableHabitat`, connect `RemoteMcpClient` (`@umwelten/protocols`) to the bridge, call the bridged tool, and verify BOTH the concise text answer AND `_uiResources` preserving `ui://bridge/report` arrive intact at the MCP client!
4. Clean shutdown in `finally`, zero `any` types, strict `tsc --noEmit` passing.
Works in Pi, Claude Code, Codex & Antigravity
Offline mock first →
--live opt-in
5. Interactive Walkthrough (Kick the Tires)
- **Test live URL detection (
--probe):** Run--probeagainst aGaiaHostroot (http://127.0.0.1:7430), a child Habitat (http://127.0.0.1:7430/habitats/research), and Lab 05's MCP server (http://127.0.0.1:7455/mcp) and verify everykindandauthbadge. - **Test live UI bridge (
--serve):** Paste a running A2A Habitat URL intohttp://127.0.0.1:7458, mount it as an MCP tool, and inspect the convertedCallToolResult(textvs._uiResources) right in the browser. - **Wire the bridge into
pi(pi mcp):** Point a standard Pi session athttp://127.0.0.1:7458/mcpsopican call a remote A2A Habitat through ordinary MCP tooling withoutpi-a2a.
6. Did the Prompt Work? (Verification & Tuning)
zsh
pnpm exec tsx examples/lab-08-url-bridge/run.ts --smoke
pnpm exec tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --esModuleInterop --strict --skipLibCheck examples/lab-08-url-bridge/run.ts
Pass criteria:
--smokeconfirmsdiscoverAgentEndpointdistinguishesa2avs.mcp, the bridge starts cleanly, andRemoteMcpClientreceives both text and_uiResourcescontainingui://bridge/report.
Tuning hints if the agent struggles:
- **
DataPartshape mismatch from A2A task artifacts:** Checkpackages/habitat/src/ui-resources.ts(uiResourceToA2APartandUI_OUTPUT_MODE = "text/html+mcp") to see the exactpart.dataandpart.metadataproperties emitted on completed A2A tasks. - **
RemoteMcpClientURL or auth errors on open loopback MCP:** Inspectpackages/protocols/src/mcp/client/remote.tsto confirm open MCP endpoints connect without triggering OAuth redirect errors.