Skip to main content
@mcp-b/webmcp-types provides TypeScript type definitions for the WebMCP API. Zero runtime. Zero side effects. Install as a dev dependency.

Activation

TypeScript may not automatically include global declarations from npm packages. Use one of these methods:
After activation, navigator.modelContext is typed as ModelContext and navigator.modelContextTesting as ModelContextTesting | undefined.

Minimal example



Core interfaces

ModelContext

Alias for ModelContextCore. This is the type of navigator.modelContext.

ModelContextCore

The strict specification surface.

ModelContextExtensions

MCP-B extension methods. Not part of the WebMCP specification.

ModelContextWithExtensions

Combines ModelContextCore & ModelContextExtensions. Use when you need both strict core and extension methods.

Tool types

ToolDescriptor<TArgs, TResult, TName>

Explicitly typed tool descriptor.

StreamedToolDescriptor<TArgs, TResult, TName>

Like ToolDescriptor but stream is true and execute receives a StreamedToolCall<TArgs>.

ToolListItem<TName>

Tool metadata returned by listTools(). Same shape as ToolDescriptor without execute.

ToolAnnotations

CallToolResult / ToolResponse


Schema inference

JsonSchemaForInference

The supported JSON Schema subset for type inference. Use with as const satisfies JsonSchemaForInference for best results.

InferArgsFromInputSchema<T>

Derives the argument type from a JSON Schema type.

Inference rules

Supported JSON Schema keywords for inference: Other keywords are accepted as metadata but do not affect inferred types.

additionalProperties behavior

Widened schemas

If schema types are widened (e.g., InputSchema loaded at runtime instead of a literal as const), inference falls back to Record<string, unknown>. This is by design for safety.

Output schema inference

ToolResultFromOutputSchema<T>

When outputSchema is a literal object schema, structuredContent is narrowed.

ToolDescriptorFromSchema<TInput, TOutput, TName>

Schema-driven descriptor type. Both execute args and structuredContent are inferred from the schemas.

Typed model context

TypedModelContext<TTools>

Provides name-aware callTool and listTools typing for known tool registries.

Helper types


Testing types

ModelContextTesting

ModelContextTestingToolInfo


Other exports