@mcp-b/webmcp-ts-sdk exports BrowserMcpServer, a WebMCP adapter that composes the official MCP TypeScript SDK v2 McpServer.
Most applications should use
@mcp-b/global, which creates and
installs the adapter on document.modelContext.BrowserMcpServer
Constructor
BrowserMcpServerOptions extends the upstream ServerOptions type.
The constructor passes the remaining options to
McpServer and enables list-change support for tools, resources, and prompts.
mcpServer
BrowserMcpServer does not wrap.
Protocol-owned sampling and elicitation APIs are not direct BrowserMcpServer methods. Legacy push-style calls live on browserServer.mcpServer.server and depend on the negotiated protocol revision.
WebMCP descriptor callbacks are single-round over MCP. An input_required result becomes a tool error. Register multi-round tools directly with browserServer.mcpServer.registerTool() so the official handler context owns the interaction.
WebMCP tool surface
The WebMCP specification is authoritative for the standard browser API.registerTool(tool, options?)
native is set, registration succeeds only after the native mirror accepts the tool.
A non-empty
exposedTo array requires native WebMCP. Invalid descriptors, duplicate names, blocked Permissions Policy, and pre-aborted signals reject the returned promise.
getTools(options?)
native, the call delegates to native.getTools(). Without native, a non-empty fromOrigins array rejects because local code cannot perform cross-document discovery.
executeTool(tool, inputArgsJson, options?)
getTools(). This optional Chrome imperative API extension is outside the strict WebMCP core. The optional signal aborts the call.
Tool change events
BrowserMcpServer extends EventTarget and exposes ontoolchange. Local registry changes queue a toolchange event. Native toolchange events trigger reconciliation before the adapter dispatches its event.
MCP-B extensions
isBrowserMcpServer(context)
document.modelContext without changing the strict global declaration or creating a second runtime handle.
listTools()
outputSchema when registered.
syncNativeTools()
native.getTools(). Backfill requires the native context’s optional descriptor-based executeTool() extension. Later native toolchange events reconcile additions, metadata changes, and removals.
Use the Model Context Tool Inspector recommended by Chrome’s WebMCP documentation to inspect native and mirrored tools.
registerResource(descriptor)
McpServer. The returned handle removes the registration through unregister().
A URI containing
{ registers a ResourceTemplate; its variables are passed to read as params. Other URIs register fixed resources.
registerPrompt(descriptor)
McpServer. The returned handle removes the registration through unregister().
Prompt and resource discovery and invocation use MCP. Connect an MCP client;
BrowserMcpServer does not duplicate the official list, read, or get methods. See Register prompts and resources for usage.
Transport lifecycle
connect(transport)
close()
mcpServer. Repeated calls return the same promise.
Schema boundary
The browser-facing tool API accepts JSON Schema and Standard Schema inputs. The adapter converts tool input schemas to the MCP v2 contract, whileMcpServer owns MCP-call validation. PromptDescriptor.argsSchema accepts InputSchema. Direct upstream registrations support Zod 4.2 or newer and the official fromJsonSchema helper; Zod 3 is unsupported.
MCP requires object-root tool input schemas. An array-root WebMCP tool remains available through WebMCP but is omitted from MCP discovery with a warning.
Exports
The package exports only its adapter surface:BrowserMcpServerBrowserMcpServerOptionsisBrowserMcpServerPromptDescriptorResourceDescriptor
@modelcontextprotocol/* packages.
The @mcp-b/transports reference documents browser transports. Strict core and MCP-B extensions defines the boundary between WebMCP and this adapter.