sunpeak 0.16.29 → 0.17.2
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/bin/commands/dev.mjs +169 -342
- package/bin/commands/inspect.mjs +763 -0
- package/bin/commands/new.mjs +2 -2
- package/bin/lib/inspect/inspect-config.d.mts +20 -0
- package/bin/lib/inspect/inspect-config.mjs +76 -0
- package/bin/lib/live/global-setup.mjs +6 -1
- package/bin/sunpeak.js +11 -1
- package/dist/chatgpt/globals.css +8 -0
- package/dist/chatgpt/index.cjs +3 -11
- package/dist/chatgpt/index.cjs.map +1 -1
- package/dist/chatgpt/index.d.ts +2 -2
- package/dist/chatgpt/index.js +4 -8
- package/dist/chatgpt/index.js.map +1 -1
- package/dist/claude/index.cjs +1 -1
- package/dist/claude/index.js +1 -1
- package/dist/discovery-Cgoegt62.js +114 -0
- package/dist/discovery-Cgoegt62.js.map +1 -0
- package/dist/discovery-Clu4uHp1.cjs +161 -0
- package/dist/discovery-Clu4uHp1.cjs.map +1 -0
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/discovery-cli.cjs +1 -1
- package/dist/lib/discovery-cli.js +1 -1
- package/dist/lib/discovery.d.ts +7 -67
- package/dist/lib/index.d.ts +0 -1
- package/dist/mcp/index.cjs +34 -23
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +34 -23
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +5 -0
- package/dist/simulator/index.cjs +5 -11
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.ts +4 -2
- package/dist/simulator/index.js +5 -8
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/simple-sidebar.d.ts +7 -4
- package/dist/simulator/simulator-url.d.ts +8 -0
- package/dist/simulator/simulator.d.ts +15 -2
- package/dist/simulator/use-mcp-connection.d.ts +19 -0
- package/dist/{simulator-DIVvI69i.cjs → simulator-CH9hs0N6.cjs} +129 -21
- package/dist/simulator-CH9hs0N6.cjs.map +1 -0
- package/dist/{simulator-C7mkK7Sz.js → simulator-Dl8B-Ljb.js} +124 -22
- package/dist/simulator-Dl8B-Ljb.js.map +1 -0
- package/dist/{simulator-url-BDGD4vZD.cjs → simulator-url-CozKF1jf.cjs} +3 -1
- package/dist/simulator-url-CozKF1jf.cjs.map +1 -0
- package/dist/{simulator-url-Bkxj43yT.js → simulator-url-KoS_ToP6.js} +3 -1
- package/dist/simulator-url-KoS_ToP6.js.map +1 -0
- package/dist/style.css +8 -0
- package/package.json +11 -3
- package/template/dist/albums/albums.html +105 -0
- package/template/dist/albums/albums.json +16 -0
- package/template/dist/carousel/carousel.html +105 -0
- package/template/dist/carousel/carousel.json +16 -0
- package/template/dist/map/map.html +3060 -0
- package/template/dist/map/map.json +22 -0
- package/template/dist/review/review.html +105 -0
- package/template/dist/review/review.json +16 -0
- package/template/dist/server.js +15 -0
- package/template/dist/tools/review-diff.js +50 -0
- package/template/dist/tools/review-post.js +50 -0
- package/template/dist/tools/review-purchase.js +61 -0
- package/template/dist/tools/review.js +31 -0
- package/template/dist/tools/show-albums.js +56 -0
- package/template/dist/tools/show-carousel.js +41 -0
- package/template/dist/tools/show-map.js +47 -0
- package/template/node_modules/.vite/deps/_metadata.json +8 -0
- package/template/node_modules/.vite/deps/package.json +3 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps.js +500 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_app-bridge.js +563 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_app-bridge.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_react.js +575 -0
- package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_react.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/@testing-library_react.js +11363 -0
- package/template/node_modules/.vite-mcp/deps/@testing-library_react.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/_metadata.json +130 -0
- package/template/node_modules/.vite-mcp/deps/chunk-BoAXSpZd.js +33 -0
- package/template/node_modules/.vite-mcp/deps/client-CU1wWud4.js +14385 -0
- package/template/node_modules/.vite-mcp/deps/client-CU1wWud4.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/clsx.js +18 -0
- package/template/node_modules/.vite-mcp/deps/clsx.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/dist-uWX8WbjY.js +505 -0
- package/template/node_modules/.vite-mcp/deps/dist-uWX8WbjY.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/embla-carousel-react.js +1461 -0
- package/template/node_modules/.vite-mcp/deps/embla-carousel-react.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/embla-carousel-wheel-gestures.js +536 -0
- package/template/node_modules/.vite-mcp/deps/embla-carousel-wheel-gestures.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/magic-string.es-Cklsmr-5.js +1013 -0
- package/template/node_modules/.vite-mcp/deps/magic-string.es-Cklsmr-5.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/mapbox-gl.js +46311 -0
- package/template/node_modules/.vite-mcp/deps/mapbox-gl.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/package.json +3 -0
- package/template/node_modules/.vite-mcp/deps/protocol-CTflwIfG.js +2090 -0
- package/template/node_modules/.vite-mcp/deps/protocol-CTflwIfG.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/react-dom.js +186 -0
- package/template/node_modules/.vite-mcp/deps/react-dom.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/react-dom_client.js +2 -0
- package/template/node_modules/.vite-mcp/deps/react.js +769 -0
- package/template/node_modules/.vite-mcp/deps/react.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/react_jsx-dev-runtime.js +205 -0
- package/template/node_modules/.vite-mcp/deps/react_jsx-dev-runtime.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/react_jsx-runtime.js +209 -0
- package/template/node_modules/.vite-mcp/deps/react_jsx-runtime.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/schemas-NsgmY9QV.js +12157 -0
- package/template/node_modules/.vite-mcp/deps/schemas-NsgmY9QV.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/tailwind-merge.js +2025 -0
- package/template/node_modules/.vite-mcp/deps/tailwind-merge.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/vitest.js +14021 -0
- package/template/node_modules/.vite-mcp/deps/vitest.js.map +1 -0
- package/template/node_modules/.vite-mcp/deps/zod.js +624 -0
- package/template/node_modules/.vite-mcp/deps/zod.js.map +1 -0
- package/template/src/tools/review-diff.test.ts +5 -1
- package/template/src/tools/review-diff.ts +1 -1
- package/template/src/tools/review-post.test.ts +5 -1
- package/template/src/tools/review-post.ts +1 -1
- package/template/src/tools/review-purchase.test.ts +5 -1
- package/template/src/tools/review-purchase.ts +1 -1
- package/template/src/tools/review.test.ts +5 -1
- package/template/src/tools/review.ts +1 -1
- package/template/src/tools/show-albums.test.ts +5 -1
- package/template/src/tools/show-albums.ts +1 -1
- package/template/src/tools/show-carousel.test.ts +5 -1
- package/template/src/tools/show-carousel.ts +1 -1
- package/template/src/tools/show-map.test.ts +5 -1
- package/template/src/tools/show-map.ts +1 -1
- package/dist/discovery-BxKCIgG5.cjs +0 -332
- package/dist/discovery-BxKCIgG5.cjs.map +0 -1
- package/dist/discovery-Du4LHrih.js +0 -261
- package/dist/discovery-Du4LHrih.js.map +0 -1
- package/dist/simulator-C7mkK7Sz.js.map +0 -1
- package/dist/simulator-DIVvI69i.cjs.map +0 -1
- package/dist/simulator-url-BDGD4vZD.cjs.map +0 -1
- package/dist/simulator-url-Bkxj43yT.js.map +0 -1
- package/template/.sunpeak/dev.tsx +0 -79
- package/template/.sunpeak/resource-loader.html +0 -20
- package/template/.sunpeak/resource-loader.tsx +0 -57
- package/template/index.html +0 -14
- package/template/src/resources/index.ts +0 -17
|
@@ -0,0 +1,2090 @@
|
|
|
1
|
+
import { Cn as object, In as string, It as custom, Jn as union, On as preprocess, Sn as number, Tt as array, Yn as unknown, jn as record, kt as boolean, ln as literal, mi as safeParse$1, tn as intersection, un as looseObject, vt as _enum, wn as optional, xr as datetime, xt as _null, zt as discriminatedUnion } from "./schemas-NsgmY9QV.js";
|
|
2
|
+
//#region ../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
3
|
+
function isZ4Schema(s) {
|
|
4
|
+
return !!s._zod;
|
|
5
|
+
}
|
|
6
|
+
function safeParse(schema, data) {
|
|
7
|
+
if (isZ4Schema(schema)) return safeParse$1(schema, data);
|
|
8
|
+
return schema.safeParse(data);
|
|
9
|
+
}
|
|
10
|
+
function getObjectShape(schema) {
|
|
11
|
+
if (!schema) return void 0;
|
|
12
|
+
let rawShape;
|
|
13
|
+
if (isZ4Schema(schema)) rawShape = schema._zod?.def?.shape;
|
|
14
|
+
else rawShape = schema.shape;
|
|
15
|
+
if (!rawShape) return void 0;
|
|
16
|
+
if (typeof rawShape === "function") try {
|
|
17
|
+
return rawShape();
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return rawShape;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gets the literal value from a schema, if it's a literal schema.
|
|
25
|
+
* Works with both Zod v3 and v4.
|
|
26
|
+
* Returns undefined if the schema is not a literal or the value cannot be determined.
|
|
27
|
+
*/
|
|
28
|
+
function getLiteralValue(schema) {
|
|
29
|
+
if (isZ4Schema(schema)) {
|
|
30
|
+
const def = schema._zod?.def;
|
|
31
|
+
if (def) {
|
|
32
|
+
if (def.value !== void 0) return def.value;
|
|
33
|
+
if (Array.isArray(def.values) && def.values.length > 0) return def.values[0];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const def = schema._def;
|
|
37
|
+
if (def) {
|
|
38
|
+
if (def.value !== void 0) return def.value;
|
|
39
|
+
if (Array.isArray(def.values) && def.values.length > 0) return def.values[0];
|
|
40
|
+
}
|
|
41
|
+
const directValue = schema.value;
|
|
42
|
+
if (directValue !== void 0) return directValue;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region ../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
46
|
+
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
47
|
+
/**
|
|
48
|
+
* Assert 'object' type schema.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
53
|
+
/**
|
|
54
|
+
* A progress token, used to associate progress notifications with the original request.
|
|
55
|
+
*/
|
|
56
|
+
var ProgressTokenSchema = union([string(), number().int()]);
|
|
57
|
+
/**
|
|
58
|
+
* An opaque token used to represent a cursor for pagination.
|
|
59
|
+
*/
|
|
60
|
+
var CursorSchema = string();
|
|
61
|
+
looseObject({
|
|
62
|
+
ttl: union([number(), _null()]).optional(),
|
|
63
|
+
pollInterval: number().optional()
|
|
64
|
+
});
|
|
65
|
+
var TaskMetadataSchema = object({ ttl: number().optional() });
|
|
66
|
+
/**
|
|
67
|
+
* Metadata for associating messages with a task.
|
|
68
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
69
|
+
*/
|
|
70
|
+
var RelatedTaskMetadataSchema = object({ taskId: string() });
|
|
71
|
+
var RequestMetaSchema = looseObject({
|
|
72
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
73
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Common params for any request.
|
|
77
|
+
*/
|
|
78
|
+
var BaseRequestParamsSchema = object({ _meta: RequestMetaSchema.optional() });
|
|
79
|
+
/**
|
|
80
|
+
* Common params for any task-augmented request.
|
|
81
|
+
*/
|
|
82
|
+
var TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({ task: TaskMetadataSchema.optional() });
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a value is a valid TaskAugmentedRequestParams.
|
|
85
|
+
* @param value - The value to check.
|
|
86
|
+
*
|
|
87
|
+
* @returns True if the value is a valid TaskAugmentedRequestParams, false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
var isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
|
|
90
|
+
var RequestSchema = object({
|
|
91
|
+
method: string(),
|
|
92
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
93
|
+
});
|
|
94
|
+
var NotificationsParamsSchema = object({ _meta: RequestMetaSchema.optional() });
|
|
95
|
+
var NotificationSchema = object({
|
|
96
|
+
method: string(),
|
|
97
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
98
|
+
});
|
|
99
|
+
var ResultSchema = looseObject({ _meta: RequestMetaSchema.optional() });
|
|
100
|
+
/**
|
|
101
|
+
* A uniquely identifying ID for a request in JSON-RPC.
|
|
102
|
+
*/
|
|
103
|
+
var RequestIdSchema = union([string(), number().int()]);
|
|
104
|
+
/**
|
|
105
|
+
* A request that expects a response.
|
|
106
|
+
*/
|
|
107
|
+
var JSONRPCRequestSchema = object({
|
|
108
|
+
jsonrpc: literal("2.0"),
|
|
109
|
+
id: RequestIdSchema,
|
|
110
|
+
...RequestSchema.shape
|
|
111
|
+
}).strict();
|
|
112
|
+
var isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success;
|
|
113
|
+
/**
|
|
114
|
+
* A notification which does not expect a response.
|
|
115
|
+
*/
|
|
116
|
+
var JSONRPCNotificationSchema = object({
|
|
117
|
+
jsonrpc: literal("2.0"),
|
|
118
|
+
...NotificationSchema.shape
|
|
119
|
+
}).strict();
|
|
120
|
+
var isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
|
|
121
|
+
/**
|
|
122
|
+
* A successful (non-error) response to a request.
|
|
123
|
+
*/
|
|
124
|
+
var JSONRPCResultResponseSchema = object({
|
|
125
|
+
jsonrpc: literal("2.0"),
|
|
126
|
+
id: RequestIdSchema,
|
|
127
|
+
result: ResultSchema
|
|
128
|
+
}).strict();
|
|
129
|
+
/**
|
|
130
|
+
* Checks if a value is a valid JSONRPCResultResponse.
|
|
131
|
+
* @param value - The value to check.
|
|
132
|
+
*
|
|
133
|
+
* @returns True if the value is a valid JSONRPCResultResponse, false otherwise.
|
|
134
|
+
*/
|
|
135
|
+
var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
|
|
136
|
+
/**
|
|
137
|
+
* Error codes defined by the JSON-RPC specification.
|
|
138
|
+
*/
|
|
139
|
+
var ErrorCode;
|
|
140
|
+
(function(ErrorCode) {
|
|
141
|
+
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
142
|
+
ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
143
|
+
ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
|
|
144
|
+
ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
145
|
+
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
146
|
+
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
147
|
+
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
148
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
149
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
150
|
+
/**
|
|
151
|
+
* A response to a request that indicates an error occurred.
|
|
152
|
+
*/
|
|
153
|
+
var JSONRPCErrorResponseSchema = object({
|
|
154
|
+
jsonrpc: literal("2.0"),
|
|
155
|
+
id: RequestIdSchema.optional(),
|
|
156
|
+
error: object({
|
|
157
|
+
code: number().int(),
|
|
158
|
+
message: string(),
|
|
159
|
+
data: unknown().optional()
|
|
160
|
+
})
|
|
161
|
+
}).strict();
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a value is a valid JSONRPCErrorResponse.
|
|
164
|
+
* @param value - The value to check.
|
|
165
|
+
*
|
|
166
|
+
* @returns True if the value is a valid JSONRPCErrorResponse, false otherwise.
|
|
167
|
+
*/
|
|
168
|
+
var isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
|
|
169
|
+
var JSONRPCMessageSchema = union([
|
|
170
|
+
JSONRPCRequestSchema,
|
|
171
|
+
JSONRPCNotificationSchema,
|
|
172
|
+
JSONRPCResultResponseSchema,
|
|
173
|
+
JSONRPCErrorResponseSchema
|
|
174
|
+
]);
|
|
175
|
+
union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
176
|
+
/**
|
|
177
|
+
* A response that indicates success but carries no data.
|
|
178
|
+
*/
|
|
179
|
+
var EmptyResultSchema = ResultSchema.strict();
|
|
180
|
+
var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
181
|
+
requestId: RequestIdSchema.optional(),
|
|
182
|
+
reason: string().optional()
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
186
|
+
*
|
|
187
|
+
* The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
|
|
188
|
+
*
|
|
189
|
+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
|
|
190
|
+
*
|
|
191
|
+
* A client MUST NOT attempt to cancel its `initialize` request.
|
|
192
|
+
*/
|
|
193
|
+
var CancelledNotificationSchema = NotificationSchema.extend({
|
|
194
|
+
method: literal("notifications/cancelled"),
|
|
195
|
+
params: CancelledNotificationParamsSchema
|
|
196
|
+
});
|
|
197
|
+
/**
|
|
198
|
+
* Base schema to add `icons` property.
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
var IconsSchema = object({ icons: array(object({
|
|
202
|
+
src: string(),
|
|
203
|
+
mimeType: string().optional(),
|
|
204
|
+
sizes: array(string()).optional(),
|
|
205
|
+
theme: _enum(["light", "dark"]).optional()
|
|
206
|
+
})).optional() });
|
|
207
|
+
/**
|
|
208
|
+
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
209
|
+
*/
|
|
210
|
+
var BaseMetadataSchema = object({
|
|
211
|
+
name: string(),
|
|
212
|
+
title: string().optional()
|
|
213
|
+
});
|
|
214
|
+
/**
|
|
215
|
+
* Describes the name and version of an MCP implementation.
|
|
216
|
+
*/
|
|
217
|
+
var ImplementationSchema = BaseMetadataSchema.extend({
|
|
218
|
+
...BaseMetadataSchema.shape,
|
|
219
|
+
...IconsSchema.shape,
|
|
220
|
+
version: string(),
|
|
221
|
+
websiteUrl: string().optional(),
|
|
222
|
+
description: string().optional()
|
|
223
|
+
});
|
|
224
|
+
var ElicitationCapabilitySchema = preprocess((value) => {
|
|
225
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
226
|
+
if (Object.keys(value).length === 0) return { form: {} };
|
|
227
|
+
}
|
|
228
|
+
return value;
|
|
229
|
+
}, intersection(object({
|
|
230
|
+
form: intersection(object({ applyDefaults: boolean().optional() }), record(string(), unknown())).optional(),
|
|
231
|
+
url: AssertObjectSchema.optional()
|
|
232
|
+
}), record(string(), unknown()).optional()));
|
|
233
|
+
/**
|
|
234
|
+
* Task capabilities for clients, indicating which request types support task creation.
|
|
235
|
+
*/
|
|
236
|
+
var ClientTasksCapabilitySchema = looseObject({
|
|
237
|
+
list: AssertObjectSchema.optional(),
|
|
238
|
+
cancel: AssertObjectSchema.optional(),
|
|
239
|
+
requests: looseObject({
|
|
240
|
+
sampling: looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
|
|
241
|
+
elicitation: looseObject({ create: AssertObjectSchema.optional() }).optional()
|
|
242
|
+
}).optional()
|
|
243
|
+
});
|
|
244
|
+
/**
|
|
245
|
+
* Task capabilities for servers, indicating which request types support task creation.
|
|
246
|
+
*/
|
|
247
|
+
var ServerTasksCapabilitySchema = looseObject({
|
|
248
|
+
list: AssertObjectSchema.optional(),
|
|
249
|
+
cancel: AssertObjectSchema.optional(),
|
|
250
|
+
requests: looseObject({ tools: looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
|
|
251
|
+
});
|
|
252
|
+
/**
|
|
253
|
+
* Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
|
|
254
|
+
*/
|
|
255
|
+
var ClientCapabilitiesSchema = object({
|
|
256
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
257
|
+
sampling: object({
|
|
258
|
+
context: AssertObjectSchema.optional(),
|
|
259
|
+
tools: AssertObjectSchema.optional()
|
|
260
|
+
}).optional(),
|
|
261
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
262
|
+
roots: object({ listChanged: boolean().optional() }).optional(),
|
|
263
|
+
tasks: ClientTasksCapabilitySchema.optional()
|
|
264
|
+
});
|
|
265
|
+
var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
266
|
+
protocolVersion: string(),
|
|
267
|
+
capabilities: ClientCapabilitiesSchema,
|
|
268
|
+
clientInfo: ImplementationSchema
|
|
269
|
+
});
|
|
270
|
+
/**
|
|
271
|
+
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
272
|
+
*/
|
|
273
|
+
var InitializeRequestSchema = RequestSchema.extend({
|
|
274
|
+
method: literal("initialize"),
|
|
275
|
+
params: InitializeRequestParamsSchema
|
|
276
|
+
});
|
|
277
|
+
/**
|
|
278
|
+
* Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
|
|
279
|
+
*/
|
|
280
|
+
var ServerCapabilitiesSchema = object({
|
|
281
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
282
|
+
logging: AssertObjectSchema.optional(),
|
|
283
|
+
completions: AssertObjectSchema.optional(),
|
|
284
|
+
prompts: object({ listChanged: boolean().optional() }).optional(),
|
|
285
|
+
resources: object({
|
|
286
|
+
subscribe: boolean().optional(),
|
|
287
|
+
listChanged: boolean().optional()
|
|
288
|
+
}).optional(),
|
|
289
|
+
tools: object({ listChanged: boolean().optional() }).optional(),
|
|
290
|
+
tasks: ServerTasksCapabilitySchema.optional()
|
|
291
|
+
});
|
|
292
|
+
/**
|
|
293
|
+
* After receiving an initialize request from the client, the server sends this response.
|
|
294
|
+
*/
|
|
295
|
+
var InitializeResultSchema = ResultSchema.extend({
|
|
296
|
+
protocolVersion: string(),
|
|
297
|
+
capabilities: ServerCapabilitiesSchema,
|
|
298
|
+
serverInfo: ImplementationSchema,
|
|
299
|
+
instructions: string().optional()
|
|
300
|
+
});
|
|
301
|
+
/**
|
|
302
|
+
* This notification is sent from the client to the server after initialization has finished.
|
|
303
|
+
*/
|
|
304
|
+
var InitializedNotificationSchema = NotificationSchema.extend({
|
|
305
|
+
method: literal("notifications/initialized"),
|
|
306
|
+
params: NotificationsParamsSchema.optional()
|
|
307
|
+
});
|
|
308
|
+
/**
|
|
309
|
+
* A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
|
|
310
|
+
*/
|
|
311
|
+
var PingRequestSchema = RequestSchema.extend({
|
|
312
|
+
method: literal("ping"),
|
|
313
|
+
params: BaseRequestParamsSchema.optional()
|
|
314
|
+
});
|
|
315
|
+
var ProgressSchema = object({
|
|
316
|
+
progress: number(),
|
|
317
|
+
total: optional(number()),
|
|
318
|
+
message: optional(string())
|
|
319
|
+
});
|
|
320
|
+
var ProgressNotificationParamsSchema = object({
|
|
321
|
+
...NotificationsParamsSchema.shape,
|
|
322
|
+
...ProgressSchema.shape,
|
|
323
|
+
progressToken: ProgressTokenSchema
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
327
|
+
*
|
|
328
|
+
* @category notifications/progress
|
|
329
|
+
*/
|
|
330
|
+
var ProgressNotificationSchema = NotificationSchema.extend({
|
|
331
|
+
method: literal("notifications/progress"),
|
|
332
|
+
params: ProgressNotificationParamsSchema
|
|
333
|
+
});
|
|
334
|
+
var PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({ cursor: CursorSchema.optional() });
|
|
335
|
+
var PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
|
|
336
|
+
var PaginatedResultSchema = ResultSchema.extend({ nextCursor: CursorSchema.optional() });
|
|
337
|
+
/**
|
|
338
|
+
* The status of a task.
|
|
339
|
+
* */
|
|
340
|
+
var TaskStatusSchema = _enum([
|
|
341
|
+
"working",
|
|
342
|
+
"input_required",
|
|
343
|
+
"completed",
|
|
344
|
+
"failed",
|
|
345
|
+
"cancelled"
|
|
346
|
+
]);
|
|
347
|
+
/**
|
|
348
|
+
* A pollable state object associated with a request.
|
|
349
|
+
*/
|
|
350
|
+
var TaskSchema = object({
|
|
351
|
+
taskId: string(),
|
|
352
|
+
status: TaskStatusSchema,
|
|
353
|
+
ttl: union([number(), _null()]),
|
|
354
|
+
createdAt: string(),
|
|
355
|
+
lastUpdatedAt: string(),
|
|
356
|
+
pollInterval: optional(number()),
|
|
357
|
+
statusMessage: optional(string())
|
|
358
|
+
});
|
|
359
|
+
/**
|
|
360
|
+
* Result returned when a task is created, containing the task data wrapped in a task field.
|
|
361
|
+
*/
|
|
362
|
+
var CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
|
|
363
|
+
/**
|
|
364
|
+
* Parameters for task status notification.
|
|
365
|
+
*/
|
|
366
|
+
var TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
367
|
+
/**
|
|
368
|
+
* A notification sent when a task's status changes.
|
|
369
|
+
*/
|
|
370
|
+
var TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
371
|
+
method: literal("notifications/tasks/status"),
|
|
372
|
+
params: TaskStatusNotificationParamsSchema
|
|
373
|
+
});
|
|
374
|
+
/**
|
|
375
|
+
* A request to get the state of a specific task.
|
|
376
|
+
*/
|
|
377
|
+
var GetTaskRequestSchema = RequestSchema.extend({
|
|
378
|
+
method: literal("tasks/get"),
|
|
379
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
380
|
+
});
|
|
381
|
+
/**
|
|
382
|
+
* The response to a tasks/get request.
|
|
383
|
+
*/
|
|
384
|
+
var GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
385
|
+
/**
|
|
386
|
+
* A request to get the result of a specific task.
|
|
387
|
+
*/
|
|
388
|
+
var GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
389
|
+
method: literal("tasks/result"),
|
|
390
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
391
|
+
});
|
|
392
|
+
ResultSchema.loose();
|
|
393
|
+
/**
|
|
394
|
+
* A request to list tasks.
|
|
395
|
+
*/
|
|
396
|
+
var ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: literal("tasks/list") });
|
|
397
|
+
/**
|
|
398
|
+
* The response to a tasks/list request.
|
|
399
|
+
*/
|
|
400
|
+
var ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: array(TaskSchema) });
|
|
401
|
+
/**
|
|
402
|
+
* A request to cancel a specific task.
|
|
403
|
+
*/
|
|
404
|
+
var CancelTaskRequestSchema = RequestSchema.extend({
|
|
405
|
+
method: literal("tasks/cancel"),
|
|
406
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
407
|
+
});
|
|
408
|
+
/**
|
|
409
|
+
* The response to a tasks/cancel request.
|
|
410
|
+
*/
|
|
411
|
+
var CancelTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
412
|
+
/**
|
|
413
|
+
* The contents of a specific resource or sub-resource.
|
|
414
|
+
*/
|
|
415
|
+
var ResourceContentsSchema = object({
|
|
416
|
+
uri: string(),
|
|
417
|
+
mimeType: optional(string()),
|
|
418
|
+
_meta: record(string(), unknown()).optional()
|
|
419
|
+
});
|
|
420
|
+
var TextResourceContentsSchema = ResourceContentsSchema.extend({ text: string() });
|
|
421
|
+
/**
|
|
422
|
+
* A Zod schema for validating Base64 strings that is more performant and
|
|
423
|
+
* robust for very large inputs than the default regex-based check. It avoids
|
|
424
|
+
* stack overflows by using the native `atob` function for validation.
|
|
425
|
+
*/
|
|
426
|
+
var Base64Schema = string().refine((val) => {
|
|
427
|
+
try {
|
|
428
|
+
atob(val);
|
|
429
|
+
return true;
|
|
430
|
+
} catch {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}, { message: "Invalid Base64 string" });
|
|
434
|
+
var BlobResourceContentsSchema = ResourceContentsSchema.extend({ blob: Base64Schema });
|
|
435
|
+
/**
|
|
436
|
+
* The sender or recipient of messages and data in a conversation.
|
|
437
|
+
*/
|
|
438
|
+
var RoleSchema = _enum(["user", "assistant"]);
|
|
439
|
+
/**
|
|
440
|
+
* Optional annotations providing clients additional context about a resource.
|
|
441
|
+
*/
|
|
442
|
+
var AnnotationsSchema = object({
|
|
443
|
+
audience: array(RoleSchema).optional(),
|
|
444
|
+
priority: number().min(0).max(1).optional(),
|
|
445
|
+
lastModified: datetime({ offset: true }).optional()
|
|
446
|
+
});
|
|
447
|
+
/**
|
|
448
|
+
* A known resource that the server is capable of reading.
|
|
449
|
+
*/
|
|
450
|
+
var ResourceSchema = object({
|
|
451
|
+
...BaseMetadataSchema.shape,
|
|
452
|
+
...IconsSchema.shape,
|
|
453
|
+
uri: string(),
|
|
454
|
+
description: optional(string()),
|
|
455
|
+
mimeType: optional(string()),
|
|
456
|
+
annotations: AnnotationsSchema.optional(),
|
|
457
|
+
_meta: optional(looseObject({}))
|
|
458
|
+
});
|
|
459
|
+
/**
|
|
460
|
+
* A template description for resources available on the server.
|
|
461
|
+
*/
|
|
462
|
+
var ResourceTemplateSchema = object({
|
|
463
|
+
...BaseMetadataSchema.shape,
|
|
464
|
+
...IconsSchema.shape,
|
|
465
|
+
uriTemplate: string(),
|
|
466
|
+
description: optional(string()),
|
|
467
|
+
mimeType: optional(string()),
|
|
468
|
+
annotations: AnnotationsSchema.optional(),
|
|
469
|
+
_meta: optional(looseObject({}))
|
|
470
|
+
});
|
|
471
|
+
/**
|
|
472
|
+
* Sent from the client to request a list of resources the server has.
|
|
473
|
+
*/
|
|
474
|
+
var ListResourcesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/list") });
|
|
475
|
+
/**
|
|
476
|
+
* The server's response to a resources/list request from the client.
|
|
477
|
+
*/
|
|
478
|
+
var ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: array(ResourceSchema) });
|
|
479
|
+
/**
|
|
480
|
+
* Sent from the client to request a list of resource templates the server has.
|
|
481
|
+
*/
|
|
482
|
+
var ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/templates/list") });
|
|
483
|
+
/**
|
|
484
|
+
* The server's response to a resources/templates/list request from the client.
|
|
485
|
+
*/
|
|
486
|
+
var ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: array(ResourceTemplateSchema) });
|
|
487
|
+
var ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({ uri: string() });
|
|
488
|
+
/**
|
|
489
|
+
* Parameters for a `resources/read` request.
|
|
490
|
+
*/
|
|
491
|
+
var ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
492
|
+
/**
|
|
493
|
+
* Sent from the client to the server, to read a specific resource URI.
|
|
494
|
+
*/
|
|
495
|
+
var ReadResourceRequestSchema = RequestSchema.extend({
|
|
496
|
+
method: literal("resources/read"),
|
|
497
|
+
params: ReadResourceRequestParamsSchema
|
|
498
|
+
});
|
|
499
|
+
/**
|
|
500
|
+
* The server's response to a resources/read request from the client.
|
|
501
|
+
*/
|
|
502
|
+
var ReadResourceResultSchema = ResultSchema.extend({ contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
|
|
503
|
+
/**
|
|
504
|
+
* An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
|
|
505
|
+
*/
|
|
506
|
+
var ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
507
|
+
method: literal("notifications/resources/list_changed"),
|
|
508
|
+
params: NotificationsParamsSchema.optional()
|
|
509
|
+
});
|
|
510
|
+
var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
511
|
+
/**
|
|
512
|
+
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
513
|
+
*/
|
|
514
|
+
var SubscribeRequestSchema = RequestSchema.extend({
|
|
515
|
+
method: literal("resources/subscribe"),
|
|
516
|
+
params: SubscribeRequestParamsSchema
|
|
517
|
+
});
|
|
518
|
+
var UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
519
|
+
/**
|
|
520
|
+
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
521
|
+
*/
|
|
522
|
+
var UnsubscribeRequestSchema = RequestSchema.extend({
|
|
523
|
+
method: literal("resources/unsubscribe"),
|
|
524
|
+
params: UnsubscribeRequestParamsSchema
|
|
525
|
+
});
|
|
526
|
+
/**
|
|
527
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
528
|
+
*/
|
|
529
|
+
var ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({ uri: string() });
|
|
530
|
+
/**
|
|
531
|
+
* A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
|
|
532
|
+
*/
|
|
533
|
+
var ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
534
|
+
method: literal("notifications/resources/updated"),
|
|
535
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
536
|
+
});
|
|
537
|
+
/**
|
|
538
|
+
* Describes an argument that a prompt can accept.
|
|
539
|
+
*/
|
|
540
|
+
var PromptArgumentSchema = object({
|
|
541
|
+
name: string(),
|
|
542
|
+
description: optional(string()),
|
|
543
|
+
required: optional(boolean())
|
|
544
|
+
});
|
|
545
|
+
/**
|
|
546
|
+
* A prompt or prompt template that the server offers.
|
|
547
|
+
*/
|
|
548
|
+
var PromptSchema = object({
|
|
549
|
+
...BaseMetadataSchema.shape,
|
|
550
|
+
...IconsSchema.shape,
|
|
551
|
+
description: optional(string()),
|
|
552
|
+
arguments: optional(array(PromptArgumentSchema)),
|
|
553
|
+
_meta: optional(looseObject({}))
|
|
554
|
+
});
|
|
555
|
+
/**
|
|
556
|
+
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
557
|
+
*/
|
|
558
|
+
var ListPromptsRequestSchema = PaginatedRequestSchema.extend({ method: literal("prompts/list") });
|
|
559
|
+
/**
|
|
560
|
+
* The server's response to a prompts/list request from the client.
|
|
561
|
+
*/
|
|
562
|
+
var ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: array(PromptSchema) });
|
|
563
|
+
/**
|
|
564
|
+
* Parameters for a `prompts/get` request.
|
|
565
|
+
*/
|
|
566
|
+
var GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
567
|
+
name: string(),
|
|
568
|
+
arguments: record(string(), string()).optional()
|
|
569
|
+
});
|
|
570
|
+
/**
|
|
571
|
+
* Used by the client to get a prompt provided by the server.
|
|
572
|
+
*/
|
|
573
|
+
var GetPromptRequestSchema = RequestSchema.extend({
|
|
574
|
+
method: literal("prompts/get"),
|
|
575
|
+
params: GetPromptRequestParamsSchema
|
|
576
|
+
});
|
|
577
|
+
/**
|
|
578
|
+
* Text provided to or from an LLM.
|
|
579
|
+
*/
|
|
580
|
+
var TextContentSchema = object({
|
|
581
|
+
type: literal("text"),
|
|
582
|
+
text: string(),
|
|
583
|
+
annotations: AnnotationsSchema.optional(),
|
|
584
|
+
_meta: record(string(), unknown()).optional()
|
|
585
|
+
});
|
|
586
|
+
/**
|
|
587
|
+
* An image provided to or from an LLM.
|
|
588
|
+
*/
|
|
589
|
+
var ImageContentSchema = object({
|
|
590
|
+
type: literal("image"),
|
|
591
|
+
data: Base64Schema,
|
|
592
|
+
mimeType: string(),
|
|
593
|
+
annotations: AnnotationsSchema.optional(),
|
|
594
|
+
_meta: record(string(), unknown()).optional()
|
|
595
|
+
});
|
|
596
|
+
/**
|
|
597
|
+
* An Audio provided to or from an LLM.
|
|
598
|
+
*/
|
|
599
|
+
var AudioContentSchema = object({
|
|
600
|
+
type: literal("audio"),
|
|
601
|
+
data: Base64Schema,
|
|
602
|
+
mimeType: string(),
|
|
603
|
+
annotations: AnnotationsSchema.optional(),
|
|
604
|
+
_meta: record(string(), unknown()).optional()
|
|
605
|
+
});
|
|
606
|
+
/**
|
|
607
|
+
* A tool call request from an assistant (LLM).
|
|
608
|
+
* Represents the assistant's request to use a tool.
|
|
609
|
+
*/
|
|
610
|
+
var ToolUseContentSchema = object({
|
|
611
|
+
type: literal("tool_use"),
|
|
612
|
+
name: string(),
|
|
613
|
+
id: string(),
|
|
614
|
+
input: record(string(), unknown()),
|
|
615
|
+
_meta: record(string(), unknown()).optional()
|
|
616
|
+
});
|
|
617
|
+
/**
|
|
618
|
+
* The contents of a resource, embedded into a prompt or tool call result.
|
|
619
|
+
*/
|
|
620
|
+
var EmbeddedResourceSchema = object({
|
|
621
|
+
type: literal("resource"),
|
|
622
|
+
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
623
|
+
annotations: AnnotationsSchema.optional(),
|
|
624
|
+
_meta: record(string(), unknown()).optional()
|
|
625
|
+
});
|
|
626
|
+
/**
|
|
627
|
+
* A resource that the server is capable of reading, included in a prompt or tool call result.
|
|
628
|
+
*
|
|
629
|
+
* Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
|
|
630
|
+
*/
|
|
631
|
+
var ResourceLinkSchema = ResourceSchema.extend({ type: literal("resource_link") });
|
|
632
|
+
/**
|
|
633
|
+
* A content block that can be used in prompts and tool results.
|
|
634
|
+
*/
|
|
635
|
+
var ContentBlockSchema = union([
|
|
636
|
+
TextContentSchema,
|
|
637
|
+
ImageContentSchema,
|
|
638
|
+
AudioContentSchema,
|
|
639
|
+
ResourceLinkSchema,
|
|
640
|
+
EmbeddedResourceSchema
|
|
641
|
+
]);
|
|
642
|
+
/**
|
|
643
|
+
* Describes a message returned as part of a prompt.
|
|
644
|
+
*/
|
|
645
|
+
var PromptMessageSchema = object({
|
|
646
|
+
role: RoleSchema,
|
|
647
|
+
content: ContentBlockSchema
|
|
648
|
+
});
|
|
649
|
+
/**
|
|
650
|
+
* The server's response to a prompts/get request from the client.
|
|
651
|
+
*/
|
|
652
|
+
var GetPromptResultSchema = ResultSchema.extend({
|
|
653
|
+
description: string().optional(),
|
|
654
|
+
messages: array(PromptMessageSchema)
|
|
655
|
+
});
|
|
656
|
+
/**
|
|
657
|
+
* An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
658
|
+
*/
|
|
659
|
+
var PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
660
|
+
method: literal("notifications/prompts/list_changed"),
|
|
661
|
+
params: NotificationsParamsSchema.optional()
|
|
662
|
+
});
|
|
663
|
+
/**
|
|
664
|
+
* Additional properties describing a Tool to clients.
|
|
665
|
+
*
|
|
666
|
+
* NOTE: all properties in ToolAnnotations are **hints**.
|
|
667
|
+
* They are not guaranteed to provide a faithful description of
|
|
668
|
+
* tool behavior (including descriptive properties like `title`).
|
|
669
|
+
*
|
|
670
|
+
* Clients should never make tool use decisions based on ToolAnnotations
|
|
671
|
+
* received from untrusted servers.
|
|
672
|
+
*/
|
|
673
|
+
var ToolAnnotationsSchema = object({
|
|
674
|
+
title: string().optional(),
|
|
675
|
+
readOnlyHint: boolean().optional(),
|
|
676
|
+
destructiveHint: boolean().optional(),
|
|
677
|
+
idempotentHint: boolean().optional(),
|
|
678
|
+
openWorldHint: boolean().optional()
|
|
679
|
+
});
|
|
680
|
+
/**
|
|
681
|
+
* Execution-related properties for a tool.
|
|
682
|
+
*/
|
|
683
|
+
var ToolExecutionSchema = object({ taskSupport: _enum([
|
|
684
|
+
"required",
|
|
685
|
+
"optional",
|
|
686
|
+
"forbidden"
|
|
687
|
+
]).optional() });
|
|
688
|
+
/**
|
|
689
|
+
* Definition for a tool the client can call.
|
|
690
|
+
*/
|
|
691
|
+
var ToolSchema = object({
|
|
692
|
+
...BaseMetadataSchema.shape,
|
|
693
|
+
...IconsSchema.shape,
|
|
694
|
+
description: string().optional(),
|
|
695
|
+
inputSchema: object({
|
|
696
|
+
type: literal("object"),
|
|
697
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
698
|
+
required: array(string()).optional()
|
|
699
|
+
}).catchall(unknown()),
|
|
700
|
+
outputSchema: object({
|
|
701
|
+
type: literal("object"),
|
|
702
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
703
|
+
required: array(string()).optional()
|
|
704
|
+
}).catchall(unknown()).optional(),
|
|
705
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
706
|
+
execution: ToolExecutionSchema.optional(),
|
|
707
|
+
_meta: record(string(), unknown()).optional()
|
|
708
|
+
});
|
|
709
|
+
/**
|
|
710
|
+
* Sent from the client to request a list of tools the server has.
|
|
711
|
+
*/
|
|
712
|
+
var ListToolsRequestSchema = PaginatedRequestSchema.extend({ method: literal("tools/list") });
|
|
713
|
+
/**
|
|
714
|
+
* The server's response to a tools/list request from the client.
|
|
715
|
+
*/
|
|
716
|
+
var ListToolsResultSchema = PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
717
|
+
/**
|
|
718
|
+
* The server's response to a tool call.
|
|
719
|
+
*/
|
|
720
|
+
var CallToolResultSchema = ResultSchema.extend({
|
|
721
|
+
content: array(ContentBlockSchema).default([]),
|
|
722
|
+
structuredContent: record(string(), unknown()).optional(),
|
|
723
|
+
isError: boolean().optional()
|
|
724
|
+
});
|
|
725
|
+
CallToolResultSchema.or(ResultSchema.extend({ toolResult: unknown() }));
|
|
726
|
+
/**
|
|
727
|
+
* Parameters for a `tools/call` request.
|
|
728
|
+
*/
|
|
729
|
+
var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
730
|
+
name: string(),
|
|
731
|
+
arguments: record(string(), unknown()).optional()
|
|
732
|
+
});
|
|
733
|
+
/**
|
|
734
|
+
* Used by the client to invoke a tool provided by the server.
|
|
735
|
+
*/
|
|
736
|
+
var CallToolRequestSchema = RequestSchema.extend({
|
|
737
|
+
method: literal("tools/call"),
|
|
738
|
+
params: CallToolRequestParamsSchema
|
|
739
|
+
});
|
|
740
|
+
/**
|
|
741
|
+
* An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
742
|
+
*/
|
|
743
|
+
var ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
744
|
+
method: literal("notifications/tools/list_changed"),
|
|
745
|
+
params: NotificationsParamsSchema.optional()
|
|
746
|
+
});
|
|
747
|
+
object({
|
|
748
|
+
autoRefresh: boolean().default(true),
|
|
749
|
+
debounceMs: number().int().nonnegative().default(300)
|
|
750
|
+
});
|
|
751
|
+
/**
|
|
752
|
+
* The severity of a log message.
|
|
753
|
+
*/
|
|
754
|
+
var LoggingLevelSchema = _enum([
|
|
755
|
+
"debug",
|
|
756
|
+
"info",
|
|
757
|
+
"notice",
|
|
758
|
+
"warning",
|
|
759
|
+
"error",
|
|
760
|
+
"critical",
|
|
761
|
+
"alert",
|
|
762
|
+
"emergency"
|
|
763
|
+
]);
|
|
764
|
+
/**
|
|
765
|
+
* Parameters for a `logging/setLevel` request.
|
|
766
|
+
*/
|
|
767
|
+
var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({ level: LoggingLevelSchema });
|
|
768
|
+
/**
|
|
769
|
+
* A request from the client to the server, to enable or adjust logging.
|
|
770
|
+
*/
|
|
771
|
+
var SetLevelRequestSchema = RequestSchema.extend({
|
|
772
|
+
method: literal("logging/setLevel"),
|
|
773
|
+
params: SetLevelRequestParamsSchema
|
|
774
|
+
});
|
|
775
|
+
/**
|
|
776
|
+
* Parameters for a `notifications/message` notification.
|
|
777
|
+
*/
|
|
778
|
+
var LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
779
|
+
level: LoggingLevelSchema,
|
|
780
|
+
logger: string().optional(),
|
|
781
|
+
data: unknown()
|
|
782
|
+
});
|
|
783
|
+
/**
|
|
784
|
+
* Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
|
|
785
|
+
*/
|
|
786
|
+
var LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
787
|
+
method: literal("notifications/message"),
|
|
788
|
+
params: LoggingMessageNotificationParamsSchema
|
|
789
|
+
});
|
|
790
|
+
/**
|
|
791
|
+
* The server's preferences for model selection, requested of the client during sampling.
|
|
792
|
+
*/
|
|
793
|
+
var ModelPreferencesSchema = object({
|
|
794
|
+
hints: array(object({ name: string().optional() })).optional(),
|
|
795
|
+
costPriority: number().min(0).max(1).optional(),
|
|
796
|
+
speedPriority: number().min(0).max(1).optional(),
|
|
797
|
+
intelligencePriority: number().min(0).max(1).optional()
|
|
798
|
+
});
|
|
799
|
+
/**
|
|
800
|
+
* Controls tool usage behavior in sampling requests.
|
|
801
|
+
*/
|
|
802
|
+
var ToolChoiceSchema = object({ mode: _enum([
|
|
803
|
+
"auto",
|
|
804
|
+
"required",
|
|
805
|
+
"none"
|
|
806
|
+
]).optional() });
|
|
807
|
+
/**
|
|
808
|
+
* The result of a tool execution, provided by the user (server).
|
|
809
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
810
|
+
*/
|
|
811
|
+
var ToolResultContentSchema = object({
|
|
812
|
+
type: literal("tool_result"),
|
|
813
|
+
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
814
|
+
content: array(ContentBlockSchema).default([]),
|
|
815
|
+
structuredContent: object({}).loose().optional(),
|
|
816
|
+
isError: boolean().optional(),
|
|
817
|
+
_meta: record(string(), unknown()).optional()
|
|
818
|
+
});
|
|
819
|
+
/**
|
|
820
|
+
* Basic content types for sampling responses (without tool use).
|
|
821
|
+
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
822
|
+
*/
|
|
823
|
+
var SamplingContentSchema = discriminatedUnion("type", [
|
|
824
|
+
TextContentSchema,
|
|
825
|
+
ImageContentSchema,
|
|
826
|
+
AudioContentSchema
|
|
827
|
+
]);
|
|
828
|
+
/**
|
|
829
|
+
* Content block types allowed in sampling messages.
|
|
830
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
831
|
+
*/
|
|
832
|
+
var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
833
|
+
TextContentSchema,
|
|
834
|
+
ImageContentSchema,
|
|
835
|
+
AudioContentSchema,
|
|
836
|
+
ToolUseContentSchema,
|
|
837
|
+
ToolResultContentSchema
|
|
838
|
+
]);
|
|
839
|
+
/**
|
|
840
|
+
* Describes a message issued to or received from an LLM API.
|
|
841
|
+
*/
|
|
842
|
+
var SamplingMessageSchema = object({
|
|
843
|
+
role: RoleSchema,
|
|
844
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
845
|
+
_meta: record(string(), unknown()).optional()
|
|
846
|
+
});
|
|
847
|
+
/**
|
|
848
|
+
* Parameters for a `sampling/createMessage` request.
|
|
849
|
+
*/
|
|
850
|
+
var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
851
|
+
messages: array(SamplingMessageSchema),
|
|
852
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
853
|
+
systemPrompt: string().optional(),
|
|
854
|
+
includeContext: _enum([
|
|
855
|
+
"none",
|
|
856
|
+
"thisServer",
|
|
857
|
+
"allServers"
|
|
858
|
+
]).optional(),
|
|
859
|
+
temperature: number().optional(),
|
|
860
|
+
maxTokens: number().int(),
|
|
861
|
+
stopSequences: array(string()).optional(),
|
|
862
|
+
metadata: AssertObjectSchema.optional(),
|
|
863
|
+
tools: array(ToolSchema).optional(),
|
|
864
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
865
|
+
});
|
|
866
|
+
/**
|
|
867
|
+
* A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
|
|
868
|
+
*/
|
|
869
|
+
var CreateMessageRequestSchema = RequestSchema.extend({
|
|
870
|
+
method: literal("sampling/createMessage"),
|
|
871
|
+
params: CreateMessageRequestParamsSchema
|
|
872
|
+
});
|
|
873
|
+
/**
|
|
874
|
+
* The client's response to a sampling/create_message request from the server.
|
|
875
|
+
* This is the backwards-compatible version that returns single content (no arrays).
|
|
876
|
+
* Used when the request does not include tools.
|
|
877
|
+
*/
|
|
878
|
+
var CreateMessageResultSchema = ResultSchema.extend({
|
|
879
|
+
model: string(),
|
|
880
|
+
stopReason: optional(_enum([
|
|
881
|
+
"endTurn",
|
|
882
|
+
"stopSequence",
|
|
883
|
+
"maxTokens"
|
|
884
|
+
]).or(string())),
|
|
885
|
+
role: RoleSchema,
|
|
886
|
+
content: SamplingContentSchema
|
|
887
|
+
});
|
|
888
|
+
/**
|
|
889
|
+
* The client's response to a sampling/create_message request when tools were provided.
|
|
890
|
+
* This version supports array content for tool use flows.
|
|
891
|
+
*/
|
|
892
|
+
var CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
893
|
+
model: string(),
|
|
894
|
+
stopReason: optional(_enum([
|
|
895
|
+
"endTurn",
|
|
896
|
+
"stopSequence",
|
|
897
|
+
"maxTokens",
|
|
898
|
+
"toolUse"
|
|
899
|
+
]).or(string())),
|
|
900
|
+
role: RoleSchema,
|
|
901
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
902
|
+
});
|
|
903
|
+
/**
|
|
904
|
+
* Primitive schema definition for boolean fields.
|
|
905
|
+
*/
|
|
906
|
+
var BooleanSchemaSchema = object({
|
|
907
|
+
type: literal("boolean"),
|
|
908
|
+
title: string().optional(),
|
|
909
|
+
description: string().optional(),
|
|
910
|
+
default: boolean().optional()
|
|
911
|
+
});
|
|
912
|
+
/**
|
|
913
|
+
* Primitive schema definition for string fields.
|
|
914
|
+
*/
|
|
915
|
+
var StringSchemaSchema = object({
|
|
916
|
+
type: literal("string"),
|
|
917
|
+
title: string().optional(),
|
|
918
|
+
description: string().optional(),
|
|
919
|
+
minLength: number().optional(),
|
|
920
|
+
maxLength: number().optional(),
|
|
921
|
+
format: _enum([
|
|
922
|
+
"email",
|
|
923
|
+
"uri",
|
|
924
|
+
"date",
|
|
925
|
+
"date-time"
|
|
926
|
+
]).optional(),
|
|
927
|
+
default: string().optional()
|
|
928
|
+
});
|
|
929
|
+
/**
|
|
930
|
+
* Primitive schema definition for number fields.
|
|
931
|
+
*/
|
|
932
|
+
var NumberSchemaSchema = object({
|
|
933
|
+
type: _enum(["number", "integer"]),
|
|
934
|
+
title: string().optional(),
|
|
935
|
+
description: string().optional(),
|
|
936
|
+
minimum: number().optional(),
|
|
937
|
+
maximum: number().optional(),
|
|
938
|
+
default: number().optional()
|
|
939
|
+
});
|
|
940
|
+
/**
|
|
941
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
942
|
+
*/
|
|
943
|
+
var UntitledSingleSelectEnumSchemaSchema = object({
|
|
944
|
+
type: literal("string"),
|
|
945
|
+
title: string().optional(),
|
|
946
|
+
description: string().optional(),
|
|
947
|
+
enum: array(string()),
|
|
948
|
+
default: string().optional()
|
|
949
|
+
});
|
|
950
|
+
/**
|
|
951
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
952
|
+
*/
|
|
953
|
+
var TitledSingleSelectEnumSchemaSchema = object({
|
|
954
|
+
type: literal("string"),
|
|
955
|
+
title: string().optional(),
|
|
956
|
+
description: string().optional(),
|
|
957
|
+
oneOf: array(object({
|
|
958
|
+
const: string(),
|
|
959
|
+
title: string()
|
|
960
|
+
})),
|
|
961
|
+
default: string().optional()
|
|
962
|
+
});
|
|
963
|
+
/**
|
|
964
|
+
* Union of all primitive schema definitions.
|
|
965
|
+
*/
|
|
966
|
+
var PrimitiveSchemaDefinitionSchema = union([
|
|
967
|
+
union([
|
|
968
|
+
object({
|
|
969
|
+
type: literal("string"),
|
|
970
|
+
title: string().optional(),
|
|
971
|
+
description: string().optional(),
|
|
972
|
+
enum: array(string()),
|
|
973
|
+
enumNames: array(string()).optional(),
|
|
974
|
+
default: string().optional()
|
|
975
|
+
}),
|
|
976
|
+
union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]),
|
|
977
|
+
union([object({
|
|
978
|
+
type: literal("array"),
|
|
979
|
+
title: string().optional(),
|
|
980
|
+
description: string().optional(),
|
|
981
|
+
minItems: number().optional(),
|
|
982
|
+
maxItems: number().optional(),
|
|
983
|
+
items: object({
|
|
984
|
+
type: literal("string"),
|
|
985
|
+
enum: array(string())
|
|
986
|
+
}),
|
|
987
|
+
default: array(string()).optional()
|
|
988
|
+
}), object({
|
|
989
|
+
type: literal("array"),
|
|
990
|
+
title: string().optional(),
|
|
991
|
+
description: string().optional(),
|
|
992
|
+
minItems: number().optional(),
|
|
993
|
+
maxItems: number().optional(),
|
|
994
|
+
items: object({ anyOf: array(object({
|
|
995
|
+
const: string(),
|
|
996
|
+
title: string()
|
|
997
|
+
})) }),
|
|
998
|
+
default: array(string()).optional()
|
|
999
|
+
})])
|
|
1000
|
+
]),
|
|
1001
|
+
BooleanSchemaSchema,
|
|
1002
|
+
StringSchemaSchema,
|
|
1003
|
+
NumberSchemaSchema
|
|
1004
|
+
]);
|
|
1005
|
+
/**
|
|
1006
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
1007
|
+
*/
|
|
1008
|
+
var ElicitRequestParamsSchema = union([TaskAugmentedRequestParamsSchema.extend({
|
|
1009
|
+
mode: literal("form").optional(),
|
|
1010
|
+
message: string(),
|
|
1011
|
+
requestedSchema: object({
|
|
1012
|
+
type: literal("object"),
|
|
1013
|
+
properties: record(string(), PrimitiveSchemaDefinitionSchema),
|
|
1014
|
+
required: array(string()).optional()
|
|
1015
|
+
})
|
|
1016
|
+
}), TaskAugmentedRequestParamsSchema.extend({
|
|
1017
|
+
mode: literal("url"),
|
|
1018
|
+
message: string(),
|
|
1019
|
+
elicitationId: string(),
|
|
1020
|
+
url: string().url()
|
|
1021
|
+
})]);
|
|
1022
|
+
/**
|
|
1023
|
+
* A request from the server to elicit user input via the client.
|
|
1024
|
+
* The client should present the message and form fields to the user (form mode)
|
|
1025
|
+
* or navigate to a URL (URL mode).
|
|
1026
|
+
*/
|
|
1027
|
+
var ElicitRequestSchema = RequestSchema.extend({
|
|
1028
|
+
method: literal("elicitation/create"),
|
|
1029
|
+
params: ElicitRequestParamsSchema
|
|
1030
|
+
});
|
|
1031
|
+
/**
|
|
1032
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
1033
|
+
*
|
|
1034
|
+
* @category notifications/elicitation/complete
|
|
1035
|
+
*/
|
|
1036
|
+
var ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({ elicitationId: string() });
|
|
1037
|
+
/**
|
|
1038
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
1039
|
+
*
|
|
1040
|
+
* @category notifications/elicitation/complete
|
|
1041
|
+
*/
|
|
1042
|
+
var ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
1043
|
+
method: literal("notifications/elicitation/complete"),
|
|
1044
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
1045
|
+
});
|
|
1046
|
+
/**
|
|
1047
|
+
* The client's response to an elicitation/create request from the server.
|
|
1048
|
+
*/
|
|
1049
|
+
var ElicitResultSchema = ResultSchema.extend({
|
|
1050
|
+
action: _enum([
|
|
1051
|
+
"accept",
|
|
1052
|
+
"decline",
|
|
1053
|
+
"cancel"
|
|
1054
|
+
]),
|
|
1055
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([
|
|
1056
|
+
string(),
|
|
1057
|
+
number(),
|
|
1058
|
+
boolean(),
|
|
1059
|
+
array(string())
|
|
1060
|
+
])).optional())
|
|
1061
|
+
});
|
|
1062
|
+
/**
|
|
1063
|
+
* A reference to a resource or resource template definition.
|
|
1064
|
+
*/
|
|
1065
|
+
var ResourceTemplateReferenceSchema = object({
|
|
1066
|
+
type: literal("ref/resource"),
|
|
1067
|
+
uri: string()
|
|
1068
|
+
});
|
|
1069
|
+
/**
|
|
1070
|
+
* Identifies a prompt.
|
|
1071
|
+
*/
|
|
1072
|
+
var PromptReferenceSchema = object({
|
|
1073
|
+
type: literal("ref/prompt"),
|
|
1074
|
+
name: string()
|
|
1075
|
+
});
|
|
1076
|
+
/**
|
|
1077
|
+
* Parameters for a `completion/complete` request.
|
|
1078
|
+
*/
|
|
1079
|
+
var CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1080
|
+
ref: union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
1081
|
+
argument: object({
|
|
1082
|
+
name: string(),
|
|
1083
|
+
value: string()
|
|
1084
|
+
}),
|
|
1085
|
+
context: object({ arguments: record(string(), string()).optional() }).optional()
|
|
1086
|
+
});
|
|
1087
|
+
/**
|
|
1088
|
+
* A request from the client to the server, to ask for completion options.
|
|
1089
|
+
*/
|
|
1090
|
+
var CompleteRequestSchema = RequestSchema.extend({
|
|
1091
|
+
method: literal("completion/complete"),
|
|
1092
|
+
params: CompleteRequestParamsSchema
|
|
1093
|
+
});
|
|
1094
|
+
/**
|
|
1095
|
+
* The server's response to a completion/complete request
|
|
1096
|
+
*/
|
|
1097
|
+
var CompleteResultSchema = ResultSchema.extend({ completion: looseObject({
|
|
1098
|
+
values: array(string()).max(100),
|
|
1099
|
+
total: optional(number().int()),
|
|
1100
|
+
hasMore: optional(boolean())
|
|
1101
|
+
}) });
|
|
1102
|
+
/**
|
|
1103
|
+
* Represents a root directory or file that the server can operate on.
|
|
1104
|
+
*/
|
|
1105
|
+
var RootSchema = object({
|
|
1106
|
+
uri: string().startsWith("file://"),
|
|
1107
|
+
name: string().optional(),
|
|
1108
|
+
_meta: record(string(), unknown()).optional()
|
|
1109
|
+
});
|
|
1110
|
+
/**
|
|
1111
|
+
* Sent from the server to request a list of root URIs from the client.
|
|
1112
|
+
*/
|
|
1113
|
+
var ListRootsRequestSchema = RequestSchema.extend({
|
|
1114
|
+
method: literal("roots/list"),
|
|
1115
|
+
params: BaseRequestParamsSchema.optional()
|
|
1116
|
+
});
|
|
1117
|
+
/**
|
|
1118
|
+
* The client's response to a roots/list request from the server.
|
|
1119
|
+
*/
|
|
1120
|
+
var ListRootsResultSchema = ResultSchema.extend({ roots: array(RootSchema) });
|
|
1121
|
+
/**
|
|
1122
|
+
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
1123
|
+
*/
|
|
1124
|
+
var RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
1125
|
+
method: literal("notifications/roots/list_changed"),
|
|
1126
|
+
params: NotificationsParamsSchema.optional()
|
|
1127
|
+
});
|
|
1128
|
+
union([
|
|
1129
|
+
PingRequestSchema,
|
|
1130
|
+
InitializeRequestSchema,
|
|
1131
|
+
CompleteRequestSchema,
|
|
1132
|
+
SetLevelRequestSchema,
|
|
1133
|
+
GetPromptRequestSchema,
|
|
1134
|
+
ListPromptsRequestSchema,
|
|
1135
|
+
ListResourcesRequestSchema,
|
|
1136
|
+
ListResourceTemplatesRequestSchema,
|
|
1137
|
+
ReadResourceRequestSchema,
|
|
1138
|
+
SubscribeRequestSchema,
|
|
1139
|
+
UnsubscribeRequestSchema,
|
|
1140
|
+
CallToolRequestSchema,
|
|
1141
|
+
ListToolsRequestSchema,
|
|
1142
|
+
GetTaskRequestSchema,
|
|
1143
|
+
GetTaskPayloadRequestSchema,
|
|
1144
|
+
ListTasksRequestSchema,
|
|
1145
|
+
CancelTaskRequestSchema
|
|
1146
|
+
]);
|
|
1147
|
+
union([
|
|
1148
|
+
CancelledNotificationSchema,
|
|
1149
|
+
ProgressNotificationSchema,
|
|
1150
|
+
InitializedNotificationSchema,
|
|
1151
|
+
RootsListChangedNotificationSchema,
|
|
1152
|
+
TaskStatusNotificationSchema
|
|
1153
|
+
]);
|
|
1154
|
+
union([
|
|
1155
|
+
EmptyResultSchema,
|
|
1156
|
+
CreateMessageResultSchema,
|
|
1157
|
+
CreateMessageResultWithToolsSchema,
|
|
1158
|
+
ElicitResultSchema,
|
|
1159
|
+
ListRootsResultSchema,
|
|
1160
|
+
GetTaskResultSchema,
|
|
1161
|
+
ListTasksResultSchema,
|
|
1162
|
+
CreateTaskResultSchema
|
|
1163
|
+
]);
|
|
1164
|
+
union([
|
|
1165
|
+
PingRequestSchema,
|
|
1166
|
+
CreateMessageRequestSchema,
|
|
1167
|
+
ElicitRequestSchema,
|
|
1168
|
+
ListRootsRequestSchema,
|
|
1169
|
+
GetTaskRequestSchema,
|
|
1170
|
+
GetTaskPayloadRequestSchema,
|
|
1171
|
+
ListTasksRequestSchema,
|
|
1172
|
+
CancelTaskRequestSchema
|
|
1173
|
+
]);
|
|
1174
|
+
union([
|
|
1175
|
+
CancelledNotificationSchema,
|
|
1176
|
+
ProgressNotificationSchema,
|
|
1177
|
+
LoggingMessageNotificationSchema,
|
|
1178
|
+
ResourceUpdatedNotificationSchema,
|
|
1179
|
+
ResourceListChangedNotificationSchema,
|
|
1180
|
+
ToolListChangedNotificationSchema,
|
|
1181
|
+
PromptListChangedNotificationSchema,
|
|
1182
|
+
TaskStatusNotificationSchema,
|
|
1183
|
+
ElicitationCompleteNotificationSchema
|
|
1184
|
+
]);
|
|
1185
|
+
union([
|
|
1186
|
+
EmptyResultSchema,
|
|
1187
|
+
InitializeResultSchema,
|
|
1188
|
+
CompleteResultSchema,
|
|
1189
|
+
GetPromptResultSchema,
|
|
1190
|
+
ListPromptsResultSchema,
|
|
1191
|
+
ListResourcesResultSchema,
|
|
1192
|
+
ListResourceTemplatesResultSchema,
|
|
1193
|
+
ReadResourceResultSchema,
|
|
1194
|
+
CallToolResultSchema,
|
|
1195
|
+
ListToolsResultSchema,
|
|
1196
|
+
GetTaskResultSchema,
|
|
1197
|
+
ListTasksResultSchema,
|
|
1198
|
+
CreateTaskResultSchema
|
|
1199
|
+
]);
|
|
1200
|
+
var McpError = class McpError extends Error {
|
|
1201
|
+
constructor(code, message, data) {
|
|
1202
|
+
super(`MCP error ${code}: ${message}`);
|
|
1203
|
+
this.code = code;
|
|
1204
|
+
this.data = data;
|
|
1205
|
+
this.name = "McpError";
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Factory method to create the appropriate error type based on the error code and data
|
|
1209
|
+
*/
|
|
1210
|
+
static fromError(code, message, data) {
|
|
1211
|
+
if (code === ErrorCode.UrlElicitationRequired && data) {
|
|
1212
|
+
const errorData = data;
|
|
1213
|
+
if (errorData.elicitations) return new UrlElicitationRequiredError(errorData.elicitations, message);
|
|
1214
|
+
}
|
|
1215
|
+
return new McpError(code, message, data);
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
/**
|
|
1219
|
+
* Specialized error type when a tool requires a URL mode elicitation.
|
|
1220
|
+
* This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against.
|
|
1221
|
+
*/
|
|
1222
|
+
var UrlElicitationRequiredError = class extends McpError {
|
|
1223
|
+
constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? "s" : ""} required`) {
|
|
1224
|
+
super(ErrorCode.UrlElicitationRequired, message, { elicitations });
|
|
1225
|
+
}
|
|
1226
|
+
get elicitations() {
|
|
1227
|
+
return this.data?.elicitations ?? [];
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
//#endregion
|
|
1231
|
+
//#region ../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
|
|
1232
|
+
/**
|
|
1233
|
+
* Experimental task interfaces for MCP SDK.
|
|
1234
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
1235
|
+
*/
|
|
1236
|
+
/**
|
|
1237
|
+
* Checks if a task status represents a terminal state.
|
|
1238
|
+
* Terminal states are those where the task has finished and will not change.
|
|
1239
|
+
*
|
|
1240
|
+
* @param status - The task status to check
|
|
1241
|
+
* @returns True if the status is terminal (completed, failed, or cancelled)
|
|
1242
|
+
* @experimental
|
|
1243
|
+
*/
|
|
1244
|
+
function isTerminal(status) {
|
|
1245
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
1246
|
+
}
|
|
1247
|
+
//#endregion
|
|
1248
|
+
//#region ../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
|
|
1249
|
+
function getMethodLiteral(schema) {
|
|
1250
|
+
const methodSchema = getObjectShape(schema)?.method;
|
|
1251
|
+
if (!methodSchema) throw new Error("Schema is missing a method literal");
|
|
1252
|
+
const value = getLiteralValue(methodSchema);
|
|
1253
|
+
if (typeof value !== "string") throw new Error("Schema method literal must be a string");
|
|
1254
|
+
return value;
|
|
1255
|
+
}
|
|
1256
|
+
function parseWithCompat(schema, data) {
|
|
1257
|
+
const result = safeParse(schema, data);
|
|
1258
|
+
if (!result.success) throw result.error;
|
|
1259
|
+
return result.data;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Implements MCP protocol framing on top of a pluggable transport, including
|
|
1263
|
+
* features like request/response linking, notifications, and progress.
|
|
1264
|
+
*/
|
|
1265
|
+
var Protocol = class {
|
|
1266
|
+
constructor(_options) {
|
|
1267
|
+
this._options = _options;
|
|
1268
|
+
this._requestMessageId = 0;
|
|
1269
|
+
this._requestHandlers = /* @__PURE__ */ new Map();
|
|
1270
|
+
this._requestHandlerAbortControllers = /* @__PURE__ */ new Map();
|
|
1271
|
+
this._notificationHandlers = /* @__PURE__ */ new Map();
|
|
1272
|
+
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
1273
|
+
this._progressHandlers = /* @__PURE__ */ new Map();
|
|
1274
|
+
this._timeoutInfo = /* @__PURE__ */ new Map();
|
|
1275
|
+
this._pendingDebouncedNotifications = /* @__PURE__ */ new Set();
|
|
1276
|
+
this._taskProgressTokens = /* @__PURE__ */ new Map();
|
|
1277
|
+
this._requestResolvers = /* @__PURE__ */ new Map();
|
|
1278
|
+
this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
|
|
1279
|
+
this._oncancel(notification);
|
|
1280
|
+
});
|
|
1281
|
+
this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
|
|
1282
|
+
this._onprogress(notification);
|
|
1283
|
+
});
|
|
1284
|
+
this.setRequestHandler(PingRequestSchema, (_request) => ({}));
|
|
1285
|
+
this._taskStore = _options?.taskStore;
|
|
1286
|
+
this._taskMessageQueue = _options?.taskMessageQueue;
|
|
1287
|
+
if (this._taskStore) {
|
|
1288
|
+
this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
|
|
1289
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
1290
|
+
if (!task) throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
1291
|
+
return { ...task };
|
|
1292
|
+
});
|
|
1293
|
+
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
1294
|
+
const handleTaskResult = async () => {
|
|
1295
|
+
const taskId = request.params.taskId;
|
|
1296
|
+
if (this._taskMessageQueue) {
|
|
1297
|
+
let queuedMessage;
|
|
1298
|
+
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
1299
|
+
if (queuedMessage.type === "response" || queuedMessage.type === "error") {
|
|
1300
|
+
const message = queuedMessage.message;
|
|
1301
|
+
const requestId = message.id;
|
|
1302
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
1303
|
+
if (resolver) {
|
|
1304
|
+
this._requestResolvers.delete(requestId);
|
|
1305
|
+
if (queuedMessage.type === "response") resolver(message);
|
|
1306
|
+
else {
|
|
1307
|
+
const errorMessage = message;
|
|
1308
|
+
resolver(new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data));
|
|
1309
|
+
}
|
|
1310
|
+
} else {
|
|
1311
|
+
const messageType = queuedMessage.type === "response" ? "Response" : "Error";
|
|
1312
|
+
this._onerror(/* @__PURE__ */ new Error(`${messageType} handler missing for request ${requestId}`));
|
|
1313
|
+
}
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1316
|
+
await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
const task = await this._taskStore.getTask(taskId, extra.sessionId);
|
|
1320
|
+
if (!task) throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
1321
|
+
if (!isTerminal(task.status)) {
|
|
1322
|
+
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
1323
|
+
return await handleTaskResult();
|
|
1324
|
+
}
|
|
1325
|
+
if (isTerminal(task.status)) {
|
|
1326
|
+
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
1327
|
+
this._clearTaskQueue(taskId);
|
|
1328
|
+
return {
|
|
1329
|
+
...result,
|
|
1330
|
+
_meta: {
|
|
1331
|
+
...result._meta,
|
|
1332
|
+
[RELATED_TASK_META_KEY]: { taskId }
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
return await handleTaskResult();
|
|
1337
|
+
};
|
|
1338
|
+
return await handleTaskResult();
|
|
1339
|
+
});
|
|
1340
|
+
this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
|
|
1341
|
+
try {
|
|
1342
|
+
const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
|
|
1343
|
+
return {
|
|
1344
|
+
tasks,
|
|
1345
|
+
nextCursor,
|
|
1346
|
+
_meta: {}
|
|
1347
|
+
};
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`);
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
|
|
1353
|
+
try {
|
|
1354
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
1355
|
+
if (!task) throw new McpError(ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`);
|
|
1356
|
+
if (isTerminal(task.status)) throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
1357
|
+
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
1358
|
+
this._clearTaskQueue(request.params.taskId);
|
|
1359
|
+
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
1360
|
+
if (!cancelledTask) throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
1361
|
+
return {
|
|
1362
|
+
_meta: {},
|
|
1363
|
+
...cancelledTask
|
|
1364
|
+
};
|
|
1365
|
+
} catch (error) {
|
|
1366
|
+
if (error instanceof McpError) throw error;
|
|
1367
|
+
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`);
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
async _oncancel(notification) {
|
|
1373
|
+
if (!notification.params.requestId) return;
|
|
1374
|
+
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
1375
|
+
}
|
|
1376
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
1377
|
+
this._timeoutInfo.set(messageId, {
|
|
1378
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
1379
|
+
startTime: Date.now(),
|
|
1380
|
+
timeout,
|
|
1381
|
+
maxTotalTimeout,
|
|
1382
|
+
resetTimeoutOnProgress,
|
|
1383
|
+
onTimeout
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
_resetTimeout(messageId) {
|
|
1387
|
+
const info = this._timeoutInfo.get(messageId);
|
|
1388
|
+
if (!info) return false;
|
|
1389
|
+
const totalElapsed = Date.now() - info.startTime;
|
|
1390
|
+
if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
|
|
1391
|
+
this._timeoutInfo.delete(messageId);
|
|
1392
|
+
throw McpError.fromError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", {
|
|
1393
|
+
maxTotalTimeout: info.maxTotalTimeout,
|
|
1394
|
+
totalElapsed
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
clearTimeout(info.timeoutId);
|
|
1398
|
+
info.timeoutId = setTimeout(info.onTimeout, info.timeout);
|
|
1399
|
+
return true;
|
|
1400
|
+
}
|
|
1401
|
+
_cleanupTimeout(messageId) {
|
|
1402
|
+
const info = this._timeoutInfo.get(messageId);
|
|
1403
|
+
if (info) {
|
|
1404
|
+
clearTimeout(info.timeoutId);
|
|
1405
|
+
this._timeoutInfo.delete(messageId);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
1410
|
+
*
|
|
1411
|
+
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
1412
|
+
*/
|
|
1413
|
+
async connect(transport) {
|
|
1414
|
+
if (this._transport) throw new Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");
|
|
1415
|
+
this._transport = transport;
|
|
1416
|
+
const _onclose = this.transport?.onclose;
|
|
1417
|
+
this._transport.onclose = () => {
|
|
1418
|
+
_onclose?.();
|
|
1419
|
+
this._onclose();
|
|
1420
|
+
};
|
|
1421
|
+
const _onerror = this.transport?.onerror;
|
|
1422
|
+
this._transport.onerror = (error) => {
|
|
1423
|
+
_onerror?.(error);
|
|
1424
|
+
this._onerror(error);
|
|
1425
|
+
};
|
|
1426
|
+
const _onmessage = this._transport?.onmessage;
|
|
1427
|
+
this._transport.onmessage = (message, extra) => {
|
|
1428
|
+
_onmessage?.(message, extra);
|
|
1429
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) this._onresponse(message);
|
|
1430
|
+
else if (isJSONRPCRequest(message)) this._onrequest(message, extra);
|
|
1431
|
+
else if (isJSONRPCNotification(message)) this._onnotification(message);
|
|
1432
|
+
else this._onerror(/* @__PURE__ */ new Error(`Unknown message type: ${JSON.stringify(message)}`));
|
|
1433
|
+
};
|
|
1434
|
+
await this._transport.start();
|
|
1435
|
+
}
|
|
1436
|
+
_onclose() {
|
|
1437
|
+
const responseHandlers = this._responseHandlers;
|
|
1438
|
+
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
1439
|
+
this._progressHandlers.clear();
|
|
1440
|
+
this._taskProgressTokens.clear();
|
|
1441
|
+
this._pendingDebouncedNotifications.clear();
|
|
1442
|
+
for (const controller of this._requestHandlerAbortControllers.values()) controller.abort();
|
|
1443
|
+
this._requestHandlerAbortControllers.clear();
|
|
1444
|
+
const error = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
1445
|
+
this._transport = void 0;
|
|
1446
|
+
this.onclose?.();
|
|
1447
|
+
for (const handler of responseHandlers.values()) handler(error);
|
|
1448
|
+
}
|
|
1449
|
+
_onerror(error) {
|
|
1450
|
+
this.onerror?.(error);
|
|
1451
|
+
}
|
|
1452
|
+
_onnotification(notification) {
|
|
1453
|
+
const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
|
|
1454
|
+
if (handler === void 0) return;
|
|
1455
|
+
Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Uncaught error in notification handler: ${error}`)));
|
|
1456
|
+
}
|
|
1457
|
+
_onrequest(request, extra) {
|
|
1458
|
+
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
1459
|
+
const capturedTransport = this._transport;
|
|
1460
|
+
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
1461
|
+
if (handler === void 0) {
|
|
1462
|
+
const errorResponse = {
|
|
1463
|
+
jsonrpc: "2.0",
|
|
1464
|
+
id: request.id,
|
|
1465
|
+
error: {
|
|
1466
|
+
code: ErrorCode.MethodNotFound,
|
|
1467
|
+
message: "Method not found"
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
if (relatedTaskId && this._taskMessageQueue) this._enqueueTaskMessage(relatedTaskId, {
|
|
1471
|
+
type: "error",
|
|
1472
|
+
message: errorResponse,
|
|
1473
|
+
timestamp: Date.now()
|
|
1474
|
+
}, capturedTransport?.sessionId).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Failed to enqueue error response: ${error}`)));
|
|
1475
|
+
else capturedTransport?.send(errorResponse).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Failed to send an error response: ${error}`)));
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
const abortController = new AbortController();
|
|
1479
|
+
this._requestHandlerAbortControllers.set(request.id, abortController);
|
|
1480
|
+
const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : void 0;
|
|
1481
|
+
const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : void 0;
|
|
1482
|
+
const fullExtra = {
|
|
1483
|
+
signal: abortController.signal,
|
|
1484
|
+
sessionId: capturedTransport?.sessionId,
|
|
1485
|
+
_meta: request.params?._meta,
|
|
1486
|
+
sendNotification: async (notification) => {
|
|
1487
|
+
if (abortController.signal.aborted) return;
|
|
1488
|
+
const notificationOptions = { relatedRequestId: request.id };
|
|
1489
|
+
if (relatedTaskId) notificationOptions.relatedTask = { taskId: relatedTaskId };
|
|
1490
|
+
await this.notification(notification, notificationOptions);
|
|
1491
|
+
},
|
|
1492
|
+
sendRequest: async (r, resultSchema, options) => {
|
|
1493
|
+
if (abortController.signal.aborted) throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
|
|
1494
|
+
const requestOptions = {
|
|
1495
|
+
...options,
|
|
1496
|
+
relatedRequestId: request.id
|
|
1497
|
+
};
|
|
1498
|
+
if (relatedTaskId && !requestOptions.relatedTask) requestOptions.relatedTask = { taskId: relatedTaskId };
|
|
1499
|
+
const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
|
|
1500
|
+
if (effectiveTaskId && taskStore) await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
|
|
1501
|
+
return await this.request(r, resultSchema, requestOptions);
|
|
1502
|
+
},
|
|
1503
|
+
authInfo: extra?.authInfo,
|
|
1504
|
+
requestId: request.id,
|
|
1505
|
+
requestInfo: extra?.requestInfo,
|
|
1506
|
+
taskId: relatedTaskId,
|
|
1507
|
+
taskStore,
|
|
1508
|
+
taskRequestedTtl: taskCreationParams?.ttl,
|
|
1509
|
+
closeSSEStream: extra?.closeSSEStream,
|
|
1510
|
+
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
1511
|
+
};
|
|
1512
|
+
Promise.resolve().then(() => {
|
|
1513
|
+
if (taskCreationParams) this.assertTaskHandlerCapability(request.method);
|
|
1514
|
+
}).then(() => handler(request, fullExtra)).then(async (result) => {
|
|
1515
|
+
if (abortController.signal.aborted) return;
|
|
1516
|
+
const response = {
|
|
1517
|
+
result,
|
|
1518
|
+
jsonrpc: "2.0",
|
|
1519
|
+
id: request.id
|
|
1520
|
+
};
|
|
1521
|
+
if (relatedTaskId && this._taskMessageQueue) await this._enqueueTaskMessage(relatedTaskId, {
|
|
1522
|
+
type: "response",
|
|
1523
|
+
message: response,
|
|
1524
|
+
timestamp: Date.now()
|
|
1525
|
+
}, capturedTransport?.sessionId);
|
|
1526
|
+
else await capturedTransport?.send(response);
|
|
1527
|
+
}, async (error) => {
|
|
1528
|
+
if (abortController.signal.aborted) return;
|
|
1529
|
+
const errorResponse = {
|
|
1530
|
+
jsonrpc: "2.0",
|
|
1531
|
+
id: request.id,
|
|
1532
|
+
error: {
|
|
1533
|
+
code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
|
|
1534
|
+
message: error.message ?? "Internal error",
|
|
1535
|
+
...error["data"] !== void 0 && { data: error["data"] }
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
if (relatedTaskId && this._taskMessageQueue) await this._enqueueTaskMessage(relatedTaskId, {
|
|
1539
|
+
type: "error",
|
|
1540
|
+
message: errorResponse,
|
|
1541
|
+
timestamp: Date.now()
|
|
1542
|
+
}, capturedTransport?.sessionId);
|
|
1543
|
+
else await capturedTransport?.send(errorResponse);
|
|
1544
|
+
}).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Failed to send response: ${error}`))).finally(() => {
|
|
1545
|
+
this._requestHandlerAbortControllers.delete(request.id);
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
_onprogress(notification) {
|
|
1549
|
+
const { progressToken, ...params } = notification.params;
|
|
1550
|
+
const messageId = Number(progressToken);
|
|
1551
|
+
const handler = this._progressHandlers.get(messageId);
|
|
1552
|
+
if (!handler) {
|
|
1553
|
+
this._onerror(/* @__PURE__ */ new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
const responseHandler = this._responseHandlers.get(messageId);
|
|
1557
|
+
const timeoutInfo = this._timeoutInfo.get(messageId);
|
|
1558
|
+
if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) try {
|
|
1559
|
+
this._resetTimeout(messageId);
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
this._responseHandlers.delete(messageId);
|
|
1562
|
+
this._progressHandlers.delete(messageId);
|
|
1563
|
+
this._cleanupTimeout(messageId);
|
|
1564
|
+
responseHandler(error);
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
handler(params);
|
|
1568
|
+
}
|
|
1569
|
+
_onresponse(response) {
|
|
1570
|
+
const messageId = Number(response.id);
|
|
1571
|
+
const resolver = this._requestResolvers.get(messageId);
|
|
1572
|
+
if (resolver) {
|
|
1573
|
+
this._requestResolvers.delete(messageId);
|
|
1574
|
+
if (isJSONRPCResultResponse(response)) resolver(response);
|
|
1575
|
+
else resolver(new McpError(response.error.code, response.error.message, response.error.data));
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
const handler = this._responseHandlers.get(messageId);
|
|
1579
|
+
if (handler === void 0) {
|
|
1580
|
+
this._onerror(/* @__PURE__ */ new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
this._responseHandlers.delete(messageId);
|
|
1584
|
+
this._cleanupTimeout(messageId);
|
|
1585
|
+
let isTaskResponse = false;
|
|
1586
|
+
if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
|
|
1587
|
+
const result = response.result;
|
|
1588
|
+
if (result.task && typeof result.task === "object") {
|
|
1589
|
+
const task = result.task;
|
|
1590
|
+
if (typeof task.taskId === "string") {
|
|
1591
|
+
isTaskResponse = true;
|
|
1592
|
+
this._taskProgressTokens.set(task.taskId, messageId);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
if (!isTaskResponse) this._progressHandlers.delete(messageId);
|
|
1597
|
+
if (isJSONRPCResultResponse(response)) handler(response);
|
|
1598
|
+
else handler(McpError.fromError(response.error.code, response.error.message, response.error.data));
|
|
1599
|
+
}
|
|
1600
|
+
get transport() {
|
|
1601
|
+
return this._transport;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Closes the connection.
|
|
1605
|
+
*/
|
|
1606
|
+
async close() {
|
|
1607
|
+
await this._transport?.close();
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
1611
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
1612
|
+
*
|
|
1613
|
+
* @example
|
|
1614
|
+
* ```typescript
|
|
1615
|
+
* const stream = protocol.requestStream(request, resultSchema, options);
|
|
1616
|
+
* for await (const message of stream) {
|
|
1617
|
+
* switch (message.type) {
|
|
1618
|
+
* case 'taskCreated':
|
|
1619
|
+
* console.log('Task created:', message.task.taskId);
|
|
1620
|
+
* break;
|
|
1621
|
+
* case 'taskStatus':
|
|
1622
|
+
* console.log('Task status:', message.task.status);
|
|
1623
|
+
* break;
|
|
1624
|
+
* case 'result':
|
|
1625
|
+
* console.log('Final result:', message.result);
|
|
1626
|
+
* break;
|
|
1627
|
+
* case 'error':
|
|
1628
|
+
* console.error('Error:', message.error);
|
|
1629
|
+
* break;
|
|
1630
|
+
* }
|
|
1631
|
+
* }
|
|
1632
|
+
* ```
|
|
1633
|
+
*
|
|
1634
|
+
* @experimental Use `client.experimental.tasks.requestStream()` to access this method.
|
|
1635
|
+
*/
|
|
1636
|
+
async *requestStream(request, resultSchema, options) {
|
|
1637
|
+
const { task } = options ?? {};
|
|
1638
|
+
if (!task) {
|
|
1639
|
+
try {
|
|
1640
|
+
yield {
|
|
1641
|
+
type: "result",
|
|
1642
|
+
result: await this.request(request, resultSchema, options)
|
|
1643
|
+
};
|
|
1644
|
+
} catch (error) {
|
|
1645
|
+
yield {
|
|
1646
|
+
type: "error",
|
|
1647
|
+
error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
let taskId;
|
|
1653
|
+
try {
|
|
1654
|
+
const createResult = await this.request(request, CreateTaskResultSchema, options);
|
|
1655
|
+
if (createResult.task) {
|
|
1656
|
+
taskId = createResult.task.taskId;
|
|
1657
|
+
yield {
|
|
1658
|
+
type: "taskCreated",
|
|
1659
|
+
task: createResult.task
|
|
1660
|
+
};
|
|
1661
|
+
} else throw new McpError(ErrorCode.InternalError, "Task creation did not return a task");
|
|
1662
|
+
while (true) {
|
|
1663
|
+
const task = await this.getTask({ taskId }, options);
|
|
1664
|
+
yield {
|
|
1665
|
+
type: "taskStatus",
|
|
1666
|
+
task
|
|
1667
|
+
};
|
|
1668
|
+
if (isTerminal(task.status)) {
|
|
1669
|
+
if (task.status === "completed") yield {
|
|
1670
|
+
type: "result",
|
|
1671
|
+
result: await this.getTaskResult({ taskId }, resultSchema, options)
|
|
1672
|
+
};
|
|
1673
|
+
else if (task.status === "failed") yield {
|
|
1674
|
+
type: "error",
|
|
1675
|
+
error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`)
|
|
1676
|
+
};
|
|
1677
|
+
else if (task.status === "cancelled") yield {
|
|
1678
|
+
type: "error",
|
|
1679
|
+
error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`)
|
|
1680
|
+
};
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (task.status === "input_required") {
|
|
1684
|
+
yield {
|
|
1685
|
+
type: "result",
|
|
1686
|
+
result: await this.getTaskResult({ taskId }, resultSchema, options)
|
|
1687
|
+
};
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
const pollInterval = task.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
1691
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1692
|
+
options?.signal?.throwIfAborted();
|
|
1693
|
+
}
|
|
1694
|
+
} catch (error) {
|
|
1695
|
+
yield {
|
|
1696
|
+
type: "error",
|
|
1697
|
+
error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Sends a request and waits for a response.
|
|
1703
|
+
*
|
|
1704
|
+
* Do not use this method to emit notifications! Use notification() instead.
|
|
1705
|
+
*/
|
|
1706
|
+
request(request, resultSchema, options) {
|
|
1707
|
+
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
1708
|
+
return new Promise((resolve, reject) => {
|
|
1709
|
+
const earlyReject = (error) => {
|
|
1710
|
+
reject(error);
|
|
1711
|
+
};
|
|
1712
|
+
if (!this._transport) {
|
|
1713
|
+
earlyReject(/* @__PURE__ */ new Error("Not connected"));
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
if (this._options?.enforceStrictCapabilities === true) try {
|
|
1717
|
+
this.assertCapabilityForMethod(request.method);
|
|
1718
|
+
if (task) this.assertTaskCapability(request.method);
|
|
1719
|
+
} catch (e) {
|
|
1720
|
+
earlyReject(e);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
options?.signal?.throwIfAborted();
|
|
1724
|
+
const messageId = this._requestMessageId++;
|
|
1725
|
+
const jsonrpcRequest = {
|
|
1726
|
+
...request,
|
|
1727
|
+
jsonrpc: "2.0",
|
|
1728
|
+
id: messageId
|
|
1729
|
+
};
|
|
1730
|
+
if (options?.onprogress) {
|
|
1731
|
+
this._progressHandlers.set(messageId, options.onprogress);
|
|
1732
|
+
jsonrpcRequest.params = {
|
|
1733
|
+
...request.params,
|
|
1734
|
+
_meta: {
|
|
1735
|
+
...request.params?._meta || {},
|
|
1736
|
+
progressToken: messageId
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
if (task) jsonrpcRequest.params = {
|
|
1741
|
+
...jsonrpcRequest.params,
|
|
1742
|
+
task
|
|
1743
|
+
};
|
|
1744
|
+
if (relatedTask) jsonrpcRequest.params = {
|
|
1745
|
+
...jsonrpcRequest.params,
|
|
1746
|
+
_meta: {
|
|
1747
|
+
...jsonrpcRequest.params?._meta || {},
|
|
1748
|
+
[RELATED_TASK_META_KEY]: relatedTask
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
const cancel = (reason) => {
|
|
1752
|
+
this._responseHandlers.delete(messageId);
|
|
1753
|
+
this._progressHandlers.delete(messageId);
|
|
1754
|
+
this._cleanupTimeout(messageId);
|
|
1755
|
+
this._transport?.send({
|
|
1756
|
+
jsonrpc: "2.0",
|
|
1757
|
+
method: "notifications/cancelled",
|
|
1758
|
+
params: {
|
|
1759
|
+
requestId: messageId,
|
|
1760
|
+
reason: String(reason)
|
|
1761
|
+
}
|
|
1762
|
+
}, {
|
|
1763
|
+
relatedRequestId,
|
|
1764
|
+
resumptionToken,
|
|
1765
|
+
onresumptiontoken
|
|
1766
|
+
}).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Failed to send cancellation: ${error}`)));
|
|
1767
|
+
reject(reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason)));
|
|
1768
|
+
};
|
|
1769
|
+
this._responseHandlers.set(messageId, (response) => {
|
|
1770
|
+
if (options?.signal?.aborted) return;
|
|
1771
|
+
if (response instanceof Error) return reject(response);
|
|
1772
|
+
try {
|
|
1773
|
+
const parseResult = safeParse(resultSchema, response.result);
|
|
1774
|
+
if (!parseResult.success) reject(parseResult.error);
|
|
1775
|
+
else resolve(parseResult.data);
|
|
1776
|
+
} catch (error) {
|
|
1777
|
+
reject(error);
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
options?.signal?.addEventListener("abort", () => {
|
|
1781
|
+
cancel(options?.signal?.reason);
|
|
1782
|
+
});
|
|
1783
|
+
const timeout = options?.timeout ?? 6e4;
|
|
1784
|
+
const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
1785
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
1786
|
+
const relatedTaskId = relatedTask?.taskId;
|
|
1787
|
+
if (relatedTaskId) {
|
|
1788
|
+
const responseResolver = (response) => {
|
|
1789
|
+
const handler = this._responseHandlers.get(messageId);
|
|
1790
|
+
if (handler) handler(response);
|
|
1791
|
+
else this._onerror(/* @__PURE__ */ new Error(`Response handler missing for side-channeled request ${messageId}`));
|
|
1792
|
+
};
|
|
1793
|
+
this._requestResolvers.set(messageId, responseResolver);
|
|
1794
|
+
this._enqueueTaskMessage(relatedTaskId, {
|
|
1795
|
+
type: "request",
|
|
1796
|
+
message: jsonrpcRequest,
|
|
1797
|
+
timestamp: Date.now()
|
|
1798
|
+
}).catch((error) => {
|
|
1799
|
+
this._cleanupTimeout(messageId);
|
|
1800
|
+
reject(error);
|
|
1801
|
+
});
|
|
1802
|
+
} else this._transport.send(jsonrpcRequest, {
|
|
1803
|
+
relatedRequestId,
|
|
1804
|
+
resumptionToken,
|
|
1805
|
+
onresumptiontoken
|
|
1806
|
+
}).catch((error) => {
|
|
1807
|
+
this._cleanupTimeout(messageId);
|
|
1808
|
+
reject(error);
|
|
1809
|
+
});
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Gets the current status of a task.
|
|
1814
|
+
*
|
|
1815
|
+
* @experimental Use `client.experimental.tasks.getTask()` to access this method.
|
|
1816
|
+
*/
|
|
1817
|
+
async getTask(params, options) {
|
|
1818
|
+
return this.request({
|
|
1819
|
+
method: "tasks/get",
|
|
1820
|
+
params
|
|
1821
|
+
}, GetTaskResultSchema, options);
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* Retrieves the result of a completed task.
|
|
1825
|
+
*
|
|
1826
|
+
* @experimental Use `client.experimental.tasks.getTaskResult()` to access this method.
|
|
1827
|
+
*/
|
|
1828
|
+
async getTaskResult(params, resultSchema, options) {
|
|
1829
|
+
return this.request({
|
|
1830
|
+
method: "tasks/result",
|
|
1831
|
+
params
|
|
1832
|
+
}, resultSchema, options);
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Lists tasks, optionally starting from a pagination cursor.
|
|
1836
|
+
*
|
|
1837
|
+
* @experimental Use `client.experimental.tasks.listTasks()` to access this method.
|
|
1838
|
+
*/
|
|
1839
|
+
async listTasks(params, options) {
|
|
1840
|
+
return this.request({
|
|
1841
|
+
method: "tasks/list",
|
|
1842
|
+
params
|
|
1843
|
+
}, ListTasksResultSchema, options);
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Cancels a specific task.
|
|
1847
|
+
*
|
|
1848
|
+
* @experimental Use `client.experimental.tasks.cancelTask()` to access this method.
|
|
1849
|
+
*/
|
|
1850
|
+
async cancelTask(params, options) {
|
|
1851
|
+
return this.request({
|
|
1852
|
+
method: "tasks/cancel",
|
|
1853
|
+
params
|
|
1854
|
+
}, CancelTaskResultSchema, options);
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Emits a notification, which is a one-way message that does not expect a response.
|
|
1858
|
+
*/
|
|
1859
|
+
async notification(notification, options) {
|
|
1860
|
+
if (!this._transport) throw new Error("Not connected");
|
|
1861
|
+
this.assertNotificationCapability(notification.method);
|
|
1862
|
+
const relatedTaskId = options?.relatedTask?.taskId;
|
|
1863
|
+
if (relatedTaskId) {
|
|
1864
|
+
const jsonrpcNotification = {
|
|
1865
|
+
...notification,
|
|
1866
|
+
jsonrpc: "2.0",
|
|
1867
|
+
params: {
|
|
1868
|
+
...notification.params,
|
|
1869
|
+
_meta: {
|
|
1870
|
+
...notification.params?._meta || {},
|
|
1871
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
1876
|
+
type: "notification",
|
|
1877
|
+
message: jsonrpcNotification,
|
|
1878
|
+
timestamp: Date.now()
|
|
1879
|
+
});
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
if ((this._options?.debouncedNotificationMethods ?? []).includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask) {
|
|
1883
|
+
if (this._pendingDebouncedNotifications.has(notification.method)) return;
|
|
1884
|
+
this._pendingDebouncedNotifications.add(notification.method);
|
|
1885
|
+
Promise.resolve().then(() => {
|
|
1886
|
+
this._pendingDebouncedNotifications.delete(notification.method);
|
|
1887
|
+
if (!this._transport) return;
|
|
1888
|
+
let jsonrpcNotification = {
|
|
1889
|
+
...notification,
|
|
1890
|
+
jsonrpc: "2.0"
|
|
1891
|
+
};
|
|
1892
|
+
if (options?.relatedTask) jsonrpcNotification = {
|
|
1893
|
+
...jsonrpcNotification,
|
|
1894
|
+
params: {
|
|
1895
|
+
...jsonrpcNotification.params,
|
|
1896
|
+
_meta: {
|
|
1897
|
+
...jsonrpcNotification.params?._meta || {},
|
|
1898
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
this._transport?.send(jsonrpcNotification, options).catch((error) => this._onerror(error));
|
|
1903
|
+
});
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
let jsonrpcNotification = {
|
|
1907
|
+
...notification,
|
|
1908
|
+
jsonrpc: "2.0"
|
|
1909
|
+
};
|
|
1910
|
+
if (options?.relatedTask) jsonrpcNotification = {
|
|
1911
|
+
...jsonrpcNotification,
|
|
1912
|
+
params: {
|
|
1913
|
+
...jsonrpcNotification.params,
|
|
1914
|
+
_meta: {
|
|
1915
|
+
...jsonrpcNotification.params?._meta || {},
|
|
1916
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
};
|
|
1920
|
+
await this._transport.send(jsonrpcNotification, options);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Registers a handler to invoke when this protocol object receives a request with the given method.
|
|
1924
|
+
*
|
|
1925
|
+
* Note that this will replace any previous request handler for the same method.
|
|
1926
|
+
*/
|
|
1927
|
+
setRequestHandler(requestSchema, handler) {
|
|
1928
|
+
const method = getMethodLiteral(requestSchema);
|
|
1929
|
+
this.assertRequestHandlerCapability(method);
|
|
1930
|
+
this._requestHandlers.set(method, (request, extra) => {
|
|
1931
|
+
const parsed = parseWithCompat(requestSchema, request);
|
|
1932
|
+
return Promise.resolve(handler(parsed, extra));
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Removes the request handler for the given method.
|
|
1937
|
+
*/
|
|
1938
|
+
removeRequestHandler(method) {
|
|
1939
|
+
this._requestHandlers.delete(method);
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
|
|
1943
|
+
*/
|
|
1944
|
+
assertCanSetRequestHandler(method) {
|
|
1945
|
+
if (this._requestHandlers.has(method)) throw new Error(`A request handler for ${method} already exists, which would be overridden`);
|
|
1946
|
+
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Registers a handler to invoke when this protocol object receives a notification with the given method.
|
|
1949
|
+
*
|
|
1950
|
+
* Note that this will replace any previous notification handler for the same method.
|
|
1951
|
+
*/
|
|
1952
|
+
setNotificationHandler(notificationSchema, handler) {
|
|
1953
|
+
const method = getMethodLiteral(notificationSchema);
|
|
1954
|
+
this._notificationHandlers.set(method, (notification) => {
|
|
1955
|
+
const parsed = parseWithCompat(notificationSchema, notification);
|
|
1956
|
+
return Promise.resolve(handler(parsed));
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Removes the notification handler for the given method.
|
|
1961
|
+
*/
|
|
1962
|
+
removeNotificationHandler(method) {
|
|
1963
|
+
this._notificationHandlers.delete(method);
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Cleans up the progress handler associated with a task.
|
|
1967
|
+
* This should be called when a task reaches a terminal status.
|
|
1968
|
+
*/
|
|
1969
|
+
_cleanupTaskProgressHandler(taskId) {
|
|
1970
|
+
const progressToken = this._taskProgressTokens.get(taskId);
|
|
1971
|
+
if (progressToken !== void 0) {
|
|
1972
|
+
this._progressHandlers.delete(progressToken);
|
|
1973
|
+
this._taskProgressTokens.delete(taskId);
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Enqueues a task-related message for side-channel delivery via tasks/result.
|
|
1978
|
+
* @param taskId The task ID to associate the message with
|
|
1979
|
+
* @param message The message to enqueue
|
|
1980
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
1981
|
+
* @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow)
|
|
1982
|
+
*
|
|
1983
|
+
* Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle
|
|
1984
|
+
* the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer
|
|
1985
|
+
* simply propagates the error.
|
|
1986
|
+
*/
|
|
1987
|
+
async _enqueueTaskMessage(taskId, message, sessionId) {
|
|
1988
|
+
if (!this._taskStore || !this._taskMessageQueue) throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
1989
|
+
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
1990
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
1994
|
+
* @param taskId The task ID whose queue should be cleared
|
|
1995
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
1996
|
+
*/
|
|
1997
|
+
async _clearTaskQueue(taskId, sessionId) {
|
|
1998
|
+
if (this._taskMessageQueue) {
|
|
1999
|
+
const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId);
|
|
2000
|
+
for (const message of messages) if (message.type === "request" && isJSONRPCRequest(message.message)) {
|
|
2001
|
+
const requestId = message.message.id;
|
|
2002
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
2003
|
+
if (resolver) {
|
|
2004
|
+
resolver(new McpError(ErrorCode.InternalError, "Task cancelled or completed"));
|
|
2005
|
+
this._requestResolvers.delete(requestId);
|
|
2006
|
+
} else this._onerror(/* @__PURE__ */ new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`));
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Waits for a task update (new messages or status change) with abort signal support.
|
|
2012
|
+
* Uses polling to check for updates at the task's configured poll interval.
|
|
2013
|
+
* @param taskId The task ID to wait for
|
|
2014
|
+
* @param signal Abort signal to cancel the wait
|
|
2015
|
+
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
2016
|
+
*/
|
|
2017
|
+
async _waitForTaskUpdate(taskId, signal) {
|
|
2018
|
+
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
2019
|
+
try {
|
|
2020
|
+
const task = await this._taskStore?.getTask(taskId);
|
|
2021
|
+
if (task?.pollInterval) interval = task.pollInterval;
|
|
2022
|
+
} catch {}
|
|
2023
|
+
return new Promise((resolve, reject) => {
|
|
2024
|
+
if (signal.aborted) {
|
|
2025
|
+
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
const timeoutId = setTimeout(resolve, interval);
|
|
2029
|
+
signal.addEventListener("abort", () => {
|
|
2030
|
+
clearTimeout(timeoutId);
|
|
2031
|
+
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
2032
|
+
}, { once: true });
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
requestTaskStore(request, sessionId) {
|
|
2036
|
+
const taskStore = this._taskStore;
|
|
2037
|
+
if (!taskStore) throw new Error("No task store configured");
|
|
2038
|
+
return {
|
|
2039
|
+
createTask: async (taskParams) => {
|
|
2040
|
+
if (!request) throw new Error("No request provided");
|
|
2041
|
+
return await taskStore.createTask(taskParams, request.id, {
|
|
2042
|
+
method: request.method,
|
|
2043
|
+
params: request.params
|
|
2044
|
+
}, sessionId);
|
|
2045
|
+
},
|
|
2046
|
+
getTask: async (taskId) => {
|
|
2047
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
2048
|
+
if (!task) throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
2049
|
+
return task;
|
|
2050
|
+
},
|
|
2051
|
+
storeTaskResult: async (taskId, status, result) => {
|
|
2052
|
+
await taskStore.storeTaskResult(taskId, status, result, sessionId);
|
|
2053
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
2054
|
+
if (task) {
|
|
2055
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
2056
|
+
method: "notifications/tasks/status",
|
|
2057
|
+
params: task
|
|
2058
|
+
});
|
|
2059
|
+
await this.notification(notification);
|
|
2060
|
+
if (isTerminal(task.status)) this._cleanupTaskProgressHandler(taskId);
|
|
2061
|
+
}
|
|
2062
|
+
},
|
|
2063
|
+
getTaskResult: (taskId) => {
|
|
2064
|
+
return taskStore.getTaskResult(taskId, sessionId);
|
|
2065
|
+
},
|
|
2066
|
+
updateTaskStatus: async (taskId, status, statusMessage) => {
|
|
2067
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
2068
|
+
if (!task) throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
|
|
2069
|
+
if (isTerminal(task.status)) throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
|
|
2070
|
+
await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId);
|
|
2071
|
+
const updatedTask = await taskStore.getTask(taskId, sessionId);
|
|
2072
|
+
if (updatedTask) {
|
|
2073
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
2074
|
+
method: "notifications/tasks/status",
|
|
2075
|
+
params: updatedTask
|
|
2076
|
+
});
|
|
2077
|
+
await this.notification(notification);
|
|
2078
|
+
if (isTerminal(updatedTask.status)) this._cleanupTaskProgressHandler(taskId);
|
|
2079
|
+
}
|
|
2080
|
+
},
|
|
2081
|
+
listTasks: (cursor) => {
|
|
2082
|
+
return taskStore.listTasks(cursor, sessionId);
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
//#endregion
|
|
2088
|
+
export { ResourceListChangedNotificationSchema as C, ResourceLinkSchema as S, ToolSchema as T, PingRequestSchema as _, EmbeddedResourceSchema as a, ReadResourceResultSchema as b, JSONRPCMessageSchema as c, ListResourceTemplatesRequestSchema as d, ListResourceTemplatesResultSchema as f, LoggingMessageNotificationSchema as g, ListToolsRequestSchema as h, ContentBlockSchema as i, ListPromptsRequestSchema as l, ListResourcesResultSchema as m, CallToolRequestSchema as n, EmptyResultSchema as o, ListResourcesRequestSchema as p, CallToolResultSchema as r, ImplementationSchema as s, Protocol as t, ListPromptsResultSchema as u, PromptListChangedNotificationSchema as v, ToolListChangedNotificationSchema as w, RequestIdSchema as x, ReadResourceRequestSchema as y };
|
|
2089
|
+
|
|
2090
|
+
//# sourceMappingURL=protocol-CTflwIfG.js.map
|