@atxp/client 0.2.21 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ajv.js +8 -0
- package/dist/_virtual/ajv.js.map +1 -0
- package/dist/_virtual/cache.js +4 -0
- package/dist/_virtual/cache.js.map +1 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/uri.all.js +4 -0
- package/dist/_virtual/uri.all.js.map +1 -0
- package/dist/atxpAccount.js +4 -2
- package/dist/atxpAccount.js.map +1 -1
- package/dist/atxpClient.js +12 -10
- package/dist/atxpClient.js.map +1 -1
- package/dist/atxpFetcher.js +10 -8
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/baseAccount.js +5 -3
- package/dist/baseAccount.js.map +1 -1
- package/dist/baseConstants.js +4 -0
- package/dist/baseConstants.js.map +1 -0
- package/dist/basePaymentMaker.js +15 -12
- package/dist/basePaymentMaker.js.map +1 -1
- package/dist/index.cjs +15595 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +250 -10
- package/dist/index.js +15558 -10
- package/dist/index.js.map +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js +398 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js +273 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js +378 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js +46 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js +120 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js +380 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js +1254 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js.map +1 -0
- package/dist/node_modules/ajv/lib/ajv.js +531 -0
- package/dist/node_modules/ajv/lib/ajv.js.map +1 -0
- package/dist/node_modules/ajv/lib/cache.js +37 -0
- package/dist/node_modules/ajv/lib/cache.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/async.js +102 -0
- package/dist/node_modules/ajv/lib/compile/async.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/error_classes.js +46 -0
- package/dist/node_modules/ajv/lib/compile/error_classes.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/formats.js +154 -0
- package/dist/node_modules/ajv/lib/compile/formats.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/index.js +404 -0
- package/dist/node_modules/ajv/lib/compile/index.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/resolve.js +286 -0
- package/dist/node_modules/ajv/lib/compile/resolve.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/rules.js +79 -0
- package/dist/node_modules/ajv/lib/compile/rules.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/schema_obj.js +21 -0
- package/dist/node_modules/ajv/lib/compile/schema_obj.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/ucs2length.js +30 -0
- package/dist/node_modules/ajv/lib/compile/ucs2length.js.map +1 -0
- package/dist/node_modules/ajv/lib/compile/util.js +252 -0
- package/dist/node_modules/ajv/lib/compile/util.js.map +1 -0
- package/dist/node_modules/ajv/lib/data.js +59 -0
- package/dist/node_modules/ajv/lib/data.js.map +1 -0
- package/dist/node_modules/ajv/lib/definition_schema.js +49 -0
- package/dist/node_modules/ajv/lib/definition_schema.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/_limit.js +173 -0
- package/dist/node_modules/ajv/lib/dotjs/_limit.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitItems.js +90 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitItems.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitLength.js +95 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitLength.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js +90 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/allOf.js +52 -0
- package/dist/node_modules/ajv/lib/dotjs/allOf.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/anyOf.js +83 -0
- package/dist/node_modules/ajv/lib/dotjs/anyOf.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/comment.js +24 -0
- package/dist/node_modules/ajv/lib/dotjs/comment.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/const.js +62 -0
- package/dist/node_modules/ajv/lib/dotjs/const.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/contains.js +91 -0
- package/dist/node_modules/ajv/lib/dotjs/contains.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/custom.js +238 -0
- package/dist/node_modules/ajv/lib/dotjs/custom.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/dependencies.js +178 -0
- package/dist/node_modules/ajv/lib/dotjs/dependencies.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/enum.js +72 -0
- package/dist/node_modules/ajv/lib/dotjs/enum.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/format.js +160 -0
- package/dist/node_modules/ajv/lib/dotjs/format.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/if.js +113 -0
- package/dist/node_modules/ajv/lib/dotjs/if.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/index.js +68 -0
- package/dist/node_modules/ajv/lib/dotjs/index.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/items.js +150 -0
- package/dist/node_modules/ajv/lib/dotjs/items.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/multipleOf.js +90 -0
- package/dist/node_modules/ajv/lib/dotjs/multipleOf.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/not.js +94 -0
- package/dist/node_modules/ajv/lib/dotjs/not.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/oneOf.js +83 -0
- package/dist/node_modules/ajv/lib/dotjs/oneOf.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/pattern.js +85 -0
- package/dist/node_modules/ajv/lib/dotjs/pattern.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/properties.js +345 -0
- package/dist/node_modules/ajv/lib/dotjs/properties.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/propertyNames.js +91 -0
- package/dist/node_modules/ajv/lib/dotjs/propertyNames.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/ref.js +134 -0
- package/dist/node_modules/ajv/lib/dotjs/ref.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/required.js +276 -0
- package/dist/node_modules/ajv/lib/dotjs/required.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js +96 -0
- package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js.map +1 -0
- package/dist/node_modules/ajv/lib/dotjs/validate.js +492 -0
- package/dist/node_modules/ajv/lib/dotjs/validate.js.map +1 -0
- package/dist/node_modules/ajv/lib/keyword.js +159 -0
- package/dist/node_modules/ajv/lib/keyword.js.map +1 -0
- package/dist/node_modules/ajv/lib/refs/data.json.js +33 -0
- package/dist/node_modules/ajv/lib/refs/data.json.js.map +1 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json.js +254 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json.js.map +1 -0
- package/dist/node_modules/eventsource-parser/dist/index.js +104 -0
- package/dist/node_modules/eventsource-parser/dist/index.js.map +1 -0
- package/dist/node_modules/eventsource-parser/dist/stream.js +28 -0
- package/dist/node_modules/eventsource-parser/dist/stream.js.map +1 -0
- package/dist/node_modules/fast-deep-equal/index.js +56 -0
- package/dist/node_modules/fast-deep-equal/index.js.map +1 -0
- package/dist/node_modules/fast-json-stable-stringify/index.js +69 -0
- package/dist/node_modules/fast-json-stable-stringify/index.js.map +1 -0
- package/dist/node_modules/json-schema-traverse/index.js +100 -0
- package/dist/node_modules/json-schema-traverse/index.js.map +1 -0
- package/dist/node_modules/pkce-challenge/dist/index.browser.js +66 -0
- package/dist/node_modules/pkce-challenge/dist/index.browser.js.map +1 -0
- package/dist/node_modules/uri-js/dist/es5/uri.all.js +1418 -0
- package/dist/node_modules/uri-js/dist/es5/uri.all.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/ZodError.js +132 -0
- package/dist/node_modules/zod/dist/esm/v3/ZodError.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/errors.js +9 -0
- package/dist/node_modules/zod/dist/esm/v3/errors.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/errorUtil.js +9 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/errorUtil.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/parseUtil.js +112 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/parseUtil.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/util.js +136 -0
- package/dist/node_modules/zod/dist/esm/v3/helpers/util.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/locales/en.js +110 -0
- package/dist/node_modules/zod/dist/esm/v3/locales/en.js.map +1 -0
- package/dist/node_modules/zod/dist/esm/v3/types.js +3488 -0
- package/dist/node_modules/zod/dist/esm/v3/types.js.map +1 -0
- package/dist/oAuth.js +7 -6
- package/dist/oAuth.js.map +1 -1
- package/dist/solanaAccount.js +7 -4
- package/dist/solanaAccount.js.map +1 -1
- package/dist/solanaPaymentMaker.js +15 -12
- package/dist/solanaPaymentMaker.js.map +1 -1
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -1
- package/package.json +26 -10
- package/dist/atxpAccount.d.ts +0 -13
- package/dist/atxpAccount.d.ts.map +0 -1
- package/dist/atxpClient.d.ts +0 -14
- package/dist/atxpClient.d.ts.map +0 -1
- package/dist/atxpFetcher.d.ts +0 -72
- package/dist/atxpFetcher.d.ts.map +0 -1
- package/dist/baseAccount.d.ts +0 -10
- package/dist/baseAccount.d.ts.map +0 -1
- package/dist/basePaymentMaker.d.ts +0 -16
- package/dist/basePaymentMaker.d.ts.map +0 -1
- package/dist/clientTestHelpers.d.ts +0 -6
- package/dist/clientTestHelpers.d.ts.map +0 -1
- package/dist/clientTestHelpers.js +0 -94
- package/dist/clientTestHelpers.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/oAuth.d.ts +0 -44
- package/dist/oAuth.d.ts.map +0 -1
- package/dist/setup.expo.d.ts +0 -2
- package/dist/setup.expo.d.ts.map +0 -1
- package/dist/setup.expo.js +0 -30
- package/dist/setup.expo.js.map +0 -1
- package/dist/solanaAccount.d.ts +0 -9
- package/dist/solanaAccount.d.ts.map +0 -1
- package/dist/solanaPaymentMaker.d.ts +0 -18
- package/dist/solanaPaymentMaker.d.ts.map +0 -1
- package/dist/types.d.ts +0 -70
- package/dist/types.d.ts.map +0 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { isJSONRPCRequest, isInitializedNotification, JSONRPCMessageSchema, isJSONRPCResponse } from '../types.js';
|
|
2
|
+
import { UnauthorizedError, auth, extractResourceMetadataUrl } from './auth.js';
|
|
3
|
+
import { EventSourceParserStream } from '../../../../../eventsource-parser/dist/stream.js';
|
|
4
|
+
|
|
5
|
+
// Default reconnection options for StreamableHTTP connections
|
|
6
|
+
const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
|
|
7
|
+
initialReconnectionDelay: 1000,
|
|
8
|
+
maxReconnectionDelay: 30000,
|
|
9
|
+
reconnectionDelayGrowFactor: 1.5,
|
|
10
|
+
maxRetries: 2,
|
|
11
|
+
};
|
|
12
|
+
class StreamableHTTPError extends Error {
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(`Streamable HTTP error: ${message}`);
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
|
|
20
|
+
* It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events
|
|
21
|
+
* for receiving messages.
|
|
22
|
+
*/
|
|
23
|
+
class StreamableHTTPClientTransport {
|
|
24
|
+
constructor(url, opts) {
|
|
25
|
+
var _a;
|
|
26
|
+
this._url = url;
|
|
27
|
+
this._resourceMetadataUrl = undefined;
|
|
28
|
+
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
29
|
+
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
30
|
+
this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
|
|
31
|
+
this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId;
|
|
32
|
+
this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
33
|
+
}
|
|
34
|
+
async _authThenStart() {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!this._authProvider) {
|
|
37
|
+
throw new UnauthorizedError("No auth provider");
|
|
38
|
+
}
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
if (result !== "AUTHORIZED") {
|
|
48
|
+
throw new UnauthorizedError();
|
|
49
|
+
}
|
|
50
|
+
return await this._startOrAuthSse({ resumptionToken: undefined });
|
|
51
|
+
}
|
|
52
|
+
async _commonHeaders() {
|
|
53
|
+
var _a;
|
|
54
|
+
const headers = {};
|
|
55
|
+
if (this._authProvider) {
|
|
56
|
+
const tokens = await this._authProvider.tokens();
|
|
57
|
+
if (tokens) {
|
|
58
|
+
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (this._sessionId) {
|
|
62
|
+
headers["mcp-session-id"] = this._sessionId;
|
|
63
|
+
}
|
|
64
|
+
if (this._protocolVersion) {
|
|
65
|
+
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
66
|
+
}
|
|
67
|
+
const extraHeaders = this._normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers);
|
|
68
|
+
return new Headers({
|
|
69
|
+
...headers,
|
|
70
|
+
...extraHeaders,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async _startOrAuthSse(options) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const { resumptionToken } = options;
|
|
76
|
+
try {
|
|
77
|
+
// Try to open an initial SSE stream with GET to listen for server messages
|
|
78
|
+
// This is optional according to the spec - server may not support it
|
|
79
|
+
const headers = await this._commonHeaders();
|
|
80
|
+
headers.set("Accept", "text/event-stream");
|
|
81
|
+
// Include Last-Event-ID header for resumable streams if provided
|
|
82
|
+
if (resumptionToken) {
|
|
83
|
+
headers.set("last-event-id", resumptionToken);
|
|
84
|
+
}
|
|
85
|
+
const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, {
|
|
86
|
+
method: "GET",
|
|
87
|
+
headers,
|
|
88
|
+
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal,
|
|
89
|
+
});
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
if (response.status === 401 && this._authProvider) {
|
|
92
|
+
// Need to authenticate
|
|
93
|
+
return await this._authThenStart();
|
|
94
|
+
}
|
|
95
|
+
// 405 indicates that the server does not offer an SSE stream at GET endpoint
|
|
96
|
+
// This is an expected case that should not trigger an error
|
|
97
|
+
if (response.status === 405) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
|
|
101
|
+
}
|
|
102
|
+
this._handleSseStream(response.body, options);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Calculates the next reconnection delay using backoff algorithm
|
|
111
|
+
*
|
|
112
|
+
* @param attempt Current reconnection attempt count for the specific stream
|
|
113
|
+
* @returns Time to wait in milliseconds before next reconnection attempt
|
|
114
|
+
*/
|
|
115
|
+
_getNextReconnectionDelay(attempt) {
|
|
116
|
+
// Access default values directly, ensuring they're never undefined
|
|
117
|
+
const initialDelay = this._reconnectionOptions.initialReconnectionDelay;
|
|
118
|
+
const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;
|
|
119
|
+
const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
|
|
120
|
+
// Cap at maximum delay
|
|
121
|
+
return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
|
|
122
|
+
}
|
|
123
|
+
_normalizeHeaders(headers) {
|
|
124
|
+
if (!headers)
|
|
125
|
+
return {};
|
|
126
|
+
if (headers instanceof Headers) {
|
|
127
|
+
return Object.fromEntries(headers.entries());
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(headers)) {
|
|
130
|
+
return Object.fromEntries(headers);
|
|
131
|
+
}
|
|
132
|
+
return { ...headers };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Schedule a reconnection attempt with exponential backoff
|
|
136
|
+
*
|
|
137
|
+
* @param lastEventId The ID of the last received event for resumability
|
|
138
|
+
* @param attemptCount Current reconnection attempt count for this specific stream
|
|
139
|
+
*/
|
|
140
|
+
_scheduleReconnection(options, attemptCount = 0) {
|
|
141
|
+
var _a;
|
|
142
|
+
// Use provided options or default options
|
|
143
|
+
const maxRetries = this._reconnectionOptions.maxRetries;
|
|
144
|
+
// Check if we've exceeded maximum retry attempts
|
|
145
|
+
if (maxRetries > 0 && attemptCount >= maxRetries) {
|
|
146
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Calculate next delay based on current attempt count
|
|
150
|
+
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
151
|
+
// Schedule the reconnection
|
|
152
|
+
setTimeout(() => {
|
|
153
|
+
// Use the last event ID to resume where we left off
|
|
154
|
+
this._startOrAuthSse(options).catch(error => {
|
|
155
|
+
var _a;
|
|
156
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
|
|
157
|
+
// Schedule another attempt if this one failed, incrementing the attempt counter
|
|
158
|
+
this._scheduleReconnection(options, attemptCount + 1);
|
|
159
|
+
});
|
|
160
|
+
}, delay);
|
|
161
|
+
}
|
|
162
|
+
_handleSseStream(stream, options) {
|
|
163
|
+
if (!stream) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const { onresumptiontoken, replayMessageId } = options;
|
|
167
|
+
let lastEventId;
|
|
168
|
+
const processStream = async () => {
|
|
169
|
+
var _a, _b, _c, _d;
|
|
170
|
+
// this is the closest we can get to trying to catch network errors
|
|
171
|
+
// if something happens reader will throw
|
|
172
|
+
try {
|
|
173
|
+
// Create a pipeline: binary stream -> text decoder -> SSE parser
|
|
174
|
+
const reader = stream
|
|
175
|
+
.pipeThrough(new TextDecoderStream())
|
|
176
|
+
.pipeThrough(new EventSourceParserStream())
|
|
177
|
+
.getReader();
|
|
178
|
+
while (true) {
|
|
179
|
+
const { value: event, done } = await reader.read();
|
|
180
|
+
if (done) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
// Update last event ID if provided
|
|
184
|
+
if (event.id) {
|
|
185
|
+
lastEventId = event.id;
|
|
186
|
+
onresumptiontoken === null || onresumptiontoken === void 0 ? void 0 : onresumptiontoken(event.id);
|
|
187
|
+
}
|
|
188
|
+
if (!event.event || event.event === "message") {
|
|
189
|
+
try {
|
|
190
|
+
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
|
|
191
|
+
if (replayMessageId !== undefined && isJSONRPCResponse(message)) {
|
|
192
|
+
message.id = replayMessageId;
|
|
193
|
+
}
|
|
194
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
(_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// Handle stream errors - likely a network disconnect
|
|
204
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`));
|
|
205
|
+
// Attempt to reconnect if the stream disconnects unexpectedly and we aren't closing
|
|
206
|
+
if (this._abortController && !this._abortController.signal.aborted) {
|
|
207
|
+
// Use the exponential backoff reconnection strategy
|
|
208
|
+
if (lastEventId !== undefined) {
|
|
209
|
+
try {
|
|
210
|
+
this._scheduleReconnection({
|
|
211
|
+
resumptionToken: lastEventId,
|
|
212
|
+
onresumptiontoken,
|
|
213
|
+
replayMessageId
|
|
214
|
+
}, 0);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
(_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error instanceof Error ? error.message : String(error)}`));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
processStream();
|
|
224
|
+
}
|
|
225
|
+
async start() {
|
|
226
|
+
if (this._abortController) {
|
|
227
|
+
throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
228
|
+
}
|
|
229
|
+
this._abortController = new AbortController();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 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.
|
|
233
|
+
*/
|
|
234
|
+
async finishAuth(authorizationCode) {
|
|
235
|
+
if (!this._authProvider) {
|
|
236
|
+
throw new UnauthorizedError("No auth provider");
|
|
237
|
+
}
|
|
238
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
239
|
+
if (result !== "AUTHORIZED") {
|
|
240
|
+
throw new UnauthorizedError("Failed to authorize");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async close() {
|
|
244
|
+
var _a, _b;
|
|
245
|
+
// Abort any pending requests
|
|
246
|
+
(_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
247
|
+
(_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
248
|
+
}
|
|
249
|
+
async send(message, options) {
|
|
250
|
+
var _a, _b, _c, _d;
|
|
251
|
+
try {
|
|
252
|
+
const { resumptionToken, onresumptiontoken } = options || {};
|
|
253
|
+
if (resumptionToken) {
|
|
254
|
+
// If we have at last event ID, we need to reconnect the SSE stream
|
|
255
|
+
this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const headers = await this._commonHeaders();
|
|
259
|
+
headers.set("content-type", "application/json");
|
|
260
|
+
headers.set("accept", "application/json, text/event-stream");
|
|
261
|
+
const init = {
|
|
262
|
+
...this._requestInit,
|
|
263
|
+
method: "POST",
|
|
264
|
+
headers,
|
|
265
|
+
body: JSON.stringify(message),
|
|
266
|
+
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal,
|
|
267
|
+
};
|
|
268
|
+
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
|
|
269
|
+
// Handle session ID received during initialization
|
|
270
|
+
const sessionId = response.headers.get("mcp-session-id");
|
|
271
|
+
if (sessionId) {
|
|
272
|
+
this._sessionId = sessionId;
|
|
273
|
+
}
|
|
274
|
+
if (!response.ok) {
|
|
275
|
+
if (response.status === 401 && this._authProvider) {
|
|
276
|
+
this._resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
277
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
278
|
+
if (result !== "AUTHORIZED") {
|
|
279
|
+
throw new UnauthorizedError();
|
|
280
|
+
}
|
|
281
|
+
// Purposely _not_ awaited, so we don't call onerror twice
|
|
282
|
+
return this.send(message);
|
|
283
|
+
}
|
|
284
|
+
const text = await response.text().catch(() => null);
|
|
285
|
+
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
286
|
+
}
|
|
287
|
+
// If the response is 202 Accepted, there's no body to process
|
|
288
|
+
if (response.status === 202) {
|
|
289
|
+
// if the accepted notification is initialized, we start the SSE stream
|
|
290
|
+
// if it's supported by the server
|
|
291
|
+
if (isInitializedNotification(message)) {
|
|
292
|
+
// Start without a lastEventId since this is a fresh connection
|
|
293
|
+
this._startOrAuthSse({ resumptionToken: undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); });
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// Get original message(s) for detecting request IDs
|
|
298
|
+
const messages = Array.isArray(message) ? message : [message];
|
|
299
|
+
const hasRequests = messages.filter(msg => "method" in msg && "id" in msg && msg.id !== undefined).length > 0;
|
|
300
|
+
// Check the response type
|
|
301
|
+
const contentType = response.headers.get("content-type");
|
|
302
|
+
if (hasRequests) {
|
|
303
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/event-stream")) {
|
|
304
|
+
// Handle SSE stream responses for requests
|
|
305
|
+
// We use the same handler as standalone streams, which now supports
|
|
306
|
+
// reconnection with the last event ID
|
|
307
|
+
this._handleSseStream(response.body, { onresumptiontoken });
|
|
308
|
+
}
|
|
309
|
+
else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) {
|
|
310
|
+
// For non-streaming servers, we might get direct JSON responses
|
|
311
|
+
const data = await response.json();
|
|
312
|
+
const responseMessages = Array.isArray(data)
|
|
313
|
+
? data.map(msg => JSONRPCMessageSchema.parse(msg))
|
|
314
|
+
: [JSONRPCMessageSchema.parse(data)];
|
|
315
|
+
for (const msg of responseMessages) {
|
|
316
|
+
(_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, msg);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
(_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error);
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
get sessionId() {
|
|
330
|
+
return this._sessionId;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Terminates the current session by sending a DELETE request to the server.
|
|
334
|
+
*
|
|
335
|
+
* Clients that no longer need a particular session
|
|
336
|
+
* (e.g., because the user is leaving the client application) SHOULD send an
|
|
337
|
+
* HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly
|
|
338
|
+
* terminate the session.
|
|
339
|
+
*
|
|
340
|
+
* The server MAY respond with HTTP 405 Method Not Allowed, indicating that
|
|
341
|
+
* the server does not allow clients to terminate sessions.
|
|
342
|
+
*/
|
|
343
|
+
async terminateSession() {
|
|
344
|
+
var _a, _b, _c;
|
|
345
|
+
if (!this._sessionId) {
|
|
346
|
+
return; // No session to terminate
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const headers = await this._commonHeaders();
|
|
350
|
+
const init = {
|
|
351
|
+
...this._requestInit,
|
|
352
|
+
method: "DELETE",
|
|
353
|
+
headers,
|
|
354
|
+
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal,
|
|
355
|
+
};
|
|
356
|
+
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
|
|
357
|
+
// We specifically handle 405 as a valid response according to the spec,
|
|
358
|
+
// meaning the server does not support explicit session termination
|
|
359
|
+
if (!response.ok && response.status !== 405) {
|
|
360
|
+
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
361
|
+
}
|
|
362
|
+
this._sessionId = undefined;
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
setProtocolVersion(version) {
|
|
370
|
+
this._protocolVersion = version;
|
|
371
|
+
}
|
|
372
|
+
get protocolVersion() {
|
|
373
|
+
return this._protocolVersion;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { StreamableHTTPClientTransport, StreamableHTTPError };
|
|
378
|
+
//# sourceMappingURL=streamableHttp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamableHttp.js","sources":["../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js"],"sourcesContent":["import { isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessageSchema } from \"../types.js\";\nimport { auth, extractResourceMetadataUrl, UnauthorizedError } from \"./auth.js\";\nimport { EventSourceParserStream } from \"eventsource-parser/stream\";\n// Default reconnection options for StreamableHTTP connections\nconst DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {\n initialReconnectionDelay: 1000,\n maxReconnectionDelay: 30000,\n reconnectionDelayGrowFactor: 1.5,\n maxRetries: 2,\n};\nexport class StreamableHTTPError extends Error {\n constructor(code, message) {\n super(`Streamable HTTP error: ${message}`);\n this.code = code;\n }\n}\n/**\n * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.\n * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events\n * for receiving messages.\n */\nexport class StreamableHTTPClientTransport {\n constructor(url, opts) {\n var _a;\n this._url = url;\n this._resourceMetadataUrl = undefined;\n this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;\n this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;\n this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;\n this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId;\n this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;\n }\n async _authThenStart() {\n var _a;\n if (!this._authProvider) {\n throw new UnauthorizedError(\"No auth provider\");\n }\n let result;\n try {\n result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });\n }\n catch (error) {\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n throw error;\n }\n if (result !== \"AUTHORIZED\") {\n throw new UnauthorizedError();\n }\n return await this._startOrAuthSse({ resumptionToken: undefined });\n }\n async _commonHeaders() {\n var _a;\n const headers = {};\n if (this._authProvider) {\n const tokens = await this._authProvider.tokens();\n if (tokens) {\n headers[\"Authorization\"] = `Bearer ${tokens.access_token}`;\n }\n }\n if (this._sessionId) {\n headers[\"mcp-session-id\"] = this._sessionId;\n }\n if (this._protocolVersion) {\n headers[\"mcp-protocol-version\"] = this._protocolVersion;\n }\n const extraHeaders = this._normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers);\n return new Headers({\n ...headers,\n ...extraHeaders,\n });\n }\n async _startOrAuthSse(options) {\n var _a, _b, _c;\n const { resumptionToken } = options;\n try {\n // Try to open an initial SSE stream with GET to listen for server messages\n // This is optional according to the spec - server may not support it\n const headers = await this._commonHeaders();\n headers.set(\"Accept\", \"text/event-stream\");\n // Include Last-Event-ID header for resumable streams if provided\n if (resumptionToken) {\n headers.set(\"last-event-id\", resumptionToken);\n }\n const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, {\n method: \"GET\",\n headers,\n signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal,\n });\n if (!response.ok) {\n if (response.status === 401 && this._authProvider) {\n // Need to authenticate\n return await this._authThenStart();\n }\n // 405 indicates that the server does not offer an SSE stream at GET endpoint\n // This is an expected case that should not trigger an error\n if (response.status === 405) {\n return;\n }\n throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);\n }\n this._handleSseStream(response.body, options);\n }\n catch (error) {\n (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);\n throw error;\n }\n }\n /**\n * Calculates the next reconnection delay using backoff algorithm\n *\n * @param attempt Current reconnection attempt count for the specific stream\n * @returns Time to wait in milliseconds before next reconnection attempt\n */\n _getNextReconnectionDelay(attempt) {\n // Access default values directly, ensuring they're never undefined\n const initialDelay = this._reconnectionOptions.initialReconnectionDelay;\n const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;\n const maxDelay = this._reconnectionOptions.maxReconnectionDelay;\n // Cap at maximum delay\n return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);\n }\n _normalizeHeaders(headers) {\n if (!headers)\n return {};\n if (headers instanceof Headers) {\n return Object.fromEntries(headers.entries());\n }\n if (Array.isArray(headers)) {\n return Object.fromEntries(headers);\n }\n return { ...headers };\n }\n /**\n * Schedule a reconnection attempt with exponential backoff\n *\n * @param lastEventId The ID of the last received event for resumability\n * @param attemptCount Current reconnection attempt count for this specific stream\n */\n _scheduleReconnection(options, attemptCount = 0) {\n var _a;\n // Use provided options or default options\n const maxRetries = this._reconnectionOptions.maxRetries;\n // Check if we've exceeded maximum retry attempts\n if (maxRetries > 0 && attemptCount >= maxRetries) {\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));\n return;\n }\n // Calculate next delay based on current attempt count\n const delay = this._getNextReconnectionDelay(attemptCount);\n // Schedule the reconnection\n setTimeout(() => {\n // Use the last event ID to resume where we left off\n this._startOrAuthSse(options).catch(error => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));\n // Schedule another attempt if this one failed, incrementing the attempt counter\n this._scheduleReconnection(options, attemptCount + 1);\n });\n }, delay);\n }\n _handleSseStream(stream, options) {\n if (!stream) {\n return;\n }\n const { onresumptiontoken, replayMessageId } = options;\n let lastEventId;\n const processStream = async () => {\n var _a, _b, _c, _d;\n // this is the closest we can get to trying to catch network errors\n // if something happens reader will throw\n try {\n // Create a pipeline: binary stream -> text decoder -> SSE parser\n const reader = stream\n .pipeThrough(new TextDecoderStream())\n .pipeThrough(new EventSourceParserStream())\n .getReader();\n while (true) {\n const { value: event, done } = await reader.read();\n if (done) {\n break;\n }\n // Update last event ID if provided\n if (event.id) {\n lastEventId = event.id;\n onresumptiontoken === null || onresumptiontoken === void 0 ? void 0 : onresumptiontoken(event.id);\n }\n if (!event.event || event.event === \"message\") {\n try {\n const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));\n if (replayMessageId !== undefined && isJSONRPCResponse(message)) {\n message.id = replayMessageId;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n }\n catch (error) {\n // Handle stream errors - likely a network disconnect\n (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`));\n // Attempt to reconnect if the stream disconnects unexpectedly and we aren't closing\n if (this._abortController && !this._abortController.signal.aborted) {\n // Use the exponential backoff reconnection strategy\n if (lastEventId !== undefined) {\n try {\n this._scheduleReconnection({\n resumptionToken: lastEventId,\n onresumptiontoken,\n replayMessageId\n }, 0);\n }\n catch (error) {\n (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error instanceof Error ? error.message : String(error)}`));\n }\n }\n }\n }\n };\n processStream();\n }\n async start() {\n if (this._abortController) {\n throw new Error(\"StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.\");\n }\n this._abortController = new AbortController();\n }\n /**\n * 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.\n */\n async finishAuth(authorizationCode) {\n if (!this._authProvider) {\n throw new UnauthorizedError(\"No auth provider\");\n }\n const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });\n if (result !== \"AUTHORIZED\") {\n throw new UnauthorizedError(\"Failed to authorize\");\n }\n }\n async close() {\n var _a, _b;\n // Abort any pending requests\n (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort();\n (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this);\n }\n async send(message, options) {\n var _a, _b, _c, _d;\n try {\n const { resumptionToken, onresumptiontoken } = options || {};\n if (resumptionToken) {\n // If we have at last event ID, we need to reconnect the SSE stream\n this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); });\n return;\n }\n const headers = await this._commonHeaders();\n headers.set(\"content-type\", \"application/json\");\n headers.set(\"accept\", \"application/json, text/event-stream\");\n const init = {\n ...this._requestInit,\n method: \"POST\",\n headers,\n body: JSON.stringify(message),\n signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal,\n };\n const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);\n // Handle session ID received during initialization\n const sessionId = response.headers.get(\"mcp-session-id\");\n if (sessionId) {\n this._sessionId = sessionId;\n }\n if (!response.ok) {\n if (response.status === 401 && this._authProvider) {\n this._resourceMetadataUrl = extractResourceMetadataUrl(response);\n const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });\n if (result !== \"AUTHORIZED\") {\n throw new UnauthorizedError();\n }\n // Purposely _not_ awaited, so we don't call onerror twice\n return this.send(message);\n }\n const text = await response.text().catch(() => null);\n throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);\n }\n // If the response is 202 Accepted, there's no body to process\n if (response.status === 202) {\n // if the accepted notification is initialized, we start the SSE stream\n // if it's supported by the server\n if (isInitializedNotification(message)) {\n // Start without a lastEventId since this is a fresh connection\n this._startOrAuthSse({ resumptionToken: undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); });\n }\n return;\n }\n // Get original message(s) for detecting request IDs\n const messages = Array.isArray(message) ? message : [message];\n const hasRequests = messages.filter(msg => \"method\" in msg && \"id\" in msg && msg.id !== undefined).length > 0;\n // Check the response type\n const contentType = response.headers.get(\"content-type\");\n if (hasRequests) {\n if (contentType === null || contentType === void 0 ? void 0 : contentType.includes(\"text/event-stream\")) {\n // Handle SSE stream responses for requests\n // We use the same handler as standalone streams, which now supports\n // reconnection with the last event ID\n this._handleSseStream(response.body, { onresumptiontoken });\n }\n else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes(\"application/json\")) {\n // For non-streaming servers, we might get direct JSON responses\n const data = await response.json();\n const responseMessages = Array.isArray(data)\n ? data.map(msg => JSONRPCMessageSchema.parse(msg))\n : [JSONRPCMessageSchema.parse(data)];\n for (const msg of responseMessages) {\n (_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, msg);\n }\n }\n else {\n throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);\n }\n }\n }\n catch (error) {\n (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error);\n throw error;\n }\n }\n get sessionId() {\n return this._sessionId;\n }\n /**\n * Terminates the current session by sending a DELETE request to the server.\n *\n * Clients that no longer need a particular session\n * (e.g., because the user is leaving the client application) SHOULD send an\n * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly\n * terminate the session.\n *\n * The server MAY respond with HTTP 405 Method Not Allowed, indicating that\n * the server does not allow clients to terminate sessions.\n */\n async terminateSession() {\n var _a, _b, _c;\n if (!this._sessionId) {\n return; // No session to terminate\n }\n try {\n const headers = await this._commonHeaders();\n const init = {\n ...this._requestInit,\n method: \"DELETE\",\n headers,\n signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal,\n };\n const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);\n // We specifically handle 405 as a valid response according to the spec,\n // meaning the server does not support explicit session termination\n if (!response.ok && response.status !== 405) {\n throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);\n }\n this._sessionId = undefined;\n }\n catch (error) {\n (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);\n throw error;\n }\n }\n setProtocolVersion(version) {\n this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C,QAAQ;AACR,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;AACzF,YAAY,MAAM,KAAK;AACvB,QAAQ;AACR,IAAI;AACJ,IAAI,kBAAkB,CAAC,OAAO,EAAE;AAChC,QAAQ,IAAI,CAAC,gBAAgB,GAAG,OAAO;AACvC,IAAI;AACJ,IAAI,IAAI,eAAe,GAAG;AAC1B,QAAQ,OAAO,IAAI,CAAC,gBAAgB;AACpC,IAAI;AACJ;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for handling OAuth resource URIs.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Converts a server URL to a resource URL by removing the fragment.
|
|
6
|
+
* RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
|
|
7
|
+
* Keeps everything else unchanged (scheme, domain, port, path, query).
|
|
8
|
+
*/
|
|
9
|
+
function resourceUrlFromServerUrl(url) {
|
|
10
|
+
const resourceURL = typeof url === "string" ? new URL(url) : new URL(url.href);
|
|
11
|
+
resourceURL.hash = ''; // Remove fragment
|
|
12
|
+
return resourceURL;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a requested resource URL matches a configured resource URL.
|
|
16
|
+
* A requested resource matches if it has the same scheme, domain, port,
|
|
17
|
+
* and its path starts with the configured resource's path.
|
|
18
|
+
*
|
|
19
|
+
* @param requestedResource The resource URL being requested
|
|
20
|
+
* @param configuredResource The resource URL that has been configured
|
|
21
|
+
* @returns true if the requested resource matches the configured resource, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
function checkResourceAllowed({ requestedResource, configuredResource }) {
|
|
24
|
+
const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
|
|
25
|
+
const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
|
|
26
|
+
// Compare the origin (scheme, domain, and port)
|
|
27
|
+
if (requested.origin !== configured.origin) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// Handle cases like requested=/foo and configured=/foo/
|
|
31
|
+
if (requested.pathname.length < configured.pathname.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Check if the requested path starts with the configured path
|
|
35
|
+
// Ensure both paths end with / for proper comparison
|
|
36
|
+
// This ensures that if we have paths like "/api" and "/api/users",
|
|
37
|
+
// we properly detect that "/api/users" is a subpath of "/api"
|
|
38
|
+
// By adding a trailing slash if missing, we avoid false positives
|
|
39
|
+
// where paths like "/api123" would incorrectly match "/api"
|
|
40
|
+
const requestedPath = requested.pathname.endsWith('/') ? requested.pathname : requested.pathname + '/';
|
|
41
|
+
const configuredPath = configured.pathname.endsWith('/') ? configured.pathname : configured.pathname + '/';
|
|
42
|
+
return requestedPath.startsWith(configuredPath);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { checkResourceAllowed, resourceUrlFromServerUrl };
|
|
46
|
+
//# sourceMappingURL=auth-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.js","sources":["../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js"],"sourcesContent":["/**\n * Utilities for handling OAuth resource URIs.\n */\n/**\n * Converts a server URL to a resource URL by removing the fragment.\n * RFC 8707 section 2 states that resource URIs \"MUST NOT include a fragment component\".\n * Keeps everything else unchanged (scheme, domain, port, path, query).\n */\nexport function resourceUrlFromServerUrl(url) {\n const resourceURL = typeof url === \"string\" ? new URL(url) : new URL(url.href);\n resourceURL.hash = ''; // Remove fragment\n return resourceURL;\n}\n/**\n * Checks if a requested resource URL matches a configured resource URL.\n * A requested resource matches if it has the same scheme, domain, port,\n * and its path starts with the configured resource's path.\n *\n * @param requestedResource The resource URL being requested\n * @param configuredResource The resource URL that has been configured\n * @returns true if the requested resource matches the configured resource, false otherwise\n */\nexport function checkResourceAllowed({ requestedResource, configuredResource }) {\n const requested = typeof requestedResource === \"string\" ? new URL(requestedResource) : new URL(requestedResource.href);\n const configured = typeof configuredResource === \"string\" ? new URL(configuredResource) : new URL(configuredResource.href);\n // Compare the origin (scheme, domain, and port)\n if (requested.origin !== configured.origin) {\n return false;\n }\n // Handle cases like requested=/foo and configured=/foo/\n if (requested.pathname.length < configured.pathname.length) {\n return false;\n }\n // Check if the requested path starts with the configured path\n // Ensure both paths end with / for proper comparison\n // This ensures that if we have paths like \"/api\" and \"/api/users\",\n // we properly detect that \"/api/users\" is a subpath of \"/api\"\n // By adding a trailing slash if missing, we avoid false positives\n // where paths like \"/api123\" would incorrectly match \"/api\"\n const requestedPath = requested.pathname.endsWith('/') ? requested.pathname : requested.pathname + '/';\n const configuredPath = configured.pathname.endsWith('/') ? configured.pathname : configured.pathname + '/';\n return requestedPath.startsWith(configuredPath);\n}\n//# sourceMappingURL=auth-utils.js.map"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB,CAAC,GAAG,EAAE;AAC9C,IAAI,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;AAClF,IAAI,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;AAC1B,IAAI,OAAO,WAAW;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,EAAE;AAChF,IAAI,MAAM,SAAS,GAAG,OAAO,iBAAiB,KAAK,QAAQ,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC;AAC1H,IAAI,MAAM,UAAU,GAAG,OAAO,kBAAkB,KAAK,QAAQ,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC;AAC9H;AACA,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE;AAChD,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;AACA,IAAI,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE;AAChE,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,GAAG;AAC1G,IAAI,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,GAAG,GAAG;AAC9G,IAAI,OAAO,aAAa,CAAC,UAAU,CAAC,cAAc,CAAC;AACnD;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { object as objectType, boolean as booleanType, array as arrayType, string as stringType, number as numberType, any as anyType } from '../../../../../zod/dist/esm/v3/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RFC 9728 OAuth Protected Resource Metadata
|
|
5
|
+
*/
|
|
6
|
+
const OAuthProtectedResourceMetadataSchema = objectType({
|
|
7
|
+
resource: stringType().url(),
|
|
8
|
+
authorization_servers: arrayType(stringType().url()).optional(),
|
|
9
|
+
jwks_uri: stringType().url().optional(),
|
|
10
|
+
scopes_supported: arrayType(stringType()).optional(),
|
|
11
|
+
bearer_methods_supported: arrayType(stringType()).optional(),
|
|
12
|
+
resource_signing_alg_values_supported: arrayType(stringType()).optional(),
|
|
13
|
+
resource_name: stringType().optional(),
|
|
14
|
+
resource_documentation: stringType().optional(),
|
|
15
|
+
resource_policy_uri: stringType().url().optional(),
|
|
16
|
+
resource_tos_uri: stringType().url().optional(),
|
|
17
|
+
tls_client_certificate_bound_access_tokens: booleanType().optional(),
|
|
18
|
+
authorization_details_types_supported: arrayType(stringType()).optional(),
|
|
19
|
+
dpop_signing_alg_values_supported: arrayType(stringType()).optional(),
|
|
20
|
+
dpop_bound_access_tokens_required: booleanType().optional(),
|
|
21
|
+
})
|
|
22
|
+
.passthrough();
|
|
23
|
+
/**
|
|
24
|
+
* RFC 8414 OAuth 2.0 Authorization Server Metadata
|
|
25
|
+
*/
|
|
26
|
+
const OAuthMetadataSchema = objectType({
|
|
27
|
+
issuer: stringType(),
|
|
28
|
+
authorization_endpoint: stringType(),
|
|
29
|
+
token_endpoint: stringType(),
|
|
30
|
+
registration_endpoint: stringType().optional(),
|
|
31
|
+
scopes_supported: arrayType(stringType()).optional(),
|
|
32
|
+
response_types_supported: arrayType(stringType()),
|
|
33
|
+
response_modes_supported: arrayType(stringType()).optional(),
|
|
34
|
+
grant_types_supported: arrayType(stringType()).optional(),
|
|
35
|
+
token_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
|
|
36
|
+
token_endpoint_auth_signing_alg_values_supported: arrayType(stringType())
|
|
37
|
+
.optional(),
|
|
38
|
+
service_documentation: stringType().optional(),
|
|
39
|
+
revocation_endpoint: stringType().optional(),
|
|
40
|
+
revocation_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
|
|
41
|
+
revocation_endpoint_auth_signing_alg_values_supported: arrayType(stringType())
|
|
42
|
+
.optional(),
|
|
43
|
+
introspection_endpoint: stringType().optional(),
|
|
44
|
+
introspection_endpoint_auth_methods_supported: arrayType(stringType())
|
|
45
|
+
.optional(),
|
|
46
|
+
introspection_endpoint_auth_signing_alg_values_supported: arrayType(stringType())
|
|
47
|
+
.optional(),
|
|
48
|
+
code_challenge_methods_supported: arrayType(stringType()).optional(),
|
|
49
|
+
})
|
|
50
|
+
.passthrough();
|
|
51
|
+
/**
|
|
52
|
+
* OAuth 2.1 token response
|
|
53
|
+
*/
|
|
54
|
+
const OAuthTokensSchema = objectType({
|
|
55
|
+
access_token: stringType(),
|
|
56
|
+
token_type: stringType(),
|
|
57
|
+
expires_in: numberType().optional(),
|
|
58
|
+
scope: stringType().optional(),
|
|
59
|
+
refresh_token: stringType().optional(),
|
|
60
|
+
})
|
|
61
|
+
.strip();
|
|
62
|
+
/**
|
|
63
|
+
* OAuth 2.1 error response
|
|
64
|
+
*/
|
|
65
|
+
objectType({
|
|
66
|
+
error: stringType(),
|
|
67
|
+
error_description: stringType().optional(),
|
|
68
|
+
error_uri: stringType().optional(),
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
|
|
72
|
+
*/
|
|
73
|
+
const OAuthClientMetadataSchema = objectType({
|
|
74
|
+
redirect_uris: arrayType(stringType()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: "redirect_uris must contain valid URLs" }),
|
|
75
|
+
token_endpoint_auth_method: stringType().optional(),
|
|
76
|
+
grant_types: arrayType(stringType()).optional(),
|
|
77
|
+
response_types: arrayType(stringType()).optional(),
|
|
78
|
+
client_name: stringType().optional(),
|
|
79
|
+
client_uri: stringType().optional(),
|
|
80
|
+
logo_uri: stringType().optional(),
|
|
81
|
+
scope: stringType().optional(),
|
|
82
|
+
contacts: arrayType(stringType()).optional(),
|
|
83
|
+
tos_uri: stringType().optional(),
|
|
84
|
+
policy_uri: stringType().optional(),
|
|
85
|
+
jwks_uri: stringType().optional(),
|
|
86
|
+
jwks: anyType().optional(),
|
|
87
|
+
software_id: stringType().optional(),
|
|
88
|
+
software_version: stringType().optional(),
|
|
89
|
+
software_statement: stringType().optional(),
|
|
90
|
+
}).strip();
|
|
91
|
+
/**
|
|
92
|
+
* RFC 7591 OAuth 2.0 Dynamic Client Registration client information
|
|
93
|
+
*/
|
|
94
|
+
const OAuthClientInformationSchema = objectType({
|
|
95
|
+
client_id: stringType(),
|
|
96
|
+
client_secret: stringType().optional(),
|
|
97
|
+
client_id_issued_at: numberType().optional(),
|
|
98
|
+
client_secret_expires_at: numberType().optional(),
|
|
99
|
+
}).strip();
|
|
100
|
+
/**
|
|
101
|
+
* RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
|
|
102
|
+
*/
|
|
103
|
+
const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
104
|
+
/**
|
|
105
|
+
* RFC 7591 OAuth 2.0 Dynamic Client Registration error response
|
|
106
|
+
*/
|
|
107
|
+
objectType({
|
|
108
|
+
error: stringType(),
|
|
109
|
+
error_description: stringType().optional(),
|
|
110
|
+
}).strip();
|
|
111
|
+
/**
|
|
112
|
+
* RFC 7009 OAuth 2.0 Token Revocation request
|
|
113
|
+
*/
|
|
114
|
+
objectType({
|
|
115
|
+
token: stringType(),
|
|
116
|
+
token_type_hint: stringType().optional(),
|
|
117
|
+
}).strip();
|
|
118
|
+
|
|
119
|
+
export { OAuthClientInformationFullSchema, OAuthClientInformationSchema, OAuthClientMetadataSchema, OAuthMetadataSchema, OAuthProtectedResourceMetadataSchema, OAuthTokensSchema };
|
|
120
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sources":["../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js"],"sourcesContent":["import { z } from \"zod\";\n/**\n * RFC 9728 OAuth Protected Resource Metadata\n */\nexport const OAuthProtectedResourceMetadataSchema = z\n .object({\n resource: z.string().url(),\n authorization_servers: z.array(z.string().url()).optional(),\n jwks_uri: z.string().url().optional(),\n scopes_supported: z.array(z.string()).optional(),\n bearer_methods_supported: z.array(z.string()).optional(),\n resource_signing_alg_values_supported: z.array(z.string()).optional(),\n resource_name: z.string().optional(),\n resource_documentation: z.string().optional(),\n resource_policy_uri: z.string().url().optional(),\n resource_tos_uri: z.string().url().optional(),\n tls_client_certificate_bound_access_tokens: z.boolean().optional(),\n authorization_details_types_supported: z.array(z.string()).optional(),\n dpop_signing_alg_values_supported: z.array(z.string()).optional(),\n dpop_bound_access_tokens_required: z.boolean().optional(),\n})\n .passthrough();\n/**\n * RFC 8414 OAuth 2.0 Authorization Server Metadata\n */\nexport const OAuthMetadataSchema = z\n .object({\n issuer: z.string(),\n authorization_endpoint: z.string(),\n token_endpoint: z.string(),\n registration_endpoint: z.string().optional(),\n scopes_supported: z.array(z.string()).optional(),\n response_types_supported: z.array(z.string()),\n response_modes_supported: z.array(z.string()).optional(),\n grant_types_supported: z.array(z.string()).optional(),\n token_endpoint_auth_methods_supported: z.array(z.string()).optional(),\n token_endpoint_auth_signing_alg_values_supported: z\n .array(z.string())\n .optional(),\n service_documentation: z.string().optional(),\n revocation_endpoint: z.string().optional(),\n revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(),\n revocation_endpoint_auth_signing_alg_values_supported: z\n .array(z.string())\n .optional(),\n introspection_endpoint: z.string().optional(),\n introspection_endpoint_auth_methods_supported: z\n .array(z.string())\n .optional(),\n introspection_endpoint_auth_signing_alg_values_supported: z\n .array(z.string())\n .optional(),\n code_challenge_methods_supported: z.array(z.string()).optional(),\n})\n .passthrough();\n/**\n * OAuth 2.1 token response\n */\nexport const OAuthTokensSchema = z\n .object({\n access_token: z.string(),\n token_type: z.string(),\n expires_in: z.number().optional(),\n scope: z.string().optional(),\n refresh_token: z.string().optional(),\n})\n .strip();\n/**\n * OAuth 2.1 error response\n */\nexport const OAuthErrorResponseSchema = z\n .object({\n error: z.string(),\n error_description: z.string().optional(),\n error_uri: z.string().optional(),\n});\n/**\n * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata\n */\nexport const OAuthClientMetadataSchema = z.object({\n redirect_uris: z.array(z.string()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: \"redirect_uris must contain valid URLs\" }),\n token_endpoint_auth_method: z.string().optional(),\n grant_types: z.array(z.string()).optional(),\n response_types: z.array(z.string()).optional(),\n client_name: z.string().optional(),\n client_uri: z.string().optional(),\n logo_uri: z.string().optional(),\n scope: z.string().optional(),\n contacts: z.array(z.string()).optional(),\n tos_uri: z.string().optional(),\n policy_uri: z.string().optional(),\n jwks_uri: z.string().optional(),\n jwks: z.any().optional(),\n software_id: z.string().optional(),\n software_version: z.string().optional(),\n software_statement: z.string().optional(),\n}).strip();\n/**\n * RFC 7591 OAuth 2.0 Dynamic Client Registration client information\n */\nexport const OAuthClientInformationSchema = z.object({\n client_id: z.string(),\n client_secret: z.string().optional(),\n client_id_issued_at: z.number().optional(),\n client_secret_expires_at: z.number().optional(),\n}).strip();\n/**\n * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)\n */\nexport const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);\n/**\n * RFC 7591 OAuth 2.0 Dynamic Client Registration error response\n */\nexport const OAuthClientRegistrationErrorSchema = z.object({\n error: z.string(),\n error_description: z.string().optional(),\n}).strip();\n/**\n * RFC 7009 OAuth 2.0 Token Revocation request\n */\nexport const OAuthTokenRevocationRequestSchema = z.object({\n token: z.string(),\n token_type_hint: z.string().optional(),\n}).strip();\n//# sourceMappingURL=auth.js.map"],"names":["z\n .object","z.string","z.array","z.boolean","z\n .array","z.number","z.object","z.any"],"mappings":";;AACA;AACA;AACA;AACY,MAAC,oCAAoC,GAAGA,UACzC,CAAC;AACZ,IAAI,QAAQ,EAAEC,UAAQ,EAAE,CAAC,GAAG,EAAE;AAC9B,IAAI,qBAAqB,EAAEC,SAAO,CAACD,UAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE;AAC/D,IAAI,QAAQ,EAAEA,UAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;AACzC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