@mcp-b/webmcp-types 5.1.0 → 6.0.0-beta.20261001010549
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/README.md +27 -105
- package/index.d.ts +1 -0
- package/package.json +7 -40
- package/dist/common.d.ts +0 -15
- package/dist/common.d.ts.map +0 -1
- package/dist/index.d.ts +0 -52
- package/dist/index.d.ts.map +0 -1
- package/dist/json-schema.d.ts +0 -52
- package/dist/json-schema.d.ts.map +0 -1
- package/dist/model-context.d.ts +0 -91
- package/dist/model-context.d.ts.map +0 -1
- package/dist/tool.d.ts +0 -56
- package/dist/tool.d.ts.map +0 -1
- package/src/common.ts +0 -23
- package/src/index.ts +0 -94
- package/src/json-schema.ts +0 -95
- package/src/model-context.ts +0 -164
- package/src/tool.ts +0 -101
package/README.md
CHANGED
|
@@ -1,127 +1,49 @@
|
|
|
1
1
|
# @mcp-b/webmcp-types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is a compatibility alias for the upstream
|
|
4
|
+
[`webmcp-types`](https://github.com/webmachinelearning/webmcp-types) package.
|
|
5
|
+
It forwards upstream type exports and browser declarations directly.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
**This package will eventually be removed. Please use `webmcp-types` directly.**
|
|
8
|
+
There is no removal date yet.
|
|
6
9
|
|
|
7
|
-
##
|
|
10
|
+
## Migrate to upstream
|
|
8
11
|
|
|
9
12
|
```bash
|
|
10
|
-
pnpm
|
|
13
|
+
pnpm remove @mcp-b/webmcp-types
|
|
14
|
+
pnpm add -D webmcp-types@0.1.9
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Activate the browser globals
|
|
16
|
-
|
|
17
|
-
Choose one activation method:
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"compilerOptions": {
|
|
22
|
-
"types": ["@mcp-b/webmcp-types"]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
```
|
|
17
|
+
Change the import to the upstream package:
|
|
26
18
|
|
|
27
19
|
```ts
|
|
28
|
-
|
|
29
|
-
```
|
|
20
|
+
import type { WebMCP } from 'webmcp-types';
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
import type {} from '@mcp-b/webmcp-types';
|
|
22
|
+
const context: WebMCP.ModelContext | undefined = document.modelContext;
|
|
33
23
|
```
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
Also replace `@mcp-b/webmcp-types` with `webmcp-types` in TypeScript `types`
|
|
26
|
+
configuration and triple-slash references, if used. Published libraries whose
|
|
27
|
+
declarations reference these types should declare `webmcp-types` as a production
|
|
28
|
+
dependency.
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
import type { JsonSchemaForInference } from '@mcp-b/webmcp-types';
|
|
41
|
-
|
|
42
|
-
const inputSchema = {
|
|
43
|
-
type: 'object',
|
|
44
|
-
properties: {
|
|
45
|
-
query: { type: 'string' },
|
|
46
|
-
limit: { type: 'integer', minimum: 1 },
|
|
47
|
-
},
|
|
48
|
-
required: ['query'],
|
|
49
|
-
additionalProperties: false,
|
|
50
|
-
} as const satisfies JsonSchemaForInference;
|
|
51
|
-
|
|
52
|
-
const controller = new AbortController();
|
|
30
|
+
## Compatibility
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
name: 'search',
|
|
57
|
-
description: 'Search indexed docs',
|
|
58
|
-
inputSchema,
|
|
59
|
-
execute: ({ query, limit }) => ({ query, limit }),
|
|
60
|
-
},
|
|
61
|
-
{ signal: controller.signal }
|
|
62
|
-
);
|
|
32
|
+
The alias exports the same `WebMCP` namespace as upstream. Existing consumers can
|
|
33
|
+
use it while migrating:
|
|
63
34
|
|
|
64
|
-
|
|
35
|
+
```ts
|
|
36
|
+
import type { WebMCP } from '@mcp-b/webmcp-types';
|
|
65
37
|
```
|
|
66
38
|
|
|
67
|
-
The
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
| Type | Contract |
|
|
72
|
-
| ---------------------------- | ---------------------------------------------------------------- |
|
|
73
|
-
| `ModelContext` | Current standard `document.modelContext` producer API |
|
|
74
|
-
| `ChromeModelContext` | Standard API plus feature-detectable Chromium `executeTool()` |
|
|
75
|
-
| `ModelContextExtensions` | MCP-B registration and `listTools()` extensions |
|
|
76
|
-
| `ModelContextWithExtensions` | Standard event/discovery shape with MCP-B registration overloads |
|
|
77
|
-
| `ModelContextTesting` | Deprecated optional testing compatibility surface |
|
|
78
|
-
|
|
79
|
-
Both tool descriptor callbacks receive one input argument. MCP-B `ToolDescriptor` may also declare `outputSchema`.
|
|
80
|
-
|
|
81
|
-
## Schema inference
|
|
82
|
-
|
|
83
|
-
`JsonSchemaForInference` is the JSON Schema type owned by `@modelcontextprotocol/server`. The local inference helpers add no competing schema vocabulary.
|
|
84
|
-
|
|
85
|
-
`InferJsonSchema<T>` supports:
|
|
86
|
-
|
|
87
|
-
- `type`, including multi-type arrays such as `['string', 'null']`
|
|
88
|
-
- `const` and `enum`
|
|
89
|
-
- object `properties`, `required`, and `additionalProperties`
|
|
90
|
-
- array `items`
|
|
91
|
-
- boolean subschemas
|
|
92
|
-
|
|
93
|
-
Typeless object keywords infer an object. Unsupported compositions such as `$ref` and `oneOf` remain `unknown`.
|
|
94
|
-
|
|
95
|
-
`InferArgsFromInputSchema<T>` keeps object and array inputs. A widened or runtime-defined `InputSchema` safely falls back to `WebMcpToolInput`, which is `Record<string, unknown> | unknown[]`.
|
|
96
|
-
|
|
97
|
-
MCP-B output inference uses `ToolResultFromOutputSchema<T>` or `ToolDescriptorFromSchema<TInput, TOutput>`. `outputSchema` is not part of the current standard `ModelContextTool` dictionary.
|
|
98
|
-
|
|
99
|
-
## Main exports
|
|
100
|
-
|
|
101
|
-
| Export | Purpose |
|
|
102
|
-
| ---------------------------- | -------------------------------------------- |
|
|
103
|
-
| `ModelContextTool` | Standard one-argument tool dictionary |
|
|
104
|
-
| `RegisteredTool` | Metadata returned by `getTools()` |
|
|
105
|
-
| `ToolDescriptor` | Explicit MCP-B input and result types |
|
|
106
|
-
| `ToolDescriptorFromSchema` | MCP-B input and output schema inference |
|
|
107
|
-
| `ToolListItem` | Metadata returned by `listTools()` |
|
|
108
|
-
| `InputSchema` | Broad runtime JSON Schema boundary |
|
|
109
|
-
| `JsonSchemaForInference` | Canonical upstream JSON Schema type |
|
|
110
|
-
| `InferJsonSchema` | Infer a value from supported schema keywords |
|
|
111
|
-
| `InferArgsFromInputSchema` | Infer an object or array callback input |
|
|
112
|
-
| `ToolResultFromOutputSchema` | Infer MCP `structuredContent` |
|
|
113
|
-
| `CallToolResult` | Canonical MCP tool result |
|
|
114
|
-
| `RegistrationHandle` | Handle returned by prompt/resource helpers |
|
|
115
|
-
|
|
116
|
-
## Compatibility
|
|
117
|
-
|
|
118
|
-
- `navigator.modelContext` remains optional and deprecated.
|
|
119
|
-
- `navigator.modelContextTesting` remains optional and deprecated.
|
|
120
|
-
- `unregisterTool()`, `provideContext()`, and `clearContext()` are absent. Use an `AbortSignal` to own a tool registration.
|
|
121
|
-
- Strict and `strictNullChecks: false` projects are covered by package type tests.
|
|
39
|
+
The previous package's top-level type exports are not reproduced. Use upstream
|
|
40
|
+
types such as `WebMCP.ModelContext` and `WebMCP.ModelContextTool`. MCP-B extension
|
|
41
|
+
types, including `ToolDescriptor` and `ModelContextWithExtensions`, now live in
|
|
42
|
+
[`@mcp-b/webmcp-ts-sdk`](../webmcp-ts-sdk/README.md).
|
|
122
43
|
|
|
123
|
-
See the [
|
|
44
|
+
See the [upstream README](https://github.com/webmachinelearning/webmcp-types#readme)
|
|
45
|
+
for the API and schema inference documentation.
|
|
124
46
|
|
|
125
47
|
## License
|
|
126
48
|
|
|
127
|
-
MIT
|
|
49
|
+
MIT.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from 'webmcp-types';
|
package/package.json
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/webmcp-types",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"document-modelcontext",
|
|
7
|
-
"model-context",
|
|
8
|
-
"navigator-modelcontext",
|
|
9
|
-
"types",
|
|
10
|
-
"typescript",
|
|
11
|
-
"web-standard",
|
|
12
|
-
"webmcp"
|
|
13
|
-
],
|
|
14
|
-
"homepage": "https://docs.mcp-b.ai/packages/webmcp-types/reference",
|
|
3
|
+
"version": "6.0.0-beta.20261001010549",
|
|
4
|
+
"description": "Compatibility alias for upstream webmcp-types; use webmcp-types directly",
|
|
5
|
+
"homepage": "https://github.com/webmachinelearning/webmcp-types",
|
|
15
6
|
"bugs": {
|
|
16
7
|
"url": "https://github.com/WebMCP-org/npm-packages/issues"
|
|
17
8
|
},
|
|
@@ -23,19 +14,14 @@
|
|
|
23
14
|
"directory": "packages/webmcp-types"
|
|
24
15
|
},
|
|
25
16
|
"files": [
|
|
26
|
-
"
|
|
27
|
-
"src/common.ts",
|
|
28
|
-
"src/index.ts",
|
|
29
|
-
"src/json-schema.ts",
|
|
30
|
-
"src/model-context.ts",
|
|
31
|
-
"src/tool.ts"
|
|
17
|
+
"index.d.ts"
|
|
32
18
|
],
|
|
33
19
|
"type": "module",
|
|
34
20
|
"sideEffects": false,
|
|
35
|
-
"types": "./
|
|
21
|
+
"types": "./index.d.ts",
|
|
36
22
|
"exports": {
|
|
37
23
|
".": {
|
|
38
|
-
"types": "./
|
|
24
|
+
"types": "./index.d.ts"
|
|
39
25
|
}
|
|
40
26
|
},
|
|
41
27
|
"publishConfig": {
|
|
@@ -43,25 +29,6 @@
|
|
|
43
29
|
"registry": "https://registry.npmjs.org/"
|
|
44
30
|
},
|
|
45
31
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"typescript": "^5.8.3",
|
|
50
|
-
"vite-plus": "0.1.24",
|
|
51
|
-
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.24"
|
|
52
|
-
},
|
|
53
|
-
"engines": {
|
|
54
|
-
"node": ">=20"
|
|
55
|
-
},
|
|
56
|
-
"scripts": {
|
|
57
|
-
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
58
|
-
"check": "vp check --fix",
|
|
59
|
-
"clean": "rm -rf dist",
|
|
60
|
-
"format": "vp fmt --write",
|
|
61
|
-
"lint": "vp lint --fix",
|
|
62
|
-
"publish:dry": "pnpm publish --access public --dry-run",
|
|
63
|
-
"publish:npm": "pnpm publish --access public",
|
|
64
|
-
"test": "vp test run",
|
|
65
|
-
"typecheck": "tsc --noEmit && tsc -p tsconfig.strict-null-checks-false.json && vp test run --typecheck.only --silent"
|
|
32
|
+
"webmcp-types": "0.1.9"
|
|
66
33
|
}
|
|
67
34
|
}
|
package/dist/common.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type { CallToolResult, ContentBlock, JSONObject as JsonObject, JSONValue as JsonValue, TextContent, } from '@modelcontextprotocol/server';
|
|
2
|
-
/** JSON Schema object accepted at the WebMCP boundary. */
|
|
3
|
-
export interface InputSchema {
|
|
4
|
-
type?: unknown;
|
|
5
|
-
properties?: Readonly<Record<string, unknown>> | undefined;
|
|
6
|
-
required?: readonly string[] | undefined;
|
|
7
|
-
[keyword: string]: unknown;
|
|
8
|
-
}
|
|
9
|
-
/** Values accepted by WebMCP tool callbacks. */
|
|
10
|
-
export type WebMcpToolInput = Record<string, unknown> | unknown[];
|
|
11
|
-
/** Handle returned by MCP-B registration helpers. */
|
|
12
|
-
export interface RegistrationHandle {
|
|
13
|
-
unregister(): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=common.d.ts.map
|
package/dist/common.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,YAAY,EACZ,UAAU,IAAI,UAAU,EACxB,SAAS,IAAI,SAAS,EACtB,WAAW,GACZ,MAAM,8BAA8B,CAAC;AAEtC,0DAA0D;AAC1D,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACzC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAED,gDAAgD;AAChD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;AAElE,qDAAqD;AACrD,MAAM,WAAW,kBAAkB;IACjC,UAAU,IAAI,IAAI,CAAC;CACpB"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { ModelContext, ModelContextTesting } from './model-context.js';
|
|
2
|
-
export type { CallToolResult, ContentBlock, InputSchema, JsonObject, JsonValue, RegistrationHandle, TextContent, WebMcpToolInput, } from './common.js';
|
|
3
|
-
export type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference, } from './json-schema.js';
|
|
4
|
-
export type { ChromeModelContext, ChromeModelContextExecuteToolOptions, ChromeModelContextExtensions, ModelContext, ModelContextExtensions, ModelContextGetToolOptions, ModelContextRegisterToolOptions, ModelContextTesting, ModelContextTestingToolInfo, ModelContextWithExtensions, RegisteredTool, } from './model-context.js';
|
|
5
|
-
export type { MaybePromise, ModelContextTool, ToolAnnotations, ToolDescriptor, ToolDescriptorFromSchema, ToolListItem, ToolResultFromOutputSchema, WebMcpToolAnnotations, } from './tool.js';
|
|
6
|
-
declare global {
|
|
7
|
-
/**
|
|
8
|
-
* Web IDL interface object used for branding and `instanceof`.
|
|
9
|
-
*
|
|
10
|
-
* Absent unless the document's realm implements WebMCP, so guard with
|
|
11
|
-
* `typeof ModelContext !== 'undefined'` before referencing it. A bare
|
|
12
|
-
* reference to an undeclared global throws `ReferenceError`.
|
|
13
|
-
*/
|
|
14
|
-
var ModelContext: (Function & {
|
|
15
|
-
readonly prototype: ModelContext;
|
|
16
|
-
[Symbol.hasInstance](value: unknown): value is ModelContext;
|
|
17
|
-
}) | undefined;
|
|
18
|
-
interface Document {
|
|
19
|
-
/**
|
|
20
|
-
* Canonical WebMCP API for this document.
|
|
21
|
-
*
|
|
22
|
-
* Optional because no browser ships WebMCP unflagged: Chromium exposes it
|
|
23
|
-
* only under `--enable-features=WebMCP`, and elsewhere the property is
|
|
24
|
-
* genuinely absent (`'modelContext' in document === false`). Feature-detect
|
|
25
|
-
* it, or install `@mcp-b/webmcp-polyfill`.
|
|
26
|
-
*/
|
|
27
|
-
readonly modelContext?: ModelContext;
|
|
28
|
-
}
|
|
29
|
-
interface Navigator {
|
|
30
|
-
/** @deprecated Use `document.modelContext`. */
|
|
31
|
-
readonly modelContext?: ModelContext;
|
|
32
|
-
/** @deprecated Compatibility surface for older Chromium previews. */
|
|
33
|
-
modelContextTesting?: ModelContextTesting;
|
|
34
|
-
}
|
|
35
|
-
interface SubmitEvent {
|
|
36
|
-
/**
|
|
37
|
-
* True when a declarative WebMCP tool initiated this submission.
|
|
38
|
-
*
|
|
39
|
-
* Optional because declarative forms are explainer-only: this attribute is
|
|
40
|
-
* in neither the WebMCP specification nor WPT's `webmcp.idl`, and no
|
|
41
|
-
* browser implements it. `@mcp-b/webmcp-polyfill` installs it.
|
|
42
|
-
*/
|
|
43
|
-
readonly agentInvoked?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Associates an intercepted form submission result with the invoking agent.
|
|
46
|
-
*
|
|
47
|
-
* Optional for the same reason as {@link SubmitEvent.agentInvoked}.
|
|
48
|
-
*/
|
|
49
|
-
respondWith?(agentResponse: Promise<unknown>): void;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,YAAY,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,wBAAwB,EACxB,eAAe,EACf,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,kBAAkB,EAClB,oCAAoC,EACpC,4BAA4B,EAC5B,YAAY,EACZ,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,CAAC,MAAM,CAAC;IACb;;;;;;OAMG;IACH,IAAI,YAAY,EACZ,CAAC,QAAQ,GAAG;QACV,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;QACjC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC;KAC7D,CAAC,GACF,SAAS,CAAC;IAEd,UAAU,QAAQ;QAChB;;;;;;;WAOG;QACH,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;KACtC;IAED,UAAU,SAAS;QACjB,+CAA+C;QAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;QAErC,qEAAqE;QACrE,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;KAC3C;IAED,UAAU,WAAW;QACnB;;;;;;WAMG;QACH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAEhC;;;;WAIG;QACH,WAAW,CAAC,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;KACrD;CACF"}
|
package/dist/json-schema.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type { JsonSchemaType as McpJsonSchema } from '@modelcontextprotocol/server';
|
|
3
|
-
/** JSON Schema Draft 2020-12 accepted by the inference helpers. */
|
|
4
|
-
export type JsonSchemaForInference = McpJsonSchema;
|
|
5
|
-
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'object' | 'array';
|
|
6
|
-
type Simplify<T> = {
|
|
7
|
-
[K in keyof T]: T[K];
|
|
8
|
-
} & {};
|
|
9
|
-
type EmptyObject = Record<never, never>;
|
|
10
|
-
type ConstValue<TSchema> = TSchema extends {
|
|
11
|
-
const: infer TValue;
|
|
12
|
-
} ? TValue : never;
|
|
13
|
-
type EnumValue<TSchema> = TSchema extends {
|
|
14
|
-
enum: readonly (infer TValue)[];
|
|
15
|
-
} ? TValue : never;
|
|
16
|
-
type Properties<TSchema> = TSchema extends {
|
|
17
|
-
properties: infer TProperties extends Readonly<Record<string, unknown>>;
|
|
18
|
-
} ? TProperties : EmptyObject;
|
|
19
|
-
type RequiredKeys<TSchema> = TSchema extends {
|
|
20
|
-
required: readonly (infer TKey extends string)[];
|
|
21
|
-
} ? string extends TKey ? never : Extract<TKey, keyof Properties<TSchema>> : never;
|
|
22
|
-
type AdditionalProperties<TSchema> = TSchema extends {
|
|
23
|
-
additionalProperties: false;
|
|
24
|
-
} ? keyof Properties<TSchema> extends never ? Record<string, never> : EmptyObject : keyof Properties<TSchema> extends never ? TSchema extends {
|
|
25
|
-
additionalProperties: infer TAdditional extends object;
|
|
26
|
-
} ? Record<string, InferJsonSchema<TAdditional>> : Record<string, unknown> : Record<string, unknown>;
|
|
27
|
-
type InferObject<TSchema> = Simplify<{
|
|
28
|
-
-readonly [K in keyof Properties<TSchema> as K extends RequiredKeys<TSchema> ? K : never]-?: InferJsonSchema<Properties<TSchema>[K]>;
|
|
29
|
-
} & {
|
|
30
|
-
-readonly [K in keyof Properties<TSchema> as K extends RequiredKeys<TSchema> ? never : K]?: InferJsonSchema<Properties<TSchema>[K]>;
|
|
31
|
-
} & AdditionalProperties<TSchema>>;
|
|
32
|
-
type TypeKeyword<TSchema> = TSchema extends {
|
|
33
|
-
type: infer TType;
|
|
34
|
-
} ? TType : TSchema extends {
|
|
35
|
-
properties: unknown;
|
|
36
|
-
} | {
|
|
37
|
-
required: unknown;
|
|
38
|
-
} | {
|
|
39
|
-
additionalProperties: unknown;
|
|
40
|
-
} ? 'object' : never;
|
|
41
|
-
type TypeOptions<TSchema> = TypeKeyword<TSchema> extends readonly unknown[] ? Extract<TypeKeyword<TSchema>[number], JsonSchemaType> : Extract<TypeKeyword<TSchema>, JsonSchemaType>;
|
|
42
|
-
type InferType<TSchema, TType extends JsonSchemaType> = TType extends 'object' ? InferObject<TSchema> : TType extends 'array' ? TSchema extends {
|
|
43
|
-
items: infer TItems;
|
|
44
|
-
} ? InferJsonSchema<TItems>[] : unknown[] : TType extends 'string' ? string : TType extends 'number' | 'integer' ? number : TType extends 'boolean' ? boolean : TType extends 'null' ? null : unknown;
|
|
45
|
-
/** Infers a TypeScript value from the supported JSON Schema keywords. */
|
|
46
|
-
export type InferJsonSchema<TSchema> = TSchema extends false ? never : TSchema extends true ? unknown : [InputSchema] extends [TSchema] ? unknown : [ConstValue<TSchema>] extends [never] ? [EnumValue<TSchema>] extends [never] ? TypeOptions<TSchema> extends never ? unknown : InferType<TSchema, TypeOptions<TSchema>> : EnumValue<TSchema> : ConstValue<TSchema>;
|
|
47
|
-
/** Infers the object or array passed to a WebMCP tool callback. */
|
|
48
|
-
export type InferArgsFromInputSchema<TSchema> = [
|
|
49
|
-
Extract<Exclude<InferJsonSchema<TSchema>, null | undefined>, WebMcpToolInput>
|
|
50
|
-
] extends [never] ? WebMcpToolInput : Extract<Exclude<InferJsonSchema<TSchema>, null | undefined>, WebMcpToolInput>;
|
|
51
|
-
export {};
|
|
52
|
-
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAEpF,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAEnD,KAAK,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAChG,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AACjD,KAAK,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAExC,KAAK,UAAU,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,KAAK,EAAE,MAAM,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAAC;AACpF,KAAK,SAAS,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,IAAI,EAAE,SAAS,CAAC,MAAM,MAAM,CAAC,EAAE,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAAC;AAC/F,KAAK,UAAU,CAAC,OAAO,IAAI,OAAO,SAAS;IACzC,UAAU,EAAE,MAAM,WAAW,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,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AC,SAAS,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAClC,WAAW,CAAC,OAAO,CAAC,SAAS,KAAK,GAChC,OAAO,GACP,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,GAC1C,SAAS,CAAC,OAAO,CAAC,GACpB,UAAU,CAAC,OAAO,CAAC,CAAC;AAE9B,mEAAmE;AACnE,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI;IAC9C,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,EAAE,eAAe,CAAC;CAC9E,SAAS,CAAC,KAAK,CAAC,GACb,eAAe,GACf,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,EAAE,eAAe,CAAC,CAAC"}
|
package/dist/model-context.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type { JsonSchemaForInference } from './json-schema.js';
|
|
3
|
-
import type { ModelContextTool, ModelContextToolFromSchema, ToolDescriptor, ToolDescriptorFromSchema, ToolListItem, WebMcpToolAnnotations } from './tool.js';
|
|
4
|
-
/** Options for tools exposed by descendant documents. */
|
|
5
|
-
export interface ModelContextGetToolOptions {
|
|
6
|
-
fromOrigins?: string[];
|
|
7
|
-
}
|
|
8
|
-
/** Tool metadata returned by `document.modelContext.getTools()`. */
|
|
9
|
-
export interface RegisteredTool {
|
|
10
|
-
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* Present on every tool Chrome and `@mcp-b/webmcp-polyfill` return today --
|
|
13
|
-
* the spec defaults it to the empty string when a tool registers no title.
|
|
14
|
-
* Kept optional deliberately: webmcp#224 proposes dropping that default and
|
|
15
|
-
* omitting the member instead. Read it as `tool.title || tool.name`: today the
|
|
16
|
-
* spec default makes it an empty string, which `??` does not fall through.
|
|
17
|
-
*/
|
|
18
|
-
title?: string;
|
|
19
|
-
description: string;
|
|
20
|
-
/**
|
|
21
|
-
* A JSON Schema object since webmcp#241, rolling out from Chrome 154.0.8013
|
|
22
|
-
* (cross-document tools first). Chrome 149-153 -- most of the Origin Trial
|
|
23
|
-
* population -- and 154's same-document tools still return the serialized
|
|
24
|
-
* JSON string the change replaced. Consumers that support both generations
|
|
25
|
-
* must branch on `typeof` and guard the parse of the string arm.
|
|
26
|
-
*/
|
|
27
|
-
inputSchema?: InputSchema | string;
|
|
28
|
-
window: Window;
|
|
29
|
-
origin: string;
|
|
30
|
-
/**
|
|
31
|
-
* Absent when the tool registered no annotations -- both the spec and the
|
|
32
|
-
* polyfill omit the member rather than emitting an empty object. Each hint
|
|
33
|
-
* inside it is always populated, but the object itself is not guaranteed.
|
|
34
|
-
*/
|
|
35
|
-
annotations?: WebMcpToolAnnotations;
|
|
36
|
-
}
|
|
37
|
-
export interface ChromeModelContextExecuteToolOptions {
|
|
38
|
-
signal?: AbortSignal;
|
|
39
|
-
}
|
|
40
|
-
/** Experimental Chromium methods; feature-detect them before use. */
|
|
41
|
-
export interface ChromeModelContextExtensions {
|
|
42
|
-
executeTool?(tool: RegisteredTool, inputArguments: string, options?: ChromeModelContextExecuteToolOptions): Promise<string | null>;
|
|
43
|
-
}
|
|
44
|
-
/** @deprecated Metadata returned by `navigator.modelContextTesting`. */
|
|
45
|
-
export interface ModelContextTestingToolInfo {
|
|
46
|
-
name: string;
|
|
47
|
-
description: string;
|
|
48
|
-
inputSchema?: string;
|
|
49
|
-
}
|
|
50
|
-
/** @deprecated Compatibility surface for Chromium's removed testing API. */
|
|
51
|
-
export interface ModelContextTesting extends EventTarget {
|
|
52
|
-
listTools(): ModelContextTestingToolInfo[];
|
|
53
|
-
executeTool(toolName: string, inputArgsJson: string, options?: ChromeModelContextExecuteToolOptions): Promise<string | null>;
|
|
54
|
-
ontoolchange: ((this: ModelContextTesting, event: Event) => unknown) | null;
|
|
55
|
-
}
|
|
56
|
-
/** Options accepted by `ModelContext.registerTool()`. */
|
|
57
|
-
export interface ModelContextRegisterToolOptions {
|
|
58
|
-
signal?: AbortSignal;
|
|
59
|
-
exposedTo?: string[];
|
|
60
|
-
}
|
|
61
|
-
type WidenedSchema<TSchema extends InputSchema> = string extends TSchema['type'] ? unknown : never;
|
|
62
|
-
/**
|
|
63
|
-
* Standard `document.modelContext` API.
|
|
64
|
-
* @see https://webmachinelearning.github.io/webmcp/#modelcontext
|
|
65
|
-
*/
|
|
66
|
-
export interface ModelContext extends EventTarget {
|
|
67
|
-
registerTool<const TInputSchema extends JsonSchemaForInference, TResult = unknown, TName extends string = string>(tool: ModelContextToolFromSchema<TInputSchema, TResult, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
68
|
-
registerTool<TInputSchema extends InputSchema, TArgs extends WebMcpToolInput = WebMcpToolInput, TResult = unknown, TName extends string = string>(tool: ModelContextTool<TArgs, TResult, TName> & {
|
|
69
|
-
inputSchema: TInputSchema;
|
|
70
|
-
} & WidenedSchema<TInputSchema>, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
71
|
-
registerTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string>(tool: Omit<ModelContextTool<TArgs, TResult, TName>, 'inputSchema'> & {
|
|
72
|
-
inputSchema?: undefined;
|
|
73
|
-
}, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
74
|
-
getTools(options?: ModelContextGetToolOptions): Promise<RegisteredTool[]>;
|
|
75
|
-
ontoolchange: ((this: ModelContext, event: Event) => unknown) | null;
|
|
76
|
-
}
|
|
77
|
-
/** Non-standard methods exposed by MCP-B runtimes. */
|
|
78
|
-
export interface ModelContextExtensions {
|
|
79
|
-
registerTool<const TInputSchema extends JsonSchemaForInference, const TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
80
|
-
registerTool<TInputSchema extends InputSchema, TArgs extends WebMcpToolInput = WebMcpToolInput, TName extends string = string>(tool: ToolDescriptor<TArgs, unknown, TName> & {
|
|
81
|
-
inputSchema: TInputSchema;
|
|
82
|
-
} & WidenedSchema<TInputSchema>, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
83
|
-
registerTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TName extends string = string>(tool: Omit<ToolDescriptor<TArgs, unknown, TName>, 'inputSchema'> & {
|
|
84
|
-
inputSchema?: undefined;
|
|
85
|
-
}, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
86
|
-
listTools(): ToolListItem[];
|
|
87
|
-
}
|
|
88
|
-
export type ChromeModelContext = ModelContext & ChromeModelContextExtensions;
|
|
89
|
-
export type ModelContextWithExtensions = Omit<ModelContext, 'registerTool'> & ModelContextExtensions;
|
|
90
|
-
export {};
|
|
91
|
-
//# sourceMappingURL=model-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model-context.d.ts","sourceRoot":"","sources":["../src/model-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,qBAAqB,EACtB,MAAM,WAAW,CAAC;AAEnB,yDAAyD;AACzD,MAAM,WAAW,0BAA0B;IACzC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,WAAW,G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B,GAAG,SAAS,GAAG,SAAS,EAC1E,KAAK,SAAS,MAAM,GAAG,MAAM,EAE7B,IAAI,EAAE,wBAAwB,CAAC,YAAY,EAAE,aAAa,EAAE,KAAK,CAAC,EAClE,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,YAAY,CACV,YAAY,SAAS,WAAW,EAChC,KAAK,SAAS,eAAe,GAAG,eAAe,EAC/C,KAAK,SAAS,MAAM,GAAG,MAAM,EAE7B,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG;QAC5C,WAAW,EAAE,YAAY,CAAC;KAC3B,GAAG,aAAa,CAAC,YAAY,CAAC,EAC/B,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,YAAY,CACV,KAAK,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvD,KAAK,SAAS,MAAM,GAAG,MAAM,EAE7B,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC,GAAG;QACjE,WAAW,CAAC,EAAE,SAAS,CAAC;KACzB,EACD,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,SAAS,IAAI,YAAY,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,4BAA4B,CAAC;AAC7E,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,GACzE,sBAAsB,CAAC"}
|
package/dist/tool.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CallToolResult, InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference } from './json-schema.js';
|
|
3
|
-
import type { ToolAnnotations as McpToolAnnotations } from '@modelcontextprotocol/server';
|
|
4
|
-
/**
|
|
5
|
-
* Annotations in the WebMCP tool dictionary.
|
|
6
|
-
* @see https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
|
|
7
|
-
*/
|
|
8
|
-
export interface WebMcpToolAnnotations {
|
|
9
|
-
readOnlyHint?: boolean;
|
|
10
|
-
untrustedContentHint?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/** MCP annotations plus WebMCP's untrusted-content hint. */
|
|
13
|
-
export type ToolAnnotations = McpToolAnnotations & WebMcpToolAnnotations;
|
|
14
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Tool dictionary accepted by the standard browser API.
|
|
17
|
-
* @see https://webmachinelearning.github.io/webmcp/#dictdef-modelcontexttool
|
|
18
|
-
*/
|
|
19
|
-
export interface ModelContextTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string> {
|
|
20
|
-
name: TName;
|
|
21
|
-
title?: string;
|
|
22
|
-
description: string;
|
|
23
|
-
inputSchema?: InputSchema | undefined;
|
|
24
|
-
annotations?: WebMcpToolAnnotations;
|
|
25
|
-
execute: (input: TArgs) => MaybePromise<TResult>;
|
|
26
|
-
}
|
|
27
|
-
/** Standard tool dictionary with input inferred from a JSON Schema literal. */
|
|
28
|
-
export type ModelContextToolFromSchema<TInputSchema extends InputSchema, TResult = unknown, TName extends string = string> = Omit<ModelContextTool<InferArgsFromInputSchema<TInputSchema>, TResult, TName>, 'inputSchema'> & {
|
|
29
|
-
inputSchema: TInputSchema;
|
|
30
|
-
};
|
|
31
|
-
/** MCP-B tool dictionary with output metadata. */
|
|
32
|
-
export type ToolDescriptor<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string> = Omit<ModelContextTool<TArgs, TResult, TName>, 'annotations'> & {
|
|
33
|
-
outputSchema?: JsonSchemaForInference;
|
|
34
|
-
annotations?: ToolAnnotations;
|
|
35
|
-
};
|
|
36
|
-
/** MCP response with `structuredContent` inferred from an output schema. */
|
|
37
|
-
export type ToolResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = [TOutputSchema] extends [undefined] ? CallToolResult : TOutputSchema extends JsonSchemaForInference ? Omit<CallToolResult, 'structuredContent'> & {
|
|
38
|
-
structuredContent: InferJsonSchema<TOutputSchema>;
|
|
39
|
-
} : never;
|
|
40
|
-
type ExecuteResult<TOutputSchema extends JsonSchemaForInference | undefined> = [
|
|
41
|
-
TOutputSchema
|
|
42
|
-
] extends [undefined] ? unknown : TOutputSchema extends JsonSchemaForInference ? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema> : never;
|
|
43
|
-
/** Tool dictionary with input and output inferred from JSON Schema literals. */
|
|
44
|
-
export type ToolDescriptorFromSchema<TInputSchema extends InputSchema, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string> = Omit<ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ExecuteResult<TOutputSchema>, TName>, 'inputSchema' | 'outputSchema'> & {
|
|
45
|
-
inputSchema: TInputSchema;
|
|
46
|
-
} & ([TOutputSchema] extends [undefined] ? {
|
|
47
|
-
outputSchema?: undefined;
|
|
48
|
-
} : {
|
|
49
|
-
outputSchema: TOutputSchema;
|
|
50
|
-
});
|
|
51
|
-
/** Tool metadata returned by the MCP-B `listTools()` extension. */
|
|
52
|
-
export type ToolListItem<TName extends string = string> = Omit<ToolDescriptor<Record<string, unknown>, unknown, TName>, 'execute' | 'inputSchema'> & {
|
|
53
|
-
inputSchema: InputSchema;
|
|
54
|
-
};
|
|
55
|
-
export {};
|
|
56
|
-
//# sourceMappingURL=tool.d.ts.map
|
package/dist/tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,E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Y,CAAC,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,YAAY,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AAEvC,mEAAmE;AACnE,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,CAC5D,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EACvD,SAAS,GAAG,aAAa,CAC1B,GAAG;IACF,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC"}
|
package/src/common.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
CallToolResult,
|
|
3
|
-
ContentBlock,
|
|
4
|
-
JSONObject as JsonObject,
|
|
5
|
-
JSONValue as JsonValue,
|
|
6
|
-
TextContent,
|
|
7
|
-
} from '@modelcontextprotocol/server';
|
|
8
|
-
|
|
9
|
-
/** JSON Schema object accepted at the WebMCP boundary. */
|
|
10
|
-
export interface InputSchema {
|
|
11
|
-
type?: unknown;
|
|
12
|
-
properties?: Readonly<Record<string, unknown>> | undefined;
|
|
13
|
-
required?: readonly string[] | undefined;
|
|
14
|
-
[keyword: string]: unknown;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Values accepted by WebMCP tool callbacks. */
|
|
18
|
-
export type WebMcpToolInput = Record<string, unknown> | unknown[];
|
|
19
|
-
|
|
20
|
-
/** Handle returned by MCP-B registration helpers. */
|
|
21
|
-
export interface RegistrationHandle {
|
|
22
|
-
unregister(): void;
|
|
23
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { ModelContext, ModelContextTesting } from './model-context.js';
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
CallToolResult,
|
|
5
|
-
ContentBlock,
|
|
6
|
-
InputSchema,
|
|
7
|
-
JsonObject,
|
|
8
|
-
JsonValue,
|
|
9
|
-
RegistrationHandle,
|
|
10
|
-
TextContent,
|
|
11
|
-
WebMcpToolInput,
|
|
12
|
-
} from './common.js';
|
|
13
|
-
export type {
|
|
14
|
-
InferArgsFromInputSchema,
|
|
15
|
-
InferJsonSchema,
|
|
16
|
-
JsonSchemaForInference,
|
|
17
|
-
} from './json-schema.js';
|
|
18
|
-
export type {
|
|
19
|
-
ChromeModelContext,
|
|
20
|
-
ChromeModelContextExecuteToolOptions,
|
|
21
|
-
ChromeModelContextExtensions,
|
|
22
|
-
ModelContext,
|
|
23
|
-
ModelContextExtensions,
|
|
24
|
-
ModelContextGetToolOptions,
|
|
25
|
-
ModelContextRegisterToolOptions,
|
|
26
|
-
ModelContextTesting,
|
|
27
|
-
ModelContextTestingToolInfo,
|
|
28
|
-
ModelContextWithExtensions,
|
|
29
|
-
RegisteredTool,
|
|
30
|
-
} from './model-context.js';
|
|
31
|
-
export type {
|
|
32
|
-
MaybePromise,
|
|
33
|
-
ModelContextTool,
|
|
34
|
-
ToolAnnotations,
|
|
35
|
-
ToolDescriptor,
|
|
36
|
-
ToolDescriptorFromSchema,
|
|
37
|
-
ToolListItem,
|
|
38
|
-
ToolResultFromOutputSchema,
|
|
39
|
-
WebMcpToolAnnotations,
|
|
40
|
-
} from './tool.js';
|
|
41
|
-
|
|
42
|
-
declare global {
|
|
43
|
-
/**
|
|
44
|
-
* Web IDL interface object used for branding and `instanceof`.
|
|
45
|
-
*
|
|
46
|
-
* Absent unless the document's realm implements WebMCP, so guard with
|
|
47
|
-
* `typeof ModelContext !== 'undefined'` before referencing it. A bare
|
|
48
|
-
* reference to an undeclared global throws `ReferenceError`.
|
|
49
|
-
*/
|
|
50
|
-
var ModelContext:
|
|
51
|
-
| (Function & {
|
|
52
|
-
readonly prototype: ModelContext;
|
|
53
|
-
[Symbol.hasInstance](value: unknown): value is ModelContext;
|
|
54
|
-
})
|
|
55
|
-
| undefined;
|
|
56
|
-
|
|
57
|
-
interface Document {
|
|
58
|
-
/**
|
|
59
|
-
* Canonical WebMCP API for this document.
|
|
60
|
-
*
|
|
61
|
-
* Optional because no browser ships WebMCP unflagged: Chromium exposes it
|
|
62
|
-
* only under `--enable-features=WebMCP`, and elsewhere the property is
|
|
63
|
-
* genuinely absent (`'modelContext' in document === false`). Feature-detect
|
|
64
|
-
* it, or install `@mcp-b/webmcp-polyfill`.
|
|
65
|
-
*/
|
|
66
|
-
readonly modelContext?: ModelContext;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
interface Navigator {
|
|
70
|
-
/** @deprecated Use `document.modelContext`. */
|
|
71
|
-
readonly modelContext?: ModelContext;
|
|
72
|
-
|
|
73
|
-
/** @deprecated Compatibility surface for older Chromium previews. */
|
|
74
|
-
modelContextTesting?: ModelContextTesting;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
interface SubmitEvent {
|
|
78
|
-
/**
|
|
79
|
-
* True when a declarative WebMCP tool initiated this submission.
|
|
80
|
-
*
|
|
81
|
-
* Optional because declarative forms are explainer-only: this attribute is
|
|
82
|
-
* in neither the WebMCP specification nor WPT's `webmcp.idl`, and no
|
|
83
|
-
* browser implements it. `@mcp-b/webmcp-polyfill` installs it.
|
|
84
|
-
*/
|
|
85
|
-
readonly agentInvoked?: boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Associates an intercepted form submission result with the invoking agent.
|
|
89
|
-
*
|
|
90
|
-
* Optional for the same reason as {@link SubmitEvent.agentInvoked}.
|
|
91
|
-
*/
|
|
92
|
-
respondWith?(agentResponse: Promise<unknown>): void;
|
|
93
|
-
}
|
|
94
|
-
}
|
package/src/json-schema.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type { JsonSchemaType as McpJsonSchema } from '@modelcontextprotocol/server';
|
|
3
|
-
|
|
4
|
-
/** JSON Schema Draft 2020-12 accepted by the inference helpers. */
|
|
5
|
-
export type JsonSchemaForInference = McpJsonSchema;
|
|
6
|
-
|
|
7
|
-
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'object' | 'array';
|
|
8
|
-
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
9
|
-
type EmptyObject = Record<never, never>;
|
|
10
|
-
|
|
11
|
-
type ConstValue<TSchema> = TSchema extends { const: infer TValue } ? TValue : never;
|
|
12
|
-
type EnumValue<TSchema> = TSchema extends { enum: readonly (infer TValue)[] } ? TValue : never;
|
|
13
|
-
type Properties<TSchema> = TSchema extends {
|
|
14
|
-
properties: infer TProperties extends Readonly<Record<string, unknown>>;
|
|
15
|
-
}
|
|
16
|
-
? TProperties
|
|
17
|
-
: EmptyObject;
|
|
18
|
-
type RequiredKeys<TSchema> = TSchema extends { required: readonly (infer TKey extends string)[] }
|
|
19
|
-
? string extends TKey
|
|
20
|
-
? never
|
|
21
|
-
: Extract<TKey, keyof Properties<TSchema>>
|
|
22
|
-
: never;
|
|
23
|
-
|
|
24
|
-
type AdditionalProperties<TSchema> = TSchema extends { additionalProperties: false }
|
|
25
|
-
? keyof Properties<TSchema> extends never
|
|
26
|
-
? Record<string, never>
|
|
27
|
-
: EmptyObject
|
|
28
|
-
: keyof Properties<TSchema> extends never
|
|
29
|
-
? TSchema extends { additionalProperties: infer TAdditional extends object }
|
|
30
|
-
? Record<string, InferJsonSchema<TAdditional>>
|
|
31
|
-
: Record<string, unknown>
|
|
32
|
-
: Record<string, unknown>;
|
|
33
|
-
|
|
34
|
-
type InferObject<TSchema> = Simplify<
|
|
35
|
-
{
|
|
36
|
-
-readonly [K in keyof Properties<TSchema> as K extends RequiredKeys<TSchema>
|
|
37
|
-
? K
|
|
38
|
-
: never]-?: InferJsonSchema<Properties<TSchema>[K]>;
|
|
39
|
-
} & {
|
|
40
|
-
-readonly [K in keyof Properties<TSchema> as K extends RequiredKeys<TSchema>
|
|
41
|
-
? never
|
|
42
|
-
: K]?: InferJsonSchema<Properties<TSchema>[K]>;
|
|
43
|
-
} & AdditionalProperties<TSchema>
|
|
44
|
-
>;
|
|
45
|
-
|
|
46
|
-
type TypeKeyword<TSchema> = TSchema extends { type: infer TType }
|
|
47
|
-
? TType
|
|
48
|
-
: TSchema extends
|
|
49
|
-
| { properties: unknown }
|
|
50
|
-
| { required: unknown }
|
|
51
|
-
| { additionalProperties: unknown }
|
|
52
|
-
? 'object'
|
|
53
|
-
: never;
|
|
54
|
-
type TypeOptions<TSchema> =
|
|
55
|
-
TypeKeyword<TSchema> extends readonly unknown[]
|
|
56
|
-
? Extract<TypeKeyword<TSchema>[number], JsonSchemaType>
|
|
57
|
-
: Extract<TypeKeyword<TSchema>, JsonSchemaType>;
|
|
58
|
-
|
|
59
|
-
type InferType<TSchema, TType extends JsonSchemaType> = TType extends 'object'
|
|
60
|
-
? InferObject<TSchema>
|
|
61
|
-
: TType extends 'array'
|
|
62
|
-
? TSchema extends { items: infer TItems }
|
|
63
|
-
? InferJsonSchema<TItems>[]
|
|
64
|
-
: unknown[]
|
|
65
|
-
: TType extends 'string'
|
|
66
|
-
? string
|
|
67
|
-
: TType extends 'number' | 'integer'
|
|
68
|
-
? number
|
|
69
|
-
: TType extends 'boolean'
|
|
70
|
-
? boolean
|
|
71
|
-
: TType extends 'null'
|
|
72
|
-
? null
|
|
73
|
-
: unknown;
|
|
74
|
-
|
|
75
|
-
/** Infers a TypeScript value from the supported JSON Schema keywords. */
|
|
76
|
-
export type InferJsonSchema<TSchema> = TSchema extends false
|
|
77
|
-
? never
|
|
78
|
-
: TSchema extends true
|
|
79
|
-
? unknown
|
|
80
|
-
: [InputSchema] extends [TSchema]
|
|
81
|
-
? unknown
|
|
82
|
-
: [ConstValue<TSchema>] extends [never]
|
|
83
|
-
? [EnumValue<TSchema>] extends [never]
|
|
84
|
-
? TypeOptions<TSchema> extends never
|
|
85
|
-
? unknown
|
|
86
|
-
: InferType<TSchema, TypeOptions<TSchema>>
|
|
87
|
-
: EnumValue<TSchema>
|
|
88
|
-
: ConstValue<TSchema>;
|
|
89
|
-
|
|
90
|
-
/** Infers the object or array passed to a WebMCP tool callback. */
|
|
91
|
-
export type InferArgsFromInputSchema<TSchema> = [
|
|
92
|
-
Extract<Exclude<InferJsonSchema<TSchema>, null | undefined>, WebMcpToolInput>,
|
|
93
|
-
] extends [never]
|
|
94
|
-
? WebMcpToolInput
|
|
95
|
-
: Extract<Exclude<InferJsonSchema<TSchema>, null | undefined>, WebMcpToolInput>;
|
package/src/model-context.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type { JsonSchemaForInference } from './json-schema.js';
|
|
3
|
-
import type {
|
|
4
|
-
ModelContextTool,
|
|
5
|
-
ModelContextToolFromSchema,
|
|
6
|
-
ToolDescriptor,
|
|
7
|
-
ToolDescriptorFromSchema,
|
|
8
|
-
ToolListItem,
|
|
9
|
-
WebMcpToolAnnotations,
|
|
10
|
-
} from './tool.js';
|
|
11
|
-
|
|
12
|
-
/** Options for tools exposed by descendant documents. */
|
|
13
|
-
export interface ModelContextGetToolOptions {
|
|
14
|
-
fromOrigins?: string[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Tool metadata returned by `document.modelContext.getTools()`. */
|
|
18
|
-
export interface RegisteredTool {
|
|
19
|
-
name: string;
|
|
20
|
-
/**
|
|
21
|
-
* Present on every tool Chrome and `@mcp-b/webmcp-polyfill` return today --
|
|
22
|
-
* the spec defaults it to the empty string when a tool registers no title.
|
|
23
|
-
* Kept optional deliberately: webmcp#224 proposes dropping that default and
|
|
24
|
-
* omitting the member instead. Read it as `tool.title || tool.name`: today the
|
|
25
|
-
* spec default makes it an empty string, which `??` does not fall through.
|
|
26
|
-
*/
|
|
27
|
-
title?: string;
|
|
28
|
-
description: string;
|
|
29
|
-
/**
|
|
30
|
-
* A JSON Schema object since webmcp#241, rolling out from Chrome 154.0.8013
|
|
31
|
-
* (cross-document tools first). Chrome 149-153 -- most of the Origin Trial
|
|
32
|
-
* population -- and 154's same-document tools still return the serialized
|
|
33
|
-
* JSON string the change replaced. Consumers that support both generations
|
|
34
|
-
* must branch on `typeof` and guard the parse of the string arm.
|
|
35
|
-
*/
|
|
36
|
-
inputSchema?: InputSchema | string;
|
|
37
|
-
window: Window;
|
|
38
|
-
origin: string;
|
|
39
|
-
/**
|
|
40
|
-
* Absent when the tool registered no annotations -- both the spec and the
|
|
41
|
-
* polyfill omit the member rather than emitting an empty object. Each hint
|
|
42
|
-
* inside it is always populated, but the object itself is not guaranteed.
|
|
43
|
-
*/
|
|
44
|
-
annotations?: WebMcpToolAnnotations;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ChromeModelContextExecuteToolOptions {
|
|
48
|
-
signal?: AbortSignal;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Experimental Chromium methods; feature-detect them before use. */
|
|
52
|
-
export interface ChromeModelContextExtensions {
|
|
53
|
-
executeTool?(
|
|
54
|
-
tool: RegisteredTool,
|
|
55
|
-
inputArguments: string,
|
|
56
|
-
options?: ChromeModelContextExecuteToolOptions
|
|
57
|
-
): Promise<string | null>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** @deprecated Metadata returned by `navigator.modelContextTesting`. */
|
|
61
|
-
export interface ModelContextTestingToolInfo {
|
|
62
|
-
name: string;
|
|
63
|
-
description: string;
|
|
64
|
-
inputSchema?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** @deprecated Compatibility surface for Chromium's removed testing API. */
|
|
68
|
-
export interface ModelContextTesting extends EventTarget {
|
|
69
|
-
listTools(): ModelContextTestingToolInfo[];
|
|
70
|
-
executeTool(
|
|
71
|
-
toolName: string,
|
|
72
|
-
inputArgsJson: string,
|
|
73
|
-
options?: ChromeModelContextExecuteToolOptions
|
|
74
|
-
): Promise<string | null>;
|
|
75
|
-
ontoolchange: ((this: ModelContextTesting, event: Event) => unknown) | null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Options accepted by `ModelContext.registerTool()`. */
|
|
79
|
-
export interface ModelContextRegisterToolOptions {
|
|
80
|
-
signal?: AbortSignal;
|
|
81
|
-
exposedTo?: string[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
type WidenedSchema<TSchema extends InputSchema> = string extends TSchema['type'] ? unknown : never;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Standard `document.modelContext` API.
|
|
88
|
-
* @see https://webmachinelearning.github.io/webmcp/#modelcontext
|
|
89
|
-
*/
|
|
90
|
-
export interface ModelContext extends EventTarget {
|
|
91
|
-
registerTool<
|
|
92
|
-
const TInputSchema extends JsonSchemaForInference,
|
|
93
|
-
TResult = unknown,
|
|
94
|
-
TName extends string = string,
|
|
95
|
-
>(
|
|
96
|
-
tool: ModelContextToolFromSchema<TInputSchema, TResult, TName>,
|
|
97
|
-
options?: ModelContextRegisterToolOptions
|
|
98
|
-
): Promise<void>;
|
|
99
|
-
|
|
100
|
-
registerTool<
|
|
101
|
-
TInputSchema extends InputSchema,
|
|
102
|
-
TArgs extends WebMcpToolInput = WebMcpToolInput,
|
|
103
|
-
TResult = unknown,
|
|
104
|
-
TName extends string = string,
|
|
105
|
-
>(
|
|
106
|
-
tool: ModelContextTool<TArgs, TResult, TName> & {
|
|
107
|
-
inputSchema: TInputSchema;
|
|
108
|
-
} & WidenedSchema<TInputSchema>,
|
|
109
|
-
options?: ModelContextRegisterToolOptions
|
|
110
|
-
): Promise<void>;
|
|
111
|
-
|
|
112
|
-
registerTool<
|
|
113
|
-
TArgs extends WebMcpToolInput = Record<string, unknown>,
|
|
114
|
-
TResult = unknown,
|
|
115
|
-
TName extends string = string,
|
|
116
|
-
>(
|
|
117
|
-
tool: Omit<ModelContextTool<TArgs, TResult, TName>, 'inputSchema'> & {
|
|
118
|
-
inputSchema?: undefined;
|
|
119
|
-
},
|
|
120
|
-
options?: ModelContextRegisterToolOptions
|
|
121
|
-
): Promise<void>;
|
|
122
|
-
|
|
123
|
-
getTools(options?: ModelContextGetToolOptions): Promise<RegisteredTool[]>;
|
|
124
|
-
ontoolchange: ((this: ModelContext, event: Event) => unknown) | null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Non-standard methods exposed by MCP-B runtimes. */
|
|
128
|
-
export interface ModelContextExtensions {
|
|
129
|
-
registerTool<
|
|
130
|
-
const TInputSchema extends JsonSchemaForInference,
|
|
131
|
-
const TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
132
|
-
TName extends string = string,
|
|
133
|
-
>(
|
|
134
|
-
tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>,
|
|
135
|
-
options?: ModelContextRegisterToolOptions
|
|
136
|
-
): Promise<void>;
|
|
137
|
-
|
|
138
|
-
registerTool<
|
|
139
|
-
TInputSchema extends InputSchema,
|
|
140
|
-
TArgs extends WebMcpToolInput = WebMcpToolInput,
|
|
141
|
-
TName extends string = string,
|
|
142
|
-
>(
|
|
143
|
-
tool: ToolDescriptor<TArgs, unknown, TName> & {
|
|
144
|
-
inputSchema: TInputSchema;
|
|
145
|
-
} & WidenedSchema<TInputSchema>,
|
|
146
|
-
options?: ModelContextRegisterToolOptions
|
|
147
|
-
): Promise<void>;
|
|
148
|
-
|
|
149
|
-
registerTool<
|
|
150
|
-
TArgs extends WebMcpToolInput = Record<string, unknown>,
|
|
151
|
-
TName extends string = string,
|
|
152
|
-
>(
|
|
153
|
-
tool: Omit<ToolDescriptor<TArgs, unknown, TName>, 'inputSchema'> & {
|
|
154
|
-
inputSchema?: undefined;
|
|
155
|
-
},
|
|
156
|
-
options?: ModelContextRegisterToolOptions
|
|
157
|
-
): Promise<void>;
|
|
158
|
-
|
|
159
|
-
listTools(): ToolListItem[];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export type ChromeModelContext = ModelContext & ChromeModelContextExtensions;
|
|
163
|
-
export type ModelContextWithExtensions = Omit<ModelContext, 'registerTool'> &
|
|
164
|
-
ModelContextExtensions;
|
package/src/tool.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { CallToolResult, InputSchema, WebMcpToolInput } from './common.js';
|
|
2
|
-
import type {
|
|
3
|
-
InferArgsFromInputSchema,
|
|
4
|
-
InferJsonSchema,
|
|
5
|
-
JsonSchemaForInference,
|
|
6
|
-
} from './json-schema.js';
|
|
7
|
-
import type { ToolAnnotations as McpToolAnnotations } from '@modelcontextprotocol/server';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Annotations in the WebMCP tool dictionary.
|
|
11
|
-
* @see https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
|
|
12
|
-
*/
|
|
13
|
-
export interface WebMcpToolAnnotations {
|
|
14
|
-
readOnlyHint?: boolean;
|
|
15
|
-
untrustedContentHint?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** MCP annotations plus WebMCP's untrusted-content hint. */
|
|
19
|
-
export type ToolAnnotations = McpToolAnnotations & WebMcpToolAnnotations;
|
|
20
|
-
|
|
21
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Tool dictionary accepted by the standard browser API.
|
|
25
|
-
* @see https://webmachinelearning.github.io/webmcp/#dictdef-modelcontexttool
|
|
26
|
-
*/
|
|
27
|
-
export interface ModelContextTool<
|
|
28
|
-
TArgs extends WebMcpToolInput = Record<string, unknown>,
|
|
29
|
-
TResult = unknown,
|
|
30
|
-
TName extends string = string,
|
|
31
|
-
> {
|
|
32
|
-
name: TName;
|
|
33
|
-
title?: string;
|
|
34
|
-
description: string;
|
|
35
|
-
inputSchema?: InputSchema | undefined;
|
|
36
|
-
annotations?: WebMcpToolAnnotations;
|
|
37
|
-
execute: (input: TArgs) => MaybePromise<TResult>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Standard tool dictionary with input inferred from a JSON Schema literal. */
|
|
41
|
-
export type ModelContextToolFromSchema<
|
|
42
|
-
TInputSchema extends InputSchema,
|
|
43
|
-
TResult = unknown,
|
|
44
|
-
TName extends string = string,
|
|
45
|
-
> = Omit<
|
|
46
|
-
ModelContextTool<InferArgsFromInputSchema<TInputSchema>, TResult, TName>,
|
|
47
|
-
'inputSchema'
|
|
48
|
-
> & {
|
|
49
|
-
inputSchema: TInputSchema;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** MCP-B tool dictionary with output metadata. */
|
|
53
|
-
export type ToolDescriptor<
|
|
54
|
-
TArgs extends WebMcpToolInput = Record<string, unknown>,
|
|
55
|
-
TResult = unknown,
|
|
56
|
-
TName extends string = string,
|
|
57
|
-
> = Omit<ModelContextTool<TArgs, TResult, TName>, 'annotations'> & {
|
|
58
|
-
outputSchema?: JsonSchemaForInference;
|
|
59
|
-
annotations?: ToolAnnotations;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/** MCP response with `structuredContent` inferred from an output schema. */
|
|
63
|
-
export type ToolResultFromOutputSchema<
|
|
64
|
-
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
65
|
-
> = [TOutputSchema] extends [undefined]
|
|
66
|
-
? CallToolResult
|
|
67
|
-
: TOutputSchema extends JsonSchemaForInference
|
|
68
|
-
? Omit<CallToolResult, 'structuredContent'> & {
|
|
69
|
-
structuredContent: InferJsonSchema<TOutputSchema>;
|
|
70
|
-
}
|
|
71
|
-
: never;
|
|
72
|
-
|
|
73
|
-
type ExecuteResult<TOutputSchema extends JsonSchemaForInference | undefined> = [
|
|
74
|
-
TOutputSchema,
|
|
75
|
-
] extends [undefined]
|
|
76
|
-
? unknown
|
|
77
|
-
: TOutputSchema extends JsonSchemaForInference
|
|
78
|
-
? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema>
|
|
79
|
-
: never;
|
|
80
|
-
|
|
81
|
-
/** Tool dictionary with input and output inferred from JSON Schema literals. */
|
|
82
|
-
export type ToolDescriptorFromSchema<
|
|
83
|
-
TInputSchema extends InputSchema,
|
|
84
|
-
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
85
|
-
TName extends string = string,
|
|
86
|
-
> = Omit<
|
|
87
|
-
ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ExecuteResult<TOutputSchema>, TName>,
|
|
88
|
-
'inputSchema' | 'outputSchema'
|
|
89
|
-
> & {
|
|
90
|
-
inputSchema: TInputSchema;
|
|
91
|
-
} & ([TOutputSchema] extends [undefined]
|
|
92
|
-
? { outputSchema?: undefined }
|
|
93
|
-
: { outputSchema: TOutputSchema });
|
|
94
|
-
|
|
95
|
-
/** Tool metadata returned by the MCP-B `listTools()` extension. */
|
|
96
|
-
export type ToolListItem<TName extends string = string> = Omit<
|
|
97
|
-
ToolDescriptor<Record<string, unknown>, unknown, TName>,
|
|
98
|
-
'execute' | 'inputSchema'
|
|
99
|
-
> & {
|
|
100
|
-
inputSchema: InputSchema;
|
|
101
|
-
};
|