Skip to main content

Connect an AI Browser with WebMCP

WebMCP lets a compatible AI browser discover TradeScript tools from the page it is already viewing. The chart application remains the host and the SDK remains the authority. No Node process, npx command, localhost server, pairing token, or WebSocket bridge is involved in this path.

This is an additional transport for the same six TradeScript operations. It does not replace standard MCP for desktop harnesses, IDEs, or other clients that start a local or remote MCP server.

TradeScript agent console showing one page-bound session and its exact access grants
Publish browser tools only after the user chooses the intended session and least-privilege grant.

Add WebMCP to an attachment

Attach the intended SDK surfaces and access policy exactly as you would for standard MCP, then expose that attachment to the current page:

import { attachTradeScriptSession } from '@tradescript/chart-mcp/browser';

const attachment = attachTradeScriptSession(tradeScriptAdapter.agentic, {
sessionId: crypto.randomUUID(),
title: 'Research terminal',
access: {
read: true,
write: {
families: {
chartNavigation: true,
drawings: true,
indicators: true,
},
},
trade: false,
},
});

const webMcp = await attachment.exposeWebMcp();

if (webMcp === undefined) {
// The current browser does not provide the WebMCP registration API.
}

Call this from the top-level page after the controller surfaces intended for the session have mounted and the user has chosen to expose them. WebMCP is available only in a secure context, and the current OpenAI browser integration does not discover tools registered only inside an iframe. Check the OpenAI WebMCP documentation for current browser support.

What the browser discovers

The page registers exactly these stable tools:

  • tradescript_get_context
  • tradescript_list_controls
  • tradescript_call
  • tradescript_batch
  • tradescript_subscribe
  • tradescript_snapshot

WebMCP inputs omit sessionId. The attachment binds every execution to its own opaque session identity before it reaches the shared dispatcher. The model must still discover an exact session, chart, or widget target and one effective control before calling it.

Results use one explicit envelope:

type Result =
| { ok: true; result: unknown }
| { ok: false; error: { code: string; message: string; details?: object } };

Typed errors such as revision conflicts, access denials, unsupported controls, and invalid inputs therefore remain visible to the browser client.

The authority does not change

WebMCP reuses the same attachment backend as standard MCP. The following facts are still enforced before a controller is called:

  • the SDK adapter's maximum agenticAccess
  • the attachment's narrower read, write, and trade policy
  • exact mounted target and effective-control discovery
  • current SDK-owned revisions for mutations
  • paper or live broker execution environment
  • broker and risk authorities for financial operations
  • caller-owned operation IDs and reconciliation receipts
  • bounded JSON, batch, subscription, event, and image contracts

WebMCP does not inspect DOM text, click page coordinates, infer missing capabilities, or bypass a lease. Registering a tool advertises an operation; it does not grant that operation.

Lifecycle and revocation

Keep the attachment for the lifetime of the rendered product surface:

webMcp?.close(); // Remove only this page's WebMCP tools.
attachment.detach(); // Remove WebMCP tools and close every attachment transport.

Changing an access policy requires a new attachment. Detaching the old attachment first would finally revoke the document tools. Instead, atomically hand the stable registrations to the replacement, then detach the old session:

const replacement = attachTradeScriptSession(tradeScriptAdapter.agentic, {
sessionId: crypto.randomUUID(),
access: { read: true, write: false, trade: false },
});

const replacementWebMcp = await replacement.exposeWebMcp({
replaceExisting: true,
});

attachment.detach();

The handoff aborts any old execution still waiting to cross the SDK dispatch boundary. It does not interrupt a controller call that already dispatched; its receipt remains the truthful outcome.

Only one active TradeScript WebMCP exposure is allowed per top-level document, which prevents two sessions from claiming the same stable tool names. A final close() or detach() removes all six registrations and retires them for that document lifetime. Reload the page before publishing those stable names again.

Choose the transport

ClientWhat the integrator runsBrowser bridge
Compatible AI browser with WebMCPattachment.exposeWebMcp() in the pageNone
Desktop/IDE MCP client on the same machinenpx tradescript-chart-mcp stdio plus attachment.connectWebSocket(...)Loopback WebSocket
Remote MCP clientYour HTTPS MCP gateway plus your issued browser sessionYour WSS bridge

An application may support WebMCP and standard MCP at the same time. Each path uses the same SDK-owned state and policy, while its own attachment lifecycle defines which exact browser session it can reach.

Next steps