webmcp-types 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/index.d.ts +104 -0
- package/package.json +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 each contributor listed at the beginning of each definition file.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Typescript Type Definitions for WebMCP
|
|
2
|
+
|
|
3
|
+
This package defines Typescript types (`.d.ts`) for the [WebMCP specification](https://webmachinelearning.github.io/webmcp).
|
|
4
|
+
|
|
5
|
+
Use this package to augment the ambient [`"dom"`](https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options) type definitions with the new definitions for WebMCP.
|
|
6
|
+
|
|
7
|
+
## What are declaration files?
|
|
8
|
+
|
|
9
|
+
See the [TypeScript handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html).
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## How can I use them?
|
|
13
|
+
|
|
14
|
+
### Install
|
|
15
|
+
|
|
16
|
+
- npm: `npm install --save-dev webmcp-types`
|
|
17
|
+
- yarn: `yarn add --dev webmcp-types`
|
|
18
|
+
- pnpm: `pnpm add -D webmcp-types`
|
|
19
|
+
|
|
20
|
+
### Configure
|
|
21
|
+
|
|
22
|
+
Since this package is outside DefinitelyTyped, the dependency won't be picked up automatically.
|
|
23
|
+
There are several ways to add a additional TypeScript type definition dependencies to your TypeScript project:
|
|
24
|
+
|
|
25
|
+
#### TypeScript `tsc` and `tsc`-based bundlers
|
|
26
|
+
|
|
27
|
+
In `tsconfig.json`:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
{
|
|
31
|
+
// ...
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
// ...
|
|
34
|
+
"types": ["webmcp-types"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or you can use `typeRoots`:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
{
|
|
43
|
+
// ...
|
|
44
|
+
"compilerOptions": {
|
|
45
|
+
// ...
|
|
46
|
+
"typeRoots": ["./node_modules/webmcp-types", "./node_modules/@types"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Inline in TypeScript
|
|
52
|
+
|
|
53
|
+
This may work better if your toolchain doesn't read `tsconfig.json`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
/// <reference types="webmcp-types" />
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Webpack
|
|
60
|
+
|
|
61
|
+
If you use Webpack and the options above aren't sufficient (this has not been verified),
|
|
62
|
+
you may need the following in `webpack.config.js`:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
"types": ["webmcp-types"]
|
|
66
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebMCP API enables web apps to provide JavaScript-based tools to AI agents.
|
|
3
|
+
*/
|
|
4
|
+
declare namespace WebMCP {
|
|
5
|
+
/**
|
|
6
|
+
* Callback for tool execution.
|
|
7
|
+
* @param input The input parameters for the tool, as defined by its inputSchema.
|
|
8
|
+
* @returns A promise that resolves with the tool's output.
|
|
9
|
+
*/
|
|
10
|
+
type ToolExecuteCallback = (input: object) => Promise<any>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Metadata about a tool's behavior.
|
|
14
|
+
*/
|
|
15
|
+
interface ToolAnnotations {
|
|
16
|
+
/**
|
|
17
|
+
* If `true`, the tool does not modify any state and only reads data.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
readOnlyHint?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If `true`, indicates the tool may return content from untrusted sources.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
untrustedContentHint?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Describes a tool to be registered with the model context.
|
|
30
|
+
*/
|
|
31
|
+
interface ModelContextTool {
|
|
32
|
+
/**
|
|
33
|
+
* The name of the tool. Must be 1-128 characters, ASCII alphanumeric, '_', '-', or '.'.
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* A human-readable title for the tool.
|
|
38
|
+
*/
|
|
39
|
+
title?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Natural-language description of what the tool does.
|
|
42
|
+
*/
|
|
43
|
+
description: string;
|
|
44
|
+
/**
|
|
45
|
+
* A JSON Schema describing the tool's input parameters.
|
|
46
|
+
*/
|
|
47
|
+
inputSchema?: object;
|
|
48
|
+
/**
|
|
49
|
+
* The function to execute when the tool is called.
|
|
50
|
+
*/
|
|
51
|
+
execute: ToolExecuteCallback;
|
|
52
|
+
/**
|
|
53
|
+
* Metadata about the tool's behavior.
|
|
54
|
+
*/
|
|
55
|
+
annotations?: ToolAnnotations;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Options for registering a tool.
|
|
60
|
+
*/
|
|
61
|
+
interface ModelContextRegisterToolOptions {
|
|
62
|
+
/**
|
|
63
|
+
* An AbortSignal that can be used to unregister the tool.
|
|
64
|
+
*/
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
/**
|
|
67
|
+
* A list of origins that are allowed to call this tool.
|
|
68
|
+
*/
|
|
69
|
+
exposedTo?: string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ModelContextEventMap {
|
|
73
|
+
"toolchange": Event;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The ModelContext interface provides methods for registering tools.
|
|
78
|
+
*/
|
|
79
|
+
interface ModelContext extends EventTarget {
|
|
80
|
+
/**
|
|
81
|
+
* Registers a new tool.
|
|
82
|
+
* @param tool The tool definition.
|
|
83
|
+
* @param options Registration options.
|
|
84
|
+
*/
|
|
85
|
+
registerTool(tool: ModelContextTool, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Event handler for the toolchange event.
|
|
88
|
+
*/
|
|
89
|
+
ontoolchange: ((this: ModelContext, ev: Event) => any) | null;
|
|
90
|
+
|
|
91
|
+
addEventListener<K extends keyof ModelContextEventMap>(type: K, listener: (this: ModelContext, ev: ModelContextEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
93
|
+
removeEventListener<K extends keyof ModelContextEventMap>(type: K, listener: (this: ModelContext, ev: ModelContextEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
94
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface Document {
|
|
99
|
+
/**
|
|
100
|
+
* The model context for the current document.
|
|
101
|
+
* May be undefined if the browser doesn't support WebMCP.
|
|
102
|
+
*/
|
|
103
|
+
readonly modelContext?: WebMCP.ModelContext;
|
|
104
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webmcp-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": "webmachinelearning/webmcp-types",
|
|
5
|
+
"homepage": "https://github.com/webmachinelearning/webmcp-types",
|
|
6
|
+
"bugs": "https://github.com/webmachinelearning/webmcp-types/issues",
|
|
7
|
+
"description": "TypeScript type definitions for WebMCP",
|
|
8
|
+
"main": "",
|
|
9
|
+
"types": "index.d.ts",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"webmcp",
|
|
12
|
+
"typescript",
|
|
13
|
+
"types"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT"
|
|
16
|
+
}
|