Skip to content

Bridge Client API

The Bridge Client (bridge.js) is automatically injected into HTML responses by the Resource Server. You typically don’t interact with it directly, but understanding its API helps with debugging.

The bridge self-initializes when the page loads:

  1. Detects the platform (Telegram, LINE, or generic)
  2. Establishes WebSocket connection to the Resource Server
  3. Monkey-patches window.parent.postMessage
  4. Sends ui/initialize handshake
  5. Begins forwarding JSON-RPC messages
MethodDescription
ui/initializeHandshake — get host context, capabilities
tools/callExecute an MCP tool
resources/readRead an MCP resource
ui/open-linkOpen an external URL via the platform
ui/messageSend a message to the host
ui/request-display-modeRequest inline, fullscreen, or PiP display
MethodDescription
ui/notifications/host-context-changedTheme, viewport, or locale changed
ui/notifications/tool-inputTool input data from the host
ui/notifications/tool-resultTool execution result notification
ui/notifications/tool-cancelledTool execution was cancelled
ui/resource-teardownPlatform is closing — clean up
tools/call (response)Tool execution result (JSON-RPC response)
resources/read (response)Resource content (JSON-RPC response)

The MessageRouter tracks pending requests with a 30-second timeout:

// Internal flow (simplified)
app.postMessage(request)
-> bridge.js intercepts
-> router.send(request)
-> WebSocket.send(JSON.stringify(request))
-> ... server processes ...
-> WebSocket.onmessage(response)
-> router.resolve(response.id, response)
-> window.dispatchEvent(MessageEvent)