Interfaces
Bridge
Properties
Methods
broadcastConsumerPresence()
broadcastConsumerPresence(): void;
Broadcast presence snapshot to sandbox peer and Studio consumers.
Returns
void
detachConsumer()
detachConsumer(clientSessionId: string, socket?: object): void;
Detach an in-flight consumer’s pending ops without notifying peer or tombstoning session.
With socket, only the ops that socket dispatched are rejected.
Parameters
| Parameter | Type |
|---|---|
clientSessionId | string |
socket? | object |
Returns
void
disconnectConsumer()
disconnectConsumer(clientSessionId: string): void;
Tear down consumer subscriptions, cancel pending ops, and notify peer.
Parameters
| Parameter | Type |
|---|---|
clientSessionId | string |
Returns
void
dispatch()
dispatch(
name: string,
args: Record<string, unknown>,
signal?: AbortSignal,
callerId?: string): Promise<BridgeToolResult>;
Dispatch a tool call to the connected sandbox peer.
Parameters
| Parameter | Type |
|---|---|
name | string |
args | Record<string, unknown> |
signal? | AbortSignal |
callerId? | string |
Returns
Promise<BridgeToolResult>
dispatchWorkerOp()
dispatchWorkerOp(
op: WorkerOpPayload,
clientSessionId?: string,
socket?: object): Promise<unknown>;
Relay a generic worker op to the peer’s SharedWorker. Resolves with the
worker’s res.value; rejects with an Error carrying .code.
Parameters
| Parameter | Type |
|---|---|
op | WorkerOpPayload |
clientSessionId? | string |
socket? | object |
Returns
Promise<unknown>
forwardWorkerMessage()
forwardWorkerMessage(message: InboundMessage, clientSessionId: string): void;
Parameters
| Parameter | Type |
|---|---|
message | InboundMessage |
clientSessionId | string |
Returns
void
handleSandboxMessage()
handleSandboxMessage(msg: BridgeMessage, generation?: number): void;
Handle a message from the sandbox peer (tool-result, pong, …).
generation is the peer generation the transport captured at
registration; when provided, worker-res/worker-snap frames from a
stale generation are dropped.
Parameters
| Parameter | Type |
|---|---|
msg | BridgeMessage |
generation? | number |
Returns
void
health()
health(): HealthReport;
/health endpoint payload.
Returns
interruptConsumer()
interruptConsumer(clientSessionId: string, socket?: object): void;
A consumer’s socket was lost while its session lives on for re-attach:
fail the socket’s operations in flight, drop it from presence, and tell a
host that owns worker ports the session was interrupted, so the host runs
its RTDB onDisconnect operations (ADR-0019). With socket, only the
operations that socket dispatched fail.
Parameters
| Parameter | Type |
|---|---|
clientSessionId | string |
socket? | object |
Returns
void
isSandboxConnected()
isSandboxConnected(): boolean;
True if a sandbox peer is currently registered.
Returns
boolean
onSandboxPeerConnected()
onSandboxPeerConnected(listener: () => void): () => void;
Register a browser-side peer. Returns a disconnect function the caller MUST invoke when the WS closes. Last-wins: a new registration disconnects the previous peer (its pending calls fail with a clear error).
capabilities come from the peer’s hello — the bridge only sends
worker-* frames to a peer that declared 'worker-relay'.
onReplaced fires when a NEWER registration displaces this peer. The
transport MUST use it to close the old socket: the browser side’s
close handler tears down its relayed worker subscriptions — without
this, a replaced tab’s SharedWorker listeners would live until the tab
closed, streaming snaps the bridge drops as stale-generation forever.
Parameters
| Parameter | Type |
|---|---|
listener | () => void |
Returns
(): void;
Returns
void
peerCapabilities()
peerCapabilities(): string[];
Returns
string[]
peerGeneration()
peerGeneration(): number;
Generation counter of the CURRENT peer registration (0 = no peer has ever registered). The transport captures this right after registering and tags every inbound message with it, so a frame arriving on a REPLACED peer’s socket (tab refresh mid-flight) can never resolve a new peer’s pending call or deliver a stale subscription snapshot.
Returns
number
recordToolEvent()
recordToolEvent(event: BridgeToolEvent): void;
Record a tool event in the bridge’s audit pipeline. In-process sandbox tools use this path; forwarded tools log inside dispatch().
Parameters
| Parameter | Type |
|---|---|
event | BridgeToolEvent |
Returns
void
registerSandboxPeer()
registerSandboxPeer(
send: SendToPeer,
tools: string[],
sandboxId: string,
capabilities?: string[],
onReplaced?: () => void): () => void;
Parameters
| Parameter | Type |
|---|---|
send | SendToPeer |
tools | string[] |
sandboxId | string |
capabilities? | string[] |
onReplaced? | () => void |
Returns
(): void;
Returns
void
subscribeWorker()
subscribeWorker(
sub: WorkerSubPayload,
onSnap: (value: unknown) => void,
clientSessionId?: string): () => void;
Register a worker subscription. Survives peer churn and is re-issued. Returns the unsubscribe function.
Parameters
| Parameter | Type |
|---|---|
sub | WorkerSubPayload |
onSnap | (value: unknown) => void |
clientSessionId? | string |
Returns
(): void;
Returns
void
toolNames()
toolNames(): string[];
Tool names the bridge currently exposes to MCP.
Returns
string[]
BridgeOptions
Properties
HealthReport
Health report returned by the bridge’s GET /health endpoint.
Properties
ServerHandle
Properties
| Property | Modifier | Type |
|---|---|---|
auditLogPath | readonly | string |
bridge | readonly | Bridge |
mcpUrl | readonly | string |
port | readonly | number |
sessionToken | readonly | string |
url | readonly | string |
Methods
stop()
stop(): Promise<void>;
Returns
Promise<void>
StartServerOptions
Properties
Variables
DEFAULT_BRIDGE_PORT
const DEFAULT_BRIDGE_PORT: 5174 = 5174;
Default port the standalone bridge binds to.
DEFAULT_HEALTH_PATH
const DEFAULT_HEALTH_PATH: "/health" = "/health";
Default health endpoint path.
DEFAULT_MCP_PATH
const DEFAULT_MCP_PATH: "/mcp" = "/mcp";
Default HTTP path the MCP client connects to.
DEFAULT_SANDBOX_PATH
const DEFAULT_SANDBOX_PATH: "/sandbox" = "/sandbox";
Default WS path the browser connects to.
Functions
createBridge()
function createBridge(opts: BridgeOptions): Bridge;
Parameters
| Parameter | Type |
|---|---|
opts | BridgeOptions |
Returns
startServer()
function startServer(opts?: StartServerOptions): Promise<ServerHandle>;
Parameters
| Parameter | Type |
|---|---|
opts? | StartServerOptions |
Returns
Promise<ServerHandle>