webmcp-types
TypeScript type definitions for WebMCP
Last updated 7 days ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install webmcp-types 
SYNC missed versions from official npm registry.

Typescript Type Definitions for WebMCP

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.

What are declaration files?

See the TypeScript handbook.

How can I use them?

Install

  • npm: npm install --save-dev webmcp-types
  • yarn: yarn add --dev webmcp-types
  • pnpm: pnpm add -D webmcp-types

This package requires TypeScript 5.0 or newer.

Configure

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:

TypeScript tsc and tsc-based bundlers

In tsconfig.json:

{
  // ...
  "compilerOptions": {
    // ...
    "types": ["webmcp-types"]
  }
}

Or you can use typeRoots:

{
  // ...
  "compilerOptions": {
    // ...
    "typeRoots": ["./node_modules/webmcp-types", "./node_modules/@types"]
  }
}

Inline in TypeScript

This may work better if your toolchain doesn't read tsconfig.json.

/// <reference types="webmcp-types" />

Webpack

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"]

Infer types from schemas

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 execute declares no parameters (e.g. () => ({ status: "ok" })), TypeScript checks it before inferring the output schema, so returned enum/const values are widened (e.g. to string) and rejected. Declaring the input parameter (e.g. (input) => ...) avoids this.

Run the type tests

  • npm install
  • npm test

The tests in index.test-d.ts are statically checked with Vitest typecheck mode against tsconfig.json; they are never executed.

Publish a new npm package version

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.

Current Tags

  • 0.2.0                                ...           latest (7 days ago)

13 Versions

  • 0.2.0                                ...           7 days ago
  • 0.1.11                                ...           15 days ago
  • 0.1.10                                ...           2 months ago
  • 0.1.9                                ...           2 months ago
  • 0.1.8                                ...           2 months ago
  • 0.1.7                                ...           3 months ago
  • 0.1.6                                ...           3 months ago
  • 0.1.5                                ...           3 months ago
  • 0.1.4                                ...           3 months ago
  • 0.1.3                                ...           4 months ago
  • 0.1.2                                ...           5 months ago
  • 0.1.1                                ...           5 months ago
  • 0.1.0                                ...           5 months ago
Maintainers (1)
Downloads
Total 60
Today 0
This Week 26
This Month 60
Last Day 13
Last Week 20
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE