@mcp-b/webmcp-types emits TypeScript declarations only. It defines the browser contracts implemented by MCP-B packages separately from MCP-B extensions and serialized-JSON execution compatibility.
The WebMCP draft is authoritative for the browser API.
For ambient declarations that track that proposal directly, use the Community Group’s
webmcp-types package. Use
@mcp-b/webmcp-types when you need MCP-B package contracts or schema inference.
Installation
Global activation
Choose one activation method:- tsconfig.json
- Triple-slash reference
- Type-only import
The optional members are bare optionals (
?: T, not ?: T | undefined). Where
WebMCP is absent the property is genuinely missing, so 'modelContext' in document
is false. ModelContext is | undefined instead, because a var declaration
cannot be optional; guard it with typeof ModelContext !== 'undefined'.
@mcp-b/webmcp-polyfill when you
want the surface installed rather than detected.
Example
Browser contracts
ModelContext
ModelContext is the package-supported registration and discovery type for document.modelContext. The live proposal may contain additional or changed members.
Aborting the registration signal removes that registration.
RegisteredTool contains name, optional title, description, optional inputSchema, window, origin, and optional WebMCP annotations. The compatibility type accepts either a JSON Schema object or serialized JSON string. Branch on typeof and follow the Chrome imperative API for current browser behavior.
ChromeModelContext
ChromeModelContextExtensions declares the serialized-JSON executeTool() signature supported by MCP-B and current Chrome builds. ChromeModelContext combines that compatibility shape with ModelContext. Feature-detect the method before calling it.
ModelContextExtensions
The MCP-B extension surface provides schema-aware registerTool() overloads and listTools(). It does not add removed name-based unregistration.
ModelContextWithExtensions keeps the package’s event and discovery members while replacing registration with the MCP-B descriptor overloads.
Tool contracts
ModelContextTool<TArgs, TResult, TName>
The generic tool dictionary used by the package’s browser registration contracts.
ToolDescriptor<TArgs, TResult, TName>
The MCP-B descriptor adds outputSchema and MCP annotations.
ToolDescriptorFromSchema<TInput, TOutput, TName> infers callback input and output from literal schemas. ToolListItem<TName> describes the metadata returned by listTools().
Annotation types
WebMcpToolAnnotations contains the proposal’s readOnlyHint and untrustedContentHint fields. ToolAnnotations combines those fields with the annotation contract from @modelcontextprotocol/server for MCP-B descriptors.
Result types
CallToolResult, ContentBlock, and TextContent come from the official MCP TypeScript SDK. ToolResultFromOutputSchema<T> replaces structuredContent with the type inferred from T.
Schema inference
JsonSchemaForInference
JsonSchemaForInference is the JsonSchemaType owned by @modelcontextprotocol/server. Use as const satisfies JsonSchemaForInference to preserve literal information.
InferJsonSchema<T>
Typeless
properties, required, or additionalProperties imply an object. Unsupported compositions such as $ref and oneOf remain unknown.
Use type: ['string', 'null'] for nullable values.
InferArgsFromInputSchema<T>
Tool callbacks accept object or array inputs. The helper keeps an inferred object or array and otherwise falls back to WebMcpToolInput:
InputSchema, unknown compositions, and scalar-only schemas.
Deprecated testing contracts
ModelContextTesting retains the optional older Chromium testing shape used by compatibility runtimes:
New native integrations use
document.modelContext.getTools() and feature-detect executeTool(). Follow the Chrome imperative API for the browser’s current serialized-JSON signature.
ModelContextTestingToolInfo contains name, description, and an optional serialized inputSchema.
