agents 0.0.0-cebd0de → 0.0.0-cec3cca
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +255 -27
- package/dist/ai-chat-agent.d.ts +59 -11
- package/dist/ai-chat-agent.js +532 -160
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration-DBHGW4Hv.js +155 -0
- package/dist/ai-chat-v5-migration-DBHGW4Hv.js.map +1 -0
- package/dist/ai-chat-v5-migration.d.ts +155 -0
- package/dist/ai-chat-v5-migration.js +3 -0
- package/dist/ai-react.d.ts +73 -72
- package/dist/ai-react.js +261 -192
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types-B3aQaFv3.js +20 -0
- package/dist/ai-types-B3aQaFv3.js.map +1 -0
- package/dist/ai-types-D5YoPrBZ.d.ts +95 -0
- package/dist/ai-types.d.ts +6 -69
- package/dist/ai-types.js +3 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-9Ld2_lnt.js +786 -0
- package/dist/client-9Ld2_lnt.js.map +1 -0
- package/dist/client-BfiZ3HQd.js +117 -0
- package/dist/client-BfiZ3HQd.js.map +1 -0
- package/dist/client-CbWe9FBd.d.ts +104 -0
- package/dist/client-Csp_m13H.d.ts +5315 -0
- package/dist/client.d.ts +12 -79
- package/dist/client.js +3 -130
- package/dist/codemode/ai.d.ts +27 -0
- package/dist/codemode/ai.js +151 -0
- package/dist/codemode/ai.js.map +1 -0
- package/dist/do-oauth-client-provider-CswoD5Lu.js +93 -0
- package/dist/do-oauth-client-provider-CswoD5Lu.js.map +1 -0
- package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +55 -0
- package/dist/index-DFqsR7mb.d.ts +560 -0
- package/dist/index-DhJCaDWd.d.ts +58 -0
- package/dist/index.d.ts +63 -301
- package/dist/index.js +7 -22
- package/dist/mcp/client.d.ts +4 -714
- package/dist/mcp/client.js +2 -470
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -0
- package/dist/mcp/do-oauth-client-provider.js +3 -0
- package/dist/mcp/index.d.ts +151 -41
- package/dist/mcp/index.js +1362 -332
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +34 -0
- package/dist/mcp/x402.js +194 -0
- package/dist/mcp/x402.js.map +1 -0
- package/dist/mcp-Dw5vDrY8.d.ts +61 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +7 -0
- package/dist/react-NCPvtyCY.d.ts +115 -0
- package/dist/react.d.ts +10 -39
- package/dist/react.js +183 -98
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +89 -12
- package/dist/schedule.js +46 -23
- package/dist/schedule.js.map +1 -1
- package/dist/serializable-CymX8ovI.d.ts +39 -0
- package/dist/serializable.d.ts +7 -0
- package/dist/serializable.js +1 -0
- package/dist/src-Dz0H9hSU.js +1200 -0
- package/dist/src-Dz0H9hSU.js.map +1 -0
- package/package.json +118 -52
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-YMUU7QHV.js +0 -595
- package/dist/chunk-YMUU7QHV.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp/client.js.map +0 -1
- package/src/index.ts +0 -919
package/dist/mcp/client.js
CHANGED
|
@@ -1,471 +1,3 @@
|
|
|
1
|
-
import "../
|
|
1
|
+
import { n as getNamespacedData, t as MCPClientManager } from "../client-9Ld2_lnt.js";
|
|
2
2
|
|
|
3
|
-
|
|
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.info = info;
|
|
55
|
-
this.options = options;
|
|
56
|
-
this.connectionState = "connecting";
|
|
57
|
-
this.tools = [];
|
|
58
|
-
this.prompts = [];
|
|
59
|
-
this.resources = [];
|
|
60
|
-
this.resourceTemplates = [];
|
|
61
|
-
this.client = new Client(info, options.client);
|
|
62
|
-
this.client.registerCapabilities(options.capabilities);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Initialize a client connection
|
|
66
|
-
*
|
|
67
|
-
* @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
async init(code, clientId) {
|
|
71
|
-
try {
|
|
72
|
-
const transport = new SSEEdgeClientTransport(
|
|
73
|
-
this.url,
|
|
74
|
-
this.options.transport
|
|
75
|
-
);
|
|
76
|
-
if (code) {
|
|
77
|
-
await transport.finishAuth(code);
|
|
78
|
-
}
|
|
79
|
-
await this.client.connect(transport);
|
|
80
|
-
} catch (e) {
|
|
81
|
-
if (e.toString().includes("Unauthorized")) {
|
|
82
|
-
this.connectionState = "authenticating";
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
this.connectionState = "failed";
|
|
86
|
-
throw e;
|
|
87
|
-
}
|
|
88
|
-
this.connectionState = "discovering";
|
|
89
|
-
this.serverCapabilities = await this.client.getServerCapabilities();
|
|
90
|
-
if (!this.serverCapabilities) {
|
|
91
|
-
throw new Error("The MCP Server failed to return server capabilities");
|
|
92
|
-
}
|
|
93
|
-
const [instructions, tools, resources, prompts, resourceTemplates] = await Promise.all([
|
|
94
|
-
this.client.getInstructions(),
|
|
95
|
-
this.registerTools(),
|
|
96
|
-
this.registerResources(),
|
|
97
|
-
this.registerPrompts(),
|
|
98
|
-
this.registerResourceTemplates()
|
|
99
|
-
]);
|
|
100
|
-
this.instructions = instructions;
|
|
101
|
-
this.tools = tools;
|
|
102
|
-
this.resources = resources;
|
|
103
|
-
this.prompts = prompts;
|
|
104
|
-
this.resourceTemplates = resourceTemplates;
|
|
105
|
-
this.connectionState = "ready";
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Notification handler registration
|
|
109
|
-
*/
|
|
110
|
-
async registerTools() {
|
|
111
|
-
if (!this.serverCapabilities || !this.serverCapabilities.tools) {
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
if (this.serverCapabilities.tools.listChanged) {
|
|
115
|
-
this.client.setNotificationHandler(
|
|
116
|
-
ToolListChangedNotificationSchema,
|
|
117
|
-
async (_notification) => {
|
|
118
|
-
this.tools = await this.fetchTools();
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return this.fetchTools();
|
|
123
|
-
}
|
|
124
|
-
async registerResources() {
|
|
125
|
-
if (!this.serverCapabilities || !this.serverCapabilities.resources) {
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
if (this.serverCapabilities.resources.listChanged) {
|
|
129
|
-
this.client.setNotificationHandler(
|
|
130
|
-
ResourceListChangedNotificationSchema,
|
|
131
|
-
async (_notification) => {
|
|
132
|
-
this.resources = await this.fetchResources();
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
return this.fetchResources();
|
|
137
|
-
}
|
|
138
|
-
async registerPrompts() {
|
|
139
|
-
if (!this.serverCapabilities || !this.serverCapabilities.prompts) {
|
|
140
|
-
return [];
|
|
141
|
-
}
|
|
142
|
-
if (this.serverCapabilities.prompts.listChanged) {
|
|
143
|
-
this.client.setNotificationHandler(
|
|
144
|
-
PromptListChangedNotificationSchema,
|
|
145
|
-
async (_notification) => {
|
|
146
|
-
this.prompts = await this.fetchPrompts();
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
return this.fetchPrompts();
|
|
151
|
-
}
|
|
152
|
-
async registerResourceTemplates() {
|
|
153
|
-
if (!this.serverCapabilities || !this.serverCapabilities.resources) {
|
|
154
|
-
return [];
|
|
155
|
-
}
|
|
156
|
-
return this.fetchResourceTemplates();
|
|
157
|
-
}
|
|
158
|
-
async fetchTools() {
|
|
159
|
-
let toolsAgg = [];
|
|
160
|
-
let toolsResult = { tools: [] };
|
|
161
|
-
do {
|
|
162
|
-
toolsResult = await this.client.listTools({
|
|
163
|
-
cursor: toolsResult.nextCursor
|
|
164
|
-
});
|
|
165
|
-
toolsAgg = toolsAgg.concat(toolsResult.tools);
|
|
166
|
-
} while (toolsResult.nextCursor);
|
|
167
|
-
return toolsAgg;
|
|
168
|
-
}
|
|
169
|
-
async fetchResources() {
|
|
170
|
-
let resourcesAgg = [];
|
|
171
|
-
let resourcesResult = { resources: [] };
|
|
172
|
-
do {
|
|
173
|
-
resourcesResult = await this.client.listResources({
|
|
174
|
-
cursor: resourcesResult.nextCursor
|
|
175
|
-
});
|
|
176
|
-
resourcesAgg = resourcesAgg.concat(resourcesResult.resources);
|
|
177
|
-
} while (resourcesResult.nextCursor);
|
|
178
|
-
return resourcesAgg;
|
|
179
|
-
}
|
|
180
|
-
async fetchPrompts() {
|
|
181
|
-
let promptsAgg = [];
|
|
182
|
-
let promptsResult = { prompts: [] };
|
|
183
|
-
do {
|
|
184
|
-
promptsResult = await this.client.listPrompts({
|
|
185
|
-
cursor: promptsResult.nextCursor
|
|
186
|
-
});
|
|
187
|
-
promptsAgg = promptsAgg.concat(promptsResult.prompts);
|
|
188
|
-
} while (promptsResult.nextCursor);
|
|
189
|
-
return promptsAgg;
|
|
190
|
-
}
|
|
191
|
-
async fetchResourceTemplates() {
|
|
192
|
-
let templatesAgg = [];
|
|
193
|
-
let templatesResult = {
|
|
194
|
-
resourceTemplates: []
|
|
195
|
-
};
|
|
196
|
-
do {
|
|
197
|
-
templatesResult = await this.client.listResourceTemplates({
|
|
198
|
-
cursor: templatesResult.nextCursor
|
|
199
|
-
});
|
|
200
|
-
templatesAgg = templatesAgg.concat(templatesResult.resourceTemplates);
|
|
201
|
-
} while (templatesResult.nextCursor);
|
|
202
|
-
return templatesAgg;
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// src/mcp/do-oauth-client-provider.ts
|
|
207
|
-
var DurableObjectOAuthClientProvider = class {
|
|
208
|
-
constructor(storage, clientName, sessionId, redirectUrl, clientId_) {
|
|
209
|
-
this.storage = storage;
|
|
210
|
-
this.clientName = clientName;
|
|
211
|
-
this.sessionId = sessionId;
|
|
212
|
-
this.redirectUrl = redirectUrl;
|
|
213
|
-
this.clientId_ = clientId_;
|
|
214
|
-
}
|
|
215
|
-
get clientMetadata() {
|
|
216
|
-
return {
|
|
217
|
-
redirect_uris: [this.redirectUrl],
|
|
218
|
-
token_endpoint_auth_method: "none",
|
|
219
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
220
|
-
response_types: ["code"],
|
|
221
|
-
client_name: this.clientName,
|
|
222
|
-
client_uri: "example.com"
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
get clientId() {
|
|
226
|
-
if (!this.clientId_) {
|
|
227
|
-
throw new Error("no clientId");
|
|
228
|
-
}
|
|
229
|
-
return this.clientId_;
|
|
230
|
-
}
|
|
231
|
-
set clientId(clientId_) {
|
|
232
|
-
this.clientId_ = clientId_;
|
|
233
|
-
}
|
|
234
|
-
keyPrefix(clientId) {
|
|
235
|
-
return `/${this.clientName}/${this.sessionId}/${clientId}`;
|
|
236
|
-
}
|
|
237
|
-
clientInfoKey(clientId) {
|
|
238
|
-
return `${this.keyPrefix(clientId)}/client_info/`;
|
|
239
|
-
}
|
|
240
|
-
async clientInformation() {
|
|
241
|
-
if (!this.clientId_) {
|
|
242
|
-
return void 0;
|
|
243
|
-
}
|
|
244
|
-
return await this.storage.get(
|
|
245
|
-
this.clientInfoKey(this.clientId)
|
|
246
|
-
) ?? void 0;
|
|
247
|
-
}
|
|
248
|
-
async saveClientInformation(clientInformation) {
|
|
249
|
-
await this.storage.put(
|
|
250
|
-
this.clientInfoKey(clientInformation.client_id),
|
|
251
|
-
clientInformation
|
|
252
|
-
);
|
|
253
|
-
this.clientId = clientInformation.client_id;
|
|
254
|
-
}
|
|
255
|
-
tokenKey(clientId) {
|
|
256
|
-
return `${this.keyPrefix(clientId)}/token`;
|
|
257
|
-
}
|
|
258
|
-
async tokens() {
|
|
259
|
-
if (!this.clientId_) {
|
|
260
|
-
return void 0;
|
|
261
|
-
}
|
|
262
|
-
return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
|
|
263
|
-
}
|
|
264
|
-
async saveTokens(tokens) {
|
|
265
|
-
await this.storage.put(this.tokenKey(this.clientId), tokens);
|
|
266
|
-
}
|
|
267
|
-
get authUrl() {
|
|
268
|
-
return this.authUrl_;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Because this operates on the server side (but we need browser auth), we send this url back to the user
|
|
272
|
-
* and require user interact to initiate the redirect flow
|
|
273
|
-
*/
|
|
274
|
-
async redirectToAuthorization(authUrl) {
|
|
275
|
-
const client_id = authUrl.searchParams.get("client_id");
|
|
276
|
-
if (client_id) {
|
|
277
|
-
authUrl.searchParams.append("state", client_id);
|
|
278
|
-
}
|
|
279
|
-
this.authUrl_ = authUrl.toString();
|
|
280
|
-
}
|
|
281
|
-
codeVerifierKey(clientId) {
|
|
282
|
-
return `${this.keyPrefix(clientId)}/code_verifier`;
|
|
283
|
-
}
|
|
284
|
-
async saveCodeVerifier(verifier) {
|
|
285
|
-
await this.storage.put(this.codeVerifierKey(this.clientId), verifier);
|
|
286
|
-
}
|
|
287
|
-
async codeVerifier() {
|
|
288
|
-
const codeVerifier = await this.storage.get(
|
|
289
|
-
this.codeVerifierKey(this.clientId)
|
|
290
|
-
);
|
|
291
|
-
if (!codeVerifier) {
|
|
292
|
-
throw new Error("No code verifier found");
|
|
293
|
-
}
|
|
294
|
-
return codeVerifier;
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
// src/mcp/client.ts
|
|
299
|
-
var MCPClientManager = class {
|
|
300
|
-
/**
|
|
301
|
-
* @param name Name of the MCP client
|
|
302
|
-
* @param version Version of the MCP Client
|
|
303
|
-
* @param auth Auth paramters if being used to create a DurableObjectOAuthClientProvider
|
|
304
|
-
*/
|
|
305
|
-
constructor(name, version, auth) {
|
|
306
|
-
this.name = name;
|
|
307
|
-
this.version = version;
|
|
308
|
-
this.auth = auth;
|
|
309
|
-
this.mcpConnections = {};
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Connect to and register an MCP server
|
|
313
|
-
*
|
|
314
|
-
* @param transportConfig Transport config
|
|
315
|
-
* @param clientConfig Client config
|
|
316
|
-
* @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
|
|
317
|
-
*/
|
|
318
|
-
async connect(url, opts = {}) {
|
|
319
|
-
const id = opts.reconnect?.id ?? crypto.randomUUID();
|
|
320
|
-
if (this.auth) {
|
|
321
|
-
console.warn(
|
|
322
|
-
"Using .auth configuration to generate an oauth provider, this is temporary and will be removed in the next version. Instead use transport.authProvider to provide an auth provider"
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
const authProvider = this.auth ? new DurableObjectOAuthClientProvider(
|
|
326
|
-
this.auth.storage,
|
|
327
|
-
this.name,
|
|
328
|
-
id,
|
|
329
|
-
`${this.auth.baseCallbackUri}/${id}`,
|
|
330
|
-
opts.reconnect?.oauthClientId
|
|
331
|
-
) : opts.transport?.authProvider;
|
|
332
|
-
this.mcpConnections[id] = new MCPClientConnection(
|
|
333
|
-
new URL(url),
|
|
334
|
-
{
|
|
335
|
-
name: this.name,
|
|
336
|
-
version: this.version
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
transport: {
|
|
340
|
-
...opts.transport,
|
|
341
|
-
authProvider
|
|
342
|
-
},
|
|
343
|
-
client: opts.client ?? {},
|
|
344
|
-
capabilities: opts.client ?? {}
|
|
345
|
-
}
|
|
346
|
-
);
|
|
347
|
-
await this.mcpConnections[id].init(
|
|
348
|
-
opts.reconnect?.oauthCode,
|
|
349
|
-
opts.reconnect?.oauthClientId
|
|
350
|
-
);
|
|
351
|
-
return {
|
|
352
|
-
id,
|
|
353
|
-
authUrl: authProvider?.authUrl
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
isCallbackRequest(req) {
|
|
357
|
-
if (this.auth?.baseCallbackUri) {
|
|
358
|
-
return req.url.startsWith(this.auth.baseCallbackUri) && req.method === "GET";
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
async handleCallbackRequest(req) {
|
|
363
|
-
const url = new URL(req.url);
|
|
364
|
-
const code = url.searchParams.get("code");
|
|
365
|
-
const clientId = url.searchParams.get("state");
|
|
366
|
-
let serverId = req.url.replace(this.auth.baseCallbackUri, "").split("?")[0];
|
|
367
|
-
serverId = serverId.replaceAll("/", "");
|
|
368
|
-
if (!code) {
|
|
369
|
-
throw new Error("Unauthorized: no code provided");
|
|
370
|
-
}
|
|
371
|
-
if (!clientId) {
|
|
372
|
-
throw new Error("Unauthorized: no state provided");
|
|
373
|
-
}
|
|
374
|
-
if (this.mcpConnections[serverId] === void 0) {
|
|
375
|
-
throw new Error(`Could not find serverId: ${serverId}`);
|
|
376
|
-
}
|
|
377
|
-
if (this.mcpConnections[serverId].connectionState !== "authenticating") {
|
|
378
|
-
throw new Error(
|
|
379
|
-
"Failed to authenticate: the client isn't in the `authenticating` state"
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
const serverUrl = this.mcpConnections[serverId].url.toString();
|
|
383
|
-
await this.connect(serverUrl, {
|
|
384
|
-
reconnect: {
|
|
385
|
-
id: serverId,
|
|
386
|
-
oauthClientId: clientId,
|
|
387
|
-
oauthCode: code
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
if (this.mcpConnections[serverId].connectionState === "authenticating") {
|
|
391
|
-
throw new Error("Failed to authenticate: client failed to initialize");
|
|
392
|
-
}
|
|
393
|
-
return { serverId };
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* @returns namespaced list of tools
|
|
397
|
-
*/
|
|
398
|
-
listTools() {
|
|
399
|
-
return getNamespacedData(this.mcpConnections, "tools");
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* @returns namespaced list of prompts
|
|
403
|
-
*/
|
|
404
|
-
listPrompts() {
|
|
405
|
-
return getNamespacedData(this.mcpConnections, "prompts");
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* @returns namespaced list of tools
|
|
409
|
-
*/
|
|
410
|
-
listResources() {
|
|
411
|
-
return getNamespacedData(this.mcpConnections, "resources");
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* @returns namespaced list of resource templates
|
|
415
|
-
*/
|
|
416
|
-
listResourceTemplates() {
|
|
417
|
-
return getNamespacedData(this.mcpConnections, "resourceTemplates");
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Namespaced version of callTool
|
|
421
|
-
*/
|
|
422
|
-
callTool(params, resultSchema, options) {
|
|
423
|
-
const unqualifiedName = params.name.replace(`${params.serverId}.`, "");
|
|
424
|
-
return this.mcpConnections[params.serverId].client.callTool(
|
|
425
|
-
{
|
|
426
|
-
...params,
|
|
427
|
-
name: unqualifiedName
|
|
428
|
-
},
|
|
429
|
-
resultSchema,
|
|
430
|
-
options
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Namespaced version of readResource
|
|
435
|
-
*/
|
|
436
|
-
readResource(params, options) {
|
|
437
|
-
return this.mcpConnections[params.serverId].client.readResource(
|
|
438
|
-
params,
|
|
439
|
-
options
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Namespaced version of getPrompt
|
|
444
|
-
*/
|
|
445
|
-
getPrompt(params, options) {
|
|
446
|
-
return this.mcpConnections[params.serverId].client.getPrompt(
|
|
447
|
-
params,
|
|
448
|
-
options
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
function getNamespacedData(mcpClients, type) {
|
|
453
|
-
const sets = Object.entries(mcpClients).map(([name, conn]) => {
|
|
454
|
-
return { name, data: conn[type] };
|
|
455
|
-
});
|
|
456
|
-
const namespacedData = sets.flatMap(({ name: serverId, data }) => {
|
|
457
|
-
return data.map((item) => {
|
|
458
|
-
return {
|
|
459
|
-
...item,
|
|
460
|
-
// we add a serverId so we can easily pull it out and send the tool call to the right server
|
|
461
|
-
serverId
|
|
462
|
-
};
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
return namespacedData;
|
|
466
|
-
}
|
|
467
|
-
export {
|
|
468
|
-
MCPClientManager,
|
|
469
|
-
getNamespacedData
|
|
470
|
-
};
|
|
471
|
-
//# sourceMappingURL=client.js.map
|
|
3
|
+
export { MCPClientManager, getNamespacedData };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,44 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { c as MaybePromise, d as StreamableHTTPEdgeClientTransport, f as SSEEdgeClientTransport, l as ServeOptions, n as MCPClientOAuthCallbackConfig, o as BaseTransportType, r as MCPClientOAuthResult, s as CORSOptions } from "../client-Csp_m13H.js";
|
|
2
|
+
import "../mcp-Dw5vDrY8.js";
|
|
3
|
+
import "../do-oauth-client-provider-DGc5pP0l.js";
|
|
4
|
+
import "../index-DhJCaDWd.js";
|
|
5
|
+
import "../ai-types-D5YoPrBZ.js";
|
|
6
|
+
import { c as ConnectionContext, s as Connection, t as Agent } from "../index-DFqsR7mb.js";
|
|
7
|
+
import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
//#region src/mcp/worker-transport.d.ts
|
|
13
|
+
interface WorkerTransportOptions {
|
|
14
|
+
sessionIdGenerator?: () => string;
|
|
15
|
+
enableJsonResponse?: boolean;
|
|
16
|
+
onsessioninitialized?: (sessionId: string) => void;
|
|
17
|
+
corsOptions?: CORSOptions;
|
|
10
18
|
}
|
|
11
|
-
declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response | undefined>;
|
|
41
|
-
};
|
|
19
|
+
declare class WorkerTransport implements Transport {
|
|
20
|
+
private started;
|
|
21
|
+
private initialized;
|
|
22
|
+
private sessionIdGenerator?;
|
|
23
|
+
private enableJsonResponse;
|
|
24
|
+
private onsessioninitialized?;
|
|
25
|
+
private standaloneSseStreamId;
|
|
26
|
+
private streamMapping;
|
|
27
|
+
private requestToStreamMapping;
|
|
28
|
+
private requestResponseMap;
|
|
29
|
+
private corsOptions?;
|
|
30
|
+
private protocolVersion?;
|
|
31
|
+
sessionId?: string;
|
|
32
|
+
onclose?: () => void;
|
|
33
|
+
onerror?: (error: Error) => void;
|
|
34
|
+
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
|
35
|
+
constructor(options?: WorkerTransportOptions);
|
|
36
|
+
start(): Promise<void>;
|
|
37
|
+
private validateProtocolVersion;
|
|
38
|
+
private getHeaders;
|
|
39
|
+
handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
|
|
40
|
+
private handleGetRequest;
|
|
41
|
+
private handlePostRequest;
|
|
42
|
+
private handleDeleteRequest;
|
|
43
|
+
private handleOptionsRequest;
|
|
44
|
+
private handleUnsupportedRequest;
|
|
45
|
+
private validateSession;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
send(message: JSONRPCMessage): Promise<void>;
|
|
42
48
|
}
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/mcp/handler.d.ts
|
|
51
|
+
interface CreateMcpHandlerOptions extends WorkerTransportOptions {
|
|
52
|
+
/**
|
|
53
|
+
* The route path that this MCP handler should respond to.
|
|
54
|
+
* If specified, the handler will only process requests that match this route.
|
|
55
|
+
* @default "/mcp"
|
|
56
|
+
*/
|
|
57
|
+
route?: string;
|
|
58
|
+
/**
|
|
59
|
+
* CORS configuration options for handling cross-origin requests.
|
|
60
|
+
* These options are passed to the WorkerTransport which handles adding
|
|
61
|
+
* CORS headers to all responses.
|
|
62
|
+
*
|
|
63
|
+
* Default values are:
|
|
64
|
+
* - origin: "*"
|
|
65
|
+
* - headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version"
|
|
66
|
+
* - methods: "GET, POST, DELETE, OPTIONS"
|
|
67
|
+
* - exposeHeaders: "mcp-session-id"
|
|
68
|
+
* - maxAge: 86400
|
|
69
|
+
*
|
|
70
|
+
* Provided options will overwrite the defaults.
|
|
71
|
+
*/
|
|
72
|
+
corsOptions?: CORSOptions;
|
|
73
|
+
}
|
|
74
|
+
type OAuthExecutionContext = ExecutionContext & {
|
|
75
|
+
props?: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
|
|
80
|
+
*/
|
|
81
|
+
declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/mcp/auth-context.d.ts
|
|
84
|
+
interface McpAuthContext {
|
|
85
|
+
props: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
declare function getMcpAuthContext(): McpAuthContext | undefined;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/mcp/index.d.ts
|
|
90
|
+
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
|
|
91
|
+
private _transport?;
|
|
92
|
+
props?: Props;
|
|
93
|
+
abstract server: MaybePromise<McpServer | Server>;
|
|
94
|
+
abstract init(): Promise<void>;
|
|
95
|
+
setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
|
|
96
|
+
getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
|
|
97
|
+
/** Read the transport type for this agent.
|
|
98
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
99
|
+
* or `streamable-http:${sessionId}`.
|
|
100
|
+
*/
|
|
101
|
+
getTransportType(): BaseTransportType;
|
|
102
|
+
/** Read the sessionId for this agent.
|
|
103
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
104
|
+
* or `streamable-http:${sessionId}`.
|
|
105
|
+
*/
|
|
106
|
+
getSessionId(): string;
|
|
107
|
+
/** Get the unique WebSocket. SSE transport only. */
|
|
108
|
+
private getWebSocket;
|
|
109
|
+
/** Returns a new transport matching the type of the Agent. */
|
|
110
|
+
private initTransport;
|
|
111
|
+
/** Update and store the props */
|
|
112
|
+
updateProps(props?: Props): Promise<void>;
|
|
113
|
+
reinitializeServer(): Promise<void>;
|
|
114
|
+
/** Sets up the MCP transport and server every time the Agent is started.*/
|
|
115
|
+
onStart(props?: Props): Promise<void>;
|
|
116
|
+
/** Validates new WebSocket connections. */
|
|
117
|
+
onConnect(conn: Connection, {
|
|
118
|
+
request: req
|
|
119
|
+
}: ConnectionContext): Promise<void>;
|
|
120
|
+
/** Handles MCP Messages for the legacy SSE transport. */
|
|
121
|
+
onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
|
|
122
|
+
/** Elicit user input with a message and schema */
|
|
123
|
+
elicitInput(params: {
|
|
124
|
+
message: string;
|
|
125
|
+
requestedSchema: unknown;
|
|
126
|
+
}): Promise<ElicitResult$1>;
|
|
127
|
+
/** Wait for elicitation response through storage polling */
|
|
128
|
+
private _waitForElicitationResponse;
|
|
129
|
+
/** Handle elicitation responses */
|
|
130
|
+
private _handleElicitationResponse;
|
|
131
|
+
/** Return a handler for the given path for this MCP.
|
|
132
|
+
* Defaults to Streamable HTTP transport.
|
|
133
|
+
*/
|
|
134
|
+
static serve(path: string, {
|
|
135
|
+
binding,
|
|
136
|
+
corsOptions,
|
|
137
|
+
transport,
|
|
138
|
+
jurisdiction
|
|
139
|
+
}?: ServeOptions): {
|
|
140
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Legacy api
|
|
144
|
+
**/
|
|
145
|
+
static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
146
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
147
|
+
};
|
|
148
|
+
static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
149
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, type McpAuthContext, type OAuthExecutionContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
|
154
|
+
//# sourceMappingURL=index.d.ts.map
|