$ npm install webmcp-types
This package defines Typescript types (.d.ts) for the WebMCP specification.
Use this package to augment the ambient "dom" type definitions with the new definitions for WebMCP.
See the TypeScript handbook.
npm install --save-dev webmcp-typesyarn add --dev webmcp-typespnpm add -D webmcp-typesThis package requires TypeScript 5.0 or newer.
Since this package is outside DefinitelyTyped, the dependency won't be picked up automatically. There are several ways to add a additional TypeScript type definition dependencies to your TypeScript project:
tsc and tsc-based bundlersIn tsconfig.json:
{
// ...
"compilerOptions": {
// ...
"types": ["webmcp-types"]
}
}
Or you can use typeRoots:
{
// ...
"compilerOptions": {
// ...
"typeRoots": ["./node_modules/webmcp-types", "./node_modules/@types"]
}
}
This may work better if your toolchain doesn't read tsconfig.json.
/// <reference types="webmcp-types" />
If you use Webpack and the options above aren't sufficient (this has not been verified),
you may need the following in webpack.config.js:
"types": ["webmcp-types"]
When inputSchema and outputSchema are written inline, registerTool() infers the type of
execute's input and checks its return value against the output schema:
document.modelContext?.registerTool({
name: "search",
description: "Searches the catalog.",
inputSchema: {
type: "object",
properties: { query: { type: "string" }, limit: { type: "integer" } },
required: ["query"],
},
outputSchema: {
type: "object",
properties: { results: { type: "array", items: { type: "string" } } },
required: ["results"],
},
// input: { query: string; limit?: number }
// return type: { results: string[] } (or a Promise of it)
execute: async (input) => ({ results: [input.query] }),
});
Tools without schemas, or whose schemas are typed as a plain object, fall back to a
Record<string, unknown> input and an unknown return type.
[!NOTE] If
executedeclares no parameters (e.g.() => ({ status: "ok" })), TypeScript checks it before inferring the output schema, so returnedenum/constvalues are widened (e.g. tostring) and rejected. Declaring the input parameter (e.g.(input) => ...) avoids this.
npm installnpm testThe tests in index.test-d.ts are statically checked with Vitest typecheck mode against tsconfig.json; they are never executed.
Release Please keeps a release pull request open with the next version and changelog, based on Conventional Commits on main. Merging it creates the GitHub release and publishes to npm through trusted publishing; no npm token or local publish step is needed.
© 2010 - cnpmjs.org x YWFE | Home | YWFE