agents 0.0.0-ca44ae8 → 0.0.0-cac66b8
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 +27 -1
- package/dist/ai-chat-agent.js +99 -103
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +13 -0
- package/dist/ai-react.js +0 -2
- package/dist/ai-react.js.map +1 -1
- package/dist/chunk-BZXOAZUX.js +106 -0
- package/dist/chunk-BZXOAZUX.js.map +1 -0
- package/dist/{chunk-MDL3W36D.js → chunk-DVT5CDUP.js} +260 -98
- package/dist/chunk-DVT5CDUP.js.map +1 -0
- package/dist/{chunk-Q5ZBHY4Z.js → chunk-IFXSRTKF.js} +33 -24
- 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 +97 -4
- package/dist/index.js +4 -3
- package/dist/mcp/client.d.ts +21 -15
- package/dist/mcp/client.js +1 -2
- package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
- package/dist/mcp/do-oauth-client-provider.js +3 -103
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +11 -1
- package/dist/mcp/index.js +109 -137
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +85 -5
- package/dist/react.js +14 -2
- package/dist/react.js.map +1 -1
- package/dist/schedule.js +0 -2
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/package.json +9 -7
- package/src/index.ts +336 -42
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-MDL3W36D.js.map +0 -1
- package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
- /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
package/dist/mcp/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
__privateGet,
|
|
8
|
-
__privateMethod,
|
|
9
|
-
__privateSet
|
|
10
|
-
} from "../chunk-HMLY7DHA.js";
|
|
3
|
+
} from "../chunk-DVT5CDUP.js";
|
|
4
|
+
import "../chunk-IFXSRTKF.js";
|
|
5
|
+
import "../chunk-BZXOAZUX.js";
|
|
6
|
+
import "../chunk-VCSB47AK.js";
|
|
11
7
|
|
|
12
8
|
// src/mcp/index.ts
|
|
13
9
|
import { DurableObject } from "cloudflare:workers";
|
|
@@ -20,37 +16,41 @@ import {
|
|
|
20
16
|
JSONRPCMessageSchema
|
|
21
17
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
22
18
|
var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
|
|
23
|
-
function
|
|
24
|
-
const origin =
|
|
25
|
-
|
|
26
|
-
"Access-Control-Allow-Origin": corsOptions
|
|
27
|
-
"Access-Control-Allow-Methods": corsOptions
|
|
28
|
-
"Access-Control-Allow-Headers": corsOptions
|
|
29
|
-
"Access-Control-Max-Age": (corsOptions
|
|
19
|
+
function corsHeaders(request, corsOptions = {}) {
|
|
20
|
+
const origin = "*";
|
|
21
|
+
return {
|
|
22
|
+
"Access-Control-Allow-Origin": corsOptions.origin || origin,
|
|
23
|
+
"Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
|
|
24
|
+
"Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id",
|
|
25
|
+
"Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString(),
|
|
26
|
+
"Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id"
|
|
30
27
|
};
|
|
28
|
+
}
|
|
29
|
+
function isDurableObjectNamespace(namespace) {
|
|
30
|
+
return typeof namespace === "object" && namespace !== null && "newUniqueId" in namespace && typeof namespace.newUniqueId === "function" && "idFromName" in namespace && typeof namespace.idFromName === "function";
|
|
31
|
+
}
|
|
32
|
+
function handleCORS(request, corsOptions) {
|
|
31
33
|
if (request.method === "OPTIONS") {
|
|
32
|
-
return new Response(null, { headers: corsHeaders });
|
|
34
|
+
return new Response(null, { headers: corsHeaders(request, corsOptions) });
|
|
33
35
|
}
|
|
34
36
|
return null;
|
|
35
37
|
}
|
|
36
|
-
var _getWebSocket, _started;
|
|
37
38
|
var McpSSETransport = class {
|
|
38
39
|
constructor(getWebSocket) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__privateSet(this, _getWebSocket, getWebSocket);
|
|
40
|
+
this._started = false;
|
|
41
|
+
this._getWebSocket = getWebSocket;
|
|
42
42
|
}
|
|
43
43
|
async start() {
|
|
44
|
-
if (
|
|
44
|
+
if (this._started) {
|
|
45
45
|
throw new Error("Transport already started");
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
this._started = true;
|
|
48
48
|
}
|
|
49
49
|
async send(message) {
|
|
50
|
-
if (!
|
|
50
|
+
if (!this._started) {
|
|
51
51
|
throw new Error("Transport not started");
|
|
52
52
|
}
|
|
53
|
-
const websocket =
|
|
53
|
+
const websocket = this._getWebSocket();
|
|
54
54
|
if (!websocket) {
|
|
55
55
|
throw new Error("WebSocket not connected");
|
|
56
56
|
}
|
|
@@ -65,52 +65,40 @@ var McpSSETransport = class {
|
|
|
65
65
|
this.onclose?.();
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
_getWebSocket = new WeakMap();
|
|
69
|
-
_started = new WeakMap();
|
|
70
|
-
var _getWebSocketForGetRequest, _getWebSocketForMessageID, _notifyResponseIdSent, _started2;
|
|
71
68
|
var McpStreamableHttpTransport = class {
|
|
72
69
|
constructor(getWebSocketForMessageID, notifyResponseIdSent) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
__privateAdd(this, _getWebSocketForMessageID);
|
|
78
|
-
// Notify the server that a response has been sent for a given message id
|
|
79
|
-
// so that it may clean up it's mapping of message ids to connections
|
|
80
|
-
// once they are no longer needed
|
|
81
|
-
__privateAdd(this, _notifyResponseIdSent);
|
|
82
|
-
__privateAdd(this, _started2, false);
|
|
83
|
-
__privateSet(this, _getWebSocketForMessageID, getWebSocketForMessageID);
|
|
84
|
-
__privateSet(this, _notifyResponseIdSent, notifyResponseIdSent);
|
|
85
|
-
__privateSet(this, _getWebSocketForGetRequest, () => null);
|
|
70
|
+
this._started = false;
|
|
71
|
+
this._getWebSocketForMessageID = getWebSocketForMessageID;
|
|
72
|
+
this._notifyResponseIdSent = notifyResponseIdSent;
|
|
73
|
+
this._getWebSocketForGetRequest = () => null;
|
|
86
74
|
}
|
|
87
75
|
async start() {
|
|
88
|
-
if (
|
|
76
|
+
if (this._started) {
|
|
89
77
|
throw new Error("Transport already started");
|
|
90
78
|
}
|
|
91
|
-
|
|
79
|
+
this._started = true;
|
|
92
80
|
}
|
|
93
81
|
async send(message) {
|
|
94
|
-
if (!
|
|
82
|
+
if (!this._started) {
|
|
95
83
|
throw new Error("Transport not started");
|
|
96
84
|
}
|
|
97
85
|
let websocket = null;
|
|
98
86
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
|
|
99
|
-
websocket =
|
|
87
|
+
websocket = this._getWebSocketForMessageID(message.id.toString());
|
|
100
88
|
if (!websocket) {
|
|
101
89
|
throw new Error(
|
|
102
90
|
`Could not find WebSocket for message id: ${message.id}`
|
|
103
91
|
);
|
|
104
92
|
}
|
|
105
93
|
} else if (isJSONRPCRequest(message)) {
|
|
106
|
-
websocket =
|
|
94
|
+
websocket = this._getWebSocketForGetRequest();
|
|
107
95
|
} else if (isJSONRPCNotification(message)) {
|
|
108
96
|
websocket = null;
|
|
109
97
|
}
|
|
110
98
|
try {
|
|
111
99
|
websocket?.send(JSON.stringify(message));
|
|
112
100
|
if (isJSONRPCResponse(message)) {
|
|
113
|
-
|
|
101
|
+
this._notifyResponseIdSent(message.id.toString());
|
|
114
102
|
}
|
|
115
103
|
} catch (error) {
|
|
116
104
|
this.onerror?.(error);
|
|
@@ -121,28 +109,16 @@ var McpStreamableHttpTransport = class {
|
|
|
121
109
|
this.onclose?.();
|
|
122
110
|
}
|
|
123
111
|
};
|
|
124
|
-
|
|
125
|
-
_getWebSocketForMessageID = new WeakMap();
|
|
126
|
-
_notifyResponseIdSent = new WeakMap();
|
|
127
|
-
_started2 = new WeakMap();
|
|
128
|
-
var _status, _transport, _transportType, _requestIdToConnectionId, _agent, _McpAgent_instances, initialize_fn;
|
|
129
|
-
var _McpAgent = class _McpAgent extends DurableObject {
|
|
112
|
+
var McpAgent = class _McpAgent extends DurableObject {
|
|
130
113
|
constructor(ctx, env) {
|
|
131
114
|
var _a;
|
|
132
115
|
super(ctx, env);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
__privateAdd(this, _transportType, "unset");
|
|
137
|
-
__privateAdd(this, _requestIdToConnectionId, /* @__PURE__ */ new Map());
|
|
138
|
-
/**
|
|
139
|
-
* Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
|
|
140
|
-
* to the outer class: initialState/state/setState/onStateUpdate/sql
|
|
141
|
-
*/
|
|
142
|
-
__privateAdd(this, _agent);
|
|
116
|
+
this._status = "zero";
|
|
117
|
+
this._transportType = "unset";
|
|
118
|
+
this._requestIdToConnectionId = /* @__PURE__ */ new Map();
|
|
143
119
|
this.initRun = false;
|
|
144
120
|
const self = this;
|
|
145
|
-
|
|
121
|
+
this._agent = new (_a = class extends Agent {
|
|
146
122
|
onStateUpdate(state, source) {
|
|
147
123
|
return self.onStateUpdate(state, source);
|
|
148
124
|
}
|
|
@@ -151,26 +127,26 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
151
127
|
}
|
|
152
128
|
}, _a.options = {
|
|
153
129
|
hibernate: true
|
|
154
|
-
}, _a)(ctx, env)
|
|
130
|
+
}, _a)(ctx, env);
|
|
155
131
|
}
|
|
156
132
|
get mcp() {
|
|
157
|
-
return
|
|
133
|
+
return this._agent.mcp;
|
|
158
134
|
}
|
|
159
135
|
get state() {
|
|
160
|
-
return
|
|
136
|
+
return this._agent.state;
|
|
161
137
|
}
|
|
162
138
|
sql(strings, ...values) {
|
|
163
|
-
return
|
|
139
|
+
return this._agent.sql(strings, ...values);
|
|
164
140
|
}
|
|
165
141
|
setState(state) {
|
|
166
|
-
return
|
|
142
|
+
return this._agent.setState(state);
|
|
167
143
|
}
|
|
168
144
|
onStateUpdate(state, source) {
|
|
169
145
|
}
|
|
170
146
|
async onStart() {
|
|
171
147
|
var _a;
|
|
172
148
|
const self = this;
|
|
173
|
-
|
|
149
|
+
this._agent = new (_a = class extends Agent {
|
|
174
150
|
constructor() {
|
|
175
151
|
super(...arguments);
|
|
176
152
|
this.initialState = self.initialState;
|
|
@@ -183,22 +159,22 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
183
159
|
}
|
|
184
160
|
}, _a.options = {
|
|
185
161
|
hibernate: true
|
|
186
|
-
}, _a)(this.ctx, this.env)
|
|
162
|
+
}, _a)(this.ctx, this.env);
|
|
187
163
|
this.props = await this.ctx.storage.get("props");
|
|
188
|
-
|
|
164
|
+
this._transportType = await this.ctx.storage.get(
|
|
189
165
|
"transportType"
|
|
190
|
-
)
|
|
166
|
+
);
|
|
191
167
|
await this._init(this.props);
|
|
192
168
|
const server = await this.server;
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
await server.connect(
|
|
196
|
-
} else if (
|
|
197
|
-
|
|
169
|
+
if (this._transportType === "sse") {
|
|
170
|
+
this._transport = new McpSSETransport(() => this.getWebSocket());
|
|
171
|
+
await server.connect(this._transport);
|
|
172
|
+
} else if (this._transportType === "streamable-http") {
|
|
173
|
+
this._transport = new McpStreamableHttpTransport(
|
|
198
174
|
(id) => this.getWebSocketForResponseID(id),
|
|
199
|
-
(id) =>
|
|
200
|
-
)
|
|
201
|
-
await server.connect(
|
|
175
|
+
(id) => this._requestIdToConnectionId.delete(id)
|
|
176
|
+
);
|
|
177
|
+
await server.connect(this._transport);
|
|
202
178
|
}
|
|
203
179
|
}
|
|
204
180
|
async _init(props) {
|
|
@@ -218,10 +194,17 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
218
194
|
async isInitialized() {
|
|
219
195
|
return await this.ctx.storage.get("initialized") === true;
|
|
220
196
|
}
|
|
197
|
+
async _initialize() {
|
|
198
|
+
await this.ctx.blockConcurrencyWhile(async () => {
|
|
199
|
+
this._status = "starting";
|
|
200
|
+
await this.onStart();
|
|
201
|
+
this._status = "started";
|
|
202
|
+
});
|
|
203
|
+
}
|
|
221
204
|
// Allow the worker to fetch a websocket connection to the agent
|
|
222
205
|
async fetch(request) {
|
|
223
|
-
if (
|
|
224
|
-
await
|
|
206
|
+
if (this._status !== "started") {
|
|
207
|
+
await this._initialize();
|
|
225
208
|
}
|
|
226
209
|
if (request.headers.get("Upgrade") !== "websocket") {
|
|
227
210
|
return new Response("Expected WebSocket Upgrade request", {
|
|
@@ -238,24 +221,24 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
238
221
|
return new Response("Websocket already connected", { status: 400 });
|
|
239
222
|
}
|
|
240
223
|
await this.ctx.storage.put("transportType", "sse");
|
|
241
|
-
|
|
242
|
-
if (!
|
|
243
|
-
|
|
244
|
-
await server.connect(
|
|
224
|
+
this._transportType = "sse";
|
|
225
|
+
if (!this._transport) {
|
|
226
|
+
this._transport = new McpSSETransport(() => this.getWebSocket());
|
|
227
|
+
await server.connect(this._transport);
|
|
245
228
|
}
|
|
246
|
-
return
|
|
229
|
+
return this._agent.fetch(request);
|
|
247
230
|
}
|
|
248
231
|
case "/streamable-http": {
|
|
249
|
-
if (!
|
|
250
|
-
|
|
232
|
+
if (!this._transport) {
|
|
233
|
+
this._transport = new McpStreamableHttpTransport(
|
|
251
234
|
(id) => this.getWebSocketForResponseID(id),
|
|
252
|
-
(id) =>
|
|
253
|
-
)
|
|
254
|
-
await server.connect(
|
|
235
|
+
(id) => this._requestIdToConnectionId.delete(id)
|
|
236
|
+
);
|
|
237
|
+
await server.connect(this._transport);
|
|
255
238
|
}
|
|
256
239
|
await this.ctx.storage.put("transportType", "streamable-http");
|
|
257
|
-
|
|
258
|
-
return
|
|
240
|
+
this._transportType = "streamable-http";
|
|
241
|
+
return this._agent.fetch(request);
|
|
259
242
|
}
|
|
260
243
|
default:
|
|
261
244
|
return new Response(
|
|
@@ -274,19 +257,19 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
274
257
|
return websockets[0];
|
|
275
258
|
}
|
|
276
259
|
getWebSocketForResponseID(id) {
|
|
277
|
-
const connectionId =
|
|
260
|
+
const connectionId = this._requestIdToConnectionId.get(id);
|
|
278
261
|
if (connectionId === void 0) {
|
|
279
262
|
return null;
|
|
280
263
|
}
|
|
281
|
-
return
|
|
264
|
+
return this._agent.getConnection(connectionId) ?? null;
|
|
282
265
|
}
|
|
283
266
|
// All messages received here. This is currently never called
|
|
284
267
|
async onMessage(connection, event) {
|
|
285
|
-
if (
|
|
268
|
+
if (this._transportType !== "streamable-http") {
|
|
286
269
|
const err = new Error(
|
|
287
270
|
"Internal Server Error: Expected streamable-http protocol"
|
|
288
271
|
);
|
|
289
|
-
|
|
272
|
+
this._transport?.onerror?.(err);
|
|
290
273
|
return;
|
|
291
274
|
}
|
|
292
275
|
let message;
|
|
@@ -294,21 +277,21 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
294
277
|
const data = typeof event === "string" ? event : new TextDecoder().decode(event);
|
|
295
278
|
message = JSONRPCMessageSchema.parse(JSON.parse(data));
|
|
296
279
|
} catch (error) {
|
|
297
|
-
|
|
280
|
+
this._transport?.onerror?.(error);
|
|
298
281
|
return;
|
|
299
282
|
}
|
|
300
283
|
if (isJSONRPCRequest(message)) {
|
|
301
|
-
|
|
284
|
+
this._requestIdToConnectionId.set(message.id.toString(), connection.id);
|
|
302
285
|
}
|
|
303
|
-
|
|
286
|
+
this._transport?.onmessage?.(message);
|
|
304
287
|
}
|
|
305
288
|
// All messages received over SSE after the initial connection has been established
|
|
306
289
|
// will be passed here
|
|
307
290
|
async onSSEMcpMessage(sessionId, request) {
|
|
308
|
-
if (
|
|
309
|
-
await
|
|
291
|
+
if (this._status !== "started") {
|
|
292
|
+
await this._initialize();
|
|
310
293
|
}
|
|
311
|
-
if (
|
|
294
|
+
if (this._transportType !== "sse") {
|
|
312
295
|
return new Error("Internal Server Error: Expected SSE protocol");
|
|
313
296
|
}
|
|
314
297
|
try {
|
|
@@ -317,36 +300,36 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
317
300
|
try {
|
|
318
301
|
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
319
302
|
} catch (error) {
|
|
320
|
-
|
|
303
|
+
this._transport?.onerror?.(error);
|
|
321
304
|
throw error;
|
|
322
305
|
}
|
|
323
|
-
|
|
306
|
+
this._transport?.onmessage?.(parsedMessage);
|
|
324
307
|
return null;
|
|
325
308
|
} catch (error) {
|
|
326
309
|
console.error("Error forwarding message to SSE:", error);
|
|
327
|
-
|
|
310
|
+
this._transport?.onerror?.(error);
|
|
328
311
|
return error;
|
|
329
312
|
}
|
|
330
313
|
}
|
|
331
314
|
// Delegate all websocket events to the underlying agent
|
|
332
315
|
async webSocketMessage(ws, event) {
|
|
333
|
-
if (
|
|
334
|
-
await
|
|
316
|
+
if (this._status !== "started") {
|
|
317
|
+
await this._initialize();
|
|
335
318
|
}
|
|
336
|
-
return await
|
|
319
|
+
return await this._agent.webSocketMessage(ws, event);
|
|
337
320
|
}
|
|
338
321
|
// WebSocket event handlers for hibernation support
|
|
339
322
|
async webSocketError(ws, error) {
|
|
340
|
-
if (
|
|
341
|
-
await
|
|
323
|
+
if (this._status !== "started") {
|
|
324
|
+
await this._initialize();
|
|
342
325
|
}
|
|
343
|
-
return await
|
|
326
|
+
return await this._agent.webSocketError(ws, error);
|
|
344
327
|
}
|
|
345
328
|
async webSocketClose(ws, code, reason, wasClean) {
|
|
346
|
-
if (
|
|
347
|
-
await
|
|
329
|
+
if (this._status !== "started") {
|
|
330
|
+
await this._initialize();
|
|
348
331
|
}
|
|
349
|
-
return await
|
|
332
|
+
return await this._agent.webSocketClose(ws, code, reason, wasClean);
|
|
350
333
|
}
|
|
351
334
|
static mount(path, {
|
|
352
335
|
binding = "MCP_OBJECT",
|
|
@@ -376,7 +359,7 @@ var _McpAgent = class _McpAgent extends DurableObject {
|
|
|
376
359
|
);
|
|
377
360
|
return new Response("Invalid binding", { status: 500 });
|
|
378
361
|
}
|
|
379
|
-
if (bindingValue
|
|
362
|
+
if (!isDurableObjectNamespace(bindingValue)) {
|
|
380
363
|
return new Response("Invalid binding", { status: 500 });
|
|
381
364
|
}
|
|
382
365
|
const namespace = bindingValue;
|
|
@@ -460,7 +443,7 @@ data: ${JSON.stringify(result.data)}
|
|
|
460
443
|
"Content-Type": "text/event-stream",
|
|
461
444
|
"Cache-Control": "no-cache",
|
|
462
445
|
Connection: "keep-alive",
|
|
463
|
-
|
|
446
|
+
...corsHeaders(request, corsOptions)
|
|
464
447
|
}
|
|
465
448
|
});
|
|
466
449
|
}
|
|
@@ -500,7 +483,7 @@ data: ${JSON.stringify(result.data)}
|
|
|
500
483
|
"Content-Type": "text/event-stream",
|
|
501
484
|
"Cache-Control": "no-cache",
|
|
502
485
|
Connection: "keep-alive",
|
|
503
|
-
|
|
486
|
+
...corsHeaders(request, corsOptions)
|
|
504
487
|
}
|
|
505
488
|
});
|
|
506
489
|
}
|
|
@@ -510,7 +493,7 @@ data: ${JSON.stringify(result.data)}
|
|
|
510
493
|
"Content-Type": "text/event-stream",
|
|
511
494
|
"Cache-Control": "no-cache",
|
|
512
495
|
Connection: "keep-alive",
|
|
513
|
-
|
|
496
|
+
...corsHeaders(request, corsOptions)
|
|
514
497
|
}
|
|
515
498
|
});
|
|
516
499
|
}
|
|
@@ -541,7 +524,7 @@ data: ${JSON.stringify(result.data)}
|
|
|
541
524
|
);
|
|
542
525
|
return new Response("Invalid binding", { status: 500 });
|
|
543
526
|
}
|
|
544
|
-
if (bindingValue
|
|
527
|
+
if (!isDurableObjectNamespace(bindingValue)) {
|
|
545
528
|
return new Response("Invalid binding", { status: 500 });
|
|
546
529
|
}
|
|
547
530
|
const namespace = bindingValue;
|
|
@@ -758,7 +741,10 @@ data: ${JSON.stringify(result.data)}
|
|
|
758
741
|
ws.send(JSON.stringify(message));
|
|
759
742
|
}
|
|
760
743
|
ws.close();
|
|
761
|
-
return new Response(null, {
|
|
744
|
+
return new Response(null, {
|
|
745
|
+
status: 202,
|
|
746
|
+
headers: corsHeaders(request, corsOptions)
|
|
747
|
+
});
|
|
762
748
|
}
|
|
763
749
|
for (const message of messages) {
|
|
764
750
|
if (isJSONRPCRequest(message)) {
|
|
@@ -772,7 +758,7 @@ data: ${JSON.stringify(result.data)}
|
|
|
772
758
|
"Cache-Control": "no-cache",
|
|
773
759
|
Connection: "keep-alive",
|
|
774
760
|
"mcp-session-id": sessionId,
|
|
775
|
-
|
|
761
|
+
...corsHeaders(request, corsOptions)
|
|
776
762
|
},
|
|
777
763
|
status: 200
|
|
778
764
|
});
|
|
@@ -790,20 +776,6 @@ data: ${JSON.stringify(result.data)}
|
|
|
790
776
|
};
|
|
791
777
|
}
|
|
792
778
|
};
|
|
793
|
-
_status = new WeakMap();
|
|
794
|
-
_transport = new WeakMap();
|
|
795
|
-
_transportType = new WeakMap();
|
|
796
|
-
_requestIdToConnectionId = new WeakMap();
|
|
797
|
-
_agent = new WeakMap();
|
|
798
|
-
_McpAgent_instances = new WeakSet();
|
|
799
|
-
initialize_fn = async function() {
|
|
800
|
-
await this.ctx.blockConcurrencyWhile(async () => {
|
|
801
|
-
__privateSet(this, _status, "starting");
|
|
802
|
-
await this.onStart();
|
|
803
|
-
__privateSet(this, _status, "started");
|
|
804
|
-
});
|
|
805
|
-
};
|
|
806
|
-
var McpAgent = _McpAgent;
|
|
807
779
|
export {
|
|
808
780
|
McpAgent
|
|
809
781
|
};
|