@studiometa/productive-mcp 0.10.10 → 0.10.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -0
- package/dist/api-reference/generated.d.ts +3 -0
- package/dist/api-reference/generated.d.ts.map +1 -0
- package/dist/api-reference/types.d.ts +31 -0
- package/dist/api-reference/types.d.ts.map +1 -0
- package/dist/auth.js.map +1 -1
- package/dist/crypto.js +3 -3
- package/dist/crypto.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/handlers/activities.d.ts +3 -99
- package/dist/handlers/activities.d.ts.map +1 -1
- package/dist/handlers/api-read.d.ts +14 -0
- package/dist/handlers/api-read.d.ts.map +1 -0
- package/dist/handlers/api-utils.d.ts +27 -0
- package/dist/handlers/api-utils.d.ts.map +1 -0
- package/dist/handlers/api-write.d.ts +10 -0
- package/dist/handlers/api-write.d.ts.map +1 -0
- package/dist/handlers/attachments.d.ts +3 -99
- package/dist/handlers/attachments.d.ts.map +1 -1
- package/dist/handlers/bookings.d.ts +3 -99
- package/dist/handlers/bookings.d.ts.map +1 -1
- package/dist/handlers/comments.d.ts +3 -99
- package/dist/handlers/comments.d.ts.map +1 -1
- package/dist/handlers/companies.d.ts +3 -99
- package/dist/handlers/companies.d.ts.map +1 -1
- package/dist/handlers/custom-fields.d.ts +3 -99
- package/dist/handlers/custom-fields.d.ts.map +1 -1
- package/dist/handlers/deals.d.ts +3 -99
- package/dist/handlers/deals.d.ts.map +1 -1
- package/dist/handlers/discussions.d.ts +3 -99
- package/dist/handlers/discussions.d.ts.map +1 -1
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/pages.d.ts +3 -99
- package/dist/handlers/pages.d.ts.map +1 -1
- package/dist/handlers/projects.d.ts +3 -99
- package/dist/handlers/projects.d.ts.map +1 -1
- package/dist/handlers/search.d.ts +1 -1
- package/dist/handlers/search.d.ts.map +1 -1
- package/dist/handlers/services.d.ts +3 -99
- package/dist/handlers/services.d.ts.map +1 -1
- package/dist/handlers/tasks.d.ts +3 -99
- package/dist/handlers/tasks.d.ts.map +1 -1
- package/dist/handlers/time.d.ts +3 -99
- package/dist/handlers/time.d.ts.map +1 -1
- package/dist/handlers/timers.d.ts +3 -99
- package/dist/handlers/timers.d.ts.map +1 -1
- package/dist/handlers-DonE83xo.js +41289 -0
- package/dist/handlers-DonE83xo.js.map +1 -0
- package/dist/handlers.js +1 -1
- package/dist/http-QQVUnV2e.js +3238 -0
- package/dist/http-QQVUnV2e.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/oauth.js.map +1 -1
- package/dist/schema.d.ts +32 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/{stdio-BFK9AcdQ.js → stdio-CRD2nJPs.js} +2 -2
- package/dist/{stdio-BFK9AcdQ.js.map → stdio-CRD2nJPs.js.map} +1 -1
- package/dist/stdio.js +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +193 -119
- package/dist/tools.js.map +1 -1
- package/dist/{version-Cy8UEAT1.js → version-DMEaGciu.js} +3 -3
- package/dist/{version-Cy8UEAT1.js.map → version-DMEaGciu.js.map} +1 -1
- package/package.json +6 -6
- package/skills/SKILL.md +113 -1
- package/dist/handlers-vtRpc-Lx.js +0 -4301
- package/dist/handlers-vtRpc-Lx.js.map +0 -1
- package/dist/http-CVE4qtko.js +0 -6541
- package/dist/http-CVE4qtko.js.map +0 -1
|
@@ -0,0 +1,3238 @@
|
|
|
1
|
+
import { a as INSTRUCTIONS, i as readResource, n as listResourceTemplates, r as listResources, t as VERSION } from "./version-DMEaGciu.js";
|
|
2
|
+
import { _ as union, a as boolean, c as intersection, d as number, f as object, g as string, h as record, i as array, l as literal, m as preprocess, n as _enum, o as custom, p as optional, r as _null, s as discriminatedUnion, t as executeToolWithCredentials, u as looseObject, v as unknown, y as datetime } from "./handlers-DonE83xo.js";
|
|
3
|
+
import { a as handlePrompt, t as getAvailablePrompts } from "./stdio-CRD2nJPs.js";
|
|
4
|
+
import { TOOLS } from "./tools.js";
|
|
5
|
+
import { parseAuthHeader } from "./auth.js";
|
|
6
|
+
import { authorizeGetHandler, authorizePostHandler, oauthMetadataHandler, registerHandler, tokenHandler } from "./oauth.js";
|
|
7
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
8
|
+
import { CallToolRequestSchema, ErrorCode, GetPromptRequestSchema, ListPromptsRequestSchema, ListResourceTemplatesRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, McpError, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
+
import { H3, defineHandler } from "h3";
|
|
10
|
+
import "http";
|
|
11
|
+
import { Http2ServerRequest, constants } from "http2";
|
|
12
|
+
import { Readable } from "stream";
|
|
13
|
+
import crypto$1 from "crypto";
|
|
14
|
+
//#region ../../node_modules/@hono/node-server/dist/index.mjs
|
|
15
|
+
var RequestError = class extends Error {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = "RequestError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var toRequestError = (e) => {
|
|
22
|
+
if (e instanceof RequestError) return e;
|
|
23
|
+
return new RequestError(e.message, { cause: e });
|
|
24
|
+
};
|
|
25
|
+
var GlobalRequest = global.Request;
|
|
26
|
+
var Request = class extends GlobalRequest {
|
|
27
|
+
constructor(input, options) {
|
|
28
|
+
if (typeof input === "object" && getRequestCache in input) input = input[getRequestCache]();
|
|
29
|
+
if (typeof options?.body?.getReader !== "undefined") options.duplex ??= "half";
|
|
30
|
+
super(input, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var newHeadersFromIncoming = (incoming) => {
|
|
34
|
+
const headerRecord = [];
|
|
35
|
+
const rawHeaders = incoming.rawHeaders;
|
|
36
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
37
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
38
|
+
if (key.charCodeAt(0) !== 58) headerRecord.push([key, value]);
|
|
39
|
+
}
|
|
40
|
+
return new Headers(headerRecord);
|
|
41
|
+
};
|
|
42
|
+
var wrapBodyStream = Symbol("wrapBodyStream");
|
|
43
|
+
var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
44
|
+
const init = {
|
|
45
|
+
method,
|
|
46
|
+
headers,
|
|
47
|
+
signal: abortController.signal
|
|
48
|
+
};
|
|
49
|
+
if (method === "TRACE") {
|
|
50
|
+
init.method = "GET";
|
|
51
|
+
const req = new Request(url, init);
|
|
52
|
+
Object.defineProperty(req, "method", { get() {
|
|
53
|
+
return "TRACE";
|
|
54
|
+
} });
|
|
55
|
+
return req;
|
|
56
|
+
}
|
|
57
|
+
if (!(method === "GET" || method === "HEAD")) if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) init.body = new ReadableStream({ start(controller) {
|
|
58
|
+
controller.enqueue(incoming.rawBody);
|
|
59
|
+
controller.close();
|
|
60
|
+
} });
|
|
61
|
+
else if (incoming[wrapBodyStream]) {
|
|
62
|
+
let reader;
|
|
63
|
+
init.body = new ReadableStream({ async pull(controller) {
|
|
64
|
+
try {
|
|
65
|
+
reader ||= Readable.toWeb(incoming).getReader();
|
|
66
|
+
const { done, value } = await reader.read();
|
|
67
|
+
if (done) controller.close();
|
|
68
|
+
else controller.enqueue(value);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
controller.error(error);
|
|
71
|
+
}
|
|
72
|
+
} });
|
|
73
|
+
} else init.body = Readable.toWeb(incoming);
|
|
74
|
+
return new Request(url, init);
|
|
75
|
+
};
|
|
76
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
77
|
+
var requestCache = Symbol("requestCache");
|
|
78
|
+
var incomingKey = Symbol("incomingKey");
|
|
79
|
+
var urlKey = Symbol("urlKey");
|
|
80
|
+
var headersKey = Symbol("headersKey");
|
|
81
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
82
|
+
var requestPrototype = {
|
|
83
|
+
get method() {
|
|
84
|
+
return this[incomingKey].method || "GET";
|
|
85
|
+
},
|
|
86
|
+
get url() {
|
|
87
|
+
return this[urlKey];
|
|
88
|
+
},
|
|
89
|
+
get headers() {
|
|
90
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
91
|
+
},
|
|
92
|
+
[Symbol("getAbortController")]() {
|
|
93
|
+
this[getRequestCache]();
|
|
94
|
+
return this[abortControllerKey];
|
|
95
|
+
},
|
|
96
|
+
[getRequestCache]() {
|
|
97
|
+
this[abortControllerKey] ||= new AbortController();
|
|
98
|
+
return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
[
|
|
102
|
+
"body",
|
|
103
|
+
"bodyUsed",
|
|
104
|
+
"cache",
|
|
105
|
+
"credentials",
|
|
106
|
+
"destination",
|
|
107
|
+
"integrity",
|
|
108
|
+
"mode",
|
|
109
|
+
"redirect",
|
|
110
|
+
"referrer",
|
|
111
|
+
"referrerPolicy",
|
|
112
|
+
"signal",
|
|
113
|
+
"keepalive"
|
|
114
|
+
].forEach((k) => {
|
|
115
|
+
Object.defineProperty(requestPrototype, k, { get() {
|
|
116
|
+
return this[getRequestCache]()[k];
|
|
117
|
+
} });
|
|
118
|
+
});
|
|
119
|
+
[
|
|
120
|
+
"arrayBuffer",
|
|
121
|
+
"blob",
|
|
122
|
+
"clone",
|
|
123
|
+
"formData",
|
|
124
|
+
"json",
|
|
125
|
+
"text"
|
|
126
|
+
].forEach((k) => {
|
|
127
|
+
Object.defineProperty(requestPrototype, k, { value: function() {
|
|
128
|
+
return this[getRequestCache]()[k]();
|
|
129
|
+
} });
|
|
130
|
+
});
|
|
131
|
+
Object.setPrototypeOf(requestPrototype, Request.prototype);
|
|
132
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
133
|
+
const req = Object.create(requestPrototype);
|
|
134
|
+
req[incomingKey] = incoming;
|
|
135
|
+
const incomingUrl = incoming.url || "";
|
|
136
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
137
|
+
if (incoming instanceof Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
138
|
+
try {
|
|
139
|
+
req[urlKey] = new URL(incomingUrl).href;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
142
|
+
}
|
|
143
|
+
return req;
|
|
144
|
+
}
|
|
145
|
+
const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
146
|
+
if (!host) throw new RequestError("Missing host header");
|
|
147
|
+
let scheme;
|
|
148
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
149
|
+
scheme = incoming.scheme;
|
|
150
|
+
if (!(scheme === "http" || scheme === "https")) throw new RequestError("Unsupported scheme");
|
|
151
|
+
} else scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
152
|
+
const url = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
153
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) throw new RequestError("Invalid host header");
|
|
154
|
+
req[urlKey] = url.href;
|
|
155
|
+
return req;
|
|
156
|
+
};
|
|
157
|
+
var responseCache = Symbol("responseCache");
|
|
158
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
159
|
+
var cacheKey = Symbol("cache");
|
|
160
|
+
var GlobalResponse = global.Response;
|
|
161
|
+
var Response2 = class _Response {
|
|
162
|
+
#body;
|
|
163
|
+
#init;
|
|
164
|
+
[getResponseCache]() {
|
|
165
|
+
delete this[cacheKey];
|
|
166
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
167
|
+
}
|
|
168
|
+
constructor(body, init) {
|
|
169
|
+
let headers;
|
|
170
|
+
this.#body = body;
|
|
171
|
+
if (init instanceof _Response) {
|
|
172
|
+
const cachedGlobalResponse = init[responseCache];
|
|
173
|
+
if (cachedGlobalResponse) {
|
|
174
|
+
this.#init = cachedGlobalResponse;
|
|
175
|
+
this[getResponseCache]();
|
|
176
|
+
return;
|
|
177
|
+
} else {
|
|
178
|
+
this.#init = init.#init;
|
|
179
|
+
headers = new Headers(init.#init.headers);
|
|
180
|
+
}
|
|
181
|
+
} else this.#init = init;
|
|
182
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
183
|
+
init?.status || 200,
|
|
184
|
+
body,
|
|
185
|
+
headers || init?.headers
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
get headers() {
|
|
189
|
+
const cache = this[cacheKey];
|
|
190
|
+
if (cache) {
|
|
191
|
+
if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2] || { "content-type": "text/plain; charset=UTF-8" });
|
|
192
|
+
return cache[2];
|
|
193
|
+
}
|
|
194
|
+
return this[getResponseCache]().headers;
|
|
195
|
+
}
|
|
196
|
+
get status() {
|
|
197
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
198
|
+
}
|
|
199
|
+
get ok() {
|
|
200
|
+
const status = this.status;
|
|
201
|
+
return status >= 200 && status < 300;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
[
|
|
205
|
+
"body",
|
|
206
|
+
"bodyUsed",
|
|
207
|
+
"redirected",
|
|
208
|
+
"statusText",
|
|
209
|
+
"trailers",
|
|
210
|
+
"type",
|
|
211
|
+
"url"
|
|
212
|
+
].forEach((k) => {
|
|
213
|
+
Object.defineProperty(Response2.prototype, k, { get() {
|
|
214
|
+
return this[getResponseCache]()[k];
|
|
215
|
+
} });
|
|
216
|
+
});
|
|
217
|
+
[
|
|
218
|
+
"arrayBuffer",
|
|
219
|
+
"blob",
|
|
220
|
+
"clone",
|
|
221
|
+
"formData",
|
|
222
|
+
"json",
|
|
223
|
+
"text"
|
|
224
|
+
].forEach((k) => {
|
|
225
|
+
Object.defineProperty(Response2.prototype, k, { value: function() {
|
|
226
|
+
return this[getResponseCache]()[k]();
|
|
227
|
+
} });
|
|
228
|
+
});
|
|
229
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
230
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
231
|
+
async function readWithoutBlocking(readPromise) {
|
|
232
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
233
|
+
}
|
|
234
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
235
|
+
const cancel = (error) => {
|
|
236
|
+
reader.cancel(error).catch(() => {});
|
|
237
|
+
};
|
|
238
|
+
writable.on("close", cancel);
|
|
239
|
+
writable.on("error", cancel);
|
|
240
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
241
|
+
return reader.closed.finally(() => {
|
|
242
|
+
writable.off("close", cancel);
|
|
243
|
+
writable.off("error", cancel);
|
|
244
|
+
});
|
|
245
|
+
function handleStreamError(error) {
|
|
246
|
+
if (error) writable.destroy(error);
|
|
247
|
+
}
|
|
248
|
+
function onDrain() {
|
|
249
|
+
reader.read().then(flow, handleStreamError);
|
|
250
|
+
}
|
|
251
|
+
function flow({ done, value }) {
|
|
252
|
+
try {
|
|
253
|
+
if (done) writable.end();
|
|
254
|
+
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
255
|
+
else return reader.read().then(flow, handleStreamError);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
handleStreamError(e);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function writeFromReadableStream(stream, writable) {
|
|
262
|
+
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
263
|
+
else if (writable.destroyed) return;
|
|
264
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
265
|
+
}
|
|
266
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
267
|
+
const res = {};
|
|
268
|
+
if (!(headers instanceof Headers)) headers = new Headers(headers ?? void 0);
|
|
269
|
+
const cookies = [];
|
|
270
|
+
for (const [k, v] of headers) if (k === "set-cookie") cookies.push(v);
|
|
271
|
+
else res[k] = v;
|
|
272
|
+
if (cookies.length > 0) res["set-cookie"] = cookies;
|
|
273
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
274
|
+
return res;
|
|
275
|
+
};
|
|
276
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
277
|
+
if (typeof global.crypto === "undefined") global.crypto = crypto$1;
|
|
278
|
+
var outgoingEnded = Symbol("outgoingEnded");
|
|
279
|
+
var incomingDraining = Symbol("incomingDraining");
|
|
280
|
+
var DRAIN_TIMEOUT_MS = 500;
|
|
281
|
+
var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
|
|
282
|
+
var drainIncoming = (incoming) => {
|
|
283
|
+
const incomingWithDrainState = incoming;
|
|
284
|
+
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
285
|
+
incomingWithDrainState[incomingDraining] = true;
|
|
286
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
287
|
+
try {
|
|
288
|
+
incoming.stream?.close?.(constants.NGHTTP2_NO_ERROR);
|
|
289
|
+
} catch {}
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
let bytesRead = 0;
|
|
293
|
+
const cleanup = () => {
|
|
294
|
+
clearTimeout(timer);
|
|
295
|
+
incoming.off("data", onData);
|
|
296
|
+
incoming.off("end", cleanup);
|
|
297
|
+
incoming.off("error", cleanup);
|
|
298
|
+
};
|
|
299
|
+
const forceClose = () => {
|
|
300
|
+
cleanup();
|
|
301
|
+
const socket = incoming.socket;
|
|
302
|
+
if (socket && !socket.destroyed) socket.destroySoon();
|
|
303
|
+
};
|
|
304
|
+
const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
|
|
305
|
+
timer.unref?.();
|
|
306
|
+
const onData = (chunk) => {
|
|
307
|
+
bytesRead += chunk.length;
|
|
308
|
+
if (bytesRead > MAX_DRAIN_BYTES) forceClose();
|
|
309
|
+
};
|
|
310
|
+
incoming.on("data", onData);
|
|
311
|
+
incoming.on("end", cleanup);
|
|
312
|
+
incoming.on("error", cleanup);
|
|
313
|
+
incoming.resume();
|
|
314
|
+
};
|
|
315
|
+
var handleRequestError = () => new Response(null, { status: 400 });
|
|
316
|
+
var handleFetchError = (e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 });
|
|
317
|
+
var handleResponseError = (e, outgoing) => {
|
|
318
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
319
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
|
|
320
|
+
else {
|
|
321
|
+
console.error(e);
|
|
322
|
+
if (!outgoing.headersSent) outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
323
|
+
outgoing.end(`Error: ${err.message}`);
|
|
324
|
+
outgoing.destroy(err);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
var flushHeaders = (outgoing) => {
|
|
328
|
+
if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
|
|
329
|
+
};
|
|
330
|
+
var responseViaCache = async (res, outgoing) => {
|
|
331
|
+
let [status, body, header] = res[cacheKey];
|
|
332
|
+
let hasContentLength = false;
|
|
333
|
+
if (!header) header = { "content-type": "text/plain; charset=UTF-8" };
|
|
334
|
+
else if (header instanceof Headers) {
|
|
335
|
+
hasContentLength = header.has("content-length");
|
|
336
|
+
header = buildOutgoingHttpHeaders(header);
|
|
337
|
+
} else if (Array.isArray(header)) {
|
|
338
|
+
const headerObj = new Headers(header);
|
|
339
|
+
hasContentLength = headerObj.has("content-length");
|
|
340
|
+
header = buildOutgoingHttpHeaders(headerObj);
|
|
341
|
+
} else for (const key in header) if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
342
|
+
hasContentLength = true;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
if (!hasContentLength) {
|
|
346
|
+
if (typeof body === "string") header["Content-Length"] = Buffer.byteLength(body);
|
|
347
|
+
else if (body instanceof Uint8Array) header["Content-Length"] = body.byteLength;
|
|
348
|
+
else if (body instanceof Blob) header["Content-Length"] = body.size;
|
|
349
|
+
}
|
|
350
|
+
outgoing.writeHead(status, header);
|
|
351
|
+
if (typeof body === "string" || body instanceof Uint8Array) outgoing.end(body);
|
|
352
|
+
else if (body instanceof Blob) outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
353
|
+
else {
|
|
354
|
+
flushHeaders(outgoing);
|
|
355
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
356
|
+
}
|
|
357
|
+
outgoing[outgoingEnded]?.();
|
|
358
|
+
};
|
|
359
|
+
var isPromise = (res) => typeof res.then === "function";
|
|
360
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
361
|
+
if (isPromise(res)) if (options.errorHandler) try {
|
|
362
|
+
res = await res;
|
|
363
|
+
} catch (err) {
|
|
364
|
+
const errRes = await options.errorHandler(err);
|
|
365
|
+
if (!errRes) return;
|
|
366
|
+
res = errRes;
|
|
367
|
+
}
|
|
368
|
+
else res = await res.catch(handleFetchError);
|
|
369
|
+
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
370
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
371
|
+
if (res.body) {
|
|
372
|
+
const reader = res.body.getReader();
|
|
373
|
+
const values = [];
|
|
374
|
+
let done = false;
|
|
375
|
+
let currentReadPromise = void 0;
|
|
376
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
377
|
+
let maxReadCount = 2;
|
|
378
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
379
|
+
currentReadPromise ||= reader.read();
|
|
380
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
381
|
+
console.error(e);
|
|
382
|
+
done = true;
|
|
383
|
+
});
|
|
384
|
+
if (!chunk) {
|
|
385
|
+
if (i === 1) {
|
|
386
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
387
|
+
maxReadCount = 3;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
currentReadPromise = void 0;
|
|
393
|
+
if (chunk.value) values.push(chunk.value);
|
|
394
|
+
if (chunk.done) {
|
|
395
|
+
done = true;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
400
|
+
}
|
|
401
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
402
|
+
values.forEach((value) => {
|
|
403
|
+
outgoing.write(value);
|
|
404
|
+
});
|
|
405
|
+
if (done) outgoing.end();
|
|
406
|
+
else {
|
|
407
|
+
if (values.length === 0) flushHeaders(outgoing);
|
|
408
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
409
|
+
}
|
|
410
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
|
|
411
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
412
|
+
outgoing.end();
|
|
413
|
+
}
|
|
414
|
+
outgoing[outgoingEnded]?.();
|
|
415
|
+
};
|
|
416
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
417
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
418
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request) {
|
|
419
|
+
Object.defineProperty(global, "Request", { value: Request });
|
|
420
|
+
Object.defineProperty(global, "Response", { value: Response2 });
|
|
421
|
+
}
|
|
422
|
+
return async (incoming, outgoing) => {
|
|
423
|
+
let res, req;
|
|
424
|
+
try {
|
|
425
|
+
req = newRequest(incoming, options.hostname);
|
|
426
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
427
|
+
if (!incomingEnded) {
|
|
428
|
+
incoming[wrapBodyStream] = true;
|
|
429
|
+
incoming.on("end", () => {
|
|
430
|
+
incomingEnded = true;
|
|
431
|
+
});
|
|
432
|
+
if (incoming instanceof Http2ServerRequest) outgoing[outgoingEnded] = () => {
|
|
433
|
+
if (!incomingEnded) setTimeout(() => {
|
|
434
|
+
if (!incomingEnded) setTimeout(() => {
|
|
435
|
+
drainIncoming(incoming);
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
outgoing.on("finish", () => {
|
|
440
|
+
if (!incomingEnded) drainIncoming(incoming);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
outgoing.on("close", () => {
|
|
444
|
+
if (req[abortControllerKey]) {
|
|
445
|
+
if (incoming.errored) req[abortControllerKey].abort(incoming.errored.toString());
|
|
446
|
+
else if (!outgoing.writableFinished) req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
447
|
+
}
|
|
448
|
+
if (!incomingEnded) setTimeout(() => {
|
|
449
|
+
if (!incomingEnded) setTimeout(() => {
|
|
450
|
+
drainIncoming(incoming);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
res = fetchCallback(req, {
|
|
455
|
+
incoming,
|
|
456
|
+
outgoing
|
|
457
|
+
});
|
|
458
|
+
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
459
|
+
} catch (e) {
|
|
460
|
+
if (!res) if (options.errorHandler) {
|
|
461
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
462
|
+
if (!res) return;
|
|
463
|
+
} else if (!req) res = handleRequestError();
|
|
464
|
+
else res = handleFetchError(e);
|
|
465
|
+
else return handleResponseError(e, outgoing);
|
|
466
|
+
}
|
|
467
|
+
try {
|
|
468
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
469
|
+
} catch (e) {
|
|
470
|
+
return handleResponseError(e, outgoing);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
475
|
+
"2025-11-25",
|
|
476
|
+
"2025-06-18",
|
|
477
|
+
"2025-03-26",
|
|
478
|
+
"2024-11-05",
|
|
479
|
+
"2024-10-07"
|
|
480
|
+
];
|
|
481
|
+
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
482
|
+
/**
|
|
483
|
+
* Assert 'object' type schema.
|
|
484
|
+
*
|
|
485
|
+
* @internal
|
|
486
|
+
*/
|
|
487
|
+
var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
488
|
+
/**
|
|
489
|
+
* A progress token, used to associate progress notifications with the original request.
|
|
490
|
+
*/
|
|
491
|
+
var ProgressTokenSchema = union([string(), number().int()]);
|
|
492
|
+
/**
|
|
493
|
+
* An opaque token used to represent a cursor for pagination.
|
|
494
|
+
*/
|
|
495
|
+
var CursorSchema = string();
|
|
496
|
+
looseObject({
|
|
497
|
+
/**
|
|
498
|
+
* Requested duration in milliseconds to retain task from creation.
|
|
499
|
+
*/
|
|
500
|
+
ttl: number().optional(),
|
|
501
|
+
/**
|
|
502
|
+
* Time in milliseconds to wait between task status requests.
|
|
503
|
+
*/
|
|
504
|
+
pollInterval: number().optional()
|
|
505
|
+
});
|
|
506
|
+
var TaskMetadataSchema = object({ ttl: number().optional() });
|
|
507
|
+
/**
|
|
508
|
+
* Metadata for associating messages with a task.
|
|
509
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
510
|
+
*/
|
|
511
|
+
var RelatedTaskMetadataSchema = object({ taskId: string() });
|
|
512
|
+
var RequestMetaSchema = looseObject({
|
|
513
|
+
/**
|
|
514
|
+
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
515
|
+
*/
|
|
516
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
517
|
+
/**
|
|
518
|
+
* If specified, this request is related to the provided task.
|
|
519
|
+
*/
|
|
520
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
521
|
+
});
|
|
522
|
+
/**
|
|
523
|
+
* Common params for any request.
|
|
524
|
+
*/
|
|
525
|
+
var BaseRequestParamsSchema = object({
|
|
526
|
+
/**
|
|
527
|
+
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
528
|
+
*/
|
|
529
|
+
_meta: RequestMetaSchema.optional() });
|
|
530
|
+
/**
|
|
531
|
+
* Common params for any task-augmented request.
|
|
532
|
+
*/
|
|
533
|
+
var TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
534
|
+
/**
|
|
535
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
536
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
537
|
+
* retrieved later via tasks/result.
|
|
538
|
+
*
|
|
539
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
540
|
+
* for task augmentation of specific request types in their capabilities.
|
|
541
|
+
*/
|
|
542
|
+
task: TaskMetadataSchema.optional() });
|
|
543
|
+
var RequestSchema = object({
|
|
544
|
+
method: string(),
|
|
545
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
546
|
+
});
|
|
547
|
+
var NotificationsParamsSchema = object({
|
|
548
|
+
/**
|
|
549
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
550
|
+
* for notes on _meta usage.
|
|
551
|
+
*/
|
|
552
|
+
_meta: RequestMetaSchema.optional() });
|
|
553
|
+
var NotificationSchema = object({
|
|
554
|
+
method: string(),
|
|
555
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
556
|
+
});
|
|
557
|
+
var ResultSchema = looseObject({
|
|
558
|
+
/**
|
|
559
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
560
|
+
* for notes on _meta usage.
|
|
561
|
+
*/
|
|
562
|
+
_meta: RequestMetaSchema.optional() });
|
|
563
|
+
/**
|
|
564
|
+
* A uniquely identifying ID for a request in JSON-RPC.
|
|
565
|
+
*/
|
|
566
|
+
var RequestIdSchema = union([string(), number().int()]);
|
|
567
|
+
/**
|
|
568
|
+
* A request that expects a response.
|
|
569
|
+
*/
|
|
570
|
+
var JSONRPCRequestSchema = object({
|
|
571
|
+
jsonrpc: literal("2.0"),
|
|
572
|
+
id: RequestIdSchema,
|
|
573
|
+
...RequestSchema.shape
|
|
574
|
+
}).strict();
|
|
575
|
+
var isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success;
|
|
576
|
+
/**
|
|
577
|
+
* A notification which does not expect a response.
|
|
578
|
+
*/
|
|
579
|
+
var JSONRPCNotificationSchema = object({
|
|
580
|
+
jsonrpc: literal("2.0"),
|
|
581
|
+
...NotificationSchema.shape
|
|
582
|
+
}).strict();
|
|
583
|
+
/**
|
|
584
|
+
* A successful (non-error) response to a request.
|
|
585
|
+
*/
|
|
586
|
+
var JSONRPCResultResponseSchema = object({
|
|
587
|
+
jsonrpc: literal("2.0"),
|
|
588
|
+
id: RequestIdSchema,
|
|
589
|
+
result: ResultSchema
|
|
590
|
+
}).strict();
|
|
591
|
+
/**
|
|
592
|
+
* Checks if a value is a valid JSONRPCResultResponse.
|
|
593
|
+
* @param value - The value to check.
|
|
594
|
+
*
|
|
595
|
+
* @returns True if the value is a valid JSONRPCResultResponse, false otherwise.
|
|
596
|
+
*/
|
|
597
|
+
var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
|
|
598
|
+
/**
|
|
599
|
+
* Error codes defined by the JSON-RPC specification.
|
|
600
|
+
*/
|
|
601
|
+
var ErrorCode$1;
|
|
602
|
+
(function(ErrorCode) {
|
|
603
|
+
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
604
|
+
ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
605
|
+
ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
|
|
606
|
+
ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
607
|
+
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
608
|
+
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
609
|
+
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
610
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
611
|
+
})(ErrorCode$1 || (ErrorCode$1 = {}));
|
|
612
|
+
/**
|
|
613
|
+
* A response to a request that indicates an error occurred.
|
|
614
|
+
*/
|
|
615
|
+
var JSONRPCErrorResponseSchema = object({
|
|
616
|
+
jsonrpc: literal("2.0"),
|
|
617
|
+
id: RequestIdSchema.optional(),
|
|
618
|
+
error: object({
|
|
619
|
+
/**
|
|
620
|
+
* The error type that occurred.
|
|
621
|
+
*/
|
|
622
|
+
code: number().int(),
|
|
623
|
+
/**
|
|
624
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
625
|
+
*/
|
|
626
|
+
message: string(),
|
|
627
|
+
/**
|
|
628
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
629
|
+
*/
|
|
630
|
+
data: unknown().optional()
|
|
631
|
+
})
|
|
632
|
+
}).strict();
|
|
633
|
+
/**
|
|
634
|
+
* Checks if a value is a valid JSONRPCErrorResponse.
|
|
635
|
+
* @param value - The value to check.
|
|
636
|
+
*
|
|
637
|
+
* @returns True if the value is a valid JSONRPCErrorResponse, false otherwise.
|
|
638
|
+
*/
|
|
639
|
+
var isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
|
|
640
|
+
var JSONRPCMessageSchema = union([
|
|
641
|
+
JSONRPCRequestSchema,
|
|
642
|
+
JSONRPCNotificationSchema,
|
|
643
|
+
JSONRPCResultResponseSchema,
|
|
644
|
+
JSONRPCErrorResponseSchema
|
|
645
|
+
]);
|
|
646
|
+
union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
647
|
+
/**
|
|
648
|
+
* A response that indicates success but carries no data.
|
|
649
|
+
*/
|
|
650
|
+
var EmptyResultSchema = ResultSchema.strict();
|
|
651
|
+
var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
652
|
+
/**
|
|
653
|
+
* The ID of the request to cancel.
|
|
654
|
+
*
|
|
655
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
656
|
+
*/
|
|
657
|
+
requestId: RequestIdSchema.optional(),
|
|
658
|
+
/**
|
|
659
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
660
|
+
*/
|
|
661
|
+
reason: string().optional()
|
|
662
|
+
});
|
|
663
|
+
/**
|
|
664
|
+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
665
|
+
*
|
|
666
|
+
* 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.
|
|
667
|
+
*
|
|
668
|
+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
|
|
669
|
+
*
|
|
670
|
+
* A client MUST NOT attempt to cancel its `initialize` request.
|
|
671
|
+
*/
|
|
672
|
+
var CancelledNotificationSchema = NotificationSchema.extend({
|
|
673
|
+
method: literal("notifications/cancelled"),
|
|
674
|
+
params: CancelledNotificationParamsSchema
|
|
675
|
+
});
|
|
676
|
+
/**
|
|
677
|
+
* Base schema to add `icons` property.
|
|
678
|
+
*
|
|
679
|
+
*/
|
|
680
|
+
var IconsSchema = object({
|
|
681
|
+
/**
|
|
682
|
+
* Optional set of sized icons that the client can display in a user interface.
|
|
683
|
+
*
|
|
684
|
+
* Clients that support rendering icons MUST support at least the following MIME types:
|
|
685
|
+
* - `image/png` - PNG images (safe, universal compatibility)
|
|
686
|
+
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
|
|
687
|
+
*
|
|
688
|
+
* Clients that support rendering icons SHOULD also support:
|
|
689
|
+
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
|
|
690
|
+
* - `image/webp` - WebP images (modern, efficient format)
|
|
691
|
+
*/
|
|
692
|
+
icons: array(object({
|
|
693
|
+
/**
|
|
694
|
+
* URL or data URI for the icon.
|
|
695
|
+
*/
|
|
696
|
+
src: string(),
|
|
697
|
+
/**
|
|
698
|
+
* Optional MIME type for the icon.
|
|
699
|
+
*/
|
|
700
|
+
mimeType: string().optional(),
|
|
701
|
+
/**
|
|
702
|
+
* Optional array of strings that specify sizes at which the icon can be used.
|
|
703
|
+
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
|
|
704
|
+
*
|
|
705
|
+
* If not provided, the client should assume that the icon can be used at any size.
|
|
706
|
+
*/
|
|
707
|
+
sizes: array(string()).optional(),
|
|
708
|
+
/**
|
|
709
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
710
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
711
|
+
* the icon is designed to be used with a dark background.
|
|
712
|
+
*
|
|
713
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
714
|
+
*/
|
|
715
|
+
theme: _enum(["light", "dark"]).optional()
|
|
716
|
+
})).optional() });
|
|
717
|
+
/**
|
|
718
|
+
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
719
|
+
*/
|
|
720
|
+
var BaseMetadataSchema = object({
|
|
721
|
+
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
722
|
+
name: string(),
|
|
723
|
+
/**
|
|
724
|
+
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
|
|
725
|
+
* even by those unfamiliar with domain-specific terminology.
|
|
726
|
+
*
|
|
727
|
+
* If not provided, the name should be used for display (except for Tool,
|
|
728
|
+
* where `annotations.title` should be given precedence over using `name`,
|
|
729
|
+
* if present).
|
|
730
|
+
*/
|
|
731
|
+
title: string().optional()
|
|
732
|
+
});
|
|
733
|
+
/**
|
|
734
|
+
* Describes the name and version of an MCP implementation.
|
|
735
|
+
*/
|
|
736
|
+
var ImplementationSchema = BaseMetadataSchema.extend({
|
|
737
|
+
...BaseMetadataSchema.shape,
|
|
738
|
+
...IconsSchema.shape,
|
|
739
|
+
version: string(),
|
|
740
|
+
/**
|
|
741
|
+
* An optional URL of the website for this implementation.
|
|
742
|
+
*/
|
|
743
|
+
websiteUrl: string().optional(),
|
|
744
|
+
/**
|
|
745
|
+
* An optional human-readable description of what this implementation does.
|
|
746
|
+
*
|
|
747
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
748
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
749
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
750
|
+
*/
|
|
751
|
+
description: string().optional()
|
|
752
|
+
});
|
|
753
|
+
var ElicitationCapabilitySchema = preprocess((value) => {
|
|
754
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
755
|
+
if (Object.keys(value).length === 0) return { form: {} };
|
|
756
|
+
}
|
|
757
|
+
return value;
|
|
758
|
+
}, intersection(object({
|
|
759
|
+
form: intersection(object({ applyDefaults: boolean().optional() }), record(string(), unknown())).optional(),
|
|
760
|
+
url: AssertObjectSchema.optional()
|
|
761
|
+
}), record(string(), unknown()).optional()));
|
|
762
|
+
/**
|
|
763
|
+
* Task capabilities for clients, indicating which request types support task creation.
|
|
764
|
+
*/
|
|
765
|
+
var ClientTasksCapabilitySchema = looseObject({
|
|
766
|
+
/**
|
|
767
|
+
* Present if the client supports listing tasks.
|
|
768
|
+
*/
|
|
769
|
+
list: AssertObjectSchema.optional(),
|
|
770
|
+
/**
|
|
771
|
+
* Present if the client supports cancelling tasks.
|
|
772
|
+
*/
|
|
773
|
+
cancel: AssertObjectSchema.optional(),
|
|
774
|
+
/**
|
|
775
|
+
* Capabilities for task creation on specific request types.
|
|
776
|
+
*/
|
|
777
|
+
requests: looseObject({
|
|
778
|
+
/**
|
|
779
|
+
* Task support for sampling requests.
|
|
780
|
+
*/
|
|
781
|
+
sampling: looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
|
|
782
|
+
/**
|
|
783
|
+
* Task support for elicitation requests.
|
|
784
|
+
*/
|
|
785
|
+
elicitation: looseObject({ create: AssertObjectSchema.optional() }).optional()
|
|
786
|
+
}).optional()
|
|
787
|
+
});
|
|
788
|
+
/**
|
|
789
|
+
* Task capabilities for servers, indicating which request types support task creation.
|
|
790
|
+
*/
|
|
791
|
+
var ServerTasksCapabilitySchema = looseObject({
|
|
792
|
+
/**
|
|
793
|
+
* Present if the server supports listing tasks.
|
|
794
|
+
*/
|
|
795
|
+
list: AssertObjectSchema.optional(),
|
|
796
|
+
/**
|
|
797
|
+
* Present if the server supports cancelling tasks.
|
|
798
|
+
*/
|
|
799
|
+
cancel: AssertObjectSchema.optional(),
|
|
800
|
+
/**
|
|
801
|
+
* Capabilities for task creation on specific request types.
|
|
802
|
+
*/
|
|
803
|
+
requests: looseObject({
|
|
804
|
+
/**
|
|
805
|
+
* Task support for tool requests.
|
|
806
|
+
*/
|
|
807
|
+
tools: looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
|
|
808
|
+
});
|
|
809
|
+
/**
|
|
810
|
+
* 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.
|
|
811
|
+
*/
|
|
812
|
+
var ClientCapabilitiesSchema = object({
|
|
813
|
+
/**
|
|
814
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
815
|
+
*/
|
|
816
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
817
|
+
/**
|
|
818
|
+
* Present if the client supports sampling from an LLM.
|
|
819
|
+
*/
|
|
820
|
+
sampling: object({
|
|
821
|
+
/**
|
|
822
|
+
* Present if the client supports context inclusion via includeContext parameter.
|
|
823
|
+
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
|
|
824
|
+
*/
|
|
825
|
+
context: AssertObjectSchema.optional(),
|
|
826
|
+
/**
|
|
827
|
+
* Present if the client supports tool use via tools and toolChoice parameters.
|
|
828
|
+
*/
|
|
829
|
+
tools: AssertObjectSchema.optional()
|
|
830
|
+
}).optional(),
|
|
831
|
+
/**
|
|
832
|
+
* Present if the client supports eliciting user input.
|
|
833
|
+
*/
|
|
834
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
835
|
+
/**
|
|
836
|
+
* Present if the client supports listing roots.
|
|
837
|
+
*/
|
|
838
|
+
roots: object({
|
|
839
|
+
/**
|
|
840
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
841
|
+
*/
|
|
842
|
+
listChanged: boolean().optional() }).optional(),
|
|
843
|
+
/**
|
|
844
|
+
* Present if the client supports task creation.
|
|
845
|
+
*/
|
|
846
|
+
tasks: ClientTasksCapabilitySchema.optional(),
|
|
847
|
+
/**
|
|
848
|
+
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
849
|
+
*/
|
|
850
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
851
|
+
});
|
|
852
|
+
var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
853
|
+
/**
|
|
854
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
855
|
+
*/
|
|
856
|
+
protocolVersion: string(),
|
|
857
|
+
capabilities: ClientCapabilitiesSchema,
|
|
858
|
+
clientInfo: ImplementationSchema
|
|
859
|
+
});
|
|
860
|
+
/**
|
|
861
|
+
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
862
|
+
*/
|
|
863
|
+
var InitializeRequestSchema = RequestSchema.extend({
|
|
864
|
+
method: literal("initialize"),
|
|
865
|
+
params: InitializeRequestParamsSchema
|
|
866
|
+
});
|
|
867
|
+
var isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
|
|
868
|
+
/**
|
|
869
|
+
* 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.
|
|
870
|
+
*/
|
|
871
|
+
var ServerCapabilitiesSchema = object({
|
|
872
|
+
/**
|
|
873
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
874
|
+
*/
|
|
875
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
876
|
+
/**
|
|
877
|
+
* Present if the server supports sending log messages to the client.
|
|
878
|
+
*/
|
|
879
|
+
logging: AssertObjectSchema.optional(),
|
|
880
|
+
/**
|
|
881
|
+
* Present if the server supports sending completions to the client.
|
|
882
|
+
*/
|
|
883
|
+
completions: AssertObjectSchema.optional(),
|
|
884
|
+
/**
|
|
885
|
+
* Present if the server offers any prompt templates.
|
|
886
|
+
*/
|
|
887
|
+
prompts: object({
|
|
888
|
+
/**
|
|
889
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
890
|
+
*/
|
|
891
|
+
listChanged: boolean().optional() }).optional(),
|
|
892
|
+
/**
|
|
893
|
+
* Present if the server offers any resources to read.
|
|
894
|
+
*/
|
|
895
|
+
resources: object({
|
|
896
|
+
/**
|
|
897
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
898
|
+
*/
|
|
899
|
+
subscribe: boolean().optional(),
|
|
900
|
+
/**
|
|
901
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
902
|
+
*/
|
|
903
|
+
listChanged: boolean().optional()
|
|
904
|
+
}).optional(),
|
|
905
|
+
/**
|
|
906
|
+
* Present if the server offers any tools to call.
|
|
907
|
+
*/
|
|
908
|
+
tools: object({
|
|
909
|
+
/**
|
|
910
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
911
|
+
*/
|
|
912
|
+
listChanged: boolean().optional() }).optional(),
|
|
913
|
+
/**
|
|
914
|
+
* Present if the server supports task creation.
|
|
915
|
+
*/
|
|
916
|
+
tasks: ServerTasksCapabilitySchema.optional(),
|
|
917
|
+
/**
|
|
918
|
+
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
919
|
+
*/
|
|
920
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
921
|
+
});
|
|
922
|
+
/**
|
|
923
|
+
* After receiving an initialize request from the client, the server sends this response.
|
|
924
|
+
*/
|
|
925
|
+
var InitializeResultSchema = ResultSchema.extend({
|
|
926
|
+
/**
|
|
927
|
+
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
|
|
928
|
+
*/
|
|
929
|
+
protocolVersion: string(),
|
|
930
|
+
capabilities: ServerCapabilitiesSchema,
|
|
931
|
+
serverInfo: ImplementationSchema,
|
|
932
|
+
/**
|
|
933
|
+
* Instructions describing how to use the server and its features.
|
|
934
|
+
*
|
|
935
|
+
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
|
|
936
|
+
*/
|
|
937
|
+
instructions: string().optional()
|
|
938
|
+
});
|
|
939
|
+
/**
|
|
940
|
+
* This notification is sent from the client to the server after initialization has finished.
|
|
941
|
+
*/
|
|
942
|
+
var InitializedNotificationSchema = NotificationSchema.extend({
|
|
943
|
+
method: literal("notifications/initialized"),
|
|
944
|
+
params: NotificationsParamsSchema.optional()
|
|
945
|
+
});
|
|
946
|
+
/**
|
|
947
|
+
* 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.
|
|
948
|
+
*/
|
|
949
|
+
var PingRequestSchema = RequestSchema.extend({
|
|
950
|
+
method: literal("ping"),
|
|
951
|
+
params: BaseRequestParamsSchema.optional()
|
|
952
|
+
});
|
|
953
|
+
var ProgressSchema = object({
|
|
954
|
+
/**
|
|
955
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
956
|
+
*/
|
|
957
|
+
progress: number(),
|
|
958
|
+
/**
|
|
959
|
+
* Total number of items to process (or total progress required), if known.
|
|
960
|
+
*/
|
|
961
|
+
total: optional(number()),
|
|
962
|
+
/**
|
|
963
|
+
* An optional message describing the current progress.
|
|
964
|
+
*/
|
|
965
|
+
message: optional(string())
|
|
966
|
+
});
|
|
967
|
+
var ProgressNotificationParamsSchema = object({
|
|
968
|
+
...NotificationsParamsSchema.shape,
|
|
969
|
+
...ProgressSchema.shape,
|
|
970
|
+
/**
|
|
971
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
972
|
+
*/
|
|
973
|
+
progressToken: ProgressTokenSchema
|
|
974
|
+
});
|
|
975
|
+
/**
|
|
976
|
+
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
977
|
+
*
|
|
978
|
+
* @category notifications/progress
|
|
979
|
+
*/
|
|
980
|
+
var ProgressNotificationSchema = NotificationSchema.extend({
|
|
981
|
+
method: literal("notifications/progress"),
|
|
982
|
+
params: ProgressNotificationParamsSchema
|
|
983
|
+
});
|
|
984
|
+
var PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
985
|
+
/**
|
|
986
|
+
* An opaque token representing the current pagination position.
|
|
987
|
+
* If provided, the server should return results starting after this cursor.
|
|
988
|
+
*/
|
|
989
|
+
cursor: CursorSchema.optional() });
|
|
990
|
+
var PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
|
|
991
|
+
var PaginatedResultSchema = ResultSchema.extend({
|
|
992
|
+
/**
|
|
993
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
994
|
+
* If present, there may be more results available.
|
|
995
|
+
*/
|
|
996
|
+
nextCursor: CursorSchema.optional() });
|
|
997
|
+
/**
|
|
998
|
+
* The status of a task.
|
|
999
|
+
* */
|
|
1000
|
+
var TaskStatusSchema = _enum([
|
|
1001
|
+
"working",
|
|
1002
|
+
"input_required",
|
|
1003
|
+
"completed",
|
|
1004
|
+
"failed",
|
|
1005
|
+
"cancelled"
|
|
1006
|
+
]);
|
|
1007
|
+
/**
|
|
1008
|
+
* A pollable state object associated with a request.
|
|
1009
|
+
*/
|
|
1010
|
+
var TaskSchema = object({
|
|
1011
|
+
taskId: string(),
|
|
1012
|
+
status: TaskStatusSchema,
|
|
1013
|
+
/**
|
|
1014
|
+
* Time in milliseconds to keep task results available after completion.
|
|
1015
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
1016
|
+
*/
|
|
1017
|
+
ttl: union([number(), _null()]),
|
|
1018
|
+
/**
|
|
1019
|
+
* ISO 8601 timestamp when the task was created.
|
|
1020
|
+
*/
|
|
1021
|
+
createdAt: string(),
|
|
1022
|
+
/**
|
|
1023
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
1024
|
+
*/
|
|
1025
|
+
lastUpdatedAt: string(),
|
|
1026
|
+
pollInterval: optional(number()),
|
|
1027
|
+
/**
|
|
1028
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
1029
|
+
*/
|
|
1030
|
+
statusMessage: optional(string())
|
|
1031
|
+
});
|
|
1032
|
+
/**
|
|
1033
|
+
* Result returned when a task is created, containing the task data wrapped in a task field.
|
|
1034
|
+
*/
|
|
1035
|
+
var CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
|
|
1036
|
+
/**
|
|
1037
|
+
* Parameters for task status notification.
|
|
1038
|
+
*/
|
|
1039
|
+
var TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
1040
|
+
/**
|
|
1041
|
+
* A notification sent when a task's status changes.
|
|
1042
|
+
*/
|
|
1043
|
+
var TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
1044
|
+
method: literal("notifications/tasks/status"),
|
|
1045
|
+
params: TaskStatusNotificationParamsSchema
|
|
1046
|
+
});
|
|
1047
|
+
/**
|
|
1048
|
+
* A request to get the state of a specific task.
|
|
1049
|
+
*/
|
|
1050
|
+
var GetTaskRequestSchema = RequestSchema.extend({
|
|
1051
|
+
method: literal("tasks/get"),
|
|
1052
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
1053
|
+
});
|
|
1054
|
+
/**
|
|
1055
|
+
* The response to a tasks/get request.
|
|
1056
|
+
*/
|
|
1057
|
+
var GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
1058
|
+
/**
|
|
1059
|
+
* A request to get the result of a specific task.
|
|
1060
|
+
*/
|
|
1061
|
+
var GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
1062
|
+
method: literal("tasks/result"),
|
|
1063
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
1064
|
+
});
|
|
1065
|
+
ResultSchema.loose();
|
|
1066
|
+
/**
|
|
1067
|
+
* A request to list tasks.
|
|
1068
|
+
*/
|
|
1069
|
+
var ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: literal("tasks/list") });
|
|
1070
|
+
/**
|
|
1071
|
+
* The response to a tasks/list request.
|
|
1072
|
+
*/
|
|
1073
|
+
var ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: array(TaskSchema) });
|
|
1074
|
+
/**
|
|
1075
|
+
* A request to cancel a specific task.
|
|
1076
|
+
*/
|
|
1077
|
+
var CancelTaskRequestSchema = RequestSchema.extend({
|
|
1078
|
+
method: literal("tasks/cancel"),
|
|
1079
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
1080
|
+
});
|
|
1081
|
+
ResultSchema.merge(TaskSchema);
|
|
1082
|
+
/**
|
|
1083
|
+
* The contents of a specific resource or sub-resource.
|
|
1084
|
+
*/
|
|
1085
|
+
var ResourceContentsSchema = object({
|
|
1086
|
+
/**
|
|
1087
|
+
* The URI of this resource.
|
|
1088
|
+
*/
|
|
1089
|
+
uri: string(),
|
|
1090
|
+
/**
|
|
1091
|
+
* The MIME type of this resource, if known.
|
|
1092
|
+
*/
|
|
1093
|
+
mimeType: optional(string()),
|
|
1094
|
+
/**
|
|
1095
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1096
|
+
* for notes on _meta usage.
|
|
1097
|
+
*/
|
|
1098
|
+
_meta: record(string(), unknown()).optional()
|
|
1099
|
+
});
|
|
1100
|
+
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
1101
|
+
/**
|
|
1102
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
1103
|
+
*/
|
|
1104
|
+
text: string() });
|
|
1105
|
+
/**
|
|
1106
|
+
* A Zod schema for validating Base64 strings that is more performant and
|
|
1107
|
+
* robust for very large inputs than the default regex-based check. It avoids
|
|
1108
|
+
* stack overflows by using the native `atob` function for validation.
|
|
1109
|
+
*/
|
|
1110
|
+
var Base64Schema = string().refine((val) => {
|
|
1111
|
+
try {
|
|
1112
|
+
atob(val);
|
|
1113
|
+
return true;
|
|
1114
|
+
} catch {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
}, { message: "Invalid Base64 string" });
|
|
1118
|
+
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
1119
|
+
/**
|
|
1120
|
+
* A base64-encoded string representing the binary data of the item.
|
|
1121
|
+
*/
|
|
1122
|
+
blob: Base64Schema });
|
|
1123
|
+
/**
|
|
1124
|
+
* The sender or recipient of messages and data in a conversation.
|
|
1125
|
+
*/
|
|
1126
|
+
var RoleSchema = _enum(["user", "assistant"]);
|
|
1127
|
+
/**
|
|
1128
|
+
* Optional annotations providing clients additional context about a resource.
|
|
1129
|
+
*/
|
|
1130
|
+
var AnnotationsSchema = object({
|
|
1131
|
+
/**
|
|
1132
|
+
* Intended audience(s) for the resource.
|
|
1133
|
+
*/
|
|
1134
|
+
audience: array(RoleSchema).optional(),
|
|
1135
|
+
/**
|
|
1136
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
1137
|
+
*/
|
|
1138
|
+
priority: number().min(0).max(1).optional(),
|
|
1139
|
+
/**
|
|
1140
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
1141
|
+
*/
|
|
1142
|
+
lastModified: datetime({ offset: true }).optional()
|
|
1143
|
+
});
|
|
1144
|
+
/**
|
|
1145
|
+
* A known resource that the server is capable of reading.
|
|
1146
|
+
*/
|
|
1147
|
+
var ResourceSchema = object({
|
|
1148
|
+
...BaseMetadataSchema.shape,
|
|
1149
|
+
...IconsSchema.shape,
|
|
1150
|
+
/**
|
|
1151
|
+
* The URI of this resource.
|
|
1152
|
+
*/
|
|
1153
|
+
uri: string(),
|
|
1154
|
+
/**
|
|
1155
|
+
* A description of what this resource represents.
|
|
1156
|
+
*
|
|
1157
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
1158
|
+
*/
|
|
1159
|
+
description: optional(string()),
|
|
1160
|
+
/**
|
|
1161
|
+
* The MIME type of this resource, if known.
|
|
1162
|
+
*/
|
|
1163
|
+
mimeType: optional(string()),
|
|
1164
|
+
/**
|
|
1165
|
+
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
|
|
1166
|
+
*
|
|
1167
|
+
* This can be used by Hosts to display file sizes and estimate context window usage.
|
|
1168
|
+
*/
|
|
1169
|
+
size: optional(number()),
|
|
1170
|
+
/**
|
|
1171
|
+
* Optional annotations for the client.
|
|
1172
|
+
*/
|
|
1173
|
+
annotations: AnnotationsSchema.optional(),
|
|
1174
|
+
/**
|
|
1175
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1176
|
+
* for notes on _meta usage.
|
|
1177
|
+
*/
|
|
1178
|
+
_meta: optional(looseObject({}))
|
|
1179
|
+
});
|
|
1180
|
+
/**
|
|
1181
|
+
* A template description for resources available on the server.
|
|
1182
|
+
*/
|
|
1183
|
+
var ResourceTemplateSchema = object({
|
|
1184
|
+
...BaseMetadataSchema.shape,
|
|
1185
|
+
...IconsSchema.shape,
|
|
1186
|
+
/**
|
|
1187
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
1188
|
+
*/
|
|
1189
|
+
uriTemplate: string(),
|
|
1190
|
+
/**
|
|
1191
|
+
* A description of what this template is for.
|
|
1192
|
+
*
|
|
1193
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
1194
|
+
*/
|
|
1195
|
+
description: optional(string()),
|
|
1196
|
+
/**
|
|
1197
|
+
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
|
|
1198
|
+
*/
|
|
1199
|
+
mimeType: optional(string()),
|
|
1200
|
+
/**
|
|
1201
|
+
* Optional annotations for the client.
|
|
1202
|
+
*/
|
|
1203
|
+
annotations: AnnotationsSchema.optional(),
|
|
1204
|
+
/**
|
|
1205
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1206
|
+
* for notes on _meta usage.
|
|
1207
|
+
*/
|
|
1208
|
+
_meta: optional(looseObject({}))
|
|
1209
|
+
});
|
|
1210
|
+
/**
|
|
1211
|
+
* Sent from the client to request a list of resources the server has.
|
|
1212
|
+
*/
|
|
1213
|
+
var ListResourcesRequestSchema$1 = PaginatedRequestSchema.extend({ method: literal("resources/list") });
|
|
1214
|
+
/**
|
|
1215
|
+
* The server's response to a resources/list request from the client.
|
|
1216
|
+
*/
|
|
1217
|
+
var ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: array(ResourceSchema) });
|
|
1218
|
+
/**
|
|
1219
|
+
* Sent from the client to request a list of resource templates the server has.
|
|
1220
|
+
*/
|
|
1221
|
+
var ListResourceTemplatesRequestSchema$1 = PaginatedRequestSchema.extend({ method: literal("resources/templates/list") });
|
|
1222
|
+
/**
|
|
1223
|
+
* The server's response to a resources/templates/list request from the client.
|
|
1224
|
+
*/
|
|
1225
|
+
var ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: array(ResourceTemplateSchema) });
|
|
1226
|
+
var ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1227
|
+
/**
|
|
1228
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
1229
|
+
*
|
|
1230
|
+
* @format uri
|
|
1231
|
+
*/
|
|
1232
|
+
uri: string() });
|
|
1233
|
+
/**
|
|
1234
|
+
* Parameters for a `resources/read` request.
|
|
1235
|
+
*/
|
|
1236
|
+
var ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
1237
|
+
/**
|
|
1238
|
+
* Sent from the client to the server, to read a specific resource URI.
|
|
1239
|
+
*/
|
|
1240
|
+
var ReadResourceRequestSchema$1 = RequestSchema.extend({
|
|
1241
|
+
method: literal("resources/read"),
|
|
1242
|
+
params: ReadResourceRequestParamsSchema
|
|
1243
|
+
});
|
|
1244
|
+
/**
|
|
1245
|
+
* The server's response to a resources/read request from the client.
|
|
1246
|
+
*/
|
|
1247
|
+
var ReadResourceResultSchema = ResultSchema.extend({ contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
|
|
1248
|
+
/**
|
|
1249
|
+
* 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.
|
|
1250
|
+
*/
|
|
1251
|
+
var ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
1252
|
+
method: literal("notifications/resources/list_changed"),
|
|
1253
|
+
params: NotificationsParamsSchema.optional()
|
|
1254
|
+
});
|
|
1255
|
+
var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
1256
|
+
/**
|
|
1257
|
+
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
1258
|
+
*/
|
|
1259
|
+
var SubscribeRequestSchema = RequestSchema.extend({
|
|
1260
|
+
method: literal("resources/subscribe"),
|
|
1261
|
+
params: SubscribeRequestParamsSchema
|
|
1262
|
+
});
|
|
1263
|
+
var UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
1264
|
+
/**
|
|
1265
|
+
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
1266
|
+
*/
|
|
1267
|
+
var UnsubscribeRequestSchema = RequestSchema.extend({
|
|
1268
|
+
method: literal("resources/unsubscribe"),
|
|
1269
|
+
params: UnsubscribeRequestParamsSchema
|
|
1270
|
+
});
|
|
1271
|
+
/**
|
|
1272
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
1273
|
+
*/
|
|
1274
|
+
var ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
1275
|
+
/**
|
|
1276
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
1277
|
+
*/
|
|
1278
|
+
uri: string() });
|
|
1279
|
+
/**
|
|
1280
|
+
* 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.
|
|
1281
|
+
*/
|
|
1282
|
+
var ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
1283
|
+
method: literal("notifications/resources/updated"),
|
|
1284
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
1285
|
+
});
|
|
1286
|
+
/**
|
|
1287
|
+
* Describes an argument that a prompt can accept.
|
|
1288
|
+
*/
|
|
1289
|
+
var PromptArgumentSchema = object({
|
|
1290
|
+
/**
|
|
1291
|
+
* The name of the argument.
|
|
1292
|
+
*/
|
|
1293
|
+
name: string(),
|
|
1294
|
+
/**
|
|
1295
|
+
* A human-readable description of the argument.
|
|
1296
|
+
*/
|
|
1297
|
+
description: optional(string()),
|
|
1298
|
+
/**
|
|
1299
|
+
* Whether this argument must be provided.
|
|
1300
|
+
*/
|
|
1301
|
+
required: optional(boolean())
|
|
1302
|
+
});
|
|
1303
|
+
/**
|
|
1304
|
+
* A prompt or prompt template that the server offers.
|
|
1305
|
+
*/
|
|
1306
|
+
var PromptSchema = object({
|
|
1307
|
+
...BaseMetadataSchema.shape,
|
|
1308
|
+
...IconsSchema.shape,
|
|
1309
|
+
/**
|
|
1310
|
+
* An optional description of what this prompt provides
|
|
1311
|
+
*/
|
|
1312
|
+
description: optional(string()),
|
|
1313
|
+
/**
|
|
1314
|
+
* A list of arguments to use for templating the prompt.
|
|
1315
|
+
*/
|
|
1316
|
+
arguments: optional(array(PromptArgumentSchema)),
|
|
1317
|
+
/**
|
|
1318
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1319
|
+
* for notes on _meta usage.
|
|
1320
|
+
*/
|
|
1321
|
+
_meta: optional(looseObject({}))
|
|
1322
|
+
});
|
|
1323
|
+
/**
|
|
1324
|
+
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
1325
|
+
*/
|
|
1326
|
+
var ListPromptsRequestSchema$1 = PaginatedRequestSchema.extend({ method: literal("prompts/list") });
|
|
1327
|
+
/**
|
|
1328
|
+
* The server's response to a prompts/list request from the client.
|
|
1329
|
+
*/
|
|
1330
|
+
var ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: array(PromptSchema) });
|
|
1331
|
+
/**
|
|
1332
|
+
* Parameters for a `prompts/get` request.
|
|
1333
|
+
*/
|
|
1334
|
+
var GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1335
|
+
/**
|
|
1336
|
+
* The name of the prompt or prompt template.
|
|
1337
|
+
*/
|
|
1338
|
+
name: string(),
|
|
1339
|
+
/**
|
|
1340
|
+
* Arguments to use for templating the prompt.
|
|
1341
|
+
*/
|
|
1342
|
+
arguments: record(string(), string()).optional()
|
|
1343
|
+
});
|
|
1344
|
+
/**
|
|
1345
|
+
* Used by the client to get a prompt provided by the server.
|
|
1346
|
+
*/
|
|
1347
|
+
var GetPromptRequestSchema$1 = RequestSchema.extend({
|
|
1348
|
+
method: literal("prompts/get"),
|
|
1349
|
+
params: GetPromptRequestParamsSchema
|
|
1350
|
+
});
|
|
1351
|
+
/**
|
|
1352
|
+
* Text provided to or from an LLM.
|
|
1353
|
+
*/
|
|
1354
|
+
var TextContentSchema = object({
|
|
1355
|
+
type: literal("text"),
|
|
1356
|
+
/**
|
|
1357
|
+
* The text content of the message.
|
|
1358
|
+
*/
|
|
1359
|
+
text: string(),
|
|
1360
|
+
/**
|
|
1361
|
+
* Optional annotations for the client.
|
|
1362
|
+
*/
|
|
1363
|
+
annotations: AnnotationsSchema.optional(),
|
|
1364
|
+
/**
|
|
1365
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1366
|
+
* for notes on _meta usage.
|
|
1367
|
+
*/
|
|
1368
|
+
_meta: record(string(), unknown()).optional()
|
|
1369
|
+
});
|
|
1370
|
+
/**
|
|
1371
|
+
* An image provided to or from an LLM.
|
|
1372
|
+
*/
|
|
1373
|
+
var ImageContentSchema = object({
|
|
1374
|
+
type: literal("image"),
|
|
1375
|
+
/**
|
|
1376
|
+
* The base64-encoded image data.
|
|
1377
|
+
*/
|
|
1378
|
+
data: Base64Schema,
|
|
1379
|
+
/**
|
|
1380
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
1381
|
+
*/
|
|
1382
|
+
mimeType: string(),
|
|
1383
|
+
/**
|
|
1384
|
+
* Optional annotations for the client.
|
|
1385
|
+
*/
|
|
1386
|
+
annotations: AnnotationsSchema.optional(),
|
|
1387
|
+
/**
|
|
1388
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1389
|
+
* for notes on _meta usage.
|
|
1390
|
+
*/
|
|
1391
|
+
_meta: record(string(), unknown()).optional()
|
|
1392
|
+
});
|
|
1393
|
+
/**
|
|
1394
|
+
* An Audio provided to or from an LLM.
|
|
1395
|
+
*/
|
|
1396
|
+
var AudioContentSchema = object({
|
|
1397
|
+
type: literal("audio"),
|
|
1398
|
+
/**
|
|
1399
|
+
* The base64-encoded audio data.
|
|
1400
|
+
*/
|
|
1401
|
+
data: Base64Schema,
|
|
1402
|
+
/**
|
|
1403
|
+
* The MIME type of the audio. Different providers may support different audio types.
|
|
1404
|
+
*/
|
|
1405
|
+
mimeType: string(),
|
|
1406
|
+
/**
|
|
1407
|
+
* Optional annotations for the client.
|
|
1408
|
+
*/
|
|
1409
|
+
annotations: AnnotationsSchema.optional(),
|
|
1410
|
+
/**
|
|
1411
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1412
|
+
* for notes on _meta usage.
|
|
1413
|
+
*/
|
|
1414
|
+
_meta: record(string(), unknown()).optional()
|
|
1415
|
+
});
|
|
1416
|
+
/**
|
|
1417
|
+
* A tool call request from an assistant (LLM).
|
|
1418
|
+
* Represents the assistant's request to use a tool.
|
|
1419
|
+
*/
|
|
1420
|
+
var ToolUseContentSchema = object({
|
|
1421
|
+
type: literal("tool_use"),
|
|
1422
|
+
/**
|
|
1423
|
+
* The name of the tool to invoke.
|
|
1424
|
+
* Must match a tool name from the request's tools array.
|
|
1425
|
+
*/
|
|
1426
|
+
name: string(),
|
|
1427
|
+
/**
|
|
1428
|
+
* Unique identifier for this tool call.
|
|
1429
|
+
* Used to correlate with ToolResultContent in subsequent messages.
|
|
1430
|
+
*/
|
|
1431
|
+
id: string(),
|
|
1432
|
+
/**
|
|
1433
|
+
* Arguments to pass to the tool.
|
|
1434
|
+
* Must conform to the tool's inputSchema.
|
|
1435
|
+
*/
|
|
1436
|
+
input: record(string(), unknown()),
|
|
1437
|
+
/**
|
|
1438
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1439
|
+
* for notes on _meta usage.
|
|
1440
|
+
*/
|
|
1441
|
+
_meta: record(string(), unknown()).optional()
|
|
1442
|
+
});
|
|
1443
|
+
/**
|
|
1444
|
+
* The contents of a resource, embedded into a prompt or tool call result.
|
|
1445
|
+
*/
|
|
1446
|
+
var EmbeddedResourceSchema = object({
|
|
1447
|
+
type: literal("resource"),
|
|
1448
|
+
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
1449
|
+
/**
|
|
1450
|
+
* Optional annotations for the client.
|
|
1451
|
+
*/
|
|
1452
|
+
annotations: AnnotationsSchema.optional(),
|
|
1453
|
+
/**
|
|
1454
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1455
|
+
* for notes on _meta usage.
|
|
1456
|
+
*/
|
|
1457
|
+
_meta: record(string(), unknown()).optional()
|
|
1458
|
+
});
|
|
1459
|
+
/**
|
|
1460
|
+
* A content block that can be used in prompts and tool results.
|
|
1461
|
+
*/
|
|
1462
|
+
var ContentBlockSchema = union([
|
|
1463
|
+
TextContentSchema,
|
|
1464
|
+
ImageContentSchema,
|
|
1465
|
+
AudioContentSchema,
|
|
1466
|
+
ResourceSchema.extend({ type: literal("resource_link") }),
|
|
1467
|
+
EmbeddedResourceSchema
|
|
1468
|
+
]);
|
|
1469
|
+
/**
|
|
1470
|
+
* Describes a message returned as part of a prompt.
|
|
1471
|
+
*/
|
|
1472
|
+
var PromptMessageSchema = object({
|
|
1473
|
+
role: RoleSchema,
|
|
1474
|
+
content: ContentBlockSchema
|
|
1475
|
+
});
|
|
1476
|
+
/**
|
|
1477
|
+
* The server's response to a prompts/get request from the client.
|
|
1478
|
+
*/
|
|
1479
|
+
var GetPromptResultSchema = ResultSchema.extend({
|
|
1480
|
+
/**
|
|
1481
|
+
* An optional description for the prompt.
|
|
1482
|
+
*/
|
|
1483
|
+
description: string().optional(),
|
|
1484
|
+
messages: array(PromptMessageSchema)
|
|
1485
|
+
});
|
|
1486
|
+
/**
|
|
1487
|
+
* 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.
|
|
1488
|
+
*/
|
|
1489
|
+
var PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
1490
|
+
method: literal("notifications/prompts/list_changed"),
|
|
1491
|
+
params: NotificationsParamsSchema.optional()
|
|
1492
|
+
});
|
|
1493
|
+
/**
|
|
1494
|
+
* Additional properties describing a Tool to clients.
|
|
1495
|
+
*
|
|
1496
|
+
* NOTE: all properties in ToolAnnotations are **hints**.
|
|
1497
|
+
* They are not guaranteed to provide a faithful description of
|
|
1498
|
+
* tool behavior (including descriptive properties like `title`).
|
|
1499
|
+
*
|
|
1500
|
+
* Clients should never make tool use decisions based on ToolAnnotations
|
|
1501
|
+
* received from untrusted servers.
|
|
1502
|
+
*/
|
|
1503
|
+
var ToolAnnotationsSchema = object({
|
|
1504
|
+
/**
|
|
1505
|
+
* A human-readable title for the tool.
|
|
1506
|
+
*/
|
|
1507
|
+
title: string().optional(),
|
|
1508
|
+
/**
|
|
1509
|
+
* If true, the tool does not modify its environment.
|
|
1510
|
+
*
|
|
1511
|
+
* Default: false
|
|
1512
|
+
*/
|
|
1513
|
+
readOnlyHint: boolean().optional(),
|
|
1514
|
+
/**
|
|
1515
|
+
* If true, the tool may perform destructive updates to its environment.
|
|
1516
|
+
* If false, the tool performs only additive updates.
|
|
1517
|
+
*
|
|
1518
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
1519
|
+
*
|
|
1520
|
+
* Default: true
|
|
1521
|
+
*/
|
|
1522
|
+
destructiveHint: boolean().optional(),
|
|
1523
|
+
/**
|
|
1524
|
+
* If true, calling the tool repeatedly with the same arguments
|
|
1525
|
+
* will have no additional effect on the its environment.
|
|
1526
|
+
*
|
|
1527
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
1528
|
+
*
|
|
1529
|
+
* Default: false
|
|
1530
|
+
*/
|
|
1531
|
+
idempotentHint: boolean().optional(),
|
|
1532
|
+
/**
|
|
1533
|
+
* If true, this tool may interact with an "open world" of external
|
|
1534
|
+
* entities. If false, the tool's domain of interaction is closed.
|
|
1535
|
+
* For example, the world of a web search tool is open, whereas that
|
|
1536
|
+
* of a memory tool is not.
|
|
1537
|
+
*
|
|
1538
|
+
* Default: true
|
|
1539
|
+
*/
|
|
1540
|
+
openWorldHint: boolean().optional()
|
|
1541
|
+
});
|
|
1542
|
+
/**
|
|
1543
|
+
* Execution-related properties for a tool.
|
|
1544
|
+
*/
|
|
1545
|
+
var ToolExecutionSchema = object({
|
|
1546
|
+
/**
|
|
1547
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
1548
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
1549
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
1550
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
1551
|
+
*
|
|
1552
|
+
* If not present, defaults to "forbidden".
|
|
1553
|
+
*/
|
|
1554
|
+
taskSupport: _enum([
|
|
1555
|
+
"required",
|
|
1556
|
+
"optional",
|
|
1557
|
+
"forbidden"
|
|
1558
|
+
]).optional() });
|
|
1559
|
+
/**
|
|
1560
|
+
* Definition for a tool the client can call.
|
|
1561
|
+
*/
|
|
1562
|
+
var ToolSchema = object({
|
|
1563
|
+
...BaseMetadataSchema.shape,
|
|
1564
|
+
...IconsSchema.shape,
|
|
1565
|
+
/**
|
|
1566
|
+
* A human-readable description of the tool.
|
|
1567
|
+
*/
|
|
1568
|
+
description: string().optional(),
|
|
1569
|
+
/**
|
|
1570
|
+
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
|
|
1571
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
1572
|
+
*/
|
|
1573
|
+
inputSchema: object({
|
|
1574
|
+
type: literal("object"),
|
|
1575
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
1576
|
+
required: array(string()).optional()
|
|
1577
|
+
}).catchall(unknown()),
|
|
1578
|
+
/**
|
|
1579
|
+
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
|
|
1580
|
+
* returned in the structuredContent field of a CallToolResult.
|
|
1581
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
1582
|
+
*/
|
|
1583
|
+
outputSchema: object({
|
|
1584
|
+
type: literal("object"),
|
|
1585
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
1586
|
+
required: array(string()).optional()
|
|
1587
|
+
}).catchall(unknown()).optional(),
|
|
1588
|
+
/**
|
|
1589
|
+
* Optional additional tool information.
|
|
1590
|
+
*/
|
|
1591
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
1592
|
+
/**
|
|
1593
|
+
* Execution-related properties for this tool.
|
|
1594
|
+
*/
|
|
1595
|
+
execution: ToolExecutionSchema.optional(),
|
|
1596
|
+
/**
|
|
1597
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1598
|
+
* for notes on _meta usage.
|
|
1599
|
+
*/
|
|
1600
|
+
_meta: record(string(), unknown()).optional()
|
|
1601
|
+
});
|
|
1602
|
+
/**
|
|
1603
|
+
* Sent from the client to request a list of tools the server has.
|
|
1604
|
+
*/
|
|
1605
|
+
var ListToolsRequestSchema$1 = PaginatedRequestSchema.extend({ method: literal("tools/list") });
|
|
1606
|
+
/**
|
|
1607
|
+
* The server's response to a tools/list request from the client.
|
|
1608
|
+
*/
|
|
1609
|
+
var ListToolsResultSchema = PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
1610
|
+
/**
|
|
1611
|
+
* The server's response to a tool call.
|
|
1612
|
+
*/
|
|
1613
|
+
var CallToolResultSchema = ResultSchema.extend({
|
|
1614
|
+
/**
|
|
1615
|
+
* A list of content objects that represent the result of the tool call.
|
|
1616
|
+
*
|
|
1617
|
+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
|
|
1618
|
+
* For backwards compatibility, this field is always present, but it may be empty.
|
|
1619
|
+
*/
|
|
1620
|
+
content: array(ContentBlockSchema).default([]),
|
|
1621
|
+
/**
|
|
1622
|
+
* An object containing structured tool output.
|
|
1623
|
+
*
|
|
1624
|
+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
1625
|
+
*/
|
|
1626
|
+
structuredContent: record(string(), unknown()).optional(),
|
|
1627
|
+
/**
|
|
1628
|
+
* Whether the tool call ended in an error.
|
|
1629
|
+
*
|
|
1630
|
+
* If not set, this is assumed to be false (the call was successful).
|
|
1631
|
+
*
|
|
1632
|
+
* Any errors that originate from the tool SHOULD be reported inside the result
|
|
1633
|
+
* object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
1634
|
+
* response. Otherwise, the LLM would not be able to see that an error occurred
|
|
1635
|
+
* and self-correct.
|
|
1636
|
+
*
|
|
1637
|
+
* However, any errors in _finding_ the tool, an error indicating that the
|
|
1638
|
+
* server does not support tool calls, or any other exceptional conditions,
|
|
1639
|
+
* should be reported as an MCP error response.
|
|
1640
|
+
*/
|
|
1641
|
+
isError: boolean().optional()
|
|
1642
|
+
});
|
|
1643
|
+
CallToolResultSchema.or(ResultSchema.extend({ toolResult: unknown() }));
|
|
1644
|
+
/**
|
|
1645
|
+
* Parameters for a `tools/call` request.
|
|
1646
|
+
*/
|
|
1647
|
+
var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1648
|
+
/**
|
|
1649
|
+
* The name of the tool to call.
|
|
1650
|
+
*/
|
|
1651
|
+
name: string(),
|
|
1652
|
+
/**
|
|
1653
|
+
* Arguments to pass to the tool.
|
|
1654
|
+
*/
|
|
1655
|
+
arguments: record(string(), unknown()).optional()
|
|
1656
|
+
});
|
|
1657
|
+
/**
|
|
1658
|
+
* Used by the client to invoke a tool provided by the server.
|
|
1659
|
+
*/
|
|
1660
|
+
var CallToolRequestSchema$1 = RequestSchema.extend({
|
|
1661
|
+
method: literal("tools/call"),
|
|
1662
|
+
params: CallToolRequestParamsSchema
|
|
1663
|
+
});
|
|
1664
|
+
/**
|
|
1665
|
+
* 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.
|
|
1666
|
+
*/
|
|
1667
|
+
var ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
1668
|
+
method: literal("notifications/tools/list_changed"),
|
|
1669
|
+
params: NotificationsParamsSchema.optional()
|
|
1670
|
+
});
|
|
1671
|
+
object({
|
|
1672
|
+
/**
|
|
1673
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
1674
|
+
* The callback will be called with the updated list.
|
|
1675
|
+
*
|
|
1676
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
1677
|
+
*
|
|
1678
|
+
* @default true
|
|
1679
|
+
*/
|
|
1680
|
+
autoRefresh: boolean().default(true),
|
|
1681
|
+
/**
|
|
1682
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
1683
|
+
*
|
|
1684
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
1685
|
+
* Set to 0 to disable debouncing.
|
|
1686
|
+
*
|
|
1687
|
+
* @default 300
|
|
1688
|
+
*/
|
|
1689
|
+
debounceMs: number().int().nonnegative().default(300)
|
|
1690
|
+
});
|
|
1691
|
+
/**
|
|
1692
|
+
* The severity of a log message.
|
|
1693
|
+
*/
|
|
1694
|
+
var LoggingLevelSchema = _enum([
|
|
1695
|
+
"debug",
|
|
1696
|
+
"info",
|
|
1697
|
+
"notice",
|
|
1698
|
+
"warning",
|
|
1699
|
+
"error",
|
|
1700
|
+
"critical",
|
|
1701
|
+
"alert",
|
|
1702
|
+
"emergency"
|
|
1703
|
+
]);
|
|
1704
|
+
/**
|
|
1705
|
+
* Parameters for a `logging/setLevel` request.
|
|
1706
|
+
*/
|
|
1707
|
+
var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1708
|
+
/**
|
|
1709
|
+
* The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
|
|
1710
|
+
*/
|
|
1711
|
+
level: LoggingLevelSchema });
|
|
1712
|
+
/**
|
|
1713
|
+
* A request from the client to the server, to enable or adjust logging.
|
|
1714
|
+
*/
|
|
1715
|
+
var SetLevelRequestSchema = RequestSchema.extend({
|
|
1716
|
+
method: literal("logging/setLevel"),
|
|
1717
|
+
params: SetLevelRequestParamsSchema
|
|
1718
|
+
});
|
|
1719
|
+
/**
|
|
1720
|
+
* Parameters for a `notifications/message` notification.
|
|
1721
|
+
*/
|
|
1722
|
+
var LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
1723
|
+
/**
|
|
1724
|
+
* The severity of this log message.
|
|
1725
|
+
*/
|
|
1726
|
+
level: LoggingLevelSchema,
|
|
1727
|
+
/**
|
|
1728
|
+
* An optional name of the logger issuing this message.
|
|
1729
|
+
*/
|
|
1730
|
+
logger: string().optional(),
|
|
1731
|
+
/**
|
|
1732
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
1733
|
+
*/
|
|
1734
|
+
data: unknown()
|
|
1735
|
+
});
|
|
1736
|
+
/**
|
|
1737
|
+
* 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.
|
|
1738
|
+
*/
|
|
1739
|
+
var LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
1740
|
+
method: literal("notifications/message"),
|
|
1741
|
+
params: LoggingMessageNotificationParamsSchema
|
|
1742
|
+
});
|
|
1743
|
+
/**
|
|
1744
|
+
* The server's preferences for model selection, requested of the client during sampling.
|
|
1745
|
+
*/
|
|
1746
|
+
var ModelPreferencesSchema = object({
|
|
1747
|
+
/**
|
|
1748
|
+
* Optional hints to use for model selection.
|
|
1749
|
+
*/
|
|
1750
|
+
hints: array(object({
|
|
1751
|
+
/**
|
|
1752
|
+
* A hint for a model name.
|
|
1753
|
+
*/
|
|
1754
|
+
name: string().optional() })).optional(),
|
|
1755
|
+
/**
|
|
1756
|
+
* How much to prioritize cost when selecting a model.
|
|
1757
|
+
*/
|
|
1758
|
+
costPriority: number().min(0).max(1).optional(),
|
|
1759
|
+
/**
|
|
1760
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
1761
|
+
*/
|
|
1762
|
+
speedPriority: number().min(0).max(1).optional(),
|
|
1763
|
+
/**
|
|
1764
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
1765
|
+
*/
|
|
1766
|
+
intelligencePriority: number().min(0).max(1).optional()
|
|
1767
|
+
});
|
|
1768
|
+
/**
|
|
1769
|
+
* Controls tool usage behavior in sampling requests.
|
|
1770
|
+
*/
|
|
1771
|
+
var ToolChoiceSchema = object({
|
|
1772
|
+
/**
|
|
1773
|
+
* Controls when tools are used:
|
|
1774
|
+
* - "auto": Model decides whether to use tools (default)
|
|
1775
|
+
* - "required": Model MUST use at least one tool before completing
|
|
1776
|
+
* - "none": Model MUST NOT use any tools
|
|
1777
|
+
*/
|
|
1778
|
+
mode: _enum([
|
|
1779
|
+
"auto",
|
|
1780
|
+
"required",
|
|
1781
|
+
"none"
|
|
1782
|
+
]).optional() });
|
|
1783
|
+
/**
|
|
1784
|
+
* The result of a tool execution, provided by the user (server).
|
|
1785
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
1786
|
+
*/
|
|
1787
|
+
var ToolResultContentSchema = object({
|
|
1788
|
+
type: literal("tool_result"),
|
|
1789
|
+
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
1790
|
+
content: array(ContentBlockSchema).default([]),
|
|
1791
|
+
structuredContent: object({}).loose().optional(),
|
|
1792
|
+
isError: boolean().optional(),
|
|
1793
|
+
/**
|
|
1794
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1795
|
+
* for notes on _meta usage.
|
|
1796
|
+
*/
|
|
1797
|
+
_meta: record(string(), unknown()).optional()
|
|
1798
|
+
});
|
|
1799
|
+
/**
|
|
1800
|
+
* Basic content types for sampling responses (without tool use).
|
|
1801
|
+
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
1802
|
+
*/
|
|
1803
|
+
var SamplingContentSchema = discriminatedUnion("type", [
|
|
1804
|
+
TextContentSchema,
|
|
1805
|
+
ImageContentSchema,
|
|
1806
|
+
AudioContentSchema
|
|
1807
|
+
]);
|
|
1808
|
+
/**
|
|
1809
|
+
* Content block types allowed in sampling messages.
|
|
1810
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
1811
|
+
*/
|
|
1812
|
+
var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
1813
|
+
TextContentSchema,
|
|
1814
|
+
ImageContentSchema,
|
|
1815
|
+
AudioContentSchema,
|
|
1816
|
+
ToolUseContentSchema,
|
|
1817
|
+
ToolResultContentSchema
|
|
1818
|
+
]);
|
|
1819
|
+
/**
|
|
1820
|
+
* Describes a message issued to or received from an LLM API.
|
|
1821
|
+
*/
|
|
1822
|
+
var SamplingMessageSchema = object({
|
|
1823
|
+
role: RoleSchema,
|
|
1824
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
1825
|
+
/**
|
|
1826
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1827
|
+
* for notes on _meta usage.
|
|
1828
|
+
*/
|
|
1829
|
+
_meta: record(string(), unknown()).optional()
|
|
1830
|
+
});
|
|
1831
|
+
/**
|
|
1832
|
+
* Parameters for a `sampling/createMessage` request.
|
|
1833
|
+
*/
|
|
1834
|
+
var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1835
|
+
messages: array(SamplingMessageSchema),
|
|
1836
|
+
/**
|
|
1837
|
+
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
1838
|
+
*/
|
|
1839
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
1840
|
+
/**
|
|
1841
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
1842
|
+
*/
|
|
1843
|
+
systemPrompt: string().optional(),
|
|
1844
|
+
/**
|
|
1845
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
1846
|
+
* The client MAY ignore this request.
|
|
1847
|
+
*
|
|
1848
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
1849
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
1850
|
+
*/
|
|
1851
|
+
includeContext: _enum([
|
|
1852
|
+
"none",
|
|
1853
|
+
"thisServer",
|
|
1854
|
+
"allServers"
|
|
1855
|
+
]).optional(),
|
|
1856
|
+
temperature: number().optional(),
|
|
1857
|
+
/**
|
|
1858
|
+
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
1859
|
+
*
|
|
1860
|
+
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
1861
|
+
*/
|
|
1862
|
+
maxTokens: number().int(),
|
|
1863
|
+
stopSequences: array(string()).optional(),
|
|
1864
|
+
/**
|
|
1865
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
1866
|
+
*/
|
|
1867
|
+
metadata: AssertObjectSchema.optional(),
|
|
1868
|
+
/**
|
|
1869
|
+
* Tools that the model may use during generation.
|
|
1870
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1871
|
+
*/
|
|
1872
|
+
tools: array(ToolSchema).optional(),
|
|
1873
|
+
/**
|
|
1874
|
+
* Controls how the model uses tools.
|
|
1875
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1876
|
+
* Default is `{ mode: "auto" }`.
|
|
1877
|
+
*/
|
|
1878
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
1879
|
+
});
|
|
1880
|
+
/**
|
|
1881
|
+
* 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.
|
|
1882
|
+
*/
|
|
1883
|
+
var CreateMessageRequestSchema = RequestSchema.extend({
|
|
1884
|
+
method: literal("sampling/createMessage"),
|
|
1885
|
+
params: CreateMessageRequestParamsSchema
|
|
1886
|
+
});
|
|
1887
|
+
/**
|
|
1888
|
+
* The client's response to a sampling/create_message request from the server.
|
|
1889
|
+
* This is the backwards-compatible version that returns single content (no arrays).
|
|
1890
|
+
* Used when the request does not include tools.
|
|
1891
|
+
*/
|
|
1892
|
+
var CreateMessageResultSchema = ResultSchema.extend({
|
|
1893
|
+
/**
|
|
1894
|
+
* The name of the model that generated the message.
|
|
1895
|
+
*/
|
|
1896
|
+
model: string(),
|
|
1897
|
+
/**
|
|
1898
|
+
* The reason why sampling stopped, if known.
|
|
1899
|
+
*
|
|
1900
|
+
* Standard values:
|
|
1901
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
1902
|
+
* - "stopSequence": A stop sequence was encountered
|
|
1903
|
+
* - "maxTokens": Maximum token limit was reached
|
|
1904
|
+
*
|
|
1905
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
1906
|
+
*/
|
|
1907
|
+
stopReason: optional(_enum([
|
|
1908
|
+
"endTurn",
|
|
1909
|
+
"stopSequence",
|
|
1910
|
+
"maxTokens"
|
|
1911
|
+
]).or(string())),
|
|
1912
|
+
role: RoleSchema,
|
|
1913
|
+
/**
|
|
1914
|
+
* Response content. Single content block (text, image, or audio).
|
|
1915
|
+
*/
|
|
1916
|
+
content: SamplingContentSchema
|
|
1917
|
+
});
|
|
1918
|
+
/**
|
|
1919
|
+
* The client's response to a sampling/create_message request when tools were provided.
|
|
1920
|
+
* This version supports array content for tool use flows.
|
|
1921
|
+
*/
|
|
1922
|
+
var CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
1923
|
+
/**
|
|
1924
|
+
* The name of the model that generated the message.
|
|
1925
|
+
*/
|
|
1926
|
+
model: string(),
|
|
1927
|
+
/**
|
|
1928
|
+
* The reason why sampling stopped, if known.
|
|
1929
|
+
*
|
|
1930
|
+
* Standard values:
|
|
1931
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
1932
|
+
* - "stopSequence": A stop sequence was encountered
|
|
1933
|
+
* - "maxTokens": Maximum token limit was reached
|
|
1934
|
+
* - "toolUse": The model wants to use one or more tools
|
|
1935
|
+
*
|
|
1936
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
1937
|
+
*/
|
|
1938
|
+
stopReason: optional(_enum([
|
|
1939
|
+
"endTurn",
|
|
1940
|
+
"stopSequence",
|
|
1941
|
+
"maxTokens",
|
|
1942
|
+
"toolUse"
|
|
1943
|
+
]).or(string())),
|
|
1944
|
+
role: RoleSchema,
|
|
1945
|
+
/**
|
|
1946
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
1947
|
+
*/
|
|
1948
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
1949
|
+
});
|
|
1950
|
+
/**
|
|
1951
|
+
* Primitive schema definition for boolean fields.
|
|
1952
|
+
*/
|
|
1953
|
+
var BooleanSchemaSchema = object({
|
|
1954
|
+
type: literal("boolean"),
|
|
1955
|
+
title: string().optional(),
|
|
1956
|
+
description: string().optional(),
|
|
1957
|
+
default: boolean().optional()
|
|
1958
|
+
});
|
|
1959
|
+
/**
|
|
1960
|
+
* Primitive schema definition for string fields.
|
|
1961
|
+
*/
|
|
1962
|
+
var StringSchemaSchema = object({
|
|
1963
|
+
type: literal("string"),
|
|
1964
|
+
title: string().optional(),
|
|
1965
|
+
description: string().optional(),
|
|
1966
|
+
minLength: number().optional(),
|
|
1967
|
+
maxLength: number().optional(),
|
|
1968
|
+
format: _enum([
|
|
1969
|
+
"email",
|
|
1970
|
+
"uri",
|
|
1971
|
+
"date",
|
|
1972
|
+
"date-time"
|
|
1973
|
+
]).optional(),
|
|
1974
|
+
default: string().optional()
|
|
1975
|
+
});
|
|
1976
|
+
/**
|
|
1977
|
+
* Primitive schema definition for number fields.
|
|
1978
|
+
*/
|
|
1979
|
+
var NumberSchemaSchema = object({
|
|
1980
|
+
type: _enum(["number", "integer"]),
|
|
1981
|
+
title: string().optional(),
|
|
1982
|
+
description: string().optional(),
|
|
1983
|
+
minimum: number().optional(),
|
|
1984
|
+
maximum: number().optional(),
|
|
1985
|
+
default: number().optional()
|
|
1986
|
+
});
|
|
1987
|
+
/**
|
|
1988
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
1989
|
+
*/
|
|
1990
|
+
var UntitledSingleSelectEnumSchemaSchema = object({
|
|
1991
|
+
type: literal("string"),
|
|
1992
|
+
title: string().optional(),
|
|
1993
|
+
description: string().optional(),
|
|
1994
|
+
enum: array(string()),
|
|
1995
|
+
default: string().optional()
|
|
1996
|
+
});
|
|
1997
|
+
/**
|
|
1998
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
1999
|
+
*/
|
|
2000
|
+
var TitledSingleSelectEnumSchemaSchema = object({
|
|
2001
|
+
type: literal("string"),
|
|
2002
|
+
title: string().optional(),
|
|
2003
|
+
description: string().optional(),
|
|
2004
|
+
oneOf: array(object({
|
|
2005
|
+
const: string(),
|
|
2006
|
+
title: string()
|
|
2007
|
+
})),
|
|
2008
|
+
default: string().optional()
|
|
2009
|
+
});
|
|
2010
|
+
/**
|
|
2011
|
+
* Union of all primitive schema definitions.
|
|
2012
|
+
*/
|
|
2013
|
+
var PrimitiveSchemaDefinitionSchema = union([
|
|
2014
|
+
union([
|
|
2015
|
+
object({
|
|
2016
|
+
type: literal("string"),
|
|
2017
|
+
title: string().optional(),
|
|
2018
|
+
description: string().optional(),
|
|
2019
|
+
enum: array(string()),
|
|
2020
|
+
enumNames: array(string()).optional(),
|
|
2021
|
+
default: string().optional()
|
|
2022
|
+
}),
|
|
2023
|
+
union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]),
|
|
2024
|
+
union([object({
|
|
2025
|
+
type: literal("array"),
|
|
2026
|
+
title: string().optional(),
|
|
2027
|
+
description: string().optional(),
|
|
2028
|
+
minItems: number().optional(),
|
|
2029
|
+
maxItems: number().optional(),
|
|
2030
|
+
items: object({
|
|
2031
|
+
type: literal("string"),
|
|
2032
|
+
enum: array(string())
|
|
2033
|
+
}),
|
|
2034
|
+
default: array(string()).optional()
|
|
2035
|
+
}), object({
|
|
2036
|
+
type: literal("array"),
|
|
2037
|
+
title: string().optional(),
|
|
2038
|
+
description: string().optional(),
|
|
2039
|
+
minItems: number().optional(),
|
|
2040
|
+
maxItems: number().optional(),
|
|
2041
|
+
items: object({ anyOf: array(object({
|
|
2042
|
+
const: string(),
|
|
2043
|
+
title: string()
|
|
2044
|
+
})) }),
|
|
2045
|
+
default: array(string()).optional()
|
|
2046
|
+
})])
|
|
2047
|
+
]),
|
|
2048
|
+
BooleanSchemaSchema,
|
|
2049
|
+
StringSchemaSchema,
|
|
2050
|
+
NumberSchemaSchema
|
|
2051
|
+
]);
|
|
2052
|
+
/**
|
|
2053
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
2054
|
+
*/
|
|
2055
|
+
var ElicitRequestParamsSchema = union([TaskAugmentedRequestParamsSchema.extend({
|
|
2056
|
+
/**
|
|
2057
|
+
* The elicitation mode.
|
|
2058
|
+
*
|
|
2059
|
+
* Optional for backward compatibility. Clients MUST treat missing mode as "form".
|
|
2060
|
+
*/
|
|
2061
|
+
mode: literal("form").optional(),
|
|
2062
|
+
/**
|
|
2063
|
+
* The message to present to the user describing what information is being requested.
|
|
2064
|
+
*/
|
|
2065
|
+
message: string(),
|
|
2066
|
+
/**
|
|
2067
|
+
* A restricted subset of JSON Schema.
|
|
2068
|
+
* Only top-level properties are allowed, without nesting.
|
|
2069
|
+
*/
|
|
2070
|
+
requestedSchema: object({
|
|
2071
|
+
type: literal("object"),
|
|
2072
|
+
properties: record(string(), PrimitiveSchemaDefinitionSchema),
|
|
2073
|
+
required: array(string()).optional()
|
|
2074
|
+
})
|
|
2075
|
+
}), TaskAugmentedRequestParamsSchema.extend({
|
|
2076
|
+
/**
|
|
2077
|
+
* The elicitation mode.
|
|
2078
|
+
*/
|
|
2079
|
+
mode: literal("url"),
|
|
2080
|
+
/**
|
|
2081
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
2082
|
+
*/
|
|
2083
|
+
message: string(),
|
|
2084
|
+
/**
|
|
2085
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
2086
|
+
* The client MUST treat this ID as an opaque value.
|
|
2087
|
+
*/
|
|
2088
|
+
elicitationId: string(),
|
|
2089
|
+
/**
|
|
2090
|
+
* The URL that the user should navigate to.
|
|
2091
|
+
*/
|
|
2092
|
+
url: string().url()
|
|
2093
|
+
})]);
|
|
2094
|
+
/**
|
|
2095
|
+
* A request from the server to elicit user input via the client.
|
|
2096
|
+
* The client should present the message and form fields to the user (form mode)
|
|
2097
|
+
* or navigate to a URL (URL mode).
|
|
2098
|
+
*/
|
|
2099
|
+
var ElicitRequestSchema = RequestSchema.extend({
|
|
2100
|
+
method: literal("elicitation/create"),
|
|
2101
|
+
params: ElicitRequestParamsSchema
|
|
2102
|
+
});
|
|
2103
|
+
/**
|
|
2104
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
2105
|
+
*
|
|
2106
|
+
* @category notifications/elicitation/complete
|
|
2107
|
+
*/
|
|
2108
|
+
var ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
2109
|
+
/**
|
|
2110
|
+
* The ID of the elicitation that completed.
|
|
2111
|
+
*/
|
|
2112
|
+
elicitationId: string() });
|
|
2113
|
+
/**
|
|
2114
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
2115
|
+
*
|
|
2116
|
+
* @category notifications/elicitation/complete
|
|
2117
|
+
*/
|
|
2118
|
+
var ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
2119
|
+
method: literal("notifications/elicitation/complete"),
|
|
2120
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
2121
|
+
});
|
|
2122
|
+
/**
|
|
2123
|
+
* The client's response to an elicitation/create request from the server.
|
|
2124
|
+
*/
|
|
2125
|
+
var ElicitResultSchema = ResultSchema.extend({
|
|
2126
|
+
/**
|
|
2127
|
+
* The user action in response to the elicitation.
|
|
2128
|
+
* - "accept": User submitted the form/confirmed the action
|
|
2129
|
+
* - "decline": User explicitly decline the action
|
|
2130
|
+
* - "cancel": User dismissed without making an explicit choice
|
|
2131
|
+
*/
|
|
2132
|
+
action: _enum([
|
|
2133
|
+
"accept",
|
|
2134
|
+
"decline",
|
|
2135
|
+
"cancel"
|
|
2136
|
+
]),
|
|
2137
|
+
/**
|
|
2138
|
+
* The submitted form data, only present when action is "accept".
|
|
2139
|
+
* Contains values matching the requested schema.
|
|
2140
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
2141
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
2142
|
+
*/
|
|
2143
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([
|
|
2144
|
+
string(),
|
|
2145
|
+
number(),
|
|
2146
|
+
boolean(),
|
|
2147
|
+
array(string())
|
|
2148
|
+
])).optional())
|
|
2149
|
+
});
|
|
2150
|
+
/**
|
|
2151
|
+
* A reference to a resource or resource template definition.
|
|
2152
|
+
*/
|
|
2153
|
+
var ResourceTemplateReferenceSchema = object({
|
|
2154
|
+
type: literal("ref/resource"),
|
|
2155
|
+
/**
|
|
2156
|
+
* The URI or URI template of the resource.
|
|
2157
|
+
*/
|
|
2158
|
+
uri: string()
|
|
2159
|
+
});
|
|
2160
|
+
/**
|
|
2161
|
+
* Identifies a prompt.
|
|
2162
|
+
*/
|
|
2163
|
+
var PromptReferenceSchema = object({
|
|
2164
|
+
type: literal("ref/prompt"),
|
|
2165
|
+
/**
|
|
2166
|
+
* The name of the prompt or prompt template
|
|
2167
|
+
*/
|
|
2168
|
+
name: string()
|
|
2169
|
+
});
|
|
2170
|
+
/**
|
|
2171
|
+
* Parameters for a `completion/complete` request.
|
|
2172
|
+
*/
|
|
2173
|
+
var CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
2174
|
+
ref: union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
2175
|
+
/**
|
|
2176
|
+
* The argument's information
|
|
2177
|
+
*/
|
|
2178
|
+
argument: object({
|
|
2179
|
+
/**
|
|
2180
|
+
* The name of the argument
|
|
2181
|
+
*/
|
|
2182
|
+
name: string(),
|
|
2183
|
+
/**
|
|
2184
|
+
* The value of the argument to use for completion matching.
|
|
2185
|
+
*/
|
|
2186
|
+
value: string()
|
|
2187
|
+
}),
|
|
2188
|
+
context: object({
|
|
2189
|
+
/**
|
|
2190
|
+
* Previously-resolved variables in a URI template or prompt.
|
|
2191
|
+
*/
|
|
2192
|
+
arguments: record(string(), string()).optional() }).optional()
|
|
2193
|
+
});
|
|
2194
|
+
/**
|
|
2195
|
+
* A request from the client to the server, to ask for completion options.
|
|
2196
|
+
*/
|
|
2197
|
+
var CompleteRequestSchema = RequestSchema.extend({
|
|
2198
|
+
method: literal("completion/complete"),
|
|
2199
|
+
params: CompleteRequestParamsSchema
|
|
2200
|
+
});
|
|
2201
|
+
/**
|
|
2202
|
+
* The server's response to a completion/complete request
|
|
2203
|
+
*/
|
|
2204
|
+
var CompleteResultSchema = ResultSchema.extend({ completion: looseObject({
|
|
2205
|
+
/**
|
|
2206
|
+
* An array of completion values. Must not exceed 100 items.
|
|
2207
|
+
*/
|
|
2208
|
+
values: array(string()).max(100),
|
|
2209
|
+
/**
|
|
2210
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
2211
|
+
*/
|
|
2212
|
+
total: optional(number().int()),
|
|
2213
|
+
/**
|
|
2214
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
2215
|
+
*/
|
|
2216
|
+
hasMore: optional(boolean())
|
|
2217
|
+
}) });
|
|
2218
|
+
/**
|
|
2219
|
+
* Represents a root directory or file that the server can operate on.
|
|
2220
|
+
*/
|
|
2221
|
+
var RootSchema = object({
|
|
2222
|
+
/**
|
|
2223
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
2224
|
+
*/
|
|
2225
|
+
uri: string().startsWith("file://"),
|
|
2226
|
+
/**
|
|
2227
|
+
* An optional name for the root.
|
|
2228
|
+
*/
|
|
2229
|
+
name: string().optional(),
|
|
2230
|
+
/**
|
|
2231
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
2232
|
+
* for notes on _meta usage.
|
|
2233
|
+
*/
|
|
2234
|
+
_meta: record(string(), unknown()).optional()
|
|
2235
|
+
});
|
|
2236
|
+
/**
|
|
2237
|
+
* Sent from the server to request a list of root URIs from the client.
|
|
2238
|
+
*/
|
|
2239
|
+
var ListRootsRequestSchema = RequestSchema.extend({
|
|
2240
|
+
method: literal("roots/list"),
|
|
2241
|
+
params: BaseRequestParamsSchema.optional()
|
|
2242
|
+
});
|
|
2243
|
+
/**
|
|
2244
|
+
* The client's response to a roots/list request from the server.
|
|
2245
|
+
*/
|
|
2246
|
+
var ListRootsResultSchema = ResultSchema.extend({ roots: array(RootSchema) });
|
|
2247
|
+
/**
|
|
2248
|
+
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
2249
|
+
*/
|
|
2250
|
+
var RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
2251
|
+
method: literal("notifications/roots/list_changed"),
|
|
2252
|
+
params: NotificationsParamsSchema.optional()
|
|
2253
|
+
});
|
|
2254
|
+
union([
|
|
2255
|
+
PingRequestSchema,
|
|
2256
|
+
InitializeRequestSchema,
|
|
2257
|
+
CompleteRequestSchema,
|
|
2258
|
+
SetLevelRequestSchema,
|
|
2259
|
+
GetPromptRequestSchema$1,
|
|
2260
|
+
ListPromptsRequestSchema$1,
|
|
2261
|
+
ListResourcesRequestSchema$1,
|
|
2262
|
+
ListResourceTemplatesRequestSchema$1,
|
|
2263
|
+
ReadResourceRequestSchema$1,
|
|
2264
|
+
SubscribeRequestSchema,
|
|
2265
|
+
UnsubscribeRequestSchema,
|
|
2266
|
+
CallToolRequestSchema$1,
|
|
2267
|
+
ListToolsRequestSchema$1,
|
|
2268
|
+
GetTaskRequestSchema,
|
|
2269
|
+
GetTaskPayloadRequestSchema,
|
|
2270
|
+
ListTasksRequestSchema,
|
|
2271
|
+
CancelTaskRequestSchema
|
|
2272
|
+
]);
|
|
2273
|
+
union([
|
|
2274
|
+
CancelledNotificationSchema,
|
|
2275
|
+
ProgressNotificationSchema,
|
|
2276
|
+
InitializedNotificationSchema,
|
|
2277
|
+
RootsListChangedNotificationSchema,
|
|
2278
|
+
TaskStatusNotificationSchema
|
|
2279
|
+
]);
|
|
2280
|
+
union([
|
|
2281
|
+
EmptyResultSchema,
|
|
2282
|
+
CreateMessageResultSchema,
|
|
2283
|
+
CreateMessageResultWithToolsSchema,
|
|
2284
|
+
ElicitResultSchema,
|
|
2285
|
+
ListRootsResultSchema,
|
|
2286
|
+
GetTaskResultSchema,
|
|
2287
|
+
ListTasksResultSchema,
|
|
2288
|
+
CreateTaskResultSchema
|
|
2289
|
+
]);
|
|
2290
|
+
union([
|
|
2291
|
+
PingRequestSchema,
|
|
2292
|
+
CreateMessageRequestSchema,
|
|
2293
|
+
ElicitRequestSchema,
|
|
2294
|
+
ListRootsRequestSchema,
|
|
2295
|
+
GetTaskRequestSchema,
|
|
2296
|
+
GetTaskPayloadRequestSchema,
|
|
2297
|
+
ListTasksRequestSchema,
|
|
2298
|
+
CancelTaskRequestSchema
|
|
2299
|
+
]);
|
|
2300
|
+
union([
|
|
2301
|
+
CancelledNotificationSchema,
|
|
2302
|
+
ProgressNotificationSchema,
|
|
2303
|
+
LoggingMessageNotificationSchema,
|
|
2304
|
+
ResourceUpdatedNotificationSchema,
|
|
2305
|
+
ResourceListChangedNotificationSchema,
|
|
2306
|
+
ToolListChangedNotificationSchema,
|
|
2307
|
+
PromptListChangedNotificationSchema,
|
|
2308
|
+
TaskStatusNotificationSchema,
|
|
2309
|
+
ElicitationCompleteNotificationSchema
|
|
2310
|
+
]);
|
|
2311
|
+
union([
|
|
2312
|
+
EmptyResultSchema,
|
|
2313
|
+
InitializeResultSchema,
|
|
2314
|
+
CompleteResultSchema,
|
|
2315
|
+
GetPromptResultSchema,
|
|
2316
|
+
ListPromptsResultSchema,
|
|
2317
|
+
ListResourcesResultSchema,
|
|
2318
|
+
ListResourceTemplatesResultSchema,
|
|
2319
|
+
ReadResourceResultSchema,
|
|
2320
|
+
CallToolResultSchema,
|
|
2321
|
+
ListToolsResultSchema,
|
|
2322
|
+
GetTaskResultSchema,
|
|
2323
|
+
ListTasksResultSchema,
|
|
2324
|
+
CreateTaskResultSchema
|
|
2325
|
+
]);
|
|
2326
|
+
//#endregion
|
|
2327
|
+
//#region ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js
|
|
2328
|
+
/**
|
|
2329
|
+
* Web Standards Streamable HTTP Server Transport
|
|
2330
|
+
*
|
|
2331
|
+
* This is the core transport implementation using Web Standard APIs (Request, Response, ReadableStream).
|
|
2332
|
+
* It can run on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
|
2333
|
+
*
|
|
2334
|
+
* For Node.js Express/HTTP compatibility, use `StreamableHTTPServerTransport` which wraps this transport.
|
|
2335
|
+
*/
|
|
2336
|
+
/**
|
|
2337
|
+
* Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification
|
|
2338
|
+
* using Web Standard APIs (Request, Response, ReadableStream).
|
|
2339
|
+
*
|
|
2340
|
+
* This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
|
2341
|
+
*
|
|
2342
|
+
* Usage example:
|
|
2343
|
+
*
|
|
2344
|
+
* ```typescript
|
|
2345
|
+
* // Stateful mode - server sets the session ID
|
|
2346
|
+
* const statefulTransport = new WebStandardStreamableHTTPServerTransport({
|
|
2347
|
+
* sessionIdGenerator: () => crypto.randomUUID(),
|
|
2348
|
+
* });
|
|
2349
|
+
*
|
|
2350
|
+
* // Stateless mode - explicitly set session ID to undefined
|
|
2351
|
+
* const statelessTransport = new WebStandardStreamableHTTPServerTransport({
|
|
2352
|
+
* sessionIdGenerator: undefined,
|
|
2353
|
+
* });
|
|
2354
|
+
*
|
|
2355
|
+
* // Hono.js usage
|
|
2356
|
+
* app.all('/mcp', async (c) => {
|
|
2357
|
+
* return transport.handleRequest(c.req.raw);
|
|
2358
|
+
* });
|
|
2359
|
+
*
|
|
2360
|
+
* // Cloudflare Workers usage
|
|
2361
|
+
* export default {
|
|
2362
|
+
* async fetch(request: Request): Promise<Response> {
|
|
2363
|
+
* return transport.handleRequest(request);
|
|
2364
|
+
* }
|
|
2365
|
+
* };
|
|
2366
|
+
* ```
|
|
2367
|
+
*
|
|
2368
|
+
* In stateful mode:
|
|
2369
|
+
* - Session ID is generated and included in response headers
|
|
2370
|
+
* - Session ID is always included in initialization responses
|
|
2371
|
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
|
2372
|
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
|
2373
|
+
* - State is maintained in-memory (connections, message history)
|
|
2374
|
+
*
|
|
2375
|
+
* In stateless mode:
|
|
2376
|
+
* - No Session ID is included in any responses
|
|
2377
|
+
* - No session validation is performed
|
|
2378
|
+
*/
|
|
2379
|
+
var WebStandardStreamableHTTPServerTransport = class {
|
|
2380
|
+
constructor(options = {}) {
|
|
2381
|
+
this._started = false;
|
|
2382
|
+
this._hasHandledRequest = false;
|
|
2383
|
+
this._streamMapping = /* @__PURE__ */ new Map();
|
|
2384
|
+
this._requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
2385
|
+
this._requestResponseMap = /* @__PURE__ */ new Map();
|
|
2386
|
+
this._initialized = false;
|
|
2387
|
+
this._enableJsonResponse = false;
|
|
2388
|
+
this._standaloneSseStreamId = "_GET_stream";
|
|
2389
|
+
this.sessionIdGenerator = options.sessionIdGenerator;
|
|
2390
|
+
this._enableJsonResponse = options.enableJsonResponse ?? false;
|
|
2391
|
+
this._eventStore = options.eventStore;
|
|
2392
|
+
this._onsessioninitialized = options.onsessioninitialized;
|
|
2393
|
+
this._onsessionclosed = options.onsessionclosed;
|
|
2394
|
+
this._allowedHosts = options.allowedHosts;
|
|
2395
|
+
this._allowedOrigins = options.allowedOrigins;
|
|
2396
|
+
this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
|
|
2397
|
+
this._retryInterval = options.retryInterval;
|
|
2398
|
+
}
|
|
2399
|
+
/**
|
|
2400
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
2401
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
2402
|
+
*/
|
|
2403
|
+
async start() {
|
|
2404
|
+
if (this._started) throw new Error("Transport already started");
|
|
2405
|
+
this._started = true;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Helper to create a JSON error response
|
|
2409
|
+
*/
|
|
2410
|
+
createJsonErrorResponse(status, code, message, options) {
|
|
2411
|
+
const error = {
|
|
2412
|
+
code,
|
|
2413
|
+
message
|
|
2414
|
+
};
|
|
2415
|
+
if (options?.data !== void 0) error.data = options.data;
|
|
2416
|
+
return new Response(JSON.stringify({
|
|
2417
|
+
jsonrpc: "2.0",
|
|
2418
|
+
error,
|
|
2419
|
+
id: null
|
|
2420
|
+
}), {
|
|
2421
|
+
status,
|
|
2422
|
+
headers: {
|
|
2423
|
+
"Content-Type": "application/json",
|
|
2424
|
+
...options?.headers
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Validates request headers for DNS rebinding protection.
|
|
2430
|
+
* @returns Error response if validation fails, undefined if validation passes.
|
|
2431
|
+
*/
|
|
2432
|
+
validateRequestHeaders(req) {
|
|
2433
|
+
if (!this._enableDnsRebindingProtection) return;
|
|
2434
|
+
if (this._allowedHosts && this._allowedHosts.length > 0) {
|
|
2435
|
+
const hostHeader = req.headers.get("host");
|
|
2436
|
+
if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
|
|
2437
|
+
const error = `Invalid Host header: ${hostHeader}`;
|
|
2438
|
+
this.onerror?.(new Error(error));
|
|
2439
|
+
return this.createJsonErrorResponse(403, -32e3, error);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
if (this._allowedOrigins && this._allowedOrigins.length > 0) {
|
|
2443
|
+
const originHeader = req.headers.get("origin");
|
|
2444
|
+
if (originHeader && !this._allowedOrigins.includes(originHeader)) {
|
|
2445
|
+
const error = `Invalid Origin header: ${originHeader}`;
|
|
2446
|
+
this.onerror?.(new Error(error));
|
|
2447
|
+
return this.createJsonErrorResponse(403, -32e3, error);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
|
2453
|
+
* Returns a Response object (Web Standard)
|
|
2454
|
+
*/
|
|
2455
|
+
async handleRequest(req, options) {
|
|
2456
|
+
if (!this.sessionIdGenerator && this._hasHandledRequest) throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
|
|
2457
|
+
this._hasHandledRequest = true;
|
|
2458
|
+
const validationError = this.validateRequestHeaders(req);
|
|
2459
|
+
if (validationError) return validationError;
|
|
2460
|
+
switch (req.method) {
|
|
2461
|
+
case "POST": return this.handlePostRequest(req, options);
|
|
2462
|
+
case "GET": return this.handleGetRequest(req);
|
|
2463
|
+
case "DELETE": return this.handleDeleteRequest(req);
|
|
2464
|
+
default: return this.handleUnsupportedRequest();
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
/**
|
|
2468
|
+
* Writes a priming event to establish resumption capability.
|
|
2469
|
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
|
2470
|
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
|
2471
|
+
*/
|
|
2472
|
+
async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
|
|
2473
|
+
if (!this._eventStore) return;
|
|
2474
|
+
if (protocolVersion < "2025-11-25") return;
|
|
2475
|
+
const primingEventId = await this._eventStore.storeEvent(streamId, {});
|
|
2476
|
+
let primingEvent = `id: ${primingEventId}\ndata: \n\n`;
|
|
2477
|
+
if (this._retryInterval !== void 0) primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`;
|
|
2478
|
+
controller.enqueue(encoder.encode(primingEvent));
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Handles GET requests for SSE stream
|
|
2482
|
+
*/
|
|
2483
|
+
async handleGetRequest(req) {
|
|
2484
|
+
if (!req.headers.get("accept")?.includes("text/event-stream")) {
|
|
2485
|
+
this.onerror?.(/* @__PURE__ */ new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
2486
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
2487
|
+
}
|
|
2488
|
+
const sessionError = this.validateSession(req);
|
|
2489
|
+
if (sessionError) return sessionError;
|
|
2490
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
2491
|
+
if (protocolError) return protocolError;
|
|
2492
|
+
if (this._eventStore) {
|
|
2493
|
+
const lastEventId = req.headers.get("last-event-id");
|
|
2494
|
+
if (lastEventId) return this.replayEvents(lastEventId);
|
|
2495
|
+
}
|
|
2496
|
+
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
2497
|
+
this.onerror?.(/* @__PURE__ */ new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
2498
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
2499
|
+
}
|
|
2500
|
+
const encoder = new TextEncoder();
|
|
2501
|
+
let streamController;
|
|
2502
|
+
const readable = new ReadableStream({
|
|
2503
|
+
start: (controller) => {
|
|
2504
|
+
streamController = controller;
|
|
2505
|
+
},
|
|
2506
|
+
cancel: () => {
|
|
2507
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
2508
|
+
}
|
|
2509
|
+
});
|
|
2510
|
+
const headers = {
|
|
2511
|
+
"Content-Type": "text/event-stream",
|
|
2512
|
+
"Cache-Control": "no-cache, no-transform",
|
|
2513
|
+
Connection: "keep-alive"
|
|
2514
|
+
};
|
|
2515
|
+
if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
|
|
2516
|
+
this._streamMapping.set(this._standaloneSseStreamId, {
|
|
2517
|
+
controller: streamController,
|
|
2518
|
+
encoder,
|
|
2519
|
+
cleanup: () => {
|
|
2520
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
2521
|
+
try {
|
|
2522
|
+
streamController.close();
|
|
2523
|
+
} catch {}
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2526
|
+
return new Response(readable, { headers });
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Replays events that would have been sent after the specified event ID
|
|
2530
|
+
* Only used when resumability is enabled
|
|
2531
|
+
*/
|
|
2532
|
+
async replayEvents(lastEventId) {
|
|
2533
|
+
if (!this._eventStore) {
|
|
2534
|
+
this.onerror?.(/* @__PURE__ */ new Error("Event store not configured"));
|
|
2535
|
+
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
2536
|
+
}
|
|
2537
|
+
try {
|
|
2538
|
+
let streamId;
|
|
2539
|
+
if (this._eventStore.getStreamIdForEventId) {
|
|
2540
|
+
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
2541
|
+
if (!streamId) {
|
|
2542
|
+
this.onerror?.(/* @__PURE__ */ new Error("Invalid event ID format"));
|
|
2543
|
+
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
2544
|
+
}
|
|
2545
|
+
if (this._streamMapping.get(streamId) !== void 0) {
|
|
2546
|
+
this.onerror?.(/* @__PURE__ */ new Error("Conflict: Stream already has an active connection"));
|
|
2547
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
const headers = {
|
|
2551
|
+
"Content-Type": "text/event-stream",
|
|
2552
|
+
"Cache-Control": "no-cache, no-transform",
|
|
2553
|
+
Connection: "keep-alive"
|
|
2554
|
+
};
|
|
2555
|
+
if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
|
|
2556
|
+
const encoder = new TextEncoder();
|
|
2557
|
+
let streamController;
|
|
2558
|
+
const readable = new ReadableStream({
|
|
2559
|
+
start: (controller) => {
|
|
2560
|
+
streamController = controller;
|
|
2561
|
+
},
|
|
2562
|
+
cancel: () => {}
|
|
2563
|
+
});
|
|
2564
|
+
const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, { send: async (eventId, message) => {
|
|
2565
|
+
if (!this.writeSSEEvent(streamController, encoder, message, eventId)) {
|
|
2566
|
+
this.onerror?.(/* @__PURE__ */ new Error("Failed replay events"));
|
|
2567
|
+
try {
|
|
2568
|
+
streamController.close();
|
|
2569
|
+
} catch {}
|
|
2570
|
+
}
|
|
2571
|
+
} });
|
|
2572
|
+
this._streamMapping.set(replayedStreamId, {
|
|
2573
|
+
controller: streamController,
|
|
2574
|
+
encoder,
|
|
2575
|
+
cleanup: () => {
|
|
2576
|
+
this._streamMapping.delete(replayedStreamId);
|
|
2577
|
+
try {
|
|
2578
|
+
streamController.close();
|
|
2579
|
+
} catch {}
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
return new Response(readable, { headers });
|
|
2583
|
+
} catch (error) {
|
|
2584
|
+
this.onerror?.(error);
|
|
2585
|
+
return this.createJsonErrorResponse(500, -32e3, "Error replaying events");
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
/**
|
|
2589
|
+
* Writes an event to an SSE stream via controller with proper formatting
|
|
2590
|
+
*/
|
|
2591
|
+
writeSSEEvent(controller, encoder, message, eventId) {
|
|
2592
|
+
try {
|
|
2593
|
+
let eventData = `event: message\n`;
|
|
2594
|
+
if (eventId) eventData += `id: ${eventId}\n`;
|
|
2595
|
+
eventData += `data: ${JSON.stringify(message)}\n\n`;
|
|
2596
|
+
controller.enqueue(encoder.encode(eventData));
|
|
2597
|
+
return true;
|
|
2598
|
+
} catch (error) {
|
|
2599
|
+
this.onerror?.(error);
|
|
2600
|
+
return false;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
2605
|
+
*/
|
|
2606
|
+
handleUnsupportedRequest() {
|
|
2607
|
+
this.onerror?.(/* @__PURE__ */ new Error("Method not allowed."));
|
|
2608
|
+
return new Response(JSON.stringify({
|
|
2609
|
+
jsonrpc: "2.0",
|
|
2610
|
+
error: {
|
|
2611
|
+
code: -32e3,
|
|
2612
|
+
message: "Method not allowed."
|
|
2613
|
+
},
|
|
2614
|
+
id: null
|
|
2615
|
+
}), {
|
|
2616
|
+
status: 405,
|
|
2617
|
+
headers: {
|
|
2618
|
+
Allow: "GET, POST, DELETE",
|
|
2619
|
+
"Content-Type": "application/json"
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Handles POST requests containing JSON-RPC messages
|
|
2625
|
+
*/
|
|
2626
|
+
async handlePostRequest(req, options) {
|
|
2627
|
+
try {
|
|
2628
|
+
const acceptHeader = req.headers.get("accept");
|
|
2629
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
2630
|
+
this.onerror?.(/* @__PURE__ */ new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
2631
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
2632
|
+
}
|
|
2633
|
+
const ct = req.headers.get("content-type");
|
|
2634
|
+
if (!ct || !ct.includes("application/json")) {
|
|
2635
|
+
this.onerror?.(/* @__PURE__ */ new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
2636
|
+
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
2637
|
+
}
|
|
2638
|
+
const requestInfo = {
|
|
2639
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
2640
|
+
url: new URL(req.url)
|
|
2641
|
+
};
|
|
2642
|
+
let rawMessage;
|
|
2643
|
+
if (options?.parsedBody !== void 0) rawMessage = options.parsedBody;
|
|
2644
|
+
else try {
|
|
2645
|
+
rawMessage = await req.json();
|
|
2646
|
+
} catch {
|
|
2647
|
+
this.onerror?.(/* @__PURE__ */ new Error("Parse error: Invalid JSON"));
|
|
2648
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
2649
|
+
}
|
|
2650
|
+
let messages;
|
|
2651
|
+
try {
|
|
2652
|
+
if (Array.isArray(rawMessage)) messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
2653
|
+
else messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
2654
|
+
} catch {
|
|
2655
|
+
this.onerror?.(/* @__PURE__ */ new Error("Parse error: Invalid JSON-RPC message"));
|
|
2656
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
2657
|
+
}
|
|
2658
|
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
2659
|
+
if (isInitializationRequest) {
|
|
2660
|
+
if (this._initialized && this.sessionId !== void 0) {
|
|
2661
|
+
this.onerror?.(/* @__PURE__ */ new Error("Invalid Request: Server already initialized"));
|
|
2662
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
2663
|
+
}
|
|
2664
|
+
if (messages.length > 1) {
|
|
2665
|
+
this.onerror?.(/* @__PURE__ */ new Error("Invalid Request: Only one initialization request is allowed"));
|
|
2666
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
2667
|
+
}
|
|
2668
|
+
this.sessionId = this.sessionIdGenerator?.();
|
|
2669
|
+
this._initialized = true;
|
|
2670
|
+
if (this.sessionId && this._onsessioninitialized) await Promise.resolve(this._onsessioninitialized(this.sessionId));
|
|
2671
|
+
}
|
|
2672
|
+
if (!isInitializationRequest) {
|
|
2673
|
+
const sessionError = this.validateSession(req);
|
|
2674
|
+
if (sessionError) return sessionError;
|
|
2675
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
2676
|
+
if (protocolError) return protocolError;
|
|
2677
|
+
}
|
|
2678
|
+
if (!messages.some(isJSONRPCRequest)) {
|
|
2679
|
+
for (const message of messages) this.onmessage?.(message, {
|
|
2680
|
+
authInfo: options?.authInfo,
|
|
2681
|
+
requestInfo
|
|
2682
|
+
});
|
|
2683
|
+
return new Response(null, { status: 202 });
|
|
2684
|
+
}
|
|
2685
|
+
const streamId = crypto.randomUUID();
|
|
2686
|
+
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
2687
|
+
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? "2025-03-26";
|
|
2688
|
+
if (this._enableJsonResponse) return new Promise((resolve) => {
|
|
2689
|
+
this._streamMapping.set(streamId, {
|
|
2690
|
+
resolveJson: resolve,
|
|
2691
|
+
cleanup: () => {
|
|
2692
|
+
this._streamMapping.delete(streamId);
|
|
2693
|
+
}
|
|
2694
|
+
});
|
|
2695
|
+
for (const message of messages) if (isJSONRPCRequest(message)) this._requestToStreamMapping.set(message.id, streamId);
|
|
2696
|
+
for (const message of messages) this.onmessage?.(message, {
|
|
2697
|
+
authInfo: options?.authInfo,
|
|
2698
|
+
requestInfo
|
|
2699
|
+
});
|
|
2700
|
+
});
|
|
2701
|
+
const encoder = new TextEncoder();
|
|
2702
|
+
let streamController;
|
|
2703
|
+
const readable = new ReadableStream({
|
|
2704
|
+
start: (controller) => {
|
|
2705
|
+
streamController = controller;
|
|
2706
|
+
},
|
|
2707
|
+
cancel: () => {
|
|
2708
|
+
this._streamMapping.delete(streamId);
|
|
2709
|
+
}
|
|
2710
|
+
});
|
|
2711
|
+
const headers = {
|
|
2712
|
+
"Content-Type": "text/event-stream",
|
|
2713
|
+
"Cache-Control": "no-cache",
|
|
2714
|
+
Connection: "keep-alive"
|
|
2715
|
+
};
|
|
2716
|
+
if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
|
|
2717
|
+
for (const message of messages) if (isJSONRPCRequest(message)) {
|
|
2718
|
+
this._streamMapping.set(streamId, {
|
|
2719
|
+
controller: streamController,
|
|
2720
|
+
encoder,
|
|
2721
|
+
cleanup: () => {
|
|
2722
|
+
this._streamMapping.delete(streamId);
|
|
2723
|
+
try {
|
|
2724
|
+
streamController.close();
|
|
2725
|
+
} catch {}
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
2729
|
+
}
|
|
2730
|
+
await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
|
|
2731
|
+
for (const message of messages) {
|
|
2732
|
+
let closeSSEStream;
|
|
2733
|
+
let closeStandaloneSSEStream;
|
|
2734
|
+
if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= "2025-11-25") {
|
|
2735
|
+
closeSSEStream = () => {
|
|
2736
|
+
this.closeSSEStream(message.id);
|
|
2737
|
+
};
|
|
2738
|
+
closeStandaloneSSEStream = () => {
|
|
2739
|
+
this.closeStandaloneSSEStream();
|
|
2740
|
+
};
|
|
2741
|
+
}
|
|
2742
|
+
this.onmessage?.(message, {
|
|
2743
|
+
authInfo: options?.authInfo,
|
|
2744
|
+
requestInfo,
|
|
2745
|
+
closeSSEStream,
|
|
2746
|
+
closeStandaloneSSEStream
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
return new Response(readable, {
|
|
2750
|
+
status: 200,
|
|
2751
|
+
headers
|
|
2752
|
+
});
|
|
2753
|
+
} catch (error) {
|
|
2754
|
+
this.onerror?.(error);
|
|
2755
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error) });
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Handles DELETE requests to terminate sessions
|
|
2760
|
+
*/
|
|
2761
|
+
async handleDeleteRequest(req) {
|
|
2762
|
+
const sessionError = this.validateSession(req);
|
|
2763
|
+
if (sessionError) return sessionError;
|
|
2764
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
2765
|
+
if (protocolError) return protocolError;
|
|
2766
|
+
await Promise.resolve(this._onsessionclosed?.(this.sessionId));
|
|
2767
|
+
await this.close();
|
|
2768
|
+
return new Response(null, { status: 200 });
|
|
2769
|
+
}
|
|
2770
|
+
/**
|
|
2771
|
+
* Validates session ID for non-initialization requests.
|
|
2772
|
+
* Returns Response error if invalid, undefined otherwise
|
|
2773
|
+
*/
|
|
2774
|
+
validateSession(req) {
|
|
2775
|
+
if (this.sessionIdGenerator === void 0) return;
|
|
2776
|
+
if (!this._initialized) {
|
|
2777
|
+
this.onerror?.(/* @__PURE__ */ new Error("Bad Request: Server not initialized"));
|
|
2778
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
2779
|
+
}
|
|
2780
|
+
const sessionId = req.headers.get("mcp-session-id");
|
|
2781
|
+
if (!sessionId) {
|
|
2782
|
+
this.onerror?.(/* @__PURE__ */ new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
2783
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
2784
|
+
}
|
|
2785
|
+
if (sessionId !== this.sessionId) {
|
|
2786
|
+
this.onerror?.(/* @__PURE__ */ new Error("Session not found"));
|
|
2787
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
/**
|
|
2791
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
2792
|
+
*
|
|
2793
|
+
* For initialization: Version negotiation handles unknown versions gracefully
|
|
2794
|
+
* (server responds with its supported version).
|
|
2795
|
+
*
|
|
2796
|
+
* For subsequent requests with MCP-Protocol-Version header:
|
|
2797
|
+
* - Accept if in supported list
|
|
2798
|
+
* - 400 if unsupported
|
|
2799
|
+
*
|
|
2800
|
+
* For HTTP requests without the MCP-Protocol-Version header:
|
|
2801
|
+
* - Accept and default to the version negotiated at initialization
|
|
2802
|
+
*/
|
|
2803
|
+
validateProtocolVersion(req) {
|
|
2804
|
+
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
2805
|
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
2806
|
+
this.onerror?.(/* @__PURE__ */ new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
2807
|
+
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
async close() {
|
|
2811
|
+
this._streamMapping.forEach(({ cleanup }) => {
|
|
2812
|
+
cleanup();
|
|
2813
|
+
});
|
|
2814
|
+
this._streamMapping.clear();
|
|
2815
|
+
this._requestResponseMap.clear();
|
|
2816
|
+
this.onclose?.();
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
2820
|
+
* Use this to implement polling behavior during long-running operations -
|
|
2821
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
2822
|
+
*/
|
|
2823
|
+
closeSSEStream(requestId) {
|
|
2824
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
2825
|
+
if (!streamId) return;
|
|
2826
|
+
const stream = this._streamMapping.get(streamId);
|
|
2827
|
+
if (stream) stream.cleanup();
|
|
2828
|
+
}
|
|
2829
|
+
/**
|
|
2830
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
2831
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
2832
|
+
*/
|
|
2833
|
+
closeStandaloneSSEStream() {
|
|
2834
|
+
const stream = this._streamMapping.get(this._standaloneSseStreamId);
|
|
2835
|
+
if (stream) stream.cleanup();
|
|
2836
|
+
}
|
|
2837
|
+
async send(message, options) {
|
|
2838
|
+
let requestId = options?.relatedRequestId;
|
|
2839
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) requestId = message.id;
|
|
2840
|
+
if (requestId === void 0) {
|
|
2841
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
2842
|
+
let eventId;
|
|
2843
|
+
if (this._eventStore) eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
|
|
2844
|
+
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
|
|
2845
|
+
if (standaloneSse === void 0) return;
|
|
2846
|
+
if (standaloneSse.controller && standaloneSse.encoder) this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
|
|
2847
|
+
return;
|
|
2848
|
+
}
|
|
2849
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
2850
|
+
if (!streamId) throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
2851
|
+
const stream = this._streamMapping.get(streamId);
|
|
2852
|
+
if (!this._enableJsonResponse && stream?.controller && stream?.encoder) {
|
|
2853
|
+
let eventId;
|
|
2854
|
+
if (this._eventStore) eventId = await this._eventStore.storeEvent(streamId, message);
|
|
2855
|
+
this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
|
|
2856
|
+
}
|
|
2857
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
2858
|
+
this._requestResponseMap.set(requestId, message);
|
|
2859
|
+
const relatedIds = Array.from(this._requestToStreamMapping.entries()).filter(([_, sid]) => sid === streamId).map(([id]) => id);
|
|
2860
|
+
if (relatedIds.every((id) => this._requestResponseMap.has(id))) {
|
|
2861
|
+
if (!stream) throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
2862
|
+
if (this._enableJsonResponse && stream.resolveJson) {
|
|
2863
|
+
const headers = { "Content-Type": "application/json" };
|
|
2864
|
+
if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
|
|
2865
|
+
const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
|
|
2866
|
+
if (responses.length === 1) stream.resolveJson(new Response(JSON.stringify(responses[0]), {
|
|
2867
|
+
status: 200,
|
|
2868
|
+
headers
|
|
2869
|
+
}));
|
|
2870
|
+
else stream.resolveJson(new Response(JSON.stringify(responses), {
|
|
2871
|
+
status: 200,
|
|
2872
|
+
headers
|
|
2873
|
+
}));
|
|
2874
|
+
} else stream.cleanup();
|
|
2875
|
+
for (const id of relatedIds) {
|
|
2876
|
+
this._requestResponseMap.delete(id);
|
|
2877
|
+
this._requestToStreamMapping.delete(id);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
//#endregion
|
|
2884
|
+
//#region ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js
|
|
2885
|
+
/**
|
|
2886
|
+
* Node.js HTTP Streamable HTTP Server Transport
|
|
2887
|
+
*
|
|
2888
|
+
* This is a thin wrapper around `WebStandardStreamableHTTPServerTransport` that provides
|
|
2889
|
+
* compatibility with Node.js HTTP server (IncomingMessage/ServerResponse).
|
|
2890
|
+
*
|
|
2891
|
+
* For web-standard environments (Cloudflare Workers, Deno, Bun), use `WebStandardStreamableHTTPServerTransport` directly.
|
|
2892
|
+
*/
|
|
2893
|
+
/**
|
|
2894
|
+
* Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
|
|
2895
|
+
* It supports both SSE streaming and direct HTTP responses.
|
|
2896
|
+
*
|
|
2897
|
+
* This is a wrapper around `WebStandardStreamableHTTPServerTransport` that provides Node.js HTTP compatibility.
|
|
2898
|
+
* It uses the `@hono/node-server` library to convert between Node.js HTTP and Web Standard APIs.
|
|
2899
|
+
*
|
|
2900
|
+
* Usage example:
|
|
2901
|
+
*
|
|
2902
|
+
* ```typescript
|
|
2903
|
+
* // Stateful mode - server sets the session ID
|
|
2904
|
+
* const statefulTransport = new StreamableHTTPServerTransport({
|
|
2905
|
+
* sessionIdGenerator: () => randomUUID(),
|
|
2906
|
+
* });
|
|
2907
|
+
*
|
|
2908
|
+
* // Stateless mode - explicitly set session ID to undefined
|
|
2909
|
+
* const statelessTransport = new StreamableHTTPServerTransport({
|
|
2910
|
+
* sessionIdGenerator: undefined,
|
|
2911
|
+
* });
|
|
2912
|
+
*
|
|
2913
|
+
* // Using with pre-parsed request body
|
|
2914
|
+
* app.post('/mcp', (req, res) => {
|
|
2915
|
+
* transport.handleRequest(req, res, req.body);
|
|
2916
|
+
* });
|
|
2917
|
+
* ```
|
|
2918
|
+
*
|
|
2919
|
+
* In stateful mode:
|
|
2920
|
+
* - Session ID is generated and included in response headers
|
|
2921
|
+
* - Session ID is always included in initialization responses
|
|
2922
|
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
|
2923
|
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
|
2924
|
+
* - State is maintained in-memory (connections, message history)
|
|
2925
|
+
*
|
|
2926
|
+
* In stateless mode:
|
|
2927
|
+
* - No Session ID is included in any responses
|
|
2928
|
+
* - No session validation is performed
|
|
2929
|
+
*/
|
|
2930
|
+
var StreamableHTTPServerTransport = class {
|
|
2931
|
+
constructor(options = {}) {
|
|
2932
|
+
this._requestContext = /* @__PURE__ */ new WeakMap();
|
|
2933
|
+
this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options);
|
|
2934
|
+
this._requestListener = getRequestListener(async (webRequest) => {
|
|
2935
|
+
const context = this._requestContext.get(webRequest);
|
|
2936
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
2937
|
+
authInfo: context?.authInfo,
|
|
2938
|
+
parsedBody: context?.parsedBody
|
|
2939
|
+
});
|
|
2940
|
+
}, { overrideGlobalObjects: false });
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* Gets the session ID for this transport instance.
|
|
2944
|
+
*/
|
|
2945
|
+
get sessionId() {
|
|
2946
|
+
return this._webStandardTransport.sessionId;
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Sets callback for when the transport is closed.
|
|
2950
|
+
*/
|
|
2951
|
+
set onclose(handler) {
|
|
2952
|
+
this._webStandardTransport.onclose = handler;
|
|
2953
|
+
}
|
|
2954
|
+
get onclose() {
|
|
2955
|
+
return this._webStandardTransport.onclose;
|
|
2956
|
+
}
|
|
2957
|
+
/**
|
|
2958
|
+
* Sets callback for transport errors.
|
|
2959
|
+
*/
|
|
2960
|
+
set onerror(handler) {
|
|
2961
|
+
this._webStandardTransport.onerror = handler;
|
|
2962
|
+
}
|
|
2963
|
+
get onerror() {
|
|
2964
|
+
return this._webStandardTransport.onerror;
|
|
2965
|
+
}
|
|
2966
|
+
/**
|
|
2967
|
+
* Sets callback for incoming messages.
|
|
2968
|
+
*/
|
|
2969
|
+
set onmessage(handler) {
|
|
2970
|
+
this._webStandardTransport.onmessage = handler;
|
|
2971
|
+
}
|
|
2972
|
+
get onmessage() {
|
|
2973
|
+
return this._webStandardTransport.onmessage;
|
|
2974
|
+
}
|
|
2975
|
+
/**
|
|
2976
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
2977
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
2978
|
+
*/
|
|
2979
|
+
async start() {
|
|
2980
|
+
return this._webStandardTransport.start();
|
|
2981
|
+
}
|
|
2982
|
+
/**
|
|
2983
|
+
* Closes the transport and all active connections.
|
|
2984
|
+
*/
|
|
2985
|
+
async close() {
|
|
2986
|
+
return this._webStandardTransport.close();
|
|
2987
|
+
}
|
|
2988
|
+
/**
|
|
2989
|
+
* Sends a JSON-RPC message through the transport.
|
|
2990
|
+
*/
|
|
2991
|
+
async send(message, options) {
|
|
2992
|
+
return this._webStandardTransport.send(message, options);
|
|
2993
|
+
}
|
|
2994
|
+
/**
|
|
2995
|
+
* Handles an incoming HTTP request, whether GET or POST.
|
|
2996
|
+
*
|
|
2997
|
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
|
2998
|
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
|
2999
|
+
*
|
|
3000
|
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
|
3001
|
+
* @param res - Node.js ServerResponse
|
|
3002
|
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
|
3003
|
+
*/
|
|
3004
|
+
async handleRequest(req, res, parsedBody) {
|
|
3005
|
+
const authInfo = req.auth;
|
|
3006
|
+
await getRequestListener(async (webRequest) => {
|
|
3007
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
3008
|
+
authInfo,
|
|
3009
|
+
parsedBody
|
|
3010
|
+
});
|
|
3011
|
+
}, { overrideGlobalObjects: false })(req, res);
|
|
3012
|
+
}
|
|
3013
|
+
/**
|
|
3014
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
3015
|
+
* Use this to implement polling behavior during long-running operations -
|
|
3016
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
3017
|
+
*/
|
|
3018
|
+
closeSSEStream(requestId) {
|
|
3019
|
+
this._webStandardTransport.closeSSEStream(requestId);
|
|
3020
|
+
}
|
|
3021
|
+
/**
|
|
3022
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
3023
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
3024
|
+
*/
|
|
3025
|
+
closeStandaloneSSEStream() {
|
|
3026
|
+
this._webStandardTransport.closeStandaloneSSEStream();
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
//#endregion
|
|
3030
|
+
//#region src/http.ts
|
|
3031
|
+
var OAUTH_PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource/mcp";
|
|
3032
|
+
/**
|
|
3033
|
+
* JSON-RPC error response
|
|
3034
|
+
*/
|
|
3035
|
+
function jsonRpcError(code, message, id = null) {
|
|
3036
|
+
return {
|
|
3037
|
+
jsonrpc: "2.0",
|
|
3038
|
+
error: {
|
|
3039
|
+
code,
|
|
3040
|
+
message
|
|
3041
|
+
},
|
|
3042
|
+
id
|
|
3043
|
+
};
|
|
3044
|
+
}
|
|
3045
|
+
/**
|
|
3046
|
+
* JSON-RPC success response
|
|
3047
|
+
*/
|
|
3048
|
+
function jsonRpcSuccess(result, id = null) {
|
|
3049
|
+
return {
|
|
3050
|
+
jsonrpc: "2.0",
|
|
3051
|
+
result,
|
|
3052
|
+
id
|
|
3053
|
+
};
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* Handle the initialize JSON-RPC method
|
|
3057
|
+
*/
|
|
3058
|
+
function handleInitialize() {
|
|
3059
|
+
return {
|
|
3060
|
+
protocolVersion: "2024-11-05",
|
|
3061
|
+
serverInfo: {
|
|
3062
|
+
name: "productive-mcp",
|
|
3063
|
+
version: VERSION
|
|
3064
|
+
},
|
|
3065
|
+
capabilities: {
|
|
3066
|
+
tools: {},
|
|
3067
|
+
prompts: {},
|
|
3068
|
+
resources: {}
|
|
3069
|
+
},
|
|
3070
|
+
instructions: INSTRUCTIONS
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Handle the tools/list JSON-RPC method
|
|
3075
|
+
*/
|
|
3076
|
+
function handleToolsList() {
|
|
3077
|
+
return { tools: TOOLS };
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Get base URL from event headers
|
|
3081
|
+
*/
|
|
3082
|
+
function getBaseUrl(event) {
|
|
3083
|
+
const host = event.req.headers.get("host") || "localhost:3000";
|
|
3084
|
+
return `${event.req.headers.get("x-forwarded-proto") || "http"}://${host}`;
|
|
3085
|
+
}
|
|
3086
|
+
function buildProtectedResourceMetadata(event) {
|
|
3087
|
+
const baseUrl = getBaseUrl(event);
|
|
3088
|
+
return {
|
|
3089
|
+
resource: `${baseUrl}/mcp`,
|
|
3090
|
+
authorization_servers: [baseUrl],
|
|
3091
|
+
scopes_supported: ["productive"],
|
|
3092
|
+
bearer_methods_supported: ["header"]
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
function createAuthInfo(token, credentials) {
|
|
3096
|
+
return {
|
|
3097
|
+
token,
|
|
3098
|
+
clientId: credentials.userId || credentials.organizationId,
|
|
3099
|
+
scopes: ["productive"],
|
|
3100
|
+
extra: { credentials }
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
function getCredentialsFromAuthInfo(authInfo) {
|
|
3104
|
+
const credentials = authInfo?.extra?.credentials;
|
|
3105
|
+
if (!credentials || typeof credentials !== "object" || !("organizationId" in credentials) || !("apiToken" in credentials) || typeof credentials.organizationId !== "string" || typeof credentials.apiToken !== "string") throw new Error("Authentication required. Provide Bearer token with base64(organizationId:apiToken:userId)");
|
|
3106
|
+
const userId = "userId" in credentials && typeof credentials.userId === "string" ? credentials.userId : void 0;
|
|
3107
|
+
return {
|
|
3108
|
+
organizationId: credentials.organizationId,
|
|
3109
|
+
apiToken: credentials.apiToken,
|
|
3110
|
+
userId
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
function createHttpMcpServer() {
|
|
3114
|
+
const server = new Server({
|
|
3115
|
+
name: "productive-mcp",
|
|
3116
|
+
version: VERSION
|
|
3117
|
+
}, {
|
|
3118
|
+
capabilities: {
|
|
3119
|
+
tools: {},
|
|
3120
|
+
prompts: {},
|
|
3121
|
+
resources: {}
|
|
3122
|
+
},
|
|
3123
|
+
instructions: INSTRUCTIONS
|
|
3124
|
+
});
|
|
3125
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
3126
|
+
return { tools: TOOLS };
|
|
3127
|
+
});
|
|
3128
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
3129
|
+
return { prompts: getAvailablePrompts() };
|
|
3130
|
+
});
|
|
3131
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
3132
|
+
return handlePrompt(request.params.name, request.params.arguments);
|
|
3133
|
+
});
|
|
3134
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
3135
|
+
return { resources: listResources() };
|
|
3136
|
+
});
|
|
3137
|
+
server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
|
|
3138
|
+
return { resourceTemplates: listResourceTemplates() };
|
|
3139
|
+
});
|
|
3140
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request, extra) => {
|
|
3141
|
+
const credentials = getCredentialsFromAuthInfo(extra.authInfo);
|
|
3142
|
+
if (!request.params.uri) throw new McpError(ErrorCode.InvalidParams, "Invalid params: uri is required");
|
|
3143
|
+
return readResource(request.params.uri, credentials);
|
|
3144
|
+
});
|
|
3145
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
3146
|
+
const credentials = getCredentialsFromAuthInfo(extra.authInfo);
|
|
3147
|
+
return executeToolWithCredentials(request.params.name, request.params.arguments || {}, credentials);
|
|
3148
|
+
});
|
|
3149
|
+
return server;
|
|
3150
|
+
}
|
|
3151
|
+
async function createHttpMcpTransport() {
|
|
3152
|
+
const transport = new StreamableHTTPServerTransport({
|
|
3153
|
+
sessionIdGenerator: void 0,
|
|
3154
|
+
enableJsonResponse: true
|
|
3155
|
+
});
|
|
3156
|
+
await createHttpMcpServer().connect(transport);
|
|
3157
|
+
return transport;
|
|
3158
|
+
}
|
|
3159
|
+
function setUnauthorizedResponseHeaders(event) {
|
|
3160
|
+
const baseUrl = getBaseUrl(event);
|
|
3161
|
+
event.res.headers.delete("Set-Cookie");
|
|
3162
|
+
event.res.headers.set("WWW-Authenticate", `Bearer resource_metadata="${baseUrl}${OAUTH_PROTECTED_RESOURCE_PATH}"`);
|
|
3163
|
+
}
|
|
3164
|
+
function authenticateRequest(event) {
|
|
3165
|
+
const authHeader = event.req.headers.get("authorization");
|
|
3166
|
+
const tokenMatch = authHeader?.match(/^Bearer\s+(.+)$/i);
|
|
3167
|
+
const credentials = parseAuthHeader(authHeader);
|
|
3168
|
+
if (!credentials || !tokenMatch?.[1]) return null;
|
|
3169
|
+
return createAuthInfo(tokenMatch[1], credentials);
|
|
3170
|
+
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Create the H3 application with all routes
|
|
3173
|
+
*/
|
|
3174
|
+
function createHttpApp() {
|
|
3175
|
+
const app = new H3();
|
|
3176
|
+
app.get("/.well-known/oauth-authorization-server", oauthMetadataHandler);
|
|
3177
|
+
app.post("/register", registerHandler);
|
|
3178
|
+
app.get("/authorize", authorizeGetHandler);
|
|
3179
|
+
app.post("/authorize", authorizePostHandler);
|
|
3180
|
+
app.post("/token", tokenHandler);
|
|
3181
|
+
const protectedResourceMetadataHandler = defineHandler((event) => {
|
|
3182
|
+
event.res.headers.set("Content-Type", "application/json");
|
|
3183
|
+
event.res.headers.set("Cache-Control", "public, max-age=3600");
|
|
3184
|
+
return buildProtectedResourceMetadata(event);
|
|
3185
|
+
});
|
|
3186
|
+
app.get(OAUTH_PROTECTED_RESOURCE_PATH, protectedResourceMetadataHandler);
|
|
3187
|
+
app.get("/", defineHandler(() => {
|
|
3188
|
+
return {
|
|
3189
|
+
status: "ok",
|
|
3190
|
+
service: "productive-mcp",
|
|
3191
|
+
version: VERSION
|
|
3192
|
+
};
|
|
3193
|
+
}));
|
|
3194
|
+
app.get("/health", defineHandler(() => {
|
|
3195
|
+
return { status: "ok" };
|
|
3196
|
+
}));
|
|
3197
|
+
const mcpHandler = defineHandler(async (event) => {
|
|
3198
|
+
const authInfo = authenticateRequest(event);
|
|
3199
|
+
if (!authInfo) {
|
|
3200
|
+
setUnauthorizedResponseHeaders(event);
|
|
3201
|
+
event.res.status = 401;
|
|
3202
|
+
event.res.headers.set("Content-Type", "application/json");
|
|
3203
|
+
return event.req.method === "POST" ? jsonRpcError(-32001, "Authentication required. Provide Bearer token with base64(organizationId:apiToken:userId)") : { error: "Authentication required" };
|
|
3204
|
+
}
|
|
3205
|
+
const nodeReq = event.runtime?.node?.req;
|
|
3206
|
+
const nodeRes = event.runtime?.node?.res;
|
|
3207
|
+
if (!nodeReq || !nodeRes) {
|
|
3208
|
+
event.res.status = 501;
|
|
3209
|
+
return { error: "MCP HTTP transport requires Node.js runtime" };
|
|
3210
|
+
}
|
|
3211
|
+
nodeReq.auth = authInfo;
|
|
3212
|
+
let parsedBody;
|
|
3213
|
+
if (event.req.method === "POST") {
|
|
3214
|
+
try {
|
|
3215
|
+
parsedBody = await event.req.json();
|
|
3216
|
+
} catch {
|
|
3217
|
+
event.res.status = 400;
|
|
3218
|
+
event.res.headers.set("Content-Type", "application/json");
|
|
3219
|
+
return jsonRpcError(-32700, "Parse error: Invalid JSON");
|
|
3220
|
+
}
|
|
3221
|
+
const body = parsedBody;
|
|
3222
|
+
if (body?.method === "resources/read" && !body.params?.uri) {
|
|
3223
|
+
event.res.status = 200;
|
|
3224
|
+
event.res.headers.set("Content-Type", "application/json");
|
|
3225
|
+
return jsonRpcError(-32602, "Invalid params: uri is required", body.id ?? null);
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
await (await createHttpMcpTransport()).handleRequest(nodeReq, nodeRes, parsedBody);
|
|
3229
|
+
});
|
|
3230
|
+
app.get("/mcp", mcpHandler);
|
|
3231
|
+
app.post("/mcp", mcpHandler);
|
|
3232
|
+
app.delete("/mcp", mcpHandler);
|
|
3233
|
+
return app;
|
|
3234
|
+
}
|
|
3235
|
+
//#endregion
|
|
3236
|
+
export { handleToolsList as a, handleInitialize as i, createHttpMcpServer as n, jsonRpcError as o, createHttpMcpTransport as r, jsonRpcSuccess as s, createHttpApp as t };
|
|
3237
|
+
|
|
3238
|
+
//# sourceMappingURL=http-QQVUnV2e.js.map
|