@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:- tsconfig.json
- Triple-slash reference
- Type-only import
document.modelContext is typed as ModelContext and navigator.modelContextTesting as ModelContextTesting | undefined.
Minimal example
Global augmentation
Core interfaces
ModelContext
Alias for ModelContextCore. This is the type of document.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 JSON Schema, structuredContent is narrowed to
that schema. Object, array, string, number, boolean, and null schemas are
supported for MCP-B type inference. Native Chrome WebMCP does not currently
define or enforce outputSchema.
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.
getTools() and executeTool(tool, inputArgsJson). The standard execution method accepts JSON strings and returns JSON strings, so it does not provide the name-aware argument inference that the compatibility callTool overloads provide.
Helper types
Testing types
ModelContextTesting
ModelContextTestingToolInfo
Other exports
Related pages
- WebMCP standard API for the API these types describe
- Use Schemas and Structured Output for practical schema usage patterns
- Strict Core vs MCP-B Extensions for the boundary between
ModelContextCoreandModelContextExtensions
