@mcp-b/webmcp-types 0.0.0-beta-20260216200013
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 +307 -0
- package/dist/common.d.ts +297 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/json-schema.d.ts +198 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/model-context.d.ts +232 -0
- package/dist/model-context.d.ts.map +1 -0
- package/dist/standard-schema.d.ts +32 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/tool.d.ts +153 -0
- package/dist/tool.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/common.ts +368 -0
- package/src/index.ts +95 -0
- package/src/json-schema.ts +290 -0
- package/src/model-context.ts +346 -0
- package/src/tool.ts +207 -0
package/src/tool.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CallToolResult,
|
|
3
|
+
ElicitationParams,
|
|
4
|
+
ElicitationResult,
|
|
5
|
+
InputSchema,
|
|
6
|
+
} from './common.js';
|
|
7
|
+
import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaObject } from './json-schema.js';
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Tool Annotations
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Annotations providing hints about tool behavior.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
17
|
+
*/
|
|
18
|
+
export interface ToolAnnotations {
|
|
19
|
+
/**
|
|
20
|
+
* Optional display title.
|
|
21
|
+
*/
|
|
22
|
+
title?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Indicates the tool is read-only.
|
|
26
|
+
*/
|
|
27
|
+
readOnlyHint?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Indicates the tool may perform destructive actions.
|
|
31
|
+
*/
|
|
32
|
+
destructiveHint?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Indicates the tool can be called repeatedly without changing outcome.
|
|
36
|
+
*/
|
|
37
|
+
idempotentHint?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Indicates the tool may reach beyond local context (network, external systems, etc.).
|
|
41
|
+
*/
|
|
42
|
+
openWorldHint?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Tool Descriptor
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Per-call client provided to tool handlers.
|
|
51
|
+
*/
|
|
52
|
+
export interface ModelContextClient {
|
|
53
|
+
/**
|
|
54
|
+
* Requests user interaction during the current tool call.
|
|
55
|
+
*/
|
|
56
|
+
requestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* MCPB extension context with additional elicitation helper.
|
|
61
|
+
*/
|
|
62
|
+
export interface ToolExecutionContext extends ModelContextClient {
|
|
63
|
+
/**
|
|
64
|
+
* Requests user input for the current tool call.
|
|
65
|
+
*
|
|
66
|
+
* This function is bound to the active tool call and should only be used
|
|
67
|
+
* during execution of that call.
|
|
68
|
+
*/
|
|
69
|
+
elicitInput(params: ElicitationParams): Promise<ElicitationResult>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Value that may be returned synchronously or via Promise.
|
|
74
|
+
*/
|
|
75
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Tool descriptor for the Web Model Context API.
|
|
79
|
+
*
|
|
80
|
+
* Tools are functions that AI models can call to perform actions or retrieve
|
|
81
|
+
* information. This interface uses JSON Schema for input/output typing.
|
|
82
|
+
*
|
|
83
|
+
* @template TArgs - Tool input arguments.
|
|
84
|
+
* @template TResult - Tool execution result shape.
|
|
85
|
+
* @template TName - Tool name literal type.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
88
|
+
*/
|
|
89
|
+
export interface ToolDescriptor<
|
|
90
|
+
TArgs extends Record<string, unknown> = Record<string, unknown>,
|
|
91
|
+
TResult extends CallToolResult = CallToolResult,
|
|
92
|
+
TName extends string = string,
|
|
93
|
+
> {
|
|
94
|
+
/**
|
|
95
|
+
* Unique tool identifier.
|
|
96
|
+
*/
|
|
97
|
+
name: TName;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Human-readable summary of what the tool does.
|
|
101
|
+
*/
|
|
102
|
+
description: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Schema describing accepted input arguments.
|
|
106
|
+
*/
|
|
107
|
+
inputSchema?: InputSchema;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Optional schema describing output payload shape.
|
|
111
|
+
*/
|
|
112
|
+
outputSchema?: InputSchema;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Optional behavior hints for LLM planners.
|
|
116
|
+
*/
|
|
117
|
+
annotations?: ToolAnnotations;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Tool execution function.
|
|
121
|
+
*/
|
|
122
|
+
execute: (args: TArgs, client: ModelContextClient) => MaybePromise<TResult>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Tool response shape inferred from an `outputSchema`.
|
|
127
|
+
*
|
|
128
|
+
* When a literal object output schema is provided, `structuredContent` is
|
|
129
|
+
* narrowed to the inferred schema type. Otherwise, this resolves to the
|
|
130
|
+
* base `CallToolResult`.
|
|
131
|
+
*
|
|
132
|
+
* @template TOutputSchema - Optional literal JSON object schema.
|
|
133
|
+
*/
|
|
134
|
+
export type ToolResultFromOutputSchema<
|
|
135
|
+
TOutputSchema extends JsonSchemaObject | undefined = undefined,
|
|
136
|
+
> = TOutputSchema extends JsonSchemaObject
|
|
137
|
+
? CallToolResult & { structuredContent?: InferJsonSchema<TOutputSchema> }
|
|
138
|
+
: CallToolResult;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Tool descriptor whose `execute` args are inferred from a JSON Schema.
|
|
142
|
+
*
|
|
143
|
+
* For widened/non-literal schemas, arguments fall back to `Record<string, unknown>`.
|
|
144
|
+
* When `outputSchema` is an inferable literal object schema, `structuredContent` is inferred.
|
|
145
|
+
*
|
|
146
|
+
* @template TInputSchema - JSON Schema for tool arguments.
|
|
147
|
+
* @template TOutputSchema - Optional JSON schema for `structuredContent`.
|
|
148
|
+
* @template TName - Tool name literal type.
|
|
149
|
+
* @template TResult - Optional result type override constrained by inferred output schema.
|
|
150
|
+
*/
|
|
151
|
+
export type ToolDescriptorFromSchema<
|
|
152
|
+
TInputSchema extends { type: string | readonly string[] },
|
|
153
|
+
TOutputSchema extends JsonSchemaObject | undefined = undefined,
|
|
154
|
+
TName extends string = string,
|
|
155
|
+
> = Omit<
|
|
156
|
+
ToolDescriptor<
|
|
157
|
+
InferArgsFromInputSchema<TInputSchema>,
|
|
158
|
+
ToolResultFromOutputSchema<TOutputSchema>,
|
|
159
|
+
TName
|
|
160
|
+
>,
|
|
161
|
+
'inputSchema' | 'outputSchema'
|
|
162
|
+
> & {
|
|
163
|
+
inputSchema: TInputSchema;
|
|
164
|
+
} & (TOutputSchema extends JsonSchemaObject
|
|
165
|
+
? {
|
|
166
|
+
outputSchema: TOutputSchema;
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
outputSchema?: undefined;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Tool List Item
|
|
174
|
+
// ============================================================================
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Tool information returned by listTools().
|
|
178
|
+
* Provides metadata about a registered tool without exposing the execute function.
|
|
179
|
+
*
|
|
180
|
+
* @template TName - Tool name literal type.
|
|
181
|
+
*/
|
|
182
|
+
export interface ToolListItem<TName extends string = string> {
|
|
183
|
+
/**
|
|
184
|
+
* Unique tool identifier.
|
|
185
|
+
*/
|
|
186
|
+
name: TName;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Human-readable summary of what the tool does.
|
|
190
|
+
*/
|
|
191
|
+
description: string;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* JSON Schema describing accepted input arguments.
|
|
195
|
+
*/
|
|
196
|
+
inputSchema: InputSchema;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Optional JSON Schema describing output payload shape.
|
|
200
|
+
*/
|
|
201
|
+
outputSchema?: InputSchema;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Optional behavior hints for LLM planners.
|
|
205
|
+
*/
|
|
206
|
+
annotations?: ToolAnnotations;
|
|
207
|
+
}
|