agents 0.0.0-74a8c74 → 0.0.0-7972da4
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/dist/ai-chat-agent.d.ts +49 -4
- package/dist/ai-chat-agent.js +88 -29
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +13 -0
- package/dist/ai-react.js +38 -22
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +5 -0
- package/dist/chunk-BZXOAZUX.js +106 -0
- package/dist/chunk-BZXOAZUX.js.map +1 -0
- package/dist/{chunk-SZEXGW6W.js → chunk-CFTLYEEK.js} +345 -142
- package/dist/chunk-CFTLYEEK.js.map +1 -0
- package/dist/chunk-IFXSRTKF.js +465 -0
- package/dist/chunk-IFXSRTKF.js.map +1 -0
- package/dist/chunk-VCSB47AK.js +116 -0
- package/dist/chunk-VCSB47AK.js.map +1 -0
- package/dist/client.d.ts +15 -1
- package/dist/client.js +6 -126
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +120 -17
- package/dist/index.js +8 -7
- package/dist/mcp/client.d.ts +142 -34
- package/dist/mcp/client.js +3 -780
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +41 -0
- package/dist/mcp/do-oauth-client-provider.js +7 -0
- package/dist/mcp/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/index.d.ts +50 -7
- package/dist/mcp/index.js +718 -71
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +85 -5
- package/dist/react.js +48 -27
- package/dist/react.js.map +1 -1
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/dist/serializable.js.map +1 -0
- package/package.json +28 -5
- package/src/index.ts +389 -58
- package/dist/chunk-EZ76ZGDB.js +0 -1721
- package/dist/chunk-EZ76ZGDB.js.map +0 -1
- package/dist/chunk-SZEXGW6W.js.map +0 -1
package/dist/chunk-EZ76ZGDB.js
DELETED
|
@@ -1,1721 +0,0 @@
|
|
|
1
|
-
// ../../node_modules/eventsource-parser/dist/index.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
var ParseError = class extends Error {
|
|
6
|
-
constructor(message, options) {
|
|
7
|
-
super(message), __publicField(this, "type"), __publicField(this, "field"), __publicField(this, "value"), __publicField(this, "line"), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
function noop(_arg) {
|
|
11
|
-
}
|
|
12
|
-
function createParser(callbacks) {
|
|
13
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
14
|
-
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
15
|
-
function feed(newChunk) {
|
|
16
|
-
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
17
|
-
for (const line of complete)
|
|
18
|
-
parseLine(line);
|
|
19
|
-
incompleteLine = incomplete, isFirstChunk = false;
|
|
20
|
-
}
|
|
21
|
-
function parseLine(line) {
|
|
22
|
-
if (line === "") {
|
|
23
|
-
dispatchEvent();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (line.startsWith(":")) {
|
|
27
|
-
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
31
|
-
if (fieldSeparatorIndex !== -1) {
|
|
32
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
33
|
-
processField(field, value, line);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
processField(line, "", line);
|
|
37
|
-
}
|
|
38
|
-
function processField(field, value, line) {
|
|
39
|
-
switch (field) {
|
|
40
|
-
case "event":
|
|
41
|
-
eventType = value;
|
|
42
|
-
break;
|
|
43
|
-
case "data":
|
|
44
|
-
data = `${data}${value}
|
|
45
|
-
`;
|
|
46
|
-
break;
|
|
47
|
-
case "id":
|
|
48
|
-
id = value.includes("\0") ? void 0 : value;
|
|
49
|
-
break;
|
|
50
|
-
case "retry":
|
|
51
|
-
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
52
|
-
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
53
|
-
type: "invalid-retry",
|
|
54
|
-
value,
|
|
55
|
-
line
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
break;
|
|
59
|
-
default:
|
|
60
|
-
onError(
|
|
61
|
-
new ParseError(
|
|
62
|
-
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
63
|
-
{ type: "unknown-field", field, value, line }
|
|
64
|
-
)
|
|
65
|
-
);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function dispatchEvent() {
|
|
70
|
-
data.length > 0 && onEvent({
|
|
71
|
-
id,
|
|
72
|
-
event: eventType || void 0,
|
|
73
|
-
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
74
|
-
// then remove the last character from the data buffer.
|
|
75
|
-
data: data.endsWith(`
|
|
76
|
-
`) ? data.slice(0, -1) : data
|
|
77
|
-
}), id = void 0, data = "", eventType = "";
|
|
78
|
-
}
|
|
79
|
-
function reset(options = {}) {
|
|
80
|
-
incompleteLine && options.consume && parseLine(incompleteLine), id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
81
|
-
}
|
|
82
|
-
return { feed, reset };
|
|
83
|
-
}
|
|
84
|
-
function splitLines(chunk) {
|
|
85
|
-
const lines = [];
|
|
86
|
-
let incompleteLine = "";
|
|
87
|
-
const totalLength = chunk.length;
|
|
88
|
-
for (let i = 0; i < totalLength; i++) {
|
|
89
|
-
const char = chunk[i];
|
|
90
|
-
char === "\r" && chunk[i + 1] === `
|
|
91
|
-
` ? (lines.push(incompleteLine), incompleteLine = "", i++) : char === "\r" || char === `
|
|
92
|
-
` ? (lines.push(incompleteLine), incompleteLine = "") : incompleteLine += char;
|
|
93
|
-
}
|
|
94
|
-
return [lines, incompleteLine];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ../../node_modules/eventsource/dist/index.js
|
|
98
|
-
var ErrorEvent = class extends Event {
|
|
99
|
-
/**
|
|
100
|
-
* Constructs a new `ErrorEvent` instance. This is typically not called directly,
|
|
101
|
-
* but rather emitted by the `EventSource` object when an error occurs.
|
|
102
|
-
*
|
|
103
|
-
* @param type - The type of the event (should be "error")
|
|
104
|
-
* @param errorEventInitDict - Optional properties to include in the error event
|
|
105
|
-
*/
|
|
106
|
-
constructor(type, errorEventInitDict) {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
super(type), this.code = (_a = errorEventInitDict == null ? void 0 : errorEventInitDict.code) != null ? _a : void 0, this.message = (_b = errorEventInitDict == null ? void 0 : errorEventInitDict.message) != null ? _b : void 0;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
|
112
|
-
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
|
113
|
-
* we explicitly include the properties in the `inspect` method.
|
|
114
|
-
*
|
|
115
|
-
* This is automatically called by Node.js when you `console.log` an instance of this class.
|
|
116
|
-
*
|
|
117
|
-
* @param _depth - The current depth
|
|
118
|
-
* @param options - The options passed to `util.inspect`
|
|
119
|
-
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
|
120
|
-
* @returns A string representation of the error
|
|
121
|
-
*/
|
|
122
|
-
[Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) {
|
|
123
|
-
return inspect(inspectableError(this), options);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
|
127
|
-
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
|
128
|
-
* we explicitly include the properties in the `inspect` method.
|
|
129
|
-
*
|
|
130
|
-
* This is automatically called by Deno when you `console.log` an instance of this class.
|
|
131
|
-
*
|
|
132
|
-
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
|
133
|
-
* @param options - The options passed to `Deno.inspect`
|
|
134
|
-
* @returns A string representation of the error
|
|
135
|
-
*/
|
|
136
|
-
[Symbol.for("Deno.customInspect")](inspect, options) {
|
|
137
|
-
return inspect(inspectableError(this), options);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
function syntaxError(message) {
|
|
141
|
-
const DomException = globalThis.DOMException;
|
|
142
|
-
return typeof DomException == "function" ? new DomException(message, "SyntaxError") : new SyntaxError(message);
|
|
143
|
-
}
|
|
144
|
-
function flattenError(err) {
|
|
145
|
-
return err instanceof Error ? "errors" in err && Array.isArray(err.errors) ? err.errors.map(flattenError).join(", ") : "cause" in err && err.cause instanceof Error ? `${err}: ${flattenError(err.cause)}` : err.message : `${err}`;
|
|
146
|
-
}
|
|
147
|
-
function inspectableError(err) {
|
|
148
|
-
return {
|
|
149
|
-
type: err.type,
|
|
150
|
-
message: err.message,
|
|
151
|
-
code: err.code,
|
|
152
|
-
defaultPrevented: err.defaultPrevented,
|
|
153
|
-
cancelable: err.cancelable,
|
|
154
|
-
timeStamp: err.timeStamp
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
var __typeError = (msg) => {
|
|
158
|
-
throw TypeError(msg);
|
|
159
|
-
};
|
|
160
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
161
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
162
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
163
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
164
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
165
|
-
var _readyState;
|
|
166
|
-
var _url;
|
|
167
|
-
var _redirectUrl;
|
|
168
|
-
var _withCredentials;
|
|
169
|
-
var _fetch;
|
|
170
|
-
var _reconnectInterval;
|
|
171
|
-
var _reconnectTimer;
|
|
172
|
-
var _lastEventId;
|
|
173
|
-
var _controller;
|
|
174
|
-
var _parser;
|
|
175
|
-
var _onError;
|
|
176
|
-
var _onMessage;
|
|
177
|
-
var _onOpen;
|
|
178
|
-
var _EventSource_instances;
|
|
179
|
-
var connect_fn;
|
|
180
|
-
var _onFetchResponse;
|
|
181
|
-
var _onFetchError;
|
|
182
|
-
var getRequestOptions_fn;
|
|
183
|
-
var _onEvent;
|
|
184
|
-
var _onRetryChange;
|
|
185
|
-
var failConnection_fn;
|
|
186
|
-
var scheduleReconnect_fn;
|
|
187
|
-
var _reconnect;
|
|
188
|
-
var EventSource = class extends EventTarget {
|
|
189
|
-
constructor(url, eventSourceInitDict) {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
|
|
192
|
-
var _a2;
|
|
193
|
-
__privateGet(this, _parser).reset();
|
|
194
|
-
const { body, redirected, status, headers } = response;
|
|
195
|
-
if (status === 204) {
|
|
196
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (redirected ? __privateSet(this, _redirectUrl, new URL(response.url)) : __privateSet(this, _redirectUrl, void 0), status !== 200) {
|
|
200
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, `Non-200 status code (${status})`, status);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (!(headers.get("content-type") || "").startsWith("text/event-stream")) {
|
|
204
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, 'Invalid content type, expected "text/event-stream"', status);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (__privateGet(this, _readyState) === this.CLOSED)
|
|
208
|
-
return;
|
|
209
|
-
__privateSet(this, _readyState, this.OPEN);
|
|
210
|
-
const openEvent = new Event("open");
|
|
211
|
-
if ((_a2 = __privateGet(this, _onOpen)) == null || _a2.call(this, openEvent), this.dispatchEvent(openEvent), typeof body != "object" || !body || !("getReader" in body)) {
|
|
212
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const decoder = new TextDecoder(), reader = body.getReader();
|
|
216
|
-
let open = true;
|
|
217
|
-
do {
|
|
218
|
-
const { done, value } = await reader.read();
|
|
219
|
-
value && __privateGet(this, _parser).feed(decoder.decode(value, { stream: !done })), done && (open = false, __privateGet(this, _parser).reset(), __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this));
|
|
220
|
-
} while (open);
|
|
221
|
-
}), __privateAdd(this, _onFetchError, (err) => {
|
|
222
|
-
__privateSet(this, _controller, void 0), !(err.name === "AbortError" || err.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError(err));
|
|
223
|
-
}), __privateAdd(this, _onEvent, (event) => {
|
|
224
|
-
typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
|
|
225
|
-
const messageEvent = new MessageEvent(event.event || "message", {
|
|
226
|
-
data: event.data,
|
|
227
|
-
origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url).origin,
|
|
228
|
-
lastEventId: event.id || ""
|
|
229
|
-
});
|
|
230
|
-
__privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
|
|
231
|
-
}), __privateAdd(this, _onRetryChange, (value) => {
|
|
232
|
-
__privateSet(this, _reconnectInterval, value);
|
|
233
|
-
}), __privateAdd(this, _reconnect, () => {
|
|
234
|
-
__privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
235
|
-
});
|
|
236
|
-
try {
|
|
237
|
-
if (url instanceof URL)
|
|
238
|
-
__privateSet(this, _url, url);
|
|
239
|
-
else if (typeof url == "string")
|
|
240
|
-
__privateSet(this, _url, new URL(url, getBaseURL()));
|
|
241
|
-
else
|
|
242
|
-
throw new Error("Invalid URL");
|
|
243
|
-
} catch {
|
|
244
|
-
throw syntaxError("An invalid or illegal string was specified");
|
|
245
|
-
}
|
|
246
|
-
__privateSet(this, _parser, createParser({
|
|
247
|
-
onEvent: __privateGet(this, _onEvent),
|
|
248
|
-
onRetry: __privateGet(this, _onRetryChange)
|
|
249
|
-
})), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a : globalThis.fetch), __privateSet(this, _withCredentials, (_b = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b : false), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Returns the state of this EventSource object's connection. It can have the values described below.
|
|
253
|
-
*
|
|
254
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
|
|
255
|
-
*
|
|
256
|
-
* Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
|
|
257
|
-
* defined in the TypeScript `dom` library.
|
|
258
|
-
*
|
|
259
|
-
* @public
|
|
260
|
-
*/
|
|
261
|
-
get readyState() {
|
|
262
|
-
return __privateGet(this, _readyState);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Returns the URL providing the event stream.
|
|
266
|
-
*
|
|
267
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
|
|
268
|
-
*
|
|
269
|
-
* @public
|
|
270
|
-
*/
|
|
271
|
-
get url() {
|
|
272
|
-
return __privateGet(this, _url).href;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
|
|
276
|
-
*
|
|
277
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
|
|
278
|
-
*/
|
|
279
|
-
get withCredentials() {
|
|
280
|
-
return __privateGet(this, _withCredentials);
|
|
281
|
-
}
|
|
282
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
|
|
283
|
-
get onerror() {
|
|
284
|
-
return __privateGet(this, _onError);
|
|
285
|
-
}
|
|
286
|
-
set onerror(value) {
|
|
287
|
-
__privateSet(this, _onError, value);
|
|
288
|
-
}
|
|
289
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
|
|
290
|
-
get onmessage() {
|
|
291
|
-
return __privateGet(this, _onMessage);
|
|
292
|
-
}
|
|
293
|
-
set onmessage(value) {
|
|
294
|
-
__privateSet(this, _onMessage, value);
|
|
295
|
-
}
|
|
296
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
|
|
297
|
-
get onopen() {
|
|
298
|
-
return __privateGet(this, _onOpen);
|
|
299
|
-
}
|
|
300
|
-
set onopen(value) {
|
|
301
|
-
__privateSet(this, _onOpen, value);
|
|
302
|
-
}
|
|
303
|
-
addEventListener(type, listener, options) {
|
|
304
|
-
const listen = listener;
|
|
305
|
-
super.addEventListener(type, listen, options);
|
|
306
|
-
}
|
|
307
|
-
removeEventListener(type, listener, options) {
|
|
308
|
-
const listen = listener;
|
|
309
|
-
super.removeEventListener(type, listen, options);
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
|
|
313
|
-
*
|
|
314
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
|
|
315
|
-
*
|
|
316
|
-
* @public
|
|
317
|
-
*/
|
|
318
|
-
close() {
|
|
319
|
-
__privateGet(this, _reconnectTimer) && clearTimeout(__privateGet(this, _reconnectTimer)), __privateGet(this, _readyState) !== this.CLOSED && (__privateGet(this, _controller) && __privateGet(this, _controller).abort(), __privateSet(this, _readyState, this.CLOSED), __privateSet(this, _controller, void 0));
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
_readyState = /* @__PURE__ */ new WeakMap(), _url = /* @__PURE__ */ new WeakMap(), _redirectUrl = /* @__PURE__ */ new WeakMap(), _withCredentials = /* @__PURE__ */ new WeakMap(), _fetch = /* @__PURE__ */ new WeakMap(), _reconnectInterval = /* @__PURE__ */ new WeakMap(), _reconnectTimer = /* @__PURE__ */ new WeakMap(), _lastEventId = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _parser = /* @__PURE__ */ new WeakMap(), _onError = /* @__PURE__ */ new WeakMap(), _onMessage = /* @__PURE__ */ new WeakMap(), _onOpen = /* @__PURE__ */ new WeakMap(), _EventSource_instances = /* @__PURE__ */ new WeakSet(), /**
|
|
323
|
-
* Connect to the given URL and start receiving events
|
|
324
|
-
*
|
|
325
|
-
* @internal
|
|
326
|
-
*/
|
|
327
|
-
connect_fn = function() {
|
|
328
|
-
__privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _controller, new AbortController()), __privateGet(this, _fetch)(__privateGet(this, _url), __privateMethod(this, _EventSource_instances, getRequestOptions_fn).call(this)).then(__privateGet(this, _onFetchResponse)).catch(__privateGet(this, _onFetchError));
|
|
329
|
-
}, _onFetchResponse = /* @__PURE__ */ new WeakMap(), _onFetchError = /* @__PURE__ */ new WeakMap(), /**
|
|
330
|
-
* Get request options for the `fetch()` request
|
|
331
|
-
*
|
|
332
|
-
* @returns The request options
|
|
333
|
-
* @internal
|
|
334
|
-
*/
|
|
335
|
-
getRequestOptions_fn = function() {
|
|
336
|
-
var _a;
|
|
337
|
-
const init = {
|
|
338
|
-
// [spec] Let `corsAttributeState` be `Anonymous`…
|
|
339
|
-
// [spec] …will have their mode set to "cors"…
|
|
340
|
-
mode: "cors",
|
|
341
|
-
redirect: "follow",
|
|
342
|
-
headers: { Accept: "text/event-stream", ...__privateGet(this, _lastEventId) ? { "Last-Event-ID": __privateGet(this, _lastEventId) } : void 0 },
|
|
343
|
-
cache: "no-store",
|
|
344
|
-
signal: (_a = __privateGet(this, _controller)) == null ? void 0 : _a.signal
|
|
345
|
-
};
|
|
346
|
-
return "window" in globalThis && (init.credentials = this.withCredentials ? "include" : "same-origin"), init;
|
|
347
|
-
}, _onEvent = /* @__PURE__ */ new WeakMap(), _onRetryChange = /* @__PURE__ */ new WeakMap(), /**
|
|
348
|
-
* Handles the process referred to in the EventSource specification as "failing a connection".
|
|
349
|
-
*
|
|
350
|
-
* @param error - The error causing the connection to fail
|
|
351
|
-
* @param code - The HTTP status code, if available
|
|
352
|
-
* @internal
|
|
353
|
-
*/
|
|
354
|
-
failConnection_fn = function(message, code) {
|
|
355
|
-
var _a;
|
|
356
|
-
__privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED);
|
|
357
|
-
const errorEvent = new ErrorEvent("error", { code, message });
|
|
358
|
-
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent);
|
|
359
|
-
}, /**
|
|
360
|
-
* Schedules a reconnection attempt against the EventSource endpoint.
|
|
361
|
-
*
|
|
362
|
-
* @param message - The error causing the connection to fail
|
|
363
|
-
* @param code - The HTTP status code, if available
|
|
364
|
-
* @internal
|
|
365
|
-
*/
|
|
366
|
-
scheduleReconnect_fn = function(message, code) {
|
|
367
|
-
var _a;
|
|
368
|
-
if (__privateGet(this, _readyState) === this.CLOSED)
|
|
369
|
-
return;
|
|
370
|
-
__privateSet(this, _readyState, this.CONNECTING);
|
|
371
|
-
const errorEvent = new ErrorEvent("error", { code, message });
|
|
372
|
-
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval)));
|
|
373
|
-
}, _reconnect = /* @__PURE__ */ new WeakMap(), /**
|
|
374
|
-
* ReadyState representing an EventSource currently trying to connect
|
|
375
|
-
*
|
|
376
|
-
* @public
|
|
377
|
-
*/
|
|
378
|
-
EventSource.CONNECTING = 0, /**
|
|
379
|
-
* ReadyState representing an EventSource connection that is open (eg connected)
|
|
380
|
-
*
|
|
381
|
-
* @public
|
|
382
|
-
*/
|
|
383
|
-
EventSource.OPEN = 1, /**
|
|
384
|
-
* ReadyState representing an EventSource connection that is closed (eg disconnected)
|
|
385
|
-
*
|
|
386
|
-
* @public
|
|
387
|
-
*/
|
|
388
|
-
EventSource.CLOSED = 2;
|
|
389
|
-
function getBaseURL() {
|
|
390
|
-
const doc = "document" in globalThis ? globalThis.document : void 0;
|
|
391
|
-
return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
395
|
-
import { z } from "zod";
|
|
396
|
-
var LATEST_PROTOCOL_VERSION = "2024-11-05";
|
|
397
|
-
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
398
|
-
LATEST_PROTOCOL_VERSION,
|
|
399
|
-
"2024-10-07"
|
|
400
|
-
];
|
|
401
|
-
var JSONRPC_VERSION = "2.0";
|
|
402
|
-
var ProgressTokenSchema = z.union([z.string(), z.number().int()]);
|
|
403
|
-
var CursorSchema = z.string();
|
|
404
|
-
var BaseRequestParamsSchema = z.object({
|
|
405
|
-
_meta: z.optional(z.object({
|
|
406
|
-
/**
|
|
407
|
-
* 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.
|
|
408
|
-
*/
|
|
409
|
-
progressToken: z.optional(ProgressTokenSchema)
|
|
410
|
-
}).passthrough())
|
|
411
|
-
}).passthrough();
|
|
412
|
-
var RequestSchema = z.object({
|
|
413
|
-
method: z.string(),
|
|
414
|
-
params: z.optional(BaseRequestParamsSchema)
|
|
415
|
-
});
|
|
416
|
-
var BaseNotificationParamsSchema = z.object({
|
|
417
|
-
/**
|
|
418
|
-
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
|
419
|
-
*/
|
|
420
|
-
_meta: z.optional(z.object({}).passthrough())
|
|
421
|
-
}).passthrough();
|
|
422
|
-
var NotificationSchema = z.object({
|
|
423
|
-
method: z.string(),
|
|
424
|
-
params: z.optional(BaseNotificationParamsSchema)
|
|
425
|
-
});
|
|
426
|
-
var ResultSchema = z.object({
|
|
427
|
-
/**
|
|
428
|
-
* This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
|
|
429
|
-
*/
|
|
430
|
-
_meta: z.optional(z.object({}).passthrough())
|
|
431
|
-
}).passthrough();
|
|
432
|
-
var RequestIdSchema = z.union([z.string(), z.number().int()]);
|
|
433
|
-
var JSONRPCRequestSchema = z.object({
|
|
434
|
-
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
435
|
-
id: RequestIdSchema
|
|
436
|
-
}).merge(RequestSchema).strict();
|
|
437
|
-
var JSONRPCNotificationSchema = z.object({
|
|
438
|
-
jsonrpc: z.literal(JSONRPC_VERSION)
|
|
439
|
-
}).merge(NotificationSchema).strict();
|
|
440
|
-
var JSONRPCResponseSchema = z.object({
|
|
441
|
-
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
442
|
-
id: RequestIdSchema,
|
|
443
|
-
result: ResultSchema
|
|
444
|
-
}).strict();
|
|
445
|
-
var ErrorCode;
|
|
446
|
-
(function(ErrorCode2) {
|
|
447
|
-
ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
448
|
-
ErrorCode2[ErrorCode2["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
449
|
-
ErrorCode2[ErrorCode2["ParseError"] = -32700] = "ParseError";
|
|
450
|
-
ErrorCode2[ErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
451
|
-
ErrorCode2[ErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
452
|
-
ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
453
|
-
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
454
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
455
|
-
var JSONRPCErrorSchema = z.object({
|
|
456
|
-
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
457
|
-
id: RequestIdSchema,
|
|
458
|
-
error: z.object({
|
|
459
|
-
/**
|
|
460
|
-
* The error type that occurred.
|
|
461
|
-
*/
|
|
462
|
-
code: z.number().int(),
|
|
463
|
-
/**
|
|
464
|
-
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
465
|
-
*/
|
|
466
|
-
message: z.string(),
|
|
467
|
-
/**
|
|
468
|
-
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
469
|
-
*/
|
|
470
|
-
data: z.optional(z.unknown())
|
|
471
|
-
})
|
|
472
|
-
}).strict();
|
|
473
|
-
var JSONRPCMessageSchema = z.union([
|
|
474
|
-
JSONRPCRequestSchema,
|
|
475
|
-
JSONRPCNotificationSchema,
|
|
476
|
-
JSONRPCResponseSchema,
|
|
477
|
-
JSONRPCErrorSchema
|
|
478
|
-
]);
|
|
479
|
-
var EmptyResultSchema = ResultSchema.strict();
|
|
480
|
-
var CancelledNotificationSchema = NotificationSchema.extend({
|
|
481
|
-
method: z.literal("notifications/cancelled"),
|
|
482
|
-
params: BaseNotificationParamsSchema.extend({
|
|
483
|
-
/**
|
|
484
|
-
* The ID of the request to cancel.
|
|
485
|
-
*
|
|
486
|
-
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
487
|
-
*/
|
|
488
|
-
requestId: RequestIdSchema,
|
|
489
|
-
/**
|
|
490
|
-
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
491
|
-
*/
|
|
492
|
-
reason: z.string().optional()
|
|
493
|
-
})
|
|
494
|
-
});
|
|
495
|
-
var ImplementationSchema = z.object({
|
|
496
|
-
name: z.string(),
|
|
497
|
-
version: z.string()
|
|
498
|
-
}).passthrough();
|
|
499
|
-
var ClientCapabilitiesSchema = z.object({
|
|
500
|
-
/**
|
|
501
|
-
* Experimental, non-standard capabilities that the client supports.
|
|
502
|
-
*/
|
|
503
|
-
experimental: z.optional(z.object({}).passthrough()),
|
|
504
|
-
/**
|
|
505
|
-
* Present if the client supports sampling from an LLM.
|
|
506
|
-
*/
|
|
507
|
-
sampling: z.optional(z.object({}).passthrough()),
|
|
508
|
-
/**
|
|
509
|
-
* Present if the client supports listing roots.
|
|
510
|
-
*/
|
|
511
|
-
roots: z.optional(z.object({
|
|
512
|
-
/**
|
|
513
|
-
* Whether the client supports issuing notifications for changes to the roots list.
|
|
514
|
-
*/
|
|
515
|
-
listChanged: z.optional(z.boolean())
|
|
516
|
-
}).passthrough())
|
|
517
|
-
}).passthrough();
|
|
518
|
-
var InitializeRequestSchema = RequestSchema.extend({
|
|
519
|
-
method: z.literal("initialize"),
|
|
520
|
-
params: BaseRequestParamsSchema.extend({
|
|
521
|
-
/**
|
|
522
|
-
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
523
|
-
*/
|
|
524
|
-
protocolVersion: z.string(),
|
|
525
|
-
capabilities: ClientCapabilitiesSchema,
|
|
526
|
-
clientInfo: ImplementationSchema
|
|
527
|
-
})
|
|
528
|
-
});
|
|
529
|
-
var ServerCapabilitiesSchema = z.object({
|
|
530
|
-
/**
|
|
531
|
-
* Experimental, non-standard capabilities that the server supports.
|
|
532
|
-
*/
|
|
533
|
-
experimental: z.optional(z.object({}).passthrough()),
|
|
534
|
-
/**
|
|
535
|
-
* Present if the server supports sending log messages to the client.
|
|
536
|
-
*/
|
|
537
|
-
logging: z.optional(z.object({}).passthrough()),
|
|
538
|
-
/**
|
|
539
|
-
* Present if the server offers any prompt templates.
|
|
540
|
-
*/
|
|
541
|
-
prompts: z.optional(z.object({
|
|
542
|
-
/**
|
|
543
|
-
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
544
|
-
*/
|
|
545
|
-
listChanged: z.optional(z.boolean())
|
|
546
|
-
}).passthrough()),
|
|
547
|
-
/**
|
|
548
|
-
* Present if the server offers any resources to read.
|
|
549
|
-
*/
|
|
550
|
-
resources: z.optional(z.object({
|
|
551
|
-
/**
|
|
552
|
-
* Whether this server supports clients subscribing to resource updates.
|
|
553
|
-
*/
|
|
554
|
-
subscribe: z.optional(z.boolean()),
|
|
555
|
-
/**
|
|
556
|
-
* Whether this server supports issuing notifications for changes to the resource list.
|
|
557
|
-
*/
|
|
558
|
-
listChanged: z.optional(z.boolean())
|
|
559
|
-
}).passthrough()),
|
|
560
|
-
/**
|
|
561
|
-
* Present if the server offers any tools to call.
|
|
562
|
-
*/
|
|
563
|
-
tools: z.optional(z.object({
|
|
564
|
-
/**
|
|
565
|
-
* Whether this server supports issuing notifications for changes to the tool list.
|
|
566
|
-
*/
|
|
567
|
-
listChanged: z.optional(z.boolean())
|
|
568
|
-
}).passthrough())
|
|
569
|
-
}).passthrough();
|
|
570
|
-
var InitializeResultSchema = ResultSchema.extend({
|
|
571
|
-
/**
|
|
572
|
-
* 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.
|
|
573
|
-
*/
|
|
574
|
-
protocolVersion: z.string(),
|
|
575
|
-
capabilities: ServerCapabilitiesSchema,
|
|
576
|
-
serverInfo: ImplementationSchema,
|
|
577
|
-
/**
|
|
578
|
-
* Instructions describing how to use the server and its features.
|
|
579
|
-
*
|
|
580
|
-
* 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.
|
|
581
|
-
*/
|
|
582
|
-
instructions: z.optional(z.string())
|
|
583
|
-
});
|
|
584
|
-
var InitializedNotificationSchema = NotificationSchema.extend({
|
|
585
|
-
method: z.literal("notifications/initialized")
|
|
586
|
-
});
|
|
587
|
-
var PingRequestSchema = RequestSchema.extend({
|
|
588
|
-
method: z.literal("ping")
|
|
589
|
-
});
|
|
590
|
-
var ProgressSchema = z.object({
|
|
591
|
-
/**
|
|
592
|
-
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
593
|
-
*/
|
|
594
|
-
progress: z.number(),
|
|
595
|
-
/**
|
|
596
|
-
* Total number of items to process (or total progress required), if known.
|
|
597
|
-
*/
|
|
598
|
-
total: z.optional(z.number())
|
|
599
|
-
}).passthrough();
|
|
600
|
-
var ProgressNotificationSchema = NotificationSchema.extend({
|
|
601
|
-
method: z.literal("notifications/progress"),
|
|
602
|
-
params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
|
|
603
|
-
/**
|
|
604
|
-
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
605
|
-
*/
|
|
606
|
-
progressToken: ProgressTokenSchema
|
|
607
|
-
})
|
|
608
|
-
});
|
|
609
|
-
var PaginatedRequestSchema = RequestSchema.extend({
|
|
610
|
-
params: BaseRequestParamsSchema.extend({
|
|
611
|
-
/**
|
|
612
|
-
* An opaque token representing the current pagination position.
|
|
613
|
-
* If provided, the server should return results starting after this cursor.
|
|
614
|
-
*/
|
|
615
|
-
cursor: z.optional(CursorSchema)
|
|
616
|
-
}).optional()
|
|
617
|
-
});
|
|
618
|
-
var PaginatedResultSchema = ResultSchema.extend({
|
|
619
|
-
/**
|
|
620
|
-
* An opaque token representing the pagination position after the last returned result.
|
|
621
|
-
* If present, there may be more results available.
|
|
622
|
-
*/
|
|
623
|
-
nextCursor: z.optional(CursorSchema)
|
|
624
|
-
});
|
|
625
|
-
var ResourceContentsSchema = z.object({
|
|
626
|
-
/**
|
|
627
|
-
* The URI of this resource.
|
|
628
|
-
*/
|
|
629
|
-
uri: z.string(),
|
|
630
|
-
/**
|
|
631
|
-
* The MIME type of this resource, if known.
|
|
632
|
-
*/
|
|
633
|
-
mimeType: z.optional(z.string())
|
|
634
|
-
}).passthrough();
|
|
635
|
-
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
636
|
-
/**
|
|
637
|
-
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
638
|
-
*/
|
|
639
|
-
text: z.string()
|
|
640
|
-
});
|
|
641
|
-
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
642
|
-
/**
|
|
643
|
-
* A base64-encoded string representing the binary data of the item.
|
|
644
|
-
*/
|
|
645
|
-
blob: z.string().base64()
|
|
646
|
-
});
|
|
647
|
-
var ResourceSchema = z.object({
|
|
648
|
-
/**
|
|
649
|
-
* The URI of this resource.
|
|
650
|
-
*/
|
|
651
|
-
uri: z.string(),
|
|
652
|
-
/**
|
|
653
|
-
* A human-readable name for this resource.
|
|
654
|
-
*
|
|
655
|
-
* This can be used by clients to populate UI elements.
|
|
656
|
-
*/
|
|
657
|
-
name: z.string(),
|
|
658
|
-
/**
|
|
659
|
-
* A description of what this resource represents.
|
|
660
|
-
*
|
|
661
|
-
* 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.
|
|
662
|
-
*/
|
|
663
|
-
description: z.optional(z.string()),
|
|
664
|
-
/**
|
|
665
|
-
* The MIME type of this resource, if known.
|
|
666
|
-
*/
|
|
667
|
-
mimeType: z.optional(z.string())
|
|
668
|
-
}).passthrough();
|
|
669
|
-
var ResourceTemplateSchema = z.object({
|
|
670
|
-
/**
|
|
671
|
-
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
672
|
-
*/
|
|
673
|
-
uriTemplate: z.string(),
|
|
674
|
-
/**
|
|
675
|
-
* A human-readable name for the type of resource this template refers to.
|
|
676
|
-
*
|
|
677
|
-
* This can be used by clients to populate UI elements.
|
|
678
|
-
*/
|
|
679
|
-
name: z.string(),
|
|
680
|
-
/**
|
|
681
|
-
* A description of what this template is for.
|
|
682
|
-
*
|
|
683
|
-
* 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.
|
|
684
|
-
*/
|
|
685
|
-
description: z.optional(z.string()),
|
|
686
|
-
/**
|
|
687
|
-
* 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.
|
|
688
|
-
*/
|
|
689
|
-
mimeType: z.optional(z.string())
|
|
690
|
-
}).passthrough();
|
|
691
|
-
var ListResourcesRequestSchema = PaginatedRequestSchema.extend({
|
|
692
|
-
method: z.literal("resources/list")
|
|
693
|
-
});
|
|
694
|
-
var ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
695
|
-
resources: z.array(ResourceSchema)
|
|
696
|
-
});
|
|
697
|
-
var ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
|
|
698
|
-
method: z.literal("resources/templates/list")
|
|
699
|
-
});
|
|
700
|
-
var ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
701
|
-
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
702
|
-
});
|
|
703
|
-
var ReadResourceRequestSchema = RequestSchema.extend({
|
|
704
|
-
method: z.literal("resources/read"),
|
|
705
|
-
params: BaseRequestParamsSchema.extend({
|
|
706
|
-
/**
|
|
707
|
-
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
708
|
-
*/
|
|
709
|
-
uri: z.string()
|
|
710
|
-
})
|
|
711
|
-
});
|
|
712
|
-
var ReadResourceResultSchema = ResultSchema.extend({
|
|
713
|
-
contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
714
|
-
});
|
|
715
|
-
var ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
716
|
-
method: z.literal("notifications/resources/list_changed")
|
|
717
|
-
});
|
|
718
|
-
var SubscribeRequestSchema = RequestSchema.extend({
|
|
719
|
-
method: z.literal("resources/subscribe"),
|
|
720
|
-
params: BaseRequestParamsSchema.extend({
|
|
721
|
-
/**
|
|
722
|
-
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
|
723
|
-
*/
|
|
724
|
-
uri: z.string()
|
|
725
|
-
})
|
|
726
|
-
});
|
|
727
|
-
var UnsubscribeRequestSchema = RequestSchema.extend({
|
|
728
|
-
method: z.literal("resources/unsubscribe"),
|
|
729
|
-
params: BaseRequestParamsSchema.extend({
|
|
730
|
-
/**
|
|
731
|
-
* The URI of the resource to unsubscribe from.
|
|
732
|
-
*/
|
|
733
|
-
uri: z.string()
|
|
734
|
-
})
|
|
735
|
-
});
|
|
736
|
-
var ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
737
|
-
method: z.literal("notifications/resources/updated"),
|
|
738
|
-
params: BaseNotificationParamsSchema.extend({
|
|
739
|
-
/**
|
|
740
|
-
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
741
|
-
*/
|
|
742
|
-
uri: z.string()
|
|
743
|
-
})
|
|
744
|
-
});
|
|
745
|
-
var PromptArgumentSchema = z.object({
|
|
746
|
-
/**
|
|
747
|
-
* The name of the argument.
|
|
748
|
-
*/
|
|
749
|
-
name: z.string(),
|
|
750
|
-
/**
|
|
751
|
-
* A human-readable description of the argument.
|
|
752
|
-
*/
|
|
753
|
-
description: z.optional(z.string()),
|
|
754
|
-
/**
|
|
755
|
-
* Whether this argument must be provided.
|
|
756
|
-
*/
|
|
757
|
-
required: z.optional(z.boolean())
|
|
758
|
-
}).passthrough();
|
|
759
|
-
var PromptSchema = z.object({
|
|
760
|
-
/**
|
|
761
|
-
* The name of the prompt or prompt template.
|
|
762
|
-
*/
|
|
763
|
-
name: z.string(),
|
|
764
|
-
/**
|
|
765
|
-
* An optional description of what this prompt provides
|
|
766
|
-
*/
|
|
767
|
-
description: z.optional(z.string()),
|
|
768
|
-
/**
|
|
769
|
-
* A list of arguments to use for templating the prompt.
|
|
770
|
-
*/
|
|
771
|
-
arguments: z.optional(z.array(PromptArgumentSchema))
|
|
772
|
-
}).passthrough();
|
|
773
|
-
var ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
774
|
-
method: z.literal("prompts/list")
|
|
775
|
-
});
|
|
776
|
-
var ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
777
|
-
prompts: z.array(PromptSchema)
|
|
778
|
-
});
|
|
779
|
-
var GetPromptRequestSchema = RequestSchema.extend({
|
|
780
|
-
method: z.literal("prompts/get"),
|
|
781
|
-
params: BaseRequestParamsSchema.extend({
|
|
782
|
-
/**
|
|
783
|
-
* The name of the prompt or prompt template.
|
|
784
|
-
*/
|
|
785
|
-
name: z.string(),
|
|
786
|
-
/**
|
|
787
|
-
* Arguments to use for templating the prompt.
|
|
788
|
-
*/
|
|
789
|
-
arguments: z.optional(z.record(z.string()))
|
|
790
|
-
})
|
|
791
|
-
});
|
|
792
|
-
var TextContentSchema = z.object({
|
|
793
|
-
type: z.literal("text"),
|
|
794
|
-
/**
|
|
795
|
-
* The text content of the message.
|
|
796
|
-
*/
|
|
797
|
-
text: z.string()
|
|
798
|
-
}).passthrough();
|
|
799
|
-
var ImageContentSchema = z.object({
|
|
800
|
-
type: z.literal("image"),
|
|
801
|
-
/**
|
|
802
|
-
* The base64-encoded image data.
|
|
803
|
-
*/
|
|
804
|
-
data: z.string().base64(),
|
|
805
|
-
/**
|
|
806
|
-
* The MIME type of the image. Different providers may support different image types.
|
|
807
|
-
*/
|
|
808
|
-
mimeType: z.string()
|
|
809
|
-
}).passthrough();
|
|
810
|
-
var EmbeddedResourceSchema = z.object({
|
|
811
|
-
type: z.literal("resource"),
|
|
812
|
-
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
813
|
-
}).passthrough();
|
|
814
|
-
var PromptMessageSchema = z.object({
|
|
815
|
-
role: z.enum(["user", "assistant"]),
|
|
816
|
-
content: z.union([
|
|
817
|
-
TextContentSchema,
|
|
818
|
-
ImageContentSchema,
|
|
819
|
-
EmbeddedResourceSchema
|
|
820
|
-
])
|
|
821
|
-
}).passthrough();
|
|
822
|
-
var GetPromptResultSchema = ResultSchema.extend({
|
|
823
|
-
/**
|
|
824
|
-
* An optional description for the prompt.
|
|
825
|
-
*/
|
|
826
|
-
description: z.optional(z.string()),
|
|
827
|
-
messages: z.array(PromptMessageSchema)
|
|
828
|
-
});
|
|
829
|
-
var PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
830
|
-
method: z.literal("notifications/prompts/list_changed")
|
|
831
|
-
});
|
|
832
|
-
var ToolSchema = z.object({
|
|
833
|
-
/**
|
|
834
|
-
* The name of the tool.
|
|
835
|
-
*/
|
|
836
|
-
name: z.string(),
|
|
837
|
-
/**
|
|
838
|
-
* A human-readable description of the tool.
|
|
839
|
-
*/
|
|
840
|
-
description: z.optional(z.string()),
|
|
841
|
-
/**
|
|
842
|
-
* A JSON Schema object defining the expected parameters for the tool.
|
|
843
|
-
*/
|
|
844
|
-
inputSchema: z.object({
|
|
845
|
-
type: z.literal("object"),
|
|
846
|
-
properties: z.optional(z.object({}).passthrough())
|
|
847
|
-
}).passthrough()
|
|
848
|
-
}).passthrough();
|
|
849
|
-
var ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
850
|
-
method: z.literal("tools/list")
|
|
851
|
-
});
|
|
852
|
-
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
853
|
-
tools: z.array(ToolSchema)
|
|
854
|
-
});
|
|
855
|
-
var CallToolResultSchema = ResultSchema.extend({
|
|
856
|
-
content: z.array(z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])),
|
|
857
|
-
isError: z.boolean().default(false).optional()
|
|
858
|
-
});
|
|
859
|
-
var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
|
|
860
|
-
toolResult: z.unknown()
|
|
861
|
-
}));
|
|
862
|
-
var CallToolRequestSchema = RequestSchema.extend({
|
|
863
|
-
method: z.literal("tools/call"),
|
|
864
|
-
params: BaseRequestParamsSchema.extend({
|
|
865
|
-
name: z.string(),
|
|
866
|
-
arguments: z.optional(z.record(z.unknown()))
|
|
867
|
-
})
|
|
868
|
-
});
|
|
869
|
-
var ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
870
|
-
method: z.literal("notifications/tools/list_changed")
|
|
871
|
-
});
|
|
872
|
-
var LoggingLevelSchema = z.enum([
|
|
873
|
-
"debug",
|
|
874
|
-
"info",
|
|
875
|
-
"notice",
|
|
876
|
-
"warning",
|
|
877
|
-
"error",
|
|
878
|
-
"critical",
|
|
879
|
-
"alert",
|
|
880
|
-
"emergency"
|
|
881
|
-
]);
|
|
882
|
-
var SetLevelRequestSchema = RequestSchema.extend({
|
|
883
|
-
method: z.literal("logging/setLevel"),
|
|
884
|
-
params: BaseRequestParamsSchema.extend({
|
|
885
|
-
/**
|
|
886
|
-
* 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.
|
|
887
|
-
*/
|
|
888
|
-
level: LoggingLevelSchema
|
|
889
|
-
})
|
|
890
|
-
});
|
|
891
|
-
var LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
892
|
-
method: z.literal("notifications/message"),
|
|
893
|
-
params: BaseNotificationParamsSchema.extend({
|
|
894
|
-
/**
|
|
895
|
-
* The severity of this log message.
|
|
896
|
-
*/
|
|
897
|
-
level: LoggingLevelSchema,
|
|
898
|
-
/**
|
|
899
|
-
* An optional name of the logger issuing this message.
|
|
900
|
-
*/
|
|
901
|
-
logger: z.optional(z.string()),
|
|
902
|
-
/**
|
|
903
|
-
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
904
|
-
*/
|
|
905
|
-
data: z.unknown()
|
|
906
|
-
})
|
|
907
|
-
});
|
|
908
|
-
var ModelHintSchema = z.object({
|
|
909
|
-
/**
|
|
910
|
-
* A hint for a model name.
|
|
911
|
-
*/
|
|
912
|
-
name: z.string().optional()
|
|
913
|
-
}).passthrough();
|
|
914
|
-
var ModelPreferencesSchema = z.object({
|
|
915
|
-
/**
|
|
916
|
-
* Optional hints to use for model selection.
|
|
917
|
-
*/
|
|
918
|
-
hints: z.optional(z.array(ModelHintSchema)),
|
|
919
|
-
/**
|
|
920
|
-
* How much to prioritize cost when selecting a model.
|
|
921
|
-
*/
|
|
922
|
-
costPriority: z.optional(z.number().min(0).max(1)),
|
|
923
|
-
/**
|
|
924
|
-
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
925
|
-
*/
|
|
926
|
-
speedPriority: z.optional(z.number().min(0).max(1)),
|
|
927
|
-
/**
|
|
928
|
-
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
929
|
-
*/
|
|
930
|
-
intelligencePriority: z.optional(z.number().min(0).max(1))
|
|
931
|
-
}).passthrough();
|
|
932
|
-
var SamplingMessageSchema = z.object({
|
|
933
|
-
role: z.enum(["user", "assistant"]),
|
|
934
|
-
content: z.union([TextContentSchema, ImageContentSchema])
|
|
935
|
-
}).passthrough();
|
|
936
|
-
var CreateMessageRequestSchema = RequestSchema.extend({
|
|
937
|
-
method: z.literal("sampling/createMessage"),
|
|
938
|
-
params: BaseRequestParamsSchema.extend({
|
|
939
|
-
messages: z.array(SamplingMessageSchema),
|
|
940
|
-
/**
|
|
941
|
-
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
942
|
-
*/
|
|
943
|
-
systemPrompt: z.optional(z.string()),
|
|
944
|
-
/**
|
|
945
|
-
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
|
|
946
|
-
*/
|
|
947
|
-
includeContext: z.optional(z.enum(["none", "thisServer", "allServers"])),
|
|
948
|
-
temperature: z.optional(z.number()),
|
|
949
|
-
/**
|
|
950
|
-
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
|
|
951
|
-
*/
|
|
952
|
-
maxTokens: z.number().int(),
|
|
953
|
-
stopSequences: z.optional(z.array(z.string())),
|
|
954
|
-
/**
|
|
955
|
-
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
956
|
-
*/
|
|
957
|
-
metadata: z.optional(z.object({}).passthrough()),
|
|
958
|
-
/**
|
|
959
|
-
* The server's preferences for which model to select.
|
|
960
|
-
*/
|
|
961
|
-
modelPreferences: z.optional(ModelPreferencesSchema)
|
|
962
|
-
})
|
|
963
|
-
});
|
|
964
|
-
var CreateMessageResultSchema = ResultSchema.extend({
|
|
965
|
-
/**
|
|
966
|
-
* The name of the model that generated the message.
|
|
967
|
-
*/
|
|
968
|
-
model: z.string(),
|
|
969
|
-
/**
|
|
970
|
-
* The reason why sampling stopped.
|
|
971
|
-
*/
|
|
972
|
-
stopReason: z.optional(z.enum(["endTurn", "stopSequence", "maxTokens"]).or(z.string())),
|
|
973
|
-
role: z.enum(["user", "assistant"]),
|
|
974
|
-
content: z.discriminatedUnion("type", [
|
|
975
|
-
TextContentSchema,
|
|
976
|
-
ImageContentSchema
|
|
977
|
-
])
|
|
978
|
-
});
|
|
979
|
-
var ResourceReferenceSchema = z.object({
|
|
980
|
-
type: z.literal("ref/resource"),
|
|
981
|
-
/**
|
|
982
|
-
* The URI or URI template of the resource.
|
|
983
|
-
*/
|
|
984
|
-
uri: z.string()
|
|
985
|
-
}).passthrough();
|
|
986
|
-
var PromptReferenceSchema = z.object({
|
|
987
|
-
type: z.literal("ref/prompt"),
|
|
988
|
-
/**
|
|
989
|
-
* The name of the prompt or prompt template
|
|
990
|
-
*/
|
|
991
|
-
name: z.string()
|
|
992
|
-
}).passthrough();
|
|
993
|
-
var CompleteRequestSchema = RequestSchema.extend({
|
|
994
|
-
method: z.literal("completion/complete"),
|
|
995
|
-
params: BaseRequestParamsSchema.extend({
|
|
996
|
-
ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),
|
|
997
|
-
/**
|
|
998
|
-
* The argument's information
|
|
999
|
-
*/
|
|
1000
|
-
argument: z.object({
|
|
1001
|
-
/**
|
|
1002
|
-
* The name of the argument
|
|
1003
|
-
*/
|
|
1004
|
-
name: z.string(),
|
|
1005
|
-
/**
|
|
1006
|
-
* The value of the argument to use for completion matching.
|
|
1007
|
-
*/
|
|
1008
|
-
value: z.string()
|
|
1009
|
-
}).passthrough()
|
|
1010
|
-
})
|
|
1011
|
-
});
|
|
1012
|
-
var CompleteResultSchema = ResultSchema.extend({
|
|
1013
|
-
completion: z.object({
|
|
1014
|
-
/**
|
|
1015
|
-
* An array of completion values. Must not exceed 100 items.
|
|
1016
|
-
*/
|
|
1017
|
-
values: z.array(z.string()).max(100),
|
|
1018
|
-
/**
|
|
1019
|
-
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
1020
|
-
*/
|
|
1021
|
-
total: z.optional(z.number().int()),
|
|
1022
|
-
/**
|
|
1023
|
-
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
1024
|
-
*/
|
|
1025
|
-
hasMore: z.optional(z.boolean())
|
|
1026
|
-
}).passthrough()
|
|
1027
|
-
});
|
|
1028
|
-
var RootSchema = z.object({
|
|
1029
|
-
/**
|
|
1030
|
-
* The URI identifying the root. This *must* start with file:// for now.
|
|
1031
|
-
*/
|
|
1032
|
-
uri: z.string().startsWith("file://"),
|
|
1033
|
-
/**
|
|
1034
|
-
* An optional name for the root.
|
|
1035
|
-
*/
|
|
1036
|
-
name: z.optional(z.string())
|
|
1037
|
-
}).passthrough();
|
|
1038
|
-
var ListRootsRequestSchema = RequestSchema.extend({
|
|
1039
|
-
method: z.literal("roots/list")
|
|
1040
|
-
});
|
|
1041
|
-
var ListRootsResultSchema = ResultSchema.extend({
|
|
1042
|
-
roots: z.array(RootSchema)
|
|
1043
|
-
});
|
|
1044
|
-
var RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
1045
|
-
method: z.literal("notifications/roots/list_changed")
|
|
1046
|
-
});
|
|
1047
|
-
var ClientRequestSchema = z.union([
|
|
1048
|
-
PingRequestSchema,
|
|
1049
|
-
InitializeRequestSchema,
|
|
1050
|
-
CompleteRequestSchema,
|
|
1051
|
-
SetLevelRequestSchema,
|
|
1052
|
-
GetPromptRequestSchema,
|
|
1053
|
-
ListPromptsRequestSchema,
|
|
1054
|
-
ListResourcesRequestSchema,
|
|
1055
|
-
ListResourceTemplatesRequestSchema,
|
|
1056
|
-
ReadResourceRequestSchema,
|
|
1057
|
-
SubscribeRequestSchema,
|
|
1058
|
-
UnsubscribeRequestSchema,
|
|
1059
|
-
CallToolRequestSchema,
|
|
1060
|
-
ListToolsRequestSchema
|
|
1061
|
-
]);
|
|
1062
|
-
var ClientNotificationSchema = z.union([
|
|
1063
|
-
CancelledNotificationSchema,
|
|
1064
|
-
ProgressNotificationSchema,
|
|
1065
|
-
InitializedNotificationSchema,
|
|
1066
|
-
RootsListChangedNotificationSchema
|
|
1067
|
-
]);
|
|
1068
|
-
var ClientResultSchema = z.union([
|
|
1069
|
-
EmptyResultSchema,
|
|
1070
|
-
CreateMessageResultSchema,
|
|
1071
|
-
ListRootsResultSchema
|
|
1072
|
-
]);
|
|
1073
|
-
var ServerRequestSchema = z.union([
|
|
1074
|
-
PingRequestSchema,
|
|
1075
|
-
CreateMessageRequestSchema,
|
|
1076
|
-
ListRootsRequestSchema
|
|
1077
|
-
]);
|
|
1078
|
-
var ServerNotificationSchema = z.union([
|
|
1079
|
-
CancelledNotificationSchema,
|
|
1080
|
-
ProgressNotificationSchema,
|
|
1081
|
-
LoggingMessageNotificationSchema,
|
|
1082
|
-
ResourceUpdatedNotificationSchema,
|
|
1083
|
-
ResourceListChangedNotificationSchema,
|
|
1084
|
-
ToolListChangedNotificationSchema,
|
|
1085
|
-
PromptListChangedNotificationSchema
|
|
1086
|
-
]);
|
|
1087
|
-
var ServerResultSchema = z.union([
|
|
1088
|
-
EmptyResultSchema,
|
|
1089
|
-
InitializeResultSchema,
|
|
1090
|
-
CompleteResultSchema,
|
|
1091
|
-
GetPromptResultSchema,
|
|
1092
|
-
ListPromptsResultSchema,
|
|
1093
|
-
ListResourcesResultSchema,
|
|
1094
|
-
ListResourceTemplatesResultSchema,
|
|
1095
|
-
ReadResourceResultSchema,
|
|
1096
|
-
CallToolResultSchema,
|
|
1097
|
-
ListToolsResultSchema
|
|
1098
|
-
]);
|
|
1099
|
-
var McpError = class extends Error {
|
|
1100
|
-
constructor(code, message, data) {
|
|
1101
|
-
super(`MCP error ${code}: ${message}`);
|
|
1102
|
-
this.code = code;
|
|
1103
|
-
this.data = data;
|
|
1104
|
-
this.name = "McpError";
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
|
|
1108
|
-
// ../../node_modules/pkce-challenge/dist/index.node.js
|
|
1109
|
-
var crypto;
|
|
1110
|
-
crypto = globalThis.crypto?.webcrypto ?? // Node.js 16 REPL has globalThis.crypto as node:crypto
|
|
1111
|
-
globalThis.crypto ?? // Node.js 18+
|
|
1112
|
-
(await import("node:crypto")).webcrypto;
|
|
1113
|
-
function getRandomValues(size) {
|
|
1114
|
-
return crypto.getRandomValues(new Uint8Array(size));
|
|
1115
|
-
}
|
|
1116
|
-
function random(size) {
|
|
1117
|
-
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
1118
|
-
let result = "";
|
|
1119
|
-
const randomUints = getRandomValues(size);
|
|
1120
|
-
for (let i = 0; i < size; i++) {
|
|
1121
|
-
const randomIndex = randomUints[i] % mask.length;
|
|
1122
|
-
result += mask[randomIndex];
|
|
1123
|
-
}
|
|
1124
|
-
return result;
|
|
1125
|
-
}
|
|
1126
|
-
function generateVerifier(length) {
|
|
1127
|
-
return random(length);
|
|
1128
|
-
}
|
|
1129
|
-
async function generateChallenge(code_verifier) {
|
|
1130
|
-
const buffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
1131
|
-
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
1132
|
-
}
|
|
1133
|
-
async function pkceChallenge(length) {
|
|
1134
|
-
if (!length)
|
|
1135
|
-
length = 43;
|
|
1136
|
-
if (length < 43 || length > 128) {
|
|
1137
|
-
throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
1138
|
-
}
|
|
1139
|
-
const verifier = generateVerifier(length);
|
|
1140
|
-
const challenge = await generateChallenge(verifier);
|
|
1141
|
-
return {
|
|
1142
|
-
code_verifier: verifier,
|
|
1143
|
-
code_challenge: challenge
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
|
|
1148
|
-
import { z as z2 } from "zod";
|
|
1149
|
-
var OAuthMetadataSchema = z2.object({
|
|
1150
|
-
issuer: z2.string(),
|
|
1151
|
-
authorization_endpoint: z2.string(),
|
|
1152
|
-
token_endpoint: z2.string(),
|
|
1153
|
-
registration_endpoint: z2.string().optional(),
|
|
1154
|
-
scopes_supported: z2.array(z2.string()).optional(),
|
|
1155
|
-
response_types_supported: z2.array(z2.string()),
|
|
1156
|
-
response_modes_supported: z2.array(z2.string()).optional(),
|
|
1157
|
-
grant_types_supported: z2.array(z2.string()).optional(),
|
|
1158
|
-
token_endpoint_auth_methods_supported: z2.array(z2.string()).optional(),
|
|
1159
|
-
token_endpoint_auth_signing_alg_values_supported: z2.array(z2.string()).optional(),
|
|
1160
|
-
service_documentation: z2.string().optional(),
|
|
1161
|
-
revocation_endpoint: z2.string().optional(),
|
|
1162
|
-
revocation_endpoint_auth_methods_supported: z2.array(z2.string()).optional(),
|
|
1163
|
-
revocation_endpoint_auth_signing_alg_values_supported: z2.array(z2.string()).optional(),
|
|
1164
|
-
introspection_endpoint: z2.string().optional(),
|
|
1165
|
-
introspection_endpoint_auth_methods_supported: z2.array(z2.string()).optional(),
|
|
1166
|
-
introspection_endpoint_auth_signing_alg_values_supported: z2.array(z2.string()).optional(),
|
|
1167
|
-
code_challenge_methods_supported: z2.array(z2.string()).optional()
|
|
1168
|
-
}).passthrough();
|
|
1169
|
-
var OAuthTokensSchema = z2.object({
|
|
1170
|
-
access_token: z2.string(),
|
|
1171
|
-
token_type: z2.string(),
|
|
1172
|
-
expires_in: z2.number().optional(),
|
|
1173
|
-
scope: z2.string().optional(),
|
|
1174
|
-
refresh_token: z2.string().optional()
|
|
1175
|
-
}).strip();
|
|
1176
|
-
var OAuthErrorResponseSchema = z2.object({
|
|
1177
|
-
error: z2.string(),
|
|
1178
|
-
error_description: z2.string().optional(),
|
|
1179
|
-
error_uri: z2.string().optional()
|
|
1180
|
-
});
|
|
1181
|
-
var OAuthClientMetadataSchema = z2.object({
|
|
1182
|
-
redirect_uris: z2.array(z2.string()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: "redirect_uris must contain valid URLs" }),
|
|
1183
|
-
token_endpoint_auth_method: z2.string().optional(),
|
|
1184
|
-
grant_types: z2.array(z2.string()).optional(),
|
|
1185
|
-
response_types: z2.array(z2.string()).optional(),
|
|
1186
|
-
client_name: z2.string().optional(),
|
|
1187
|
-
client_uri: z2.string().optional(),
|
|
1188
|
-
logo_uri: z2.string().optional(),
|
|
1189
|
-
scope: z2.string().optional(),
|
|
1190
|
-
contacts: z2.array(z2.string()).optional(),
|
|
1191
|
-
tos_uri: z2.string().optional(),
|
|
1192
|
-
policy_uri: z2.string().optional(),
|
|
1193
|
-
jwks_uri: z2.string().optional(),
|
|
1194
|
-
jwks: z2.any().optional(),
|
|
1195
|
-
software_id: z2.string().optional(),
|
|
1196
|
-
software_version: z2.string().optional()
|
|
1197
|
-
}).strip();
|
|
1198
|
-
var OAuthClientInformationSchema = z2.object({
|
|
1199
|
-
client_id: z2.string(),
|
|
1200
|
-
client_secret: z2.string().optional(),
|
|
1201
|
-
client_id_issued_at: z2.number().optional(),
|
|
1202
|
-
client_secret_expires_at: z2.number().optional()
|
|
1203
|
-
}).strip();
|
|
1204
|
-
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
1205
|
-
var OAuthClientRegistrationErrorSchema = z2.object({
|
|
1206
|
-
error: z2.string(),
|
|
1207
|
-
error_description: z2.string().optional()
|
|
1208
|
-
}).strip();
|
|
1209
|
-
var OAuthTokenRevocationRequestSchema = z2.object({
|
|
1210
|
-
token: z2.string(),
|
|
1211
|
-
token_type_hint: z2.string().optional()
|
|
1212
|
-
}).strip();
|
|
1213
|
-
|
|
1214
|
-
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
|
|
1215
|
-
var UnauthorizedError = class extends Error {
|
|
1216
|
-
constructor(message) {
|
|
1217
|
-
super(message !== null && message !== void 0 ? message : "Unauthorized");
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
async function auth(provider, { serverUrl, authorizationCode }) {
|
|
1221
|
-
const metadata = await discoverOAuthMetadata(serverUrl);
|
|
1222
|
-
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
1223
|
-
if (!clientInformation) {
|
|
1224
|
-
if (authorizationCode !== void 0) {
|
|
1225
|
-
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
1226
|
-
}
|
|
1227
|
-
if (!provider.saveClientInformation) {
|
|
1228
|
-
throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
1229
|
-
}
|
|
1230
|
-
const fullInformation = await registerClient(serverUrl, {
|
|
1231
|
-
metadata,
|
|
1232
|
-
clientMetadata: provider.clientMetadata
|
|
1233
|
-
});
|
|
1234
|
-
await provider.saveClientInformation(fullInformation);
|
|
1235
|
-
clientInformation = fullInformation;
|
|
1236
|
-
}
|
|
1237
|
-
if (authorizationCode !== void 0) {
|
|
1238
|
-
const codeVerifier2 = await provider.codeVerifier();
|
|
1239
|
-
const tokens2 = await exchangeAuthorization(serverUrl, {
|
|
1240
|
-
metadata,
|
|
1241
|
-
clientInformation,
|
|
1242
|
-
authorizationCode,
|
|
1243
|
-
codeVerifier: codeVerifier2
|
|
1244
|
-
});
|
|
1245
|
-
await provider.saveTokens(tokens2);
|
|
1246
|
-
return "AUTHORIZED";
|
|
1247
|
-
}
|
|
1248
|
-
const tokens = await provider.tokens();
|
|
1249
|
-
if (tokens === null || tokens === void 0 ? void 0 : tokens.refresh_token) {
|
|
1250
|
-
try {
|
|
1251
|
-
const newTokens = await refreshAuthorization(serverUrl, {
|
|
1252
|
-
metadata,
|
|
1253
|
-
clientInformation,
|
|
1254
|
-
refreshToken: tokens.refresh_token
|
|
1255
|
-
});
|
|
1256
|
-
await provider.saveTokens(newTokens);
|
|
1257
|
-
return "AUTHORIZED";
|
|
1258
|
-
} catch (error) {
|
|
1259
|
-
console.error("Could not refresh OAuth tokens:", error);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
const { authorizationUrl, codeVerifier } = await startAuthorization(serverUrl, {
|
|
1263
|
-
metadata,
|
|
1264
|
-
clientInformation,
|
|
1265
|
-
redirectUrl: provider.redirectUrl
|
|
1266
|
-
});
|
|
1267
|
-
await provider.saveCodeVerifier(codeVerifier);
|
|
1268
|
-
await provider.redirectToAuthorization(authorizationUrl);
|
|
1269
|
-
return "REDIRECT";
|
|
1270
|
-
}
|
|
1271
|
-
async function discoverOAuthMetadata(serverUrl, opts) {
|
|
1272
|
-
var _a;
|
|
1273
|
-
const url = new URL("/.well-known/oauth-authorization-server", serverUrl);
|
|
1274
|
-
let response;
|
|
1275
|
-
try {
|
|
1276
|
-
response = await fetch(url, {
|
|
1277
|
-
headers: {
|
|
1278
|
-
"MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
} catch (error) {
|
|
1282
|
-
if (error instanceof TypeError) {
|
|
1283
|
-
response = await fetch(url);
|
|
1284
|
-
} else {
|
|
1285
|
-
throw error;
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
if (response.status === 404) {
|
|
1289
|
-
return void 0;
|
|
1290
|
-
}
|
|
1291
|
-
if (!response.ok) {
|
|
1292
|
-
throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
|
|
1293
|
-
}
|
|
1294
|
-
return OAuthMetadataSchema.parse(await response.json());
|
|
1295
|
-
}
|
|
1296
|
-
async function startAuthorization(serverUrl, { metadata, clientInformation, redirectUrl }) {
|
|
1297
|
-
const responseType = "code";
|
|
1298
|
-
const codeChallengeMethod = "S256";
|
|
1299
|
-
let authorizationUrl;
|
|
1300
|
-
if (metadata) {
|
|
1301
|
-
authorizationUrl = new URL(metadata.authorization_endpoint);
|
|
1302
|
-
if (!metadata.response_types_supported.includes(responseType)) {
|
|
1303
|
-
throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
|
|
1304
|
-
}
|
|
1305
|
-
if (!metadata.code_challenge_methods_supported || !metadata.code_challenge_methods_supported.includes(codeChallengeMethod)) {
|
|
1306
|
-
throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
|
|
1307
|
-
}
|
|
1308
|
-
} else {
|
|
1309
|
-
authorizationUrl = new URL("/authorize", serverUrl);
|
|
1310
|
-
}
|
|
1311
|
-
const challenge = await pkceChallenge();
|
|
1312
|
-
const codeVerifier = challenge.code_verifier;
|
|
1313
|
-
const codeChallenge = challenge.code_challenge;
|
|
1314
|
-
authorizationUrl.searchParams.set("response_type", responseType);
|
|
1315
|
-
authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
|
|
1316
|
-
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
1317
|
-
authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
|
|
1318
|
-
authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
|
|
1319
|
-
return { authorizationUrl, codeVerifier };
|
|
1320
|
-
}
|
|
1321
|
-
async function exchangeAuthorization(serverUrl, { metadata, clientInformation, authorizationCode, codeVerifier }) {
|
|
1322
|
-
const grantType = "authorization_code";
|
|
1323
|
-
let tokenUrl;
|
|
1324
|
-
if (metadata) {
|
|
1325
|
-
tokenUrl = new URL(metadata.token_endpoint);
|
|
1326
|
-
if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
|
|
1327
|
-
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
1328
|
-
}
|
|
1329
|
-
} else {
|
|
1330
|
-
tokenUrl = new URL("/token", serverUrl);
|
|
1331
|
-
}
|
|
1332
|
-
const params = new URLSearchParams({
|
|
1333
|
-
grant_type: grantType,
|
|
1334
|
-
client_id: clientInformation.client_id,
|
|
1335
|
-
code: authorizationCode,
|
|
1336
|
-
code_verifier: codeVerifier
|
|
1337
|
-
});
|
|
1338
|
-
if (clientInformation.client_secret) {
|
|
1339
|
-
params.set("client_secret", clientInformation.client_secret);
|
|
1340
|
-
}
|
|
1341
|
-
const response = await fetch(tokenUrl, {
|
|
1342
|
-
method: "POST",
|
|
1343
|
-
headers: {
|
|
1344
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
1345
|
-
},
|
|
1346
|
-
body: params
|
|
1347
|
-
});
|
|
1348
|
-
if (!response.ok) {
|
|
1349
|
-
throw new Error(`Token exchange failed: HTTP ${response.status}`);
|
|
1350
|
-
}
|
|
1351
|
-
return OAuthTokensSchema.parse(await response.json());
|
|
1352
|
-
}
|
|
1353
|
-
async function refreshAuthorization(serverUrl, { metadata, clientInformation, refreshToken }) {
|
|
1354
|
-
const grantType = "refresh_token";
|
|
1355
|
-
let tokenUrl;
|
|
1356
|
-
if (metadata) {
|
|
1357
|
-
tokenUrl = new URL(metadata.token_endpoint);
|
|
1358
|
-
if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
|
|
1359
|
-
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
1360
|
-
}
|
|
1361
|
-
} else {
|
|
1362
|
-
tokenUrl = new URL("/token", serverUrl);
|
|
1363
|
-
}
|
|
1364
|
-
const params = new URLSearchParams({
|
|
1365
|
-
grant_type: grantType,
|
|
1366
|
-
client_id: clientInformation.client_id,
|
|
1367
|
-
refresh_token: refreshToken
|
|
1368
|
-
});
|
|
1369
|
-
if (clientInformation.client_secret) {
|
|
1370
|
-
params.set("client_secret", clientInformation.client_secret);
|
|
1371
|
-
}
|
|
1372
|
-
const response = await fetch(tokenUrl, {
|
|
1373
|
-
method: "POST",
|
|
1374
|
-
headers: {
|
|
1375
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
1376
|
-
},
|
|
1377
|
-
body: params
|
|
1378
|
-
});
|
|
1379
|
-
if (!response.ok) {
|
|
1380
|
-
throw new Error(`Token refresh failed: HTTP ${response.status}`);
|
|
1381
|
-
}
|
|
1382
|
-
return OAuthTokensSchema.parse(await response.json());
|
|
1383
|
-
}
|
|
1384
|
-
async function registerClient(serverUrl, { metadata, clientMetadata }) {
|
|
1385
|
-
let registrationUrl;
|
|
1386
|
-
if (metadata) {
|
|
1387
|
-
if (!metadata.registration_endpoint) {
|
|
1388
|
-
throw new Error("Incompatible auth server: does not support dynamic client registration");
|
|
1389
|
-
}
|
|
1390
|
-
registrationUrl = new URL(metadata.registration_endpoint);
|
|
1391
|
-
} else {
|
|
1392
|
-
registrationUrl = new URL("/register", serverUrl);
|
|
1393
|
-
}
|
|
1394
|
-
const response = await fetch(registrationUrl, {
|
|
1395
|
-
method: "POST",
|
|
1396
|
-
headers: {
|
|
1397
|
-
"Content-Type": "application/json"
|
|
1398
|
-
},
|
|
1399
|
-
body: JSON.stringify(clientMetadata)
|
|
1400
|
-
});
|
|
1401
|
-
if (!response.ok) {
|
|
1402
|
-
throw new Error(`Dynamic client registration failed: HTTP ${response.status}`);
|
|
1403
|
-
}
|
|
1404
|
-
return OAuthClientInformationFullSchema.parse(await response.json());
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
1408
|
-
var SseError = class extends Error {
|
|
1409
|
-
constructor(code, message, event) {
|
|
1410
|
-
super(`SSE error: ${message}`);
|
|
1411
|
-
this.code = code;
|
|
1412
|
-
this.event = event;
|
|
1413
|
-
}
|
|
1414
|
-
};
|
|
1415
|
-
var SSEClientTransport = class {
|
|
1416
|
-
constructor(url, opts) {
|
|
1417
|
-
this._url = url;
|
|
1418
|
-
this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit;
|
|
1419
|
-
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
1420
|
-
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
1421
|
-
}
|
|
1422
|
-
async _authThenStart() {
|
|
1423
|
-
var _a;
|
|
1424
|
-
if (!this._authProvider) {
|
|
1425
|
-
throw new UnauthorizedError("No auth provider");
|
|
1426
|
-
}
|
|
1427
|
-
let result;
|
|
1428
|
-
try {
|
|
1429
|
-
result = await auth(this._authProvider, { serverUrl: this._url });
|
|
1430
|
-
} catch (error) {
|
|
1431
|
-
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
1432
|
-
throw error;
|
|
1433
|
-
}
|
|
1434
|
-
if (result !== "AUTHORIZED") {
|
|
1435
|
-
throw new UnauthorizedError();
|
|
1436
|
-
}
|
|
1437
|
-
return await this._startOrAuth();
|
|
1438
|
-
}
|
|
1439
|
-
async _commonHeaders() {
|
|
1440
|
-
const headers = {};
|
|
1441
|
-
if (this._authProvider) {
|
|
1442
|
-
const tokens = await this._authProvider.tokens();
|
|
1443
|
-
if (tokens) {
|
|
1444
|
-
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
return headers;
|
|
1448
|
-
}
|
|
1449
|
-
_startOrAuth() {
|
|
1450
|
-
return new Promise((resolve, reject) => {
|
|
1451
|
-
var _a;
|
|
1452
|
-
this._eventSource = new EventSource(this._url.href, (_a = this._eventSourceInit) !== null && _a !== void 0 ? _a : {
|
|
1453
|
-
fetch: (url, init) => this._commonHeaders().then((headers) => fetch(url, {
|
|
1454
|
-
...init,
|
|
1455
|
-
headers: {
|
|
1456
|
-
...headers,
|
|
1457
|
-
Accept: "text/event-stream"
|
|
1458
|
-
}
|
|
1459
|
-
}))
|
|
1460
|
-
});
|
|
1461
|
-
this._abortController = new AbortController();
|
|
1462
|
-
this._eventSource.onerror = (event) => {
|
|
1463
|
-
var _a2;
|
|
1464
|
-
if (event.code === 401 && this._authProvider) {
|
|
1465
|
-
this._authThenStart().then(resolve, reject);
|
|
1466
|
-
return;
|
|
1467
|
-
}
|
|
1468
|
-
const error = new SseError(event.code, event.message, event);
|
|
1469
|
-
reject(error);
|
|
1470
|
-
(_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error);
|
|
1471
|
-
};
|
|
1472
|
-
this._eventSource.onopen = () => {
|
|
1473
|
-
};
|
|
1474
|
-
this._eventSource.addEventListener("endpoint", (event) => {
|
|
1475
|
-
var _a2;
|
|
1476
|
-
const messageEvent = event;
|
|
1477
|
-
try {
|
|
1478
|
-
this._endpoint = new URL(messageEvent.data, this._url);
|
|
1479
|
-
if (this._endpoint.origin !== this._url.origin) {
|
|
1480
|
-
throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`);
|
|
1481
|
-
}
|
|
1482
|
-
} catch (error) {
|
|
1483
|
-
reject(error);
|
|
1484
|
-
(_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error);
|
|
1485
|
-
void this.close();
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
resolve();
|
|
1489
|
-
});
|
|
1490
|
-
this._eventSource.onmessage = (event) => {
|
|
1491
|
-
var _a2, _b;
|
|
1492
|
-
const messageEvent = event;
|
|
1493
|
-
let message;
|
|
1494
|
-
try {
|
|
1495
|
-
message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
|
|
1496
|
-
} catch (error) {
|
|
1497
|
-
(_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error);
|
|
1498
|
-
return;
|
|
1499
|
-
}
|
|
1500
|
-
(_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message);
|
|
1501
|
-
};
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
async start() {
|
|
1505
|
-
if (this._eventSource) {
|
|
1506
|
-
throw new Error("SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
1507
|
-
}
|
|
1508
|
-
return await this._startOrAuth();
|
|
1509
|
-
}
|
|
1510
|
-
/**
|
|
1511
|
-
* Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.
|
|
1512
|
-
*/
|
|
1513
|
-
async finishAuth(authorizationCode) {
|
|
1514
|
-
if (!this._authProvider) {
|
|
1515
|
-
throw new UnauthorizedError("No auth provider");
|
|
1516
|
-
}
|
|
1517
|
-
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode });
|
|
1518
|
-
if (result !== "AUTHORIZED") {
|
|
1519
|
-
throw new UnauthorizedError("Failed to authorize");
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
async close() {
|
|
1523
|
-
var _a, _b, _c;
|
|
1524
|
-
(_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1525
|
-
(_b = this._eventSource) === null || _b === void 0 ? void 0 : _b.close();
|
|
1526
|
-
(_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
1527
|
-
}
|
|
1528
|
-
async send(message) {
|
|
1529
|
-
var _a, _b, _c;
|
|
1530
|
-
if (!this._endpoint) {
|
|
1531
|
-
throw new Error("Not connected");
|
|
1532
|
-
}
|
|
1533
|
-
try {
|
|
1534
|
-
const commonHeaders = await this._commonHeaders();
|
|
1535
|
-
const headers = new Headers({ ...commonHeaders, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers });
|
|
1536
|
-
headers.set("content-type", "application/json");
|
|
1537
|
-
const init = {
|
|
1538
|
-
...this._requestInit,
|
|
1539
|
-
method: "POST",
|
|
1540
|
-
headers,
|
|
1541
|
-
body: JSON.stringify(message),
|
|
1542
|
-
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
|
|
1543
|
-
};
|
|
1544
|
-
const response = await fetch(this._endpoint, init);
|
|
1545
|
-
if (!response.ok) {
|
|
1546
|
-
if (response.status === 401 && this._authProvider) {
|
|
1547
|
-
const result = await auth(this._authProvider, { serverUrl: this._url });
|
|
1548
|
-
if (result !== "AUTHORIZED") {
|
|
1549
|
-
throw new UnauthorizedError();
|
|
1550
|
-
}
|
|
1551
|
-
return this.send(message);
|
|
1552
|
-
}
|
|
1553
|
-
const text = await response.text().catch(() => null);
|
|
1554
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
1555
|
-
}
|
|
1556
|
-
} catch (error) {
|
|
1557
|
-
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
1558
|
-
throw error;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
};
|
|
1562
|
-
|
|
1563
|
-
// src/mcp/sse-edge.ts
|
|
1564
|
-
var MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
1565
|
-
var SSEEdgeServerTransport = class {
|
|
1566
|
-
/**
|
|
1567
|
-
* Creates a new EdgeSSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
1568
|
-
*/
|
|
1569
|
-
constructor(messageUrl, sessionId) {
|
|
1570
|
-
this.messageUrl = messageUrl;
|
|
1571
|
-
this.sessionId = sessionId;
|
|
1572
|
-
this.stream = new ReadableStream({
|
|
1573
|
-
start: (controller) => {
|
|
1574
|
-
this.controller = controller;
|
|
1575
|
-
},
|
|
1576
|
-
cancel: () => {
|
|
1577
|
-
this.closed = true;
|
|
1578
|
-
this.onclose?.();
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
controller = null;
|
|
1583
|
-
stream;
|
|
1584
|
-
closed = false;
|
|
1585
|
-
onclose;
|
|
1586
|
-
onerror;
|
|
1587
|
-
onmessage;
|
|
1588
|
-
async start() {
|
|
1589
|
-
if (this.closed) {
|
|
1590
|
-
throw new Error(
|
|
1591
|
-
"SSE transport already closed! If using Server class, note that connect() calls start() automatically."
|
|
1592
|
-
);
|
|
1593
|
-
}
|
|
1594
|
-
if (!this.controller) {
|
|
1595
|
-
throw new Error("Stream controller not initialized");
|
|
1596
|
-
}
|
|
1597
|
-
const endpointMessage = `event: endpoint
|
|
1598
|
-
data: ${encodeURI(this.messageUrl)}?sessionId=${this.sessionId}
|
|
1599
|
-
|
|
1600
|
-
`;
|
|
1601
|
-
this.controller.enqueue(new TextEncoder().encode(endpointMessage));
|
|
1602
|
-
}
|
|
1603
|
-
get sseResponse() {
|
|
1604
|
-
if (!this.stream) {
|
|
1605
|
-
throw new Error("Stream not initialized");
|
|
1606
|
-
}
|
|
1607
|
-
return new Response(this.stream, {
|
|
1608
|
-
headers: {
|
|
1609
|
-
"Content-Type": "text/event-stream",
|
|
1610
|
-
"Cache-Control": "no-cache",
|
|
1611
|
-
Connection: "keep-alive"
|
|
1612
|
-
}
|
|
1613
|
-
});
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Handles incoming Requests
|
|
1617
|
-
*/
|
|
1618
|
-
async handlePostMessage(req) {
|
|
1619
|
-
if (this.closed || !this.controller) {
|
|
1620
|
-
const message = "SSE connection not established";
|
|
1621
|
-
return new Response(message, { status: 500 });
|
|
1622
|
-
}
|
|
1623
|
-
try {
|
|
1624
|
-
const contentType = req.headers.get("content-type") || "";
|
|
1625
|
-
if (!contentType.includes("application/json")) {
|
|
1626
|
-
throw new Error(`Unsupported content-type: ${contentType}`);
|
|
1627
|
-
}
|
|
1628
|
-
const contentLength = Number.parseInt(
|
|
1629
|
-
req.headers.get("content-length") || "0",
|
|
1630
|
-
10
|
|
1631
|
-
);
|
|
1632
|
-
if (contentLength > MAXIMUM_MESSAGE_SIZE) {
|
|
1633
|
-
throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
1634
|
-
}
|
|
1635
|
-
const body = await req.json();
|
|
1636
|
-
await this.handleMessage(body);
|
|
1637
|
-
return new Response("Accepted", { status: 202 });
|
|
1638
|
-
} catch (error) {
|
|
1639
|
-
this.onerror?.(error);
|
|
1640
|
-
return new Response(String(error), { status: 400 });
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
|
1645
|
-
*/
|
|
1646
|
-
async handleMessage(message) {
|
|
1647
|
-
let parsedMessage;
|
|
1648
|
-
try {
|
|
1649
|
-
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
1650
|
-
} catch (error) {
|
|
1651
|
-
this.onerror?.(error);
|
|
1652
|
-
throw error;
|
|
1653
|
-
}
|
|
1654
|
-
this.onmessage?.(parsedMessage);
|
|
1655
|
-
}
|
|
1656
|
-
async close() {
|
|
1657
|
-
if (!this.closed && this.controller) {
|
|
1658
|
-
this.controller.close();
|
|
1659
|
-
this.stream.cancel();
|
|
1660
|
-
this.closed = true;
|
|
1661
|
-
this.onclose?.();
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
async send(message) {
|
|
1665
|
-
if (this.closed || !this.controller) {
|
|
1666
|
-
throw new Error("Not connected");
|
|
1667
|
-
}
|
|
1668
|
-
const messageText = `event: message
|
|
1669
|
-
data: ${JSON.stringify(message)}
|
|
1670
|
-
|
|
1671
|
-
`;
|
|
1672
|
-
this.controller.enqueue(new TextEncoder().encode(messageText));
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1675
|
-
var SSEEdgeClientTransport = class extends SSEClientTransport {
|
|
1676
|
-
/**
|
|
1677
|
-
* Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
1678
|
-
*/
|
|
1679
|
-
constructor(url, options) {
|
|
1680
|
-
const fetchOverride = (url2, options2 = {}) => {
|
|
1681
|
-
const workerOptions = {
|
|
1682
|
-
...options2
|
|
1683
|
-
};
|
|
1684
|
-
delete workerOptions.mode;
|
|
1685
|
-
return global.fetch(url2, workerOptions);
|
|
1686
|
-
};
|
|
1687
|
-
super(url, {
|
|
1688
|
-
...options,
|
|
1689
|
-
eventSourceInit: {
|
|
1690
|
-
fetch: fetchOverride
|
|
1691
|
-
}
|
|
1692
|
-
});
|
|
1693
|
-
this.url = url;
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
export {
|
|
1698
|
-
LATEST_PROTOCOL_VERSION,
|
|
1699
|
-
SUPPORTED_PROTOCOL_VERSIONS,
|
|
1700
|
-
ErrorCode,
|
|
1701
|
-
EmptyResultSchema,
|
|
1702
|
-
CancelledNotificationSchema,
|
|
1703
|
-
InitializeResultSchema,
|
|
1704
|
-
PingRequestSchema,
|
|
1705
|
-
ProgressNotificationSchema,
|
|
1706
|
-
ListResourcesResultSchema,
|
|
1707
|
-
ListResourceTemplatesResultSchema,
|
|
1708
|
-
ReadResourceResultSchema,
|
|
1709
|
-
ResourceListChangedNotificationSchema,
|
|
1710
|
-
ListPromptsResultSchema,
|
|
1711
|
-
GetPromptResultSchema,
|
|
1712
|
-
PromptListChangedNotificationSchema,
|
|
1713
|
-
ListToolsResultSchema,
|
|
1714
|
-
CallToolResultSchema,
|
|
1715
|
-
ToolListChangedNotificationSchema,
|
|
1716
|
-
CompleteResultSchema,
|
|
1717
|
-
McpError,
|
|
1718
|
-
SSEEdgeServerTransport,
|
|
1719
|
-
SSEEdgeClientTransport
|
|
1720
|
-
};
|
|
1721
|
-
//# sourceMappingURL=chunk-EZ76ZGDB.js.map
|