agents 0.0.0-f5b5854 → 0.0.0-f64700e

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.
Files changed (70) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +56 -11
  3. package/dist/ai-chat-agent.js +532 -160
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-gdyLiTd8.js +155 -0
  6. package/dist/ai-chat-v5-migration-gdyLiTd8.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +73 -72
  10. package/dist/ai-react.js +261 -188
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-BWW4umHY.d.ts +95 -0
  13. package/dist/ai-types-UZlfLOYP.js +20 -0
  14. package/dist/ai-types-UZlfLOYP.js.map +1 -0
  15. package/dist/ai-types.d.ts +6 -69
  16. package/dist/ai-types.js +3 -1
  17. package/dist/client-C-nwz-3N.d.ts +5313 -0
  18. package/dist/client-CZBVDDoO.js +786 -0
  19. package/dist/client-CZBVDDoO.js.map +1 -0
  20. package/dist/client-CmMi85Sj.d.ts +104 -0
  21. package/dist/client-DjR-lC16.js +117 -0
  22. package/dist/client-DjR-lC16.js.map +1 -0
  23. package/dist/client.d.ts +12 -79
  24. package/dist/client.js +3 -130
  25. package/dist/codemode/ai.d.ts +27 -0
  26. package/dist/codemode/ai.js +151 -0
  27. package/dist/codemode/ai.js.map +1 -0
  28. package/dist/do-oauth-client-provider-B2jr6UNq.js +93 -0
  29. package/dist/do-oauth-client-provider-B2jr6UNq.js.map +1 -0
  30. package/dist/do-oauth-client-provider-CCwGwnrA.d.ts +55 -0
  31. package/dist/index-CMEWpbHx.d.ts +568 -0
  32. package/dist/index-W4JUkafc.d.ts +54 -0
  33. package/dist/index.d.ts +63 -295
  34. package/dist/index.js +7 -20
  35. package/dist/mcp/client.d.ts +4 -763
  36. package/dist/mcp/client.js +2 -407
  37. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  38. package/dist/mcp/do-oauth-client-provider.js +2 -106
  39. package/dist/mcp/index.d.ts +73 -59
  40. package/dist/mcp/index.js +838 -769
  41. package/dist/mcp/index.js.map +1 -1
  42. package/dist/mcp/x402.d.ts +34 -0
  43. package/dist/mcp/x402.js +194 -0
  44. package/dist/mcp/x402.js.map +1 -0
  45. package/dist/mcp-BEwaCsxO.d.ts +61 -0
  46. package/dist/observability/index.d.ts +3 -0
  47. package/dist/observability/index.js +7 -0
  48. package/dist/react-jvtffQuA.d.ts +113 -0
  49. package/dist/react.d.ts +10 -39
  50. package/dist/react.js +183 -98
  51. package/dist/react.js.map +1 -1
  52. package/dist/schedule.d.ts +89 -12
  53. package/dist/schedule.js +46 -23
  54. package/dist/schedule.js.map +1 -1
  55. package/dist/serializable-gtr9YMhp.d.ts +34 -0
  56. package/dist/serializable.d.ts +7 -0
  57. package/dist/serializable.js +1 -0
  58. package/dist/src-L3cHuAag.js +1231 -0
  59. package/dist/src-L3cHuAag.js.map +1 -0
  60. package/package.json +110 -64
  61. package/src/index.ts +1407 -152
  62. package/dist/ai-types.js.map +0 -1
  63. package/dist/chunk-HMLY7DHA.js +0 -16
  64. package/dist/chunk-HMLY7DHA.js.map +0 -1
  65. package/dist/chunk-XG52S6YY.js +0 -591
  66. package/dist/chunk-XG52S6YY.js.map +0 -1
  67. package/dist/client.js.map +0 -1
  68. package/dist/index.js.map +0 -1
  69. package/dist/mcp/client.js.map +0 -1
  70. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
@@ -1,408 +1,3 @@
1
- import "../chunk-HMLY7DHA.js";
1
+ import { MCPClientManager, getNamespacedData } from "../client-CZBVDDoO.js";
2
2
 
3
- // src/mcp/sse-edge.ts
4
- import {
5
- SSEClientTransport
6
- } from "@modelcontextprotocol/sdk/client/sse.js";
7
- var SSEEdgeClientTransport = class extends SSEClientTransport {
8
- /**
9
- * Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
10
- */
11
- constructor(url, options) {
12
- const fetchOverride = async (fetchUrl, fetchInit = {}) => {
13
- const headers = await this.authHeaders();
14
- const workerOptions = {
15
- ...fetchInit,
16
- headers: {
17
- ...fetchInit?.headers,
18
- ...headers
19
- }
20
- };
21
- delete workerOptions.mode;
22
- return fetch(fetchUrl, workerOptions);
23
- };
24
- super(url, {
25
- ...options,
26
- eventSourceInit: {
27
- fetch: fetchOverride
28
- }
29
- });
30
- this.authProvider = options.authProvider;
31
- }
32
- async authHeaders() {
33
- if (this.authProvider) {
34
- const tokens = await this.authProvider.tokens();
35
- if (tokens) {
36
- return {
37
- Authorization: `Bearer ${tokens.access_token}`
38
- };
39
- }
40
- }
41
- }
42
- };
43
-
44
- // src/mcp/client-connection.ts
45
- import {
46
- ToolListChangedNotificationSchema,
47
- ResourceListChangedNotificationSchema,
48
- PromptListChangedNotificationSchema
49
- } from "@modelcontextprotocol/sdk/types.js";
50
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
51
- var MCPClientConnection = class {
52
- constructor(url, info, options = { transport: {}, client: {}, capabilities: {} }) {
53
- this.url = url;
54
- this.options = options;
55
- this.connectionState = "connecting";
56
- this.tools = [];
57
- this.prompts = [];
58
- this.resources = [];
59
- this.resourceTemplates = [];
60
- this.client = new Client(info, options.client);
61
- this.client.registerCapabilities(options.capabilities);
62
- }
63
- /**
64
- * Initialize a client connection
65
- *
66
- * @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
67
- * @returns
68
- */
69
- async init(code, clientId) {
70
- try {
71
- const transport = new SSEEdgeClientTransport(
72
- this.url,
73
- this.options.transport
74
- );
75
- if (code) {
76
- await transport.finishAuth(code);
77
- }
78
- await this.client.connect(transport);
79
- } catch (e) {
80
- if (e.toString().includes("Unauthorized")) {
81
- this.connectionState = "authenticating";
82
- return;
83
- }
84
- this.connectionState = "failed";
85
- throw e;
86
- }
87
- this.connectionState = "discovering";
88
- this.serverCapabilities = await this.client.getServerCapabilities();
89
- if (!this.serverCapabilities) {
90
- throw new Error("The MCP Server failed to return server capabilities");
91
- }
92
- const [instructions, tools, resources, prompts, resourceTemplates] = await Promise.all([
93
- this.client.getInstructions(),
94
- this.registerTools(),
95
- this.registerResources(),
96
- this.registerPrompts(),
97
- this.registerResourceTemplates()
98
- ]);
99
- this.instructions = instructions;
100
- this.tools = tools;
101
- this.resources = resources;
102
- this.prompts = prompts;
103
- this.resourceTemplates = resourceTemplates;
104
- this.connectionState = "ready";
105
- }
106
- /**
107
- * Notification handler registration
108
- */
109
- async registerTools() {
110
- if (!this.serverCapabilities || !this.serverCapabilities.tools) {
111
- return [];
112
- }
113
- if (this.serverCapabilities.tools.listChanged) {
114
- this.client.setNotificationHandler(
115
- ToolListChangedNotificationSchema,
116
- async (_notification) => {
117
- this.tools = await this.fetchTools();
118
- }
119
- );
120
- }
121
- return this.fetchTools();
122
- }
123
- async registerResources() {
124
- if (!this.serverCapabilities || !this.serverCapabilities.resources) {
125
- return [];
126
- }
127
- if (this.serverCapabilities.resources.listChanged) {
128
- this.client.setNotificationHandler(
129
- ResourceListChangedNotificationSchema,
130
- async (_notification) => {
131
- this.resources = await this.fetchResources();
132
- }
133
- );
134
- }
135
- return this.fetchResources();
136
- }
137
- async registerPrompts() {
138
- if (!this.serverCapabilities || !this.serverCapabilities.prompts) {
139
- return [];
140
- }
141
- if (this.serverCapabilities.prompts.listChanged) {
142
- this.client.setNotificationHandler(
143
- PromptListChangedNotificationSchema,
144
- async (_notification) => {
145
- this.prompts = await this.fetchPrompts();
146
- }
147
- );
148
- }
149
- return this.fetchPrompts();
150
- }
151
- async registerResourceTemplates() {
152
- if (!this.serverCapabilities || !this.serverCapabilities.resources) {
153
- return [];
154
- }
155
- return this.fetchResourceTemplates();
156
- }
157
- async fetchTools() {
158
- let toolsAgg = [];
159
- let toolsResult = { tools: [] };
160
- do {
161
- toolsResult = await this.client.listTools({
162
- cursor: toolsResult.nextCursor
163
- }).catch(capabilityErrorHandler({ tools: [] }, "tools/list"));
164
- toolsAgg = toolsAgg.concat(toolsResult.tools);
165
- } while (toolsResult.nextCursor);
166
- return toolsAgg;
167
- }
168
- async fetchResources() {
169
- let resourcesAgg = [];
170
- let resourcesResult = { resources: [] };
171
- do {
172
- resourcesResult = await this.client.listResources({
173
- cursor: resourcesResult.nextCursor
174
- }).catch(capabilityErrorHandler({ resources: [] }, "resources/list"));
175
- resourcesAgg = resourcesAgg.concat(resourcesResult.resources);
176
- } while (resourcesResult.nextCursor);
177
- return resourcesAgg;
178
- }
179
- async fetchPrompts() {
180
- let promptsAgg = [];
181
- let promptsResult = { prompts: [] };
182
- do {
183
- promptsResult = await this.client.listPrompts({
184
- cursor: promptsResult.nextCursor
185
- }).catch(capabilityErrorHandler({ prompts: [] }, "prompts/list"));
186
- promptsAgg = promptsAgg.concat(promptsResult.prompts);
187
- } while (promptsResult.nextCursor);
188
- return promptsAgg;
189
- }
190
- async fetchResourceTemplates() {
191
- let templatesAgg = [];
192
- let templatesResult = {
193
- resourceTemplates: []
194
- };
195
- do {
196
- templatesResult = await this.client.listResourceTemplates({
197
- cursor: templatesResult.nextCursor
198
- }).catch(
199
- capabilityErrorHandler(
200
- { resourceTemplates: [] },
201
- "resources/templates/list"
202
- )
203
- );
204
- templatesAgg = templatesAgg.concat(templatesResult.resourceTemplates);
205
- } while (templatesResult.nextCursor);
206
- return templatesAgg;
207
- }
208
- };
209
- function capabilityErrorHandler(empty, method) {
210
- return (e) => {
211
- if (e.code === -32601) {
212
- console.error(
213
- `The server advertised support for the capability ${method.split("/")[0]}, but returned "Method not found" for '${method}'.`
214
- );
215
- return empty;
216
- }
217
- throw e;
218
- };
219
- }
220
-
221
- // src/mcp/client.ts
222
- var MCPClientManager = class {
223
- /**
224
- * @param name Name of the MCP client
225
- * @param version Version of the MCP Client
226
- * @param auth Auth paramters if being used to create a DurableObjectOAuthClientProvider
227
- */
228
- constructor(name, version) {
229
- this.name = name;
230
- this.version = version;
231
- this.mcpConnections = {};
232
- this.callbackUrls = [];
233
- }
234
- /**
235
- * Connect to and register an MCP server
236
- *
237
- * @param transportConfig Transport config
238
- * @param clientConfig Client config
239
- * @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
240
- */
241
- async connect(url, options = {}) {
242
- const id = options.reconnect?.id ?? crypto.randomUUID();
243
- if (!options.transport?.authProvider) {
244
- console.warn(
245
- "No authProvider provided in the transport options. This client will only support unauthenticated remote MCP Servers"
246
- );
247
- } else {
248
- options.transport.authProvider.serverId = id;
249
- }
250
- this.mcpConnections[id] = new MCPClientConnection(
251
- new URL(url),
252
- {
253
- name: this.name,
254
- version: this.version
255
- },
256
- {
257
- transport: options.transport ?? {},
258
- client: options.client ?? {},
259
- capabilities: options.client ?? {}
260
- }
261
- );
262
- await this.mcpConnections[id].init(
263
- options.reconnect?.oauthCode,
264
- options.reconnect?.oauthClientId
265
- );
266
- const authUrl = options.transport?.authProvider?.authUrl;
267
- if (authUrl && options.transport?.authProvider?.redirectUrl) {
268
- this.callbackUrls.push(
269
- options.transport.authProvider.redirectUrl.toString()
270
- );
271
- }
272
- return {
273
- id,
274
- authUrl
275
- };
276
- }
277
- isCallbackRequest(req) {
278
- return req.method === "GET" && !!this.callbackUrls.find((url) => {
279
- return req.url.startsWith(url);
280
- });
281
- }
282
- async handleCallbackRequest(req) {
283
- const url = new URL(req.url);
284
- const urlMatch = this.callbackUrls.find((url2) => {
285
- return req.url.startsWith(url2);
286
- });
287
- if (!urlMatch) {
288
- throw new Error(
289
- `No callback URI match found for the request url: ${req.url}. Was the request matched with \`isCallbackRequest()\`?`
290
- );
291
- }
292
- const code = url.searchParams.get("code");
293
- const clientId = url.searchParams.get("state");
294
- const urlParams = urlMatch.split("/");
295
- const serverId = urlParams[urlParams.length - 1];
296
- if (!code) {
297
- throw new Error("Unauthorized: no code provided");
298
- }
299
- if (!clientId) {
300
- throw new Error("Unauthorized: no state provided");
301
- }
302
- if (this.mcpConnections[serverId] === void 0) {
303
- throw new Error(`Could not find serverId: ${serverId}`);
304
- }
305
- if (this.mcpConnections[serverId].connectionState !== "authenticating") {
306
- throw new Error(
307
- "Failed to authenticate: the client isn't in the `authenticating` state"
308
- );
309
- }
310
- const conn = this.mcpConnections[serverId];
311
- if (!conn.options.transport.authProvider) {
312
- throw new Error(
313
- "Trying to finalize authentication for a server connection without an authProvider"
314
- );
315
- }
316
- conn.options.transport.authProvider.clientId = clientId;
317
- conn.options.transport.authProvider.serverId = serverId;
318
- const serverUrl = conn.url.toString();
319
- await this.connect(serverUrl, {
320
- reconnect: {
321
- id: serverId,
322
- oauthClientId: clientId,
323
- oauthCode: code
324
- },
325
- ...conn.options
326
- });
327
- if (this.mcpConnections[serverId].connectionState === "authenticating") {
328
- throw new Error("Failed to authenticate: client failed to initialize");
329
- }
330
- return { serverId };
331
- }
332
- /**
333
- * @returns namespaced list of tools
334
- */
335
- listTools() {
336
- return getNamespacedData(this.mcpConnections, "tools");
337
- }
338
- /**
339
- * @returns namespaced list of prompts
340
- */
341
- listPrompts() {
342
- return getNamespacedData(this.mcpConnections, "prompts");
343
- }
344
- /**
345
- * @returns namespaced list of tools
346
- */
347
- listResources() {
348
- return getNamespacedData(this.mcpConnections, "resources");
349
- }
350
- /**
351
- * @returns namespaced list of resource templates
352
- */
353
- listResourceTemplates() {
354
- return getNamespacedData(this.mcpConnections, "resourceTemplates");
355
- }
356
- /**
357
- * Namespaced version of callTool
358
- */
359
- callTool(params, resultSchema, options) {
360
- const unqualifiedName = params.name.replace(`${params.serverId}.`, "");
361
- return this.mcpConnections[params.serverId].client.callTool(
362
- {
363
- ...params,
364
- name: unqualifiedName
365
- },
366
- resultSchema,
367
- options
368
- );
369
- }
370
- /**
371
- * Namespaced version of readResource
372
- */
373
- readResource(params, options) {
374
- return this.mcpConnections[params.serverId].client.readResource(
375
- params,
376
- options
377
- );
378
- }
379
- /**
380
- * Namespaced version of getPrompt
381
- */
382
- getPrompt(params, options) {
383
- return this.mcpConnections[params.serverId].client.getPrompt(
384
- params,
385
- options
386
- );
387
- }
388
- };
389
- function getNamespacedData(mcpClients, type) {
390
- const sets = Object.entries(mcpClients).map(([name, conn]) => {
391
- return { name, data: conn[type] };
392
- });
393
- const namespacedData = sets.flatMap(({ name: serverId, data }) => {
394
- return data.map((item) => {
395
- return {
396
- ...item,
397
- // we add a serverId so we can easily pull it out and send the tool call to the right server
398
- serverId
399
- };
400
- });
401
- });
402
- return namespacedData;
403
- }
404
- export {
405
- MCPClientManager,
406
- getNamespacedData
407
- };
408
- //# sourceMappingURL=client.js.map
3
+ export { MCPClientManager, getNamespacedData };
@@ -1,41 +1,2 @@
1
- import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
2
- import { OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
3
-
4
- interface AgentsOAuthProvider extends OAuthClientProvider {
5
- authUrl: string | undefined;
6
- clientId: string | undefined;
7
- serverId: string | undefined;
8
- }
9
- declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
10
- storage: DurableObjectStorage;
11
- clientName: string;
12
- baseRedirectUrl: string;
13
- private authUrl_;
14
- private serverId_;
15
- private clientId_;
16
- constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
- get clientMetadata(): OAuthClientMetadata;
18
- get redirectUrl(): string;
19
- get clientId(): string;
20
- set clientId(clientId_: string);
21
- get serverId(): string;
22
- set serverId(serverId_: string);
23
- keyPrefix(clientId: string): string;
24
- clientInfoKey(clientId: string): string;
25
- clientInformation(): Promise<OAuthClientInformation | undefined>;
26
- saveClientInformation(clientInformation: OAuthClientInformationFull): Promise<void>;
27
- tokenKey(clientId: string): string;
28
- tokens(): Promise<OAuthTokens | undefined>;
29
- saveTokens(tokens: OAuthTokens): Promise<void>;
30
- get authUrl(): string | undefined;
31
- /**
32
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
33
- * and require user interact to initiate the redirect flow
34
- */
35
- redirectToAuthorization(authUrl: URL): Promise<void>;
36
- codeVerifierKey(clientId: string): string;
37
- saveCodeVerifier(verifier: string): Promise<void>;
38
- codeVerifier(): Promise<string>;
39
- }
40
-
41
- export { type AgentsOAuthProvider, DurableObjectOAuthClientProvider };
1
+ import { AgentsOAuthProvider, DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-CCwGwnrA.js";
2
+ export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,107 +1,3 @@
1
- import "../chunk-HMLY7DHA.js";
1
+ import { DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B2jr6UNq.js";
2
2
 
3
- // src/mcp/do-oauth-client-provider.ts
4
- var DurableObjectOAuthClientProvider = class {
5
- constructor(storage, clientName, baseRedirectUrl) {
6
- this.storage = storage;
7
- this.clientName = clientName;
8
- this.baseRedirectUrl = baseRedirectUrl;
9
- }
10
- get clientMetadata() {
11
- return {
12
- redirect_uris: [this.redirectUrl],
13
- token_endpoint_auth_method: "none",
14
- grant_types: ["authorization_code", "refresh_token"],
15
- response_types: ["code"],
16
- client_name: this.clientName,
17
- client_uri: "example.com"
18
- };
19
- }
20
- get redirectUrl() {
21
- return `${this.baseRedirectUrl}/${this.serverId}`;
22
- }
23
- get clientId() {
24
- if (!this.clientId_) {
25
- throw new Error("Trying to access clientId before it was set");
26
- }
27
- return this.clientId_;
28
- }
29
- set clientId(clientId_) {
30
- this.clientId_ = clientId_;
31
- }
32
- get serverId() {
33
- if (!this.serverId_) {
34
- throw new Error("Trying to access serverId before it was set");
35
- }
36
- return this.serverId_;
37
- }
38
- set serverId(serverId_) {
39
- this.serverId_ = serverId_;
40
- }
41
- keyPrefix(clientId) {
42
- return `/${this.clientName}/${this.serverId}/${clientId}`;
43
- }
44
- clientInfoKey(clientId) {
45
- return `${this.keyPrefix(clientId)}/client_info/`;
46
- }
47
- async clientInformation() {
48
- if (!this.clientId_) {
49
- return void 0;
50
- }
51
- return await this.storage.get(
52
- this.clientInfoKey(this.clientId)
53
- ) ?? void 0;
54
- }
55
- async saveClientInformation(clientInformation) {
56
- await this.storage.put(
57
- this.clientInfoKey(clientInformation.client_id),
58
- clientInformation
59
- );
60
- this.clientId = clientInformation.client_id;
61
- }
62
- tokenKey(clientId) {
63
- return `${this.keyPrefix(clientId)}/token`;
64
- }
65
- async tokens() {
66
- if (!this.clientId_) {
67
- return void 0;
68
- }
69
- return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
70
- }
71
- async saveTokens(tokens) {
72
- await this.storage.put(this.tokenKey(this.clientId), tokens);
73
- }
74
- get authUrl() {
75
- return this.authUrl_;
76
- }
77
- /**
78
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
79
- * and require user interact to initiate the redirect flow
80
- */
81
- async redirectToAuthorization(authUrl) {
82
- const client_id = authUrl.searchParams.get("client_id");
83
- if (client_id) {
84
- authUrl.searchParams.append("state", client_id);
85
- }
86
- this.authUrl_ = authUrl.toString();
87
- }
88
- codeVerifierKey(clientId) {
89
- return `${this.keyPrefix(clientId)}/code_verifier`;
90
- }
91
- async saveCodeVerifier(verifier) {
92
- await this.storage.put(this.codeVerifierKey(this.clientId), verifier);
93
- }
94
- async codeVerifier() {
95
- const codeVerifier = await this.storage.get(
96
- this.codeVerifierKey(this.clientId)
97
- );
98
- if (!codeVerifier) {
99
- throw new Error("No code verifier found");
100
- }
101
- return codeVerifier;
102
- }
103
- };
104
- export {
105
- DurableObjectOAuthClientProvider
106
- };
107
- //# sourceMappingURL=do-oauth-client-provider.js.map
3
+ export { DurableObjectOAuthClientProvider };
@@ -1,61 +1,75 @@
1
- import { DurableObject } from 'cloudflare:workers';
2
- import { Connection, WSMessage } from 'partyserver';
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
1
+ import { BaseTransportType, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MaybePromise, SSEEdgeClientTransport, ServeOptions, StreamableHTTPEdgeClientTransport } from "../client-C-nwz-3N.js";
2
+ import "../mcp-BEwaCsxO.js";
3
+ import "../do-oauth-client-provider-CCwGwnrA.js";
4
+ import "../index-W4JUkafc.js";
5
+ import "../ai-types-BWW4umHY.js";
6
+ import { Agent, Connection, ConnectionContext } from "../index-CMEWpbHx.js";
7
+ import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
8
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
10
 
5
- interface CORSOptions {
6
- origin?: string;
7
- methods?: string;
8
- headers?: string;
9
- maxAge?: number;
11
+ //#region src/mcp/index.d.ts
12
+ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
13
+ private _transport?;
14
+ props?: Props;
15
+ abstract server: MaybePromise<McpServer | Server>;
16
+ abstract init(): Promise<void>;
17
+ setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
18
+ getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
19
+ /** Read the transport type for this agent.
20
+ * This relies on the naming scheme being `sse:${sessionId}`
21
+ * or `streamable-http:${sessionId}`.
22
+ */
23
+ getTransportType(): BaseTransportType;
24
+ /** Read the sessionId for this agent.
25
+ * This relies on the naming scheme being `sse:${sessionId}`
26
+ * or `streamable-http:${sessionId}`.
27
+ */
28
+ getSessionId(): string;
29
+ /** Get the unique WebSocket. SSE transport only. */
30
+ private getWebSocket;
31
+ /** Returns a new transport matching the type of the Agent. */
32
+ private initTransport;
33
+ /** Update and store the props */
34
+ updateProps(props?: Props): Promise<void>;
35
+ reinitializeServer(): Promise<void>;
36
+ /** Sets up the MCP transport and server every time the Agent is started.*/
37
+ onStart(props?: Props): Promise<void>;
38
+ /** Validates new WebSocket connections. */
39
+ onConnect(conn: Connection, {
40
+ request: req
41
+ }: ConnectionContext): Promise<void>;
42
+ /** Handles MCP Messages for the legacy SSE transport. */
43
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
44
+ /** Elicit user input with a message and schema */
45
+ elicitInput(params: {
46
+ message: string;
47
+ requestedSchema: unknown;
48
+ }): Promise<ElicitResult$1>;
49
+ /** Wait for elicitation response through storage polling */
50
+ private _waitForElicitationResponse;
51
+ /** Handle elicitation responses */
52
+ private _handleElicitationResponse;
53
+ /** Return a handler for the given path for this MCP.
54
+ * Defaults to Streamable HTTP transport.
55
+ */
56
+ static serve(path: string, {
57
+ binding,
58
+ corsOptions,
59
+ transport
60
+ }?: ServeOptions): {
61
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
62
+ };
63
+ /**
64
+ * Legacy api
65
+ **/
66
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
67
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
68
+ };
69
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
70
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
71
+ };
10
72
  }
11
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
12
- #private;
13
- protected constructor(ctx: DurableObjectState, env: Env);
14
- /**
15
- * Agents API allowlist
16
- */
17
- initialState: State;
18
- get state(): State;
19
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
20
- setState(state: State): void;
21
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
22
- onStart(): Promise<void>;
23
- /**
24
- * McpAgent API
25
- */
26
- abstract server: McpServer;
27
- props: Props;
28
- initRun: boolean;
29
- abstract init(): Promise<void>;
30
- _init(props: Props): Promise<void>;
31
- setInitialized(): Promise<void>;
32
- isInitialized(): Promise<boolean>;
33
- fetch(request: Request): Promise<Response>;
34
- getWebSocket(): WebSocket | null;
35
- getWebSocketForResponseID(id: string): WebSocket | null;
36
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
37
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
38
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
39
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
40
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
41
- static mount(path: string, { binding, corsOptions, }?: {
42
- binding?: string;
43
- corsOptions?: CORSOptions;
44
- }): {
45
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
46
- };
47
- static serveSSE(path: string, { binding, corsOptions, }?: {
48
- binding?: string;
49
- corsOptions?: CORSOptions;
50
- }): {
51
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
52
- };
53
- static serve(path: string, { binding, corsOptions, }?: {
54
- binding?: string;
55
- corsOptions?: CORSOptions;
56
- }): {
57
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
58
- };
59
- }
60
-
61
- export { McpAgent };
73
+ //#endregion
74
+ export { type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
75
+ //# sourceMappingURL=index.d.ts.map