agents 0.2.25 → 0.2.26
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 +18 -10
- package/dist/ai-chat-agent.js +8 -2
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +3 -3
- package/dist/cli/index.d.ts +1 -0
- package/dist/{cli.js → cli/index.js} +7 -6
- package/dist/cli/index.js.map +1 -0
- package/dist/{client-BZq9qau2.js → client-CFhjXCiO.js} +2 -2
- package/dist/client-CFhjXCiO.js.map +1 -0
- package/dist/client-CwqTTb-B.d.ts +833 -0
- package/dist/codemode/ai.js +2 -2
- package/dist/{index-Bx5KK3VJ.d.ts → index-DJ4vV2-x.d.ts} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +2 -2
- package/dist/observability/index.js +2 -2
- package/dist/{react-CbwD4fBf.d.ts → react-w4GT20p4.d.ts} +2 -2
- package/dist/react.d.ts +3 -3
- package/dist/{src-D_KKH_4c.js → src-tXpYCgas.js} +2 -2
- package/dist/{src-D_KKH_4c.js.map → src-tXpYCgas.js.map} +1 -1
- package/package.json +5 -5
- package/dist/cli.d.ts +0 -8
- package/dist/cli.js.map +0 -1
- package/dist/client-BZq9qau2.js.map +0 -1
- package/dist/client-CsaP9Irq.d.ts +0 -1528
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
import { t as MCPObservabilityEvent } from "./mcp-BwPscEiF.js";
|
|
2
|
+
import { t as AgentsOAuthProvider } from "./do-oauth-client-provider-C2CHH5x-.js";
|
|
3
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
|
+
import {
|
|
5
|
+
SSEClientTransport,
|
|
6
|
+
SSEClientTransportOptions
|
|
7
|
+
} from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import {
|
|
9
|
+
StreamableHTTPClientTransport,
|
|
10
|
+
StreamableHTTPClientTransportOptions
|
|
11
|
+
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
12
|
+
import {
|
|
13
|
+
CallToolRequest,
|
|
14
|
+
CallToolResultSchema,
|
|
15
|
+
CompatibilityCallToolResultSchema,
|
|
16
|
+
ElicitRequest,
|
|
17
|
+
ElicitResult,
|
|
18
|
+
GetPromptRequest,
|
|
19
|
+
Prompt,
|
|
20
|
+
ReadResourceRequest,
|
|
21
|
+
Resource,
|
|
22
|
+
ResourceTemplate,
|
|
23
|
+
ServerCapabilities,
|
|
24
|
+
Tool
|
|
25
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
26
|
+
import * as ai0 from "ai";
|
|
27
|
+
import { ToolSet } from "ai";
|
|
28
|
+
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
29
|
+
|
|
30
|
+
//#region src/core/events.d.ts
|
|
31
|
+
interface Disposable {
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
type Event<T> = (listener: (e: T) => void) => Disposable;
|
|
35
|
+
declare class Emitter<T> implements Disposable {
|
|
36
|
+
private _listeners;
|
|
37
|
+
readonly event: Event<T>;
|
|
38
|
+
fire(data: T): void;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/mcp/types.d.ts
|
|
43
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
44
|
+
type BaseTransportType = "sse" | "streamable-http";
|
|
45
|
+
type TransportType = BaseTransportType | "auto";
|
|
46
|
+
interface CORSOptions {
|
|
47
|
+
origin?: string;
|
|
48
|
+
methods?: string;
|
|
49
|
+
headers?: string;
|
|
50
|
+
maxAge?: number;
|
|
51
|
+
exposeHeaders?: string;
|
|
52
|
+
}
|
|
53
|
+
interface ServeOptions {
|
|
54
|
+
binding?: string;
|
|
55
|
+
corsOptions?: CORSOptions;
|
|
56
|
+
transport?: BaseTransportType;
|
|
57
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/mcp/client-connection.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* Connection state machine for MCP client connections.
|
|
63
|
+
*
|
|
64
|
+
* State transitions:
|
|
65
|
+
* - Non-OAuth: init() → CONNECTING → DISCOVERING → READY
|
|
66
|
+
* - OAuth: init() → AUTHENTICATING → (callback) → CONNECTING → DISCOVERING → READY
|
|
67
|
+
* - Any state can transition to FAILED on error
|
|
68
|
+
*/
|
|
69
|
+
declare const MCPConnectionState: {
|
|
70
|
+
/** Waiting for OAuth authorization to complete */
|
|
71
|
+
readonly AUTHENTICATING: "authenticating";
|
|
72
|
+
/** Establishing transport connection to MCP server */
|
|
73
|
+
readonly CONNECTING: "connecting";
|
|
74
|
+
/** Transport connection established */
|
|
75
|
+
readonly CONNECTED: "connected";
|
|
76
|
+
/** Discovering server capabilities (tools, resources, prompts) */
|
|
77
|
+
readonly DISCOVERING: "discovering";
|
|
78
|
+
/** Fully connected and ready to use */
|
|
79
|
+
readonly READY: "ready";
|
|
80
|
+
/** Connection failed at some point */
|
|
81
|
+
readonly FAILED: "failed";
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Connection state type for MCP client connections.
|
|
85
|
+
*/
|
|
86
|
+
type MCPConnectionState =
|
|
87
|
+
(typeof MCPConnectionState)[keyof typeof MCPConnectionState];
|
|
88
|
+
type MCPTransportOptions = (
|
|
89
|
+
| SSEClientTransportOptions
|
|
90
|
+
| StreamableHTTPClientTransportOptions
|
|
91
|
+
) & {
|
|
92
|
+
authProvider?: AgentsOAuthProvider;
|
|
93
|
+
type?: TransportType;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Result of a discovery operation.
|
|
97
|
+
* success indicates whether discovery completed successfully.
|
|
98
|
+
* error is present when success is false.
|
|
99
|
+
*/
|
|
100
|
+
type MCPDiscoveryResult = {
|
|
101
|
+
success: boolean;
|
|
102
|
+
error?: string;
|
|
103
|
+
};
|
|
104
|
+
declare class MCPClientConnection {
|
|
105
|
+
url: URL;
|
|
106
|
+
options: {
|
|
107
|
+
transport: MCPTransportOptions;
|
|
108
|
+
client: ConstructorParameters<typeof Client>[1];
|
|
109
|
+
};
|
|
110
|
+
client: Client;
|
|
111
|
+
connectionState: MCPConnectionState;
|
|
112
|
+
lastConnectedTransport: BaseTransportType | undefined;
|
|
113
|
+
instructions?: string;
|
|
114
|
+
tools: Tool[];
|
|
115
|
+
prompts: Prompt[];
|
|
116
|
+
resources: Resource[];
|
|
117
|
+
resourceTemplates: ResourceTemplate[];
|
|
118
|
+
serverCapabilities: ServerCapabilities | undefined;
|
|
119
|
+
/** Tracks in-flight discovery to allow cancellation */
|
|
120
|
+
private _discoveryAbortController;
|
|
121
|
+
private readonly _onObservabilityEvent;
|
|
122
|
+
readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
|
|
123
|
+
constructor(
|
|
124
|
+
url: URL,
|
|
125
|
+
info: ConstructorParameters<typeof Client>[0],
|
|
126
|
+
options?: {
|
|
127
|
+
transport: MCPTransportOptions;
|
|
128
|
+
client: ConstructorParameters<typeof Client>[1];
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
/**
|
|
132
|
+
* Initialize a client connection, if authentication is required, the connection will be in the AUTHENTICATING state
|
|
133
|
+
* Sets connection state based on the result and emits observability events
|
|
134
|
+
*
|
|
135
|
+
* @returns Error message if connection failed, undefined otherwise
|
|
136
|
+
*/
|
|
137
|
+
init(): Promise<string | undefined>;
|
|
138
|
+
/**
|
|
139
|
+
* Finish OAuth by probing transports based on configured type.
|
|
140
|
+
* - Explicit: finish on that transport
|
|
141
|
+
* - Auto: try streamable-http, then sse on 404/405/Not Implemented
|
|
142
|
+
*/
|
|
143
|
+
private finishAuthProbe;
|
|
144
|
+
/**
|
|
145
|
+
* Complete OAuth authorization
|
|
146
|
+
*/
|
|
147
|
+
completeAuthorization(code: string): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Discover server capabilities and register tools, resources, prompts, and templates.
|
|
150
|
+
* This method does the work but does not manage connection state - that's handled by discover().
|
|
151
|
+
*/
|
|
152
|
+
discoverAndRegister(): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Discover server capabilities with timeout and cancellation support.
|
|
155
|
+
* If called while a previous discovery is in-flight, the previous discovery will be aborted.
|
|
156
|
+
*
|
|
157
|
+
* @param options Optional configuration
|
|
158
|
+
* @param options.timeoutMs Timeout in milliseconds (default: 15000)
|
|
159
|
+
* @returns Result indicating success/failure with optional error message
|
|
160
|
+
*/
|
|
161
|
+
discover(options?: { timeoutMs?: number }): Promise<MCPDiscoveryResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Cancel any in-flight discovery operation.
|
|
164
|
+
* Called when closing the connection.
|
|
165
|
+
*/
|
|
166
|
+
cancelDiscovery(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Notification handler registration for tools
|
|
169
|
+
* Should only be called if serverCapabilities.tools exists
|
|
170
|
+
*/
|
|
171
|
+
registerTools(): Promise<Tool[]>;
|
|
172
|
+
/**
|
|
173
|
+
* Notification handler registration for resources
|
|
174
|
+
* Should only be called if serverCapabilities.resources exists
|
|
175
|
+
*/
|
|
176
|
+
registerResources(): Promise<Resource[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Notification handler registration for prompts
|
|
179
|
+
* Should only be called if serverCapabilities.prompts exists
|
|
180
|
+
*/
|
|
181
|
+
registerPrompts(): Promise<Prompt[]>;
|
|
182
|
+
registerResourceTemplates(): Promise<ResourceTemplate[]>;
|
|
183
|
+
fetchTools(): Promise<
|
|
184
|
+
{
|
|
185
|
+
inputSchema: {
|
|
186
|
+
[x: string]: unknown;
|
|
187
|
+
type: "object";
|
|
188
|
+
properties?:
|
|
189
|
+
| {
|
|
190
|
+
[x: string]: object;
|
|
191
|
+
}
|
|
192
|
+
| undefined;
|
|
193
|
+
required?: string[] | undefined;
|
|
194
|
+
};
|
|
195
|
+
name: string;
|
|
196
|
+
description?: string | undefined;
|
|
197
|
+
outputSchema?:
|
|
198
|
+
| {
|
|
199
|
+
[x: string]: unknown;
|
|
200
|
+
type: "object";
|
|
201
|
+
properties?:
|
|
202
|
+
| {
|
|
203
|
+
[x: string]: object;
|
|
204
|
+
}
|
|
205
|
+
| undefined;
|
|
206
|
+
required?: string[] | undefined;
|
|
207
|
+
}
|
|
208
|
+
| undefined;
|
|
209
|
+
annotations?:
|
|
210
|
+
| {
|
|
211
|
+
title?: string | undefined;
|
|
212
|
+
readOnlyHint?: boolean | undefined;
|
|
213
|
+
destructiveHint?: boolean | undefined;
|
|
214
|
+
idempotentHint?: boolean | undefined;
|
|
215
|
+
openWorldHint?: boolean | undefined;
|
|
216
|
+
}
|
|
217
|
+
| undefined;
|
|
218
|
+
_meta?:
|
|
219
|
+
| {
|
|
220
|
+
[x: string]: unknown;
|
|
221
|
+
}
|
|
222
|
+
| undefined;
|
|
223
|
+
icons?:
|
|
224
|
+
| {
|
|
225
|
+
src: string;
|
|
226
|
+
mimeType?: string | undefined;
|
|
227
|
+
sizes?: string[] | undefined;
|
|
228
|
+
}[]
|
|
229
|
+
| undefined;
|
|
230
|
+
title?: string | undefined;
|
|
231
|
+
}[]
|
|
232
|
+
>;
|
|
233
|
+
fetchResources(): Promise<
|
|
234
|
+
{
|
|
235
|
+
uri: string;
|
|
236
|
+
name: string;
|
|
237
|
+
description?: string | undefined;
|
|
238
|
+
mimeType?: string | undefined;
|
|
239
|
+
_meta?:
|
|
240
|
+
| {
|
|
241
|
+
[x: string]: unknown;
|
|
242
|
+
}
|
|
243
|
+
| undefined;
|
|
244
|
+
icons?:
|
|
245
|
+
| {
|
|
246
|
+
src: string;
|
|
247
|
+
mimeType?: string | undefined;
|
|
248
|
+
sizes?: string[] | undefined;
|
|
249
|
+
}[]
|
|
250
|
+
| undefined;
|
|
251
|
+
title?: string | undefined;
|
|
252
|
+
}[]
|
|
253
|
+
>;
|
|
254
|
+
fetchPrompts(): Promise<
|
|
255
|
+
{
|
|
256
|
+
name: string;
|
|
257
|
+
description?: string | undefined;
|
|
258
|
+
arguments?:
|
|
259
|
+
| {
|
|
260
|
+
name: string;
|
|
261
|
+
description?: string | undefined;
|
|
262
|
+
required?: boolean | undefined;
|
|
263
|
+
}[]
|
|
264
|
+
| undefined;
|
|
265
|
+
_meta?:
|
|
266
|
+
| {
|
|
267
|
+
[x: string]: unknown;
|
|
268
|
+
}
|
|
269
|
+
| undefined;
|
|
270
|
+
icons?:
|
|
271
|
+
| {
|
|
272
|
+
src: string;
|
|
273
|
+
mimeType?: string | undefined;
|
|
274
|
+
sizes?: string[] | undefined;
|
|
275
|
+
}[]
|
|
276
|
+
| undefined;
|
|
277
|
+
title?: string | undefined;
|
|
278
|
+
}[]
|
|
279
|
+
>;
|
|
280
|
+
fetchResourceTemplates(): Promise<
|
|
281
|
+
{
|
|
282
|
+
uriTemplate: string;
|
|
283
|
+
name: string;
|
|
284
|
+
description?: string | undefined;
|
|
285
|
+
mimeType?: string | undefined;
|
|
286
|
+
_meta?:
|
|
287
|
+
| {
|
|
288
|
+
[x: string]: unknown;
|
|
289
|
+
}
|
|
290
|
+
| undefined;
|
|
291
|
+
icons?:
|
|
292
|
+
| {
|
|
293
|
+
src: string;
|
|
294
|
+
mimeType?: string | undefined;
|
|
295
|
+
sizes?: string[] | undefined;
|
|
296
|
+
}[]
|
|
297
|
+
| undefined;
|
|
298
|
+
title?: string | undefined;
|
|
299
|
+
}[]
|
|
300
|
+
>;
|
|
301
|
+
/**
|
|
302
|
+
* Handle elicitation request from server
|
|
303
|
+
* Automatically uses the Agent's built-in elicitation handling if available
|
|
304
|
+
*/
|
|
305
|
+
handleElicitationRequest(_request: ElicitRequest): Promise<ElicitResult>;
|
|
306
|
+
/**
|
|
307
|
+
* Get the transport for the client
|
|
308
|
+
* @param transportType - The transport type to get
|
|
309
|
+
* @returns The transport for the client
|
|
310
|
+
*/
|
|
311
|
+
getTransport(
|
|
312
|
+
transportType: BaseTransportType
|
|
313
|
+
): SSEClientTransport | StreamableHTTPClientTransport;
|
|
314
|
+
private tryConnect;
|
|
315
|
+
private _capabilityErrorHandler;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/mcp/client-storage.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Represents a row in the cf_agents_mcp_servers table
|
|
321
|
+
*/
|
|
322
|
+
type MCPServerRow = {
|
|
323
|
+
id: string;
|
|
324
|
+
name: string;
|
|
325
|
+
server_url: string;
|
|
326
|
+
client_id: string | null;
|
|
327
|
+
auth_url: string | null;
|
|
328
|
+
callback_url: string;
|
|
329
|
+
server_options: string | null;
|
|
330
|
+
};
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/mcp/client.d.ts
|
|
333
|
+
/**
|
|
334
|
+
* Options that can be stored in the server_options column
|
|
335
|
+
* This is what gets JSON.stringify'd and stored in the database
|
|
336
|
+
*/
|
|
337
|
+
type MCPServerOptions = {
|
|
338
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
339
|
+
transport?: {
|
|
340
|
+
headers?: HeadersInit;
|
|
341
|
+
type?: TransportType;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Options for registering an MCP server
|
|
346
|
+
*/
|
|
347
|
+
type RegisterServerOptions = {
|
|
348
|
+
url: string;
|
|
349
|
+
name: string;
|
|
350
|
+
callbackUrl: string;
|
|
351
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
352
|
+
transport?: MCPTransportOptions;
|
|
353
|
+
authUrl?: string;
|
|
354
|
+
clientId?: string;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Result of attempting to connect to an MCP server.
|
|
358
|
+
* Discriminated union ensures error is present only on failure.
|
|
359
|
+
*/
|
|
360
|
+
type MCPConnectionResult =
|
|
361
|
+
| {
|
|
362
|
+
state: typeof MCPConnectionState.FAILED;
|
|
363
|
+
error: string;
|
|
364
|
+
}
|
|
365
|
+
| {
|
|
366
|
+
state: typeof MCPConnectionState.AUTHENTICATING;
|
|
367
|
+
authUrl: string;
|
|
368
|
+
clientId?: string;
|
|
369
|
+
}
|
|
370
|
+
| {
|
|
371
|
+
state: typeof MCPConnectionState.CONNECTED;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Result of discovering server capabilities.
|
|
375
|
+
* success indicates whether discovery completed successfully.
|
|
376
|
+
* state is the current connection state at time of return.
|
|
377
|
+
* error is present when success is false.
|
|
378
|
+
*/
|
|
379
|
+
type MCPDiscoverResult = {
|
|
380
|
+
success: boolean;
|
|
381
|
+
state: MCPConnectionState;
|
|
382
|
+
error?: string;
|
|
383
|
+
};
|
|
384
|
+
type MCPClientOAuthCallbackConfig = {
|
|
385
|
+
successRedirect?: string;
|
|
386
|
+
errorRedirect?: string;
|
|
387
|
+
customHandler?: (result: MCPClientOAuthResult) => Response;
|
|
388
|
+
};
|
|
389
|
+
type MCPClientOAuthResult = {
|
|
390
|
+
serverId: string;
|
|
391
|
+
authSuccess: boolean;
|
|
392
|
+
authError?: string;
|
|
393
|
+
};
|
|
394
|
+
type MCPClientManagerOptions = {
|
|
395
|
+
storage: DurableObjectStorage;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* Utility class that aggregates multiple MCP clients into one
|
|
399
|
+
*/
|
|
400
|
+
declare class MCPClientManager {
|
|
401
|
+
private _name;
|
|
402
|
+
private _version;
|
|
403
|
+
mcpConnections: Record<string, MCPClientConnection>;
|
|
404
|
+
private _didWarnAboutUnstableGetAITools;
|
|
405
|
+
private _oauthCallbackConfig?;
|
|
406
|
+
private _connectionDisposables;
|
|
407
|
+
private _storage;
|
|
408
|
+
private _isRestored;
|
|
409
|
+
/** @internal Protected for testing purposes. */
|
|
410
|
+
protected readonly _onObservabilityEvent: Emitter<MCPObservabilityEvent>;
|
|
411
|
+
readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
|
|
412
|
+
private readonly _onServerStateChanged;
|
|
413
|
+
/**
|
|
414
|
+
* Event that fires whenever any MCP server state changes (registered, connected, removed, etc.)
|
|
415
|
+
* This is useful for broadcasting server state to clients.
|
|
416
|
+
*/
|
|
417
|
+
readonly onServerStateChanged: Event<void>;
|
|
418
|
+
/**
|
|
419
|
+
* @param _name Name of the MCP client
|
|
420
|
+
* @param _version Version of the MCP Client
|
|
421
|
+
* @param options Storage adapter for persisting MCP server state
|
|
422
|
+
*/
|
|
423
|
+
constructor(
|
|
424
|
+
_name: string,
|
|
425
|
+
_version: string,
|
|
426
|
+
options: MCPClientManagerOptions
|
|
427
|
+
);
|
|
428
|
+
private sql;
|
|
429
|
+
private saveServerToStorage;
|
|
430
|
+
private removeServerFromStorage;
|
|
431
|
+
private getServersFromStorage;
|
|
432
|
+
private clearServerAuthUrl;
|
|
433
|
+
jsonSchema: typeof ai0.jsonSchema | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* Create an auth provider for a server
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
private createAuthProvider;
|
|
439
|
+
/**
|
|
440
|
+
* Restore MCP server connections from storage
|
|
441
|
+
* This method is called on Agent initialization to restore previously connected servers
|
|
442
|
+
*
|
|
443
|
+
* @param clientName Name to use for OAuth client (typically the agent instance name)
|
|
444
|
+
*/
|
|
445
|
+
restoreConnectionsFromStorage(clientName: string): Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* Internal method to restore a single server connection and discovery
|
|
448
|
+
*/
|
|
449
|
+
private _restoreServer;
|
|
450
|
+
/**
|
|
451
|
+
* Connect to and register an MCP server
|
|
452
|
+
*
|
|
453
|
+
* @deprecated This method is maintained for backward compatibility.
|
|
454
|
+
* For new code, use registerServer() and connectToServer() separately.
|
|
455
|
+
*
|
|
456
|
+
* @param url Server URL
|
|
457
|
+
* @param options Connection options
|
|
458
|
+
* @returns Object with server ID, auth URL (if OAuth), and client ID (if OAuth)
|
|
459
|
+
*/
|
|
460
|
+
connect(
|
|
461
|
+
url: string,
|
|
462
|
+
options?: {
|
|
463
|
+
reconnect?: {
|
|
464
|
+
id: string;
|
|
465
|
+
oauthClientId?: string;
|
|
466
|
+
oauthCode?: string;
|
|
467
|
+
};
|
|
468
|
+
transport?: MCPTransportOptions;
|
|
469
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
470
|
+
}
|
|
471
|
+
): Promise<{
|
|
472
|
+
id: string;
|
|
473
|
+
authUrl?: string;
|
|
474
|
+
clientId?: string;
|
|
475
|
+
}>;
|
|
476
|
+
/**
|
|
477
|
+
* Create an in-memory connection object and set up observability
|
|
478
|
+
* Does NOT save to storage - use registerServer() for that
|
|
479
|
+
* @returns The connection object (existing or newly created)
|
|
480
|
+
*/
|
|
481
|
+
private createConnection;
|
|
482
|
+
/**
|
|
483
|
+
* Register an MCP server connection without connecting
|
|
484
|
+
* Creates the connection object, sets up observability, and saves to storage
|
|
485
|
+
*
|
|
486
|
+
* @param id Server ID
|
|
487
|
+
* @param options Registration options including URL, name, callback URL, and connection config
|
|
488
|
+
* @returns Server ID
|
|
489
|
+
*/
|
|
490
|
+
registerServer(id: string, options: RegisterServerOptions): Promise<string>;
|
|
491
|
+
/**
|
|
492
|
+
* Connect to an already registered MCP server and initialize the connection.
|
|
493
|
+
*
|
|
494
|
+
* For OAuth servers, returns `{ state: "authenticating", authUrl, clientId? }`.
|
|
495
|
+
* The user must complete the OAuth flow via the authUrl, which triggers a
|
|
496
|
+
* callback handled by `handleCallbackRequest()`.
|
|
497
|
+
*
|
|
498
|
+
* For non-OAuth servers, establishes the transport connection and returns
|
|
499
|
+
* `{ state: "connected" }`. Call `discoverIfConnected()` afterwards to
|
|
500
|
+
* discover capabilities and transition to "ready" state.
|
|
501
|
+
*
|
|
502
|
+
* @param id Server ID (must be registered first via registerServer())
|
|
503
|
+
* @returns Connection result with current state and OAuth info (if applicable)
|
|
504
|
+
*/
|
|
505
|
+
connectToServer(id: string): Promise<MCPConnectionResult>;
|
|
506
|
+
isCallbackRequest(req: Request): boolean;
|
|
507
|
+
handleCallbackRequest(req: Request): Promise<
|
|
508
|
+
| {
|
|
509
|
+
serverId: string;
|
|
510
|
+
authSuccess: boolean;
|
|
511
|
+
authError: string;
|
|
512
|
+
}
|
|
513
|
+
| {
|
|
514
|
+
serverId: string;
|
|
515
|
+
authSuccess: boolean;
|
|
516
|
+
authError?: undefined;
|
|
517
|
+
}
|
|
518
|
+
>;
|
|
519
|
+
/**
|
|
520
|
+
* Discover server capabilities if connection is in CONNECTED or READY state.
|
|
521
|
+
* Transitions to DISCOVERING then READY (or CONNECTED on error).
|
|
522
|
+
* Can be called to refresh server capabilities (e.g., from a UI refresh button).
|
|
523
|
+
*
|
|
524
|
+
* If called while a previous discovery is in-flight for the same server,
|
|
525
|
+
* the previous discovery will be aborted.
|
|
526
|
+
*
|
|
527
|
+
* @param serverId The server ID to discover
|
|
528
|
+
* @param options Optional configuration
|
|
529
|
+
* @param options.timeoutMs Timeout in milliseconds (default: 30000)
|
|
530
|
+
* @returns Result with current state and optional error, or undefined if connection not found
|
|
531
|
+
*/
|
|
532
|
+
discoverIfConnected(
|
|
533
|
+
serverId: string,
|
|
534
|
+
options?: {
|
|
535
|
+
timeoutMs?: number;
|
|
536
|
+
}
|
|
537
|
+
): Promise<MCPDiscoverResult | undefined>;
|
|
538
|
+
/**
|
|
539
|
+
* Establish connection in the background after OAuth completion
|
|
540
|
+
* This method connects to the server and discovers its capabilities
|
|
541
|
+
* @param serverId The server ID to establish connection for
|
|
542
|
+
*/
|
|
543
|
+
establishConnection(serverId: string): Promise<void>;
|
|
544
|
+
/**
|
|
545
|
+
* Configure OAuth callback handling
|
|
546
|
+
* @param config OAuth callback configuration
|
|
547
|
+
*/
|
|
548
|
+
configureOAuthCallback(config: MCPClientOAuthCallbackConfig): void;
|
|
549
|
+
/**
|
|
550
|
+
* Get the current OAuth callback configuration
|
|
551
|
+
* @returns The current OAuth callback configuration
|
|
552
|
+
*/
|
|
553
|
+
getOAuthCallbackConfig(): MCPClientOAuthCallbackConfig | undefined;
|
|
554
|
+
/**
|
|
555
|
+
* @returns namespaced list of tools
|
|
556
|
+
*/
|
|
557
|
+
listTools(): NamespacedData["tools"];
|
|
558
|
+
/**
|
|
559
|
+
* Lazy-loads the jsonSchema function from the AI SDK.
|
|
560
|
+
*
|
|
561
|
+
* This defers importing the "ai" package until it's actually needed, which helps reduce
|
|
562
|
+
* initial bundle size and startup time. The jsonSchema function is required for converting
|
|
563
|
+
* MCP tools into AI SDK tool definitions via getAITools().
|
|
564
|
+
*
|
|
565
|
+
* @internal This method is for internal use only. It's automatically called before operations
|
|
566
|
+
* that need jsonSchema (like getAITools() or OAuth flows). External consumers should not need
|
|
567
|
+
* to call this directly.
|
|
568
|
+
*/
|
|
569
|
+
ensureJsonSchema(): Promise<void>;
|
|
570
|
+
/**
|
|
571
|
+
* @returns a set of tools that you can use with the AI SDK
|
|
572
|
+
*/
|
|
573
|
+
getAITools(): ToolSet;
|
|
574
|
+
/**
|
|
575
|
+
* @deprecated this has been renamed to getAITools(), and unstable_getAITools will be removed in the next major version
|
|
576
|
+
* @returns a set of tools that you can use with the AI SDK
|
|
577
|
+
*/
|
|
578
|
+
unstable_getAITools(): ToolSet;
|
|
579
|
+
/**
|
|
580
|
+
* Closes all active in-memory connections to MCP servers.
|
|
581
|
+
*
|
|
582
|
+
* Note: This only closes the transport connections - it does NOT remove
|
|
583
|
+
* servers from storage. Servers will still be listed and their callback
|
|
584
|
+
* URLs will still match incoming OAuth requests.
|
|
585
|
+
*
|
|
586
|
+
* Use removeServer() instead if you want to fully clean up a server
|
|
587
|
+
* (closes connection AND removes from storage).
|
|
588
|
+
*/
|
|
589
|
+
closeAllConnections(): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* Closes a connection to an MCP server
|
|
592
|
+
* @param id The id of the connection to close
|
|
593
|
+
*/
|
|
594
|
+
closeConnection(id: string): Promise<void>;
|
|
595
|
+
/**
|
|
596
|
+
* Remove an MCP server - closes connection if active and removes from storage.
|
|
597
|
+
*/
|
|
598
|
+
removeServer(serverId: string): Promise<void>;
|
|
599
|
+
/**
|
|
600
|
+
* List all MCP servers from storage
|
|
601
|
+
*/
|
|
602
|
+
listServers(): MCPServerRow[];
|
|
603
|
+
/**
|
|
604
|
+
* Dispose the manager and all resources.
|
|
605
|
+
*/
|
|
606
|
+
dispose(): Promise<void>;
|
|
607
|
+
/**
|
|
608
|
+
* @returns namespaced list of prompts
|
|
609
|
+
*/
|
|
610
|
+
listPrompts(): NamespacedData["prompts"];
|
|
611
|
+
/**
|
|
612
|
+
* @returns namespaced list of tools
|
|
613
|
+
*/
|
|
614
|
+
listResources(): NamespacedData["resources"];
|
|
615
|
+
/**
|
|
616
|
+
* @returns namespaced list of resource templates
|
|
617
|
+
*/
|
|
618
|
+
listResourceTemplates(): NamespacedData["resourceTemplates"];
|
|
619
|
+
/**
|
|
620
|
+
* Namespaced version of callTool
|
|
621
|
+
*/
|
|
622
|
+
callTool(
|
|
623
|
+
params: CallToolRequest["params"] & {
|
|
624
|
+
serverId: string;
|
|
625
|
+
},
|
|
626
|
+
resultSchema?:
|
|
627
|
+
| typeof CallToolResultSchema
|
|
628
|
+
| typeof CompatibilityCallToolResultSchema,
|
|
629
|
+
options?: RequestOptions
|
|
630
|
+
): Promise<
|
|
631
|
+
| {
|
|
632
|
+
[x: string]: unknown;
|
|
633
|
+
content: (
|
|
634
|
+
| {
|
|
635
|
+
type: "text";
|
|
636
|
+
text: string;
|
|
637
|
+
_meta?: Record<string, unknown> | undefined;
|
|
638
|
+
}
|
|
639
|
+
| {
|
|
640
|
+
type: "image";
|
|
641
|
+
data: string;
|
|
642
|
+
mimeType: string;
|
|
643
|
+
_meta?: Record<string, unknown> | undefined;
|
|
644
|
+
}
|
|
645
|
+
| {
|
|
646
|
+
type: "audio";
|
|
647
|
+
data: string;
|
|
648
|
+
mimeType: string;
|
|
649
|
+
_meta?: Record<string, unknown> | undefined;
|
|
650
|
+
}
|
|
651
|
+
| {
|
|
652
|
+
type: "resource";
|
|
653
|
+
resource:
|
|
654
|
+
| {
|
|
655
|
+
uri: string;
|
|
656
|
+
text: string;
|
|
657
|
+
mimeType?: string | undefined;
|
|
658
|
+
_meta?: Record<string, unknown> | undefined;
|
|
659
|
+
}
|
|
660
|
+
| {
|
|
661
|
+
uri: string;
|
|
662
|
+
blob: string;
|
|
663
|
+
mimeType?: string | undefined;
|
|
664
|
+
_meta?: Record<string, unknown> | undefined;
|
|
665
|
+
};
|
|
666
|
+
_meta?: Record<string, unknown> | undefined;
|
|
667
|
+
}
|
|
668
|
+
| {
|
|
669
|
+
uri: string;
|
|
670
|
+
name: string;
|
|
671
|
+
type: "resource_link";
|
|
672
|
+
description?: string | undefined;
|
|
673
|
+
mimeType?: string | undefined;
|
|
674
|
+
_meta?:
|
|
675
|
+
| {
|
|
676
|
+
[x: string]: unknown;
|
|
677
|
+
}
|
|
678
|
+
| undefined;
|
|
679
|
+
icons?:
|
|
680
|
+
| {
|
|
681
|
+
src: string;
|
|
682
|
+
mimeType?: string | undefined;
|
|
683
|
+
sizes?: string[] | undefined;
|
|
684
|
+
}[]
|
|
685
|
+
| undefined;
|
|
686
|
+
title?: string | undefined;
|
|
687
|
+
}
|
|
688
|
+
)[];
|
|
689
|
+
_meta?: Record<string, unknown> | undefined;
|
|
690
|
+
structuredContent?: Record<string, unknown> | undefined;
|
|
691
|
+
isError?: boolean | undefined;
|
|
692
|
+
}
|
|
693
|
+
| {
|
|
694
|
+
[x: string]: unknown;
|
|
695
|
+
toolResult: unknown;
|
|
696
|
+
_meta?: Record<string, unknown> | undefined;
|
|
697
|
+
}
|
|
698
|
+
>;
|
|
699
|
+
/**
|
|
700
|
+
* Namespaced version of readResource
|
|
701
|
+
*/
|
|
702
|
+
readResource(
|
|
703
|
+
params: ReadResourceRequest["params"] & {
|
|
704
|
+
serverId: string;
|
|
705
|
+
},
|
|
706
|
+
options: RequestOptions
|
|
707
|
+
): Promise<{
|
|
708
|
+
[x: string]: unknown;
|
|
709
|
+
contents: (
|
|
710
|
+
| {
|
|
711
|
+
uri: string;
|
|
712
|
+
text: string;
|
|
713
|
+
mimeType?: string | undefined;
|
|
714
|
+
_meta?: Record<string, unknown> | undefined;
|
|
715
|
+
}
|
|
716
|
+
| {
|
|
717
|
+
uri: string;
|
|
718
|
+
blob: string;
|
|
719
|
+
mimeType?: string | undefined;
|
|
720
|
+
_meta?: Record<string, unknown> | undefined;
|
|
721
|
+
}
|
|
722
|
+
)[];
|
|
723
|
+
_meta?: Record<string, unknown> | undefined;
|
|
724
|
+
}>;
|
|
725
|
+
/**
|
|
726
|
+
* Namespaced version of getPrompt
|
|
727
|
+
*/
|
|
728
|
+
getPrompt(
|
|
729
|
+
params: GetPromptRequest["params"] & {
|
|
730
|
+
serverId: string;
|
|
731
|
+
},
|
|
732
|
+
options: RequestOptions
|
|
733
|
+
): Promise<{
|
|
734
|
+
[x: string]: unknown;
|
|
735
|
+
messages: {
|
|
736
|
+
role: "user" | "assistant";
|
|
737
|
+
content:
|
|
738
|
+
| {
|
|
739
|
+
type: "text";
|
|
740
|
+
text: string;
|
|
741
|
+
_meta?: Record<string, unknown> | undefined;
|
|
742
|
+
}
|
|
743
|
+
| {
|
|
744
|
+
type: "image";
|
|
745
|
+
data: string;
|
|
746
|
+
mimeType: string;
|
|
747
|
+
_meta?: Record<string, unknown> | undefined;
|
|
748
|
+
}
|
|
749
|
+
| {
|
|
750
|
+
type: "audio";
|
|
751
|
+
data: string;
|
|
752
|
+
mimeType: string;
|
|
753
|
+
_meta?: Record<string, unknown> | undefined;
|
|
754
|
+
}
|
|
755
|
+
| {
|
|
756
|
+
type: "resource";
|
|
757
|
+
resource:
|
|
758
|
+
| {
|
|
759
|
+
uri: string;
|
|
760
|
+
text: string;
|
|
761
|
+
mimeType?: string | undefined;
|
|
762
|
+
_meta?: Record<string, unknown> | undefined;
|
|
763
|
+
}
|
|
764
|
+
| {
|
|
765
|
+
uri: string;
|
|
766
|
+
blob: string;
|
|
767
|
+
mimeType?: string | undefined;
|
|
768
|
+
_meta?: Record<string, unknown> | undefined;
|
|
769
|
+
};
|
|
770
|
+
_meta?: Record<string, unknown> | undefined;
|
|
771
|
+
}
|
|
772
|
+
| {
|
|
773
|
+
uri: string;
|
|
774
|
+
name: string;
|
|
775
|
+
type: "resource_link";
|
|
776
|
+
description?: string | undefined;
|
|
777
|
+
mimeType?: string | undefined;
|
|
778
|
+
_meta?:
|
|
779
|
+
| {
|
|
780
|
+
[x: string]: unknown;
|
|
781
|
+
}
|
|
782
|
+
| undefined;
|
|
783
|
+
icons?:
|
|
784
|
+
| {
|
|
785
|
+
src: string;
|
|
786
|
+
mimeType?: string | undefined;
|
|
787
|
+
sizes?: string[] | undefined;
|
|
788
|
+
}[]
|
|
789
|
+
| undefined;
|
|
790
|
+
title?: string | undefined;
|
|
791
|
+
};
|
|
792
|
+
}[];
|
|
793
|
+
_meta?: Record<string, unknown> | undefined;
|
|
794
|
+
description?: string | undefined;
|
|
795
|
+
}>;
|
|
796
|
+
}
|
|
797
|
+
type NamespacedData = {
|
|
798
|
+
tools: (Tool & {
|
|
799
|
+
serverId: string;
|
|
800
|
+
})[];
|
|
801
|
+
prompts: (Prompt & {
|
|
802
|
+
serverId: string;
|
|
803
|
+
})[];
|
|
804
|
+
resources: (Resource & {
|
|
805
|
+
serverId: string;
|
|
806
|
+
})[];
|
|
807
|
+
resourceTemplates: (ResourceTemplate & {
|
|
808
|
+
serverId: string;
|
|
809
|
+
})[];
|
|
810
|
+
};
|
|
811
|
+
declare function getNamespacedData<T extends keyof NamespacedData>(
|
|
812
|
+
mcpClients: Record<string, MCPClientConnection>,
|
|
813
|
+
type: T
|
|
814
|
+
): NamespacedData[T];
|
|
815
|
+
//#endregion
|
|
816
|
+
export {
|
|
817
|
+
MCPConnectionResult as a,
|
|
818
|
+
RegisterServerOptions as c,
|
|
819
|
+
BaseTransportType as d,
|
|
820
|
+
CORSOptions as f,
|
|
821
|
+
TransportType as h,
|
|
822
|
+
MCPClientOAuthResult as i,
|
|
823
|
+
getNamespacedData as l,
|
|
824
|
+
ServeOptions as m,
|
|
825
|
+
MCPClientManagerOptions as n,
|
|
826
|
+
MCPDiscoverResult as o,
|
|
827
|
+
MaybePromise as p,
|
|
828
|
+
MCPClientOAuthCallbackConfig as r,
|
|
829
|
+
MCPServerOptions as s,
|
|
830
|
+
MCPClientManager as t,
|
|
831
|
+
MCPConnectionState as u
|
|
832
|
+
};
|
|
833
|
+
//# sourceMappingURL=client-CwqTTb-B.d.ts.map
|