← All Labs Lab 17 / 28 An A2A habitat as an MCP tool
Lab 17 · Tools & UI · Proposed

An A2A habitat as an MCP tool

Through a thin A2A→MCP bridge, an ordinary MCP client calls an A2A habitat as one tool and gets its text answer plus its ui:// view as an MCP embedded resource, without ever holding the habitat's A2A token.

Proposed Needs: tool-calling Source: examples/17-a2a-to-mcp-bridge

Not built yet. PROMPT.md is the prompt to build it from.

Most hosts (pi, Claude Desktop, Cursor) speak MCP, not A2A. This lab puts a thin bridge in front of a DurableHabitat's A2A surface so an MCP client can call it as one tool, ask_<agent>, and still get the view the habitat's turn produced.

The bridge has to translate what the habitat really sends. With createA2ASurface({ uiResources: true }) a completed task carries each view as a text/html URL artifact on the agent's origin, behind its bearer token (see Lab 23). The bridge fetches that URL with the token it holds and returns the HTML as an MCP EmbeddedResource under the view's original ui:// URI.

The checks the build should end with:

CheckWhat it shows
answer-arrivesThe MCP tool result's text is the habitat's answer
view-arrivesThe result carries one ui:// embedded resource with the habitat's view HTML, under the URI the habitat's tool gave it
token-stays-in-bridgeNothing the MCP client receives contains the A2A token or a /a2a/ui/ URL

Moved out

  • Probing any URL as A2A or MCP (discoverAgentEndpoint) was the other half. Its two bugs, ignoring supportedInterfaces and labelling bearer-only MCP as OAuth, were fixed with regression tests (D-30); a URL inspector UI can be its own lab later.

Known going in

  • packages/habitat/src/ui-resources.ts still exports uiResourceToA2APart (text/html+mcp DataParts), but the habitat's A2A surface doesn't use it; don't build the bridge against that shape.
  • pi-a2a 0.5.1 also requires the token for the agent card.

Prompt

Coding-Agent Prompt · Ready to Paste
Build `examples/17-a2a-to-mcp-bridge/run.ts`: a thin bridge that exposes an A2A DurableHabitat as one MCP tool, and an offline smoke that checks an MCP client gets the answer and the habitat's ui:// view without ever seeing the A2A token.

Read first: `examples/23-a2a-view-artifacts/run.ts` (how the habitat's A2A surface sends views: text/html URL artifacts on its origin, behind its bearer token, with the ui:// URI in the artifact's name and part metadata), `packages/habitat/src/durable/durable-habitat.ts` (`createA2ASurface`), `@leocavalcante/pi-a2a/client` (`connectAgent`, `sendText`, `waitForTask`), and `packages/protocols/src/mcp/client/remote.ts`. Don't import from another lab; copy what you need.

1. Start a DurableHabitat on a loopback port with a scripted faux model and one tool returning withUIResources(summary, view), served with createA2ASurface({ uiResources: true, bearerToken }).
2. The bridge holds that token. It serves one MCP tool, `ask_<agent>(message)`, on a loopback MCP server built with the official MCP SDK (no hand-rolled JSON-RPC). On a call it sends the message over A2A, waits for the task, fetches each text/html URL artifact with the token, and returns a CallToolResult with the answer text plus one `{ type: "resource", resource: { uri, mimeType: "text/html", text } }` block per view, using the view's original ui:// URI.
3. `--smoke` connects RemoteMcpClient to the bridge, calls the tool, and prints one PASS/FAIL line per check, exiting 1 on any failure: answer-arrives; view-arrives (one ui:// embedded resource with the habitat's HTML under the tool's URI); token-stays-in-bridge (the token and any /a2a/ui/ URL appear nowhere in what the MCP client received).
4. Strict TypeScript, no `any`; close everything in `finally`. README frontmatter (status built) and a FINDINGS.md with what building it taught us.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in