@mcp-b/webmcp-types 4.0.0 → 5.0.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 +1 -1
- package/README.md +61 -175
- package/dist/common.d.ts +11 -293
- package/dist/common.d.ts.map +1 -1
- package/dist/index.d.ts +36 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/json-schema.d.ts +42 -186
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/model-context.d.ts +64 -276
- package/dist/model-context.d.ts.map +1 -1
- package/dist/tool.d.ts +38 -156
- package/dist/tool.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/common.ts +17 -362
- package/src/index.ts +45 -67
- package/src/json-schema.ts +62 -266
- package/src/model-context.ts +101 -378
- package/src/tool.ts +65 -212
package/src/tool.ts
CHANGED
|
@@ -1,248 +1,101 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CallToolResult,
|
|
3
|
-
ElicitationParams,
|
|
4
|
-
ElicitationResult,
|
|
5
|
-
InputSchema,
|
|
6
|
-
} from './common.js';
|
|
1
|
+
import type { CallToolResult, InputSchema, WebMcpToolInput } from './common.js';
|
|
7
2
|
import type {
|
|
8
3
|
InferArgsFromInputSchema,
|
|
9
4
|
InferJsonSchema,
|
|
10
5
|
JsonSchemaForInference,
|
|
11
6
|
} from './json-schema.js';
|
|
12
|
-
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// Tool Annotations
|
|
15
|
-
// ============================================================================
|
|
7
|
+
import type { ToolAnnotations as McpToolAnnotations } from '@modelcontextprotocol/server';
|
|
16
8
|
|
|
17
9
|
/**
|
|
18
|
-
* Annotations
|
|
19
|
-
*
|
|
20
|
-
* @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations}
|
|
21
|
-
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
10
|
+
* Annotations in the WebMCP tool dictionary.
|
|
11
|
+
* @see https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
|
|
22
12
|
*/
|
|
23
|
-
export interface
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
title?: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Indicates the tool is read-only.
|
|
31
|
-
*/
|
|
32
|
-
readOnlyHint?: boolean | 'true' | 'false';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Indicates the tool's output may include content from outside the page's trust boundary.
|
|
36
|
-
*/
|
|
37
|
-
untrustedContentHint?: boolean | 'true' | 'false';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Indicates the tool may perform destructive actions.
|
|
41
|
-
*/
|
|
42
|
-
destructiveHint?: boolean | 'true' | 'false';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Indicates the tool can be called repeatedly without changing outcome.
|
|
46
|
-
*/
|
|
47
|
-
idempotentHint?: boolean | 'true' | 'false';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Indicates the tool may reach beyond local context (network, external systems, etc.).
|
|
51
|
-
*/
|
|
52
|
-
openWorldHint?: boolean | 'true' | 'false';
|
|
13
|
+
export interface WebMcpToolAnnotations {
|
|
14
|
+
readOnlyHint?: boolean;
|
|
15
|
+
untrustedContentHint?: boolean;
|
|
53
16
|
}
|
|
54
17
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
export type ToolRawResult = unknown;
|
|
18
|
+
/** MCP annotations plus WebMCP's untrusted-content hint. */
|
|
19
|
+
export type ToolAnnotations = McpToolAnnotations & WebMcpToolAnnotations;
|
|
59
20
|
|
|
60
|
-
/**
|
|
61
|
-
* Tool execute return value accepted by WebMCP descriptor types.
|
|
62
|
-
*/
|
|
63
|
-
export type ToolExecuteResult<TResult = ToolRawResult> = TResult extends CallToolResult
|
|
64
|
-
? TResult
|
|
65
|
-
: CallToolResult | TResult;
|
|
66
|
-
|
|
67
|
-
// ============================================================================
|
|
68
|
-
// Tool Descriptor
|
|
69
|
-
// ============================================================================
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Per-call client provided to tool handlers.
|
|
73
|
-
*/
|
|
74
|
-
export interface ModelContextClient {
|
|
75
|
-
/**
|
|
76
|
-
* Requests user interaction during the current tool call.
|
|
77
|
-
*/
|
|
78
|
-
requestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* MCPB extension context with additional elicitation helper.
|
|
83
|
-
*/
|
|
84
|
-
export interface ToolExecutionContext extends ModelContextClient {
|
|
85
|
-
/**
|
|
86
|
-
* Requests user input for the current tool call.
|
|
87
|
-
*
|
|
88
|
-
* This function is bound to the active tool call and should only be used
|
|
89
|
-
* during execution of that call.
|
|
90
|
-
*/
|
|
91
|
-
elicitInput(params: ElicitationParams): Promise<ElicitationResult>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Value that may be returned synchronously or via Promise.
|
|
96
|
-
*/
|
|
97
21
|
export type MaybePromise<T> = T | Promise<T>;
|
|
98
22
|
|
|
99
23
|
/**
|
|
100
|
-
* Tool
|
|
101
|
-
*
|
|
102
|
-
* Tools are functions that AI models can call to perform actions or retrieve
|
|
103
|
-
* information. This interface uses JSON Schema for input/output typing.
|
|
104
|
-
*
|
|
105
|
-
* @template TArgs - Tool input arguments.
|
|
106
|
-
* @template TResult - Tool execution raw result shape (or full CallToolResult).
|
|
107
|
-
* @template TName - Tool name literal type.
|
|
108
|
-
*
|
|
109
|
-
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
24
|
+
* Tool dictionary accepted by the standard browser API.
|
|
25
|
+
* @see https://webmachinelearning.github.io/webmcp/#dictdef-modelcontexttool
|
|
110
26
|
*/
|
|
111
|
-
export interface
|
|
112
|
-
TArgs extends
|
|
113
|
-
TResult =
|
|
27
|
+
export interface ModelContextTool<
|
|
28
|
+
TArgs extends WebMcpToolInput = Record<string, unknown>,
|
|
29
|
+
TResult = unknown,
|
|
114
30
|
TName extends string = string,
|
|
115
31
|
> {
|
|
116
|
-
/**
|
|
117
|
-
* Unique tool identifier.
|
|
118
|
-
*/
|
|
119
32
|
name: TName;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Optional user-facing label.
|
|
123
|
-
*/
|
|
124
33
|
title?: string;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Human-readable summary of what the tool does.
|
|
128
|
-
*/
|
|
129
34
|
description: string;
|
|
35
|
+
inputSchema?: InputSchema | undefined;
|
|
36
|
+
annotations?: WebMcpToolAnnotations;
|
|
37
|
+
execute: (input: TArgs) => MaybePromise<TResult>;
|
|
38
|
+
}
|
|
130
39
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
};
|
|
135
51
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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'> & {
|
|
139
58
|
outputSchema?: JsonSchemaForInference;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Optional behavior hints for LLM planners.
|
|
143
|
-
*/
|
|
144
59
|
annotations?: ToolAnnotations;
|
|
60
|
+
};
|
|
145
61
|
|
|
146
|
-
|
|
147
|
-
* Tool execution function.
|
|
148
|
-
*/
|
|
149
|
-
execute: (args: TArgs, client: ModelContextClient) => MaybePromise<ToolExecuteResult<TResult>>;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Tool response shape inferred from an `outputSchema`.
|
|
154
|
-
*
|
|
155
|
-
* When a literal object output schema is provided, `structuredContent` is
|
|
156
|
-
* narrowed to the inferred schema type for wrapped MCP responses.
|
|
157
|
-
*
|
|
158
|
-
* @template TOutputSchema - Optional literal JSON object schema.
|
|
159
|
-
*/
|
|
62
|
+
/** MCP response with `structuredContent` inferred from an output schema. */
|
|
160
63
|
export type ToolResultFromOutputSchema<
|
|
161
64
|
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
162
|
-
> = TOutputSchema extends
|
|
163
|
-
?
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
65
|
+
> = [TOutputSchema] extends [undefined]
|
|
66
|
+
? CallToolResult
|
|
67
|
+
: TOutputSchema extends JsonSchemaForInference
|
|
68
|
+
? Omit<CallToolResult, 'structuredContent'> & {
|
|
69
|
+
structuredContent: InferJsonSchema<TOutputSchema>;
|
|
70
|
+
}
|
|
71
|
+
: never;
|
|
167
72
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
TOutputSchema extends JsonSchemaForInference
|
|
173
|
-
>
|
|
174
|
-
|
|
175
|
-
: ToolExecuteResult;
|
|
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;
|
|
176
80
|
|
|
177
|
-
/**
|
|
178
|
-
* Tool descriptor whose `execute` args are inferred from a JSON Schema.
|
|
179
|
-
*
|
|
180
|
-
* For widened/non-literal schemas, arguments fall back to `Record<string, unknown>`.
|
|
181
|
-
* When `outputSchema` is an inferable literal object schema, `structuredContent` is inferred.
|
|
182
|
-
*
|
|
183
|
-
* @template TInputSchema - JSON Schema for tool arguments.
|
|
184
|
-
* @template TOutputSchema - Optional JSON schema for `structuredContent`.
|
|
185
|
-
* @template TName - Tool name literal type.
|
|
186
|
-
* @template TResult - Optional result type override constrained by inferred output schema.
|
|
187
|
-
*/
|
|
81
|
+
/** Tool dictionary with input and output inferred from JSON Schema literals. */
|
|
188
82
|
export type ToolDescriptorFromSchema<
|
|
189
|
-
TInputSchema extends
|
|
83
|
+
TInputSchema extends InputSchema,
|
|
190
84
|
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
191
85
|
TName extends string = string,
|
|
192
86
|
> = Omit<
|
|
193
|
-
ToolDescriptor<
|
|
194
|
-
|
|
195
|
-
ToolExecuteResultFromOutputSchema<TOutputSchema>,
|
|
196
|
-
TName
|
|
197
|
-
>,
|
|
198
|
-
'execute' | 'inputSchema' | 'outputSchema'
|
|
87
|
+
ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ExecuteResult<TOutputSchema>, TName>,
|
|
88
|
+
'inputSchema' | 'outputSchema'
|
|
199
89
|
> & {
|
|
200
90
|
inputSchema: TInputSchema;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
outputSchema?: undefined;
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// ============================================================================
|
|
214
|
-
// Tool List Item
|
|
215
|
-
// ============================================================================
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Tool information returned by listTools().
|
|
219
|
-
* Provides metadata about a registered tool without exposing the execute function.
|
|
220
|
-
*
|
|
221
|
-
* @template TName - Tool name literal type.
|
|
222
|
-
*/
|
|
223
|
-
export interface ToolListItem<TName extends string = string> {
|
|
224
|
-
/**
|
|
225
|
-
* Unique tool identifier.
|
|
226
|
-
*/
|
|
227
|
-
name: TName;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Human-readable summary of what the tool does.
|
|
231
|
-
*/
|
|
232
|
-
description: string;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* JSON Schema describing accepted input arguments.
|
|
236
|
-
*/
|
|
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
|
+
> & {
|
|
237
100
|
inputSchema: InputSchema;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Optional JSON Schema describing output payload shape.
|
|
241
|
-
*/
|
|
242
|
-
outputSchema?: JsonSchemaForInference;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Optional behavior hints for LLM planners.
|
|
246
|
-
*/
|
|
247
|
-
annotations?: ToolAnnotations;
|
|
248
|
-
}
|
|
101
|
+
};
|