Skip to main content
@mcp-b/webmcp-types emits TypeScript declarations only. It defines the standard browser surface separately from MCP-B and Chromium extensions. The WebMCP draft is authoritative for the browser API.

Installation

Use a production dependency when a published library exposes these types in its declarations.

Global activation

Choose one activation method:
Activation adds these globals:

Example

Browser contracts

ModelContext

ModelContext is the type of document.modelContext. Aborting the registration signal removes that registration. RegisteredTool contains name, optional title, description, optional serialized inputSchema, window, origin, and optional standard annotations.

ChromeModelContext

ChromeModelContextExtensions declares the optional Chromium executeTool() method. ChromeModelContext combines that extension 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 standard event and discovery members while replacing standard registration with the MCP-B descriptor overloads.

Tool contracts

ModelContextTool<TArgs, TResult, TName>

The standard tool dictionary.

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 standard 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:
That fallback applies to widened 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 Chromium executeTool(). ModelContextTestingToolInfo contains name, description, and an optional serialized inputSchema.

Public utility types