agents 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{agent-routing-vVMA7m8Y.d.ts → agent-routing-BSoZzNiP.d.ts} +537 -373
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-gGXXkf1z.d.ts → agent-tools-Be-hpRpH.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-sdk-Kon40i0q.js → ai-sdk-CRMlEBX7.js} +75 -44
- package/dist/ai-sdk-CRMlEBX7.js.map +1 -0
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.d.ts +7 -3
- package/dist/browser/index.js +2 -2
- package/dist/browser/tools/ai-sdk.d.ts +68 -3
- package/dist/browser/tools/pi.d.ts +2 -2
- package/dist/browser/tools/tanstack-ai.d.ts +2 -2
- package/dist/{browser-CI97khiJ.d.ts → browser-C9T74n4c.d.ts} +84 -5
- package/dist/{browser-tool-Cxtiwfua.d.ts → browser-tool-DxAYQY9T.d.ts} +2 -2
- package/dist/capability-DBAKc6UZ.js.map +1 -1
- package/dist/{capability-runner-BiVUtjqC.d.ts → capability-runner-uFOdSANC.d.ts} +3 -2
- package/dist/chat/index.d.ts +37 -6
- package/dist/chat/index.js +39 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +64 -63
- package/dist/client-CkT8voRY.js +3740 -0
- package/dist/client-CkT8voRY.js.map +1 -0
- package/dist/{client-eSfgYvd3.d.ts → client-DqS6oequ.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-Dl098To-.js → connector-Bphz6wIw.js} +16 -4
- package/dist/connector-Bphz6wIw.js.map +1 -0
- package/dist/{conversations-FjHDRZyD.d.ts → conversations-CoAYNW_q.d.ts} +4 -4
- package/dist/{current-agent-CKgT5d1O.d.ts → current-agent-DShbQHDO.d.ts} +24 -3
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{do-oauth-client-provider-DtNqv7oj.d.ts → do-oauth-client-provider-BsT8-vtd.d.ts} +22 -2
- package/dist/{durable-object-lifecycle-DOI_bzCH.d.ts → durable-object-lifecycle-CRCA6O0W.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/experimental/webmcp.js +1 -1
- package/dist/{gateway-BFO6vRDn.d.ts → gateway-Dz8zyZBJ.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/pi/index.d.ts +128 -12
- package/dist/harness/pi/index.js +128 -20
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/{images-CfuRCjwq.js → images-D4gtE06D.js} +119 -27
- package/dist/images-D4gtE06D.js.map +1 -0
- package/dist/{index-8k4qsX1T.d.ts → index-BXVgv6tp.d.ts} +4 -4
- package/dist/{index-BEL3ZV-s.d.ts → index-Cs7Ed9la.d.ts} +2 -2
- package/dist/{index-CBt8oRJt.d.ts → index-XiZxauMU.d.ts} +3 -3
- package/dist/index.d.ts +21 -21
- package/dist/index.js +2 -2
- package/dist/{input-schema-0uUu392-.js → input-schema-D6GilRXI.js} +2 -2
- package/dist/{input-schema-0uUu392-.js.map → input-schema-D6GilRXI.js.map} +1 -1
- package/dist/{input-schema-waggtYrH.js → input-schema-y8W5bOdM.js} +2 -2
- package/dist/{input-schema-waggtYrH.js.map → input-schema-y8W5bOdM.js.map} +1 -1
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-v1rKHV2C.js → lifecycle-CB5Dmtrt.js} +126 -38
- package/dist/lifecycle-CB5Dmtrt.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +45 -2
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +42 -36
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/client/x402.d.ts +8 -8
- package/dist/mcp/index.d.ts +17 -17
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/models/ai-sdk/index.d.ts +9 -5
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +3 -3
- package/dist/models/opencode/index.js +2 -2
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +4 -4
- package/dist/models/pi-ai/index.js +53 -29
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-CiIsJHXR.d.ts → options-CiXaymmZ.d.ts} +2 -2
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-CcIjVYTE.js → queue-B_wl6K0Z.js} +24 -5
- package/dist/queue-B_wl6K0Z.js.map +1 -0
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-BCLESHSC.d.ts → scheduler-CTpR0Ct0.d.ts} +2 -2
- package/dist/{scheduler-FIHv2-kJ.js → scheduler-DGNEmxQR.js} +2 -1
- package/dist/scheduler-DGNEmxQR.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/session-CRY0bGiI.js.map +1 -1
- package/dist/sessions/index.d.ts +1 -1
- package/dist/{settings-Dk2il2Hf.js → settings-D2F_qONv.js} +11 -2
- package/dist/settings-D2F_qONv.js.map +1 -0
- package/dist/{src-DoGNJ4Ud.js → src-BO1FdLK1.js} +145 -86
- package/dist/src-BO1FdLK1.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{streams-vrCtbUIn.d.ts → streams-CAZxZBDg.d.ts} +2 -2
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-BN_5AWqI.js → tasks-Cf_UfEO4.js} +2 -1
- package/dist/{tasks-BN_5AWqI.js.map → tasks-Cf_UfEO4.js.map} +1 -1
- package/dist/{tasks-E89KdwkS.d.ts → tasks-Cs8ilctE.d.ts} +2 -2
- package/dist/{tool-DkT_DJBm.js → tool-CmAGY6Fo.js} +24 -3
- package/dist/tool-CmAGY6Fo.js.map +1 -0
- package/dist/{tool-CxKsvxjm.js → tool-Kxcj8_22.js} +24 -4
- package/dist/tool-Kxcj8_22.js.map +1 -0
- package/dist/{transport-5moD2pW5.d.ts → transport-hV8AW4Bv.d.ts} +45 -12
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.js +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +2 -2
- package/dist/web/fetch/tools/pi.d.ts +5 -0
- package/dist/web/fetch/tools/pi.js +25 -2
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +2 -2
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.d.ts +4 -0
- package/dist/web/search/tools/pi.js +23 -2
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C6SJtWCJ.js → websockets-W4uhRg4-.js} +68 -5
- package/dist/websockets-W4uhRg4-.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +30 -4
- package/docs/browse-the-web.md +14 -0
- package/docs/chat-agents.md +13 -10
- package/docs/client-tools-continuation.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/configuration.md +6 -3
- package/docs/cross-domain-authentication.md +1 -1
- package/docs/fetch-the-web.md +20 -0
- package/docs/harnesses/pi.md +211 -22
- package/docs/harnesses/think.md +1 -1
- package/docs/http-websockets.md +40 -32
- package/docs/human-in-the-loop.md +2 -2
- package/docs/lifecycle.md +56 -0
- package/docs/mcp-client.md +104 -7
- package/docs/models-pi-ai.md +24 -10
- package/docs/models.md +42 -17
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +3 -6
- package/docs/search-the-web.md +10 -0
- package/docs/voice.md +1 -1
- package/package.json +13 -12
- package/dist/ai-sdk-CpuRsjP5.d.ts +0 -72
- package/dist/ai-sdk-Kon40i0q.js.map +0 -1
- package/dist/client-DMWujQJ1.js +0 -2325
- package/dist/client-DMWujQJ1.js.map +0 -1
- package/dist/connector-Dl098To-.js.map +0 -1
- package/dist/images-CfuRCjwq.js.map +0 -1
- package/dist/lifecycle-v1rKHV2C.js.map +0 -1
- package/dist/queue-CcIjVYTE.js.map +0 -1
- package/dist/scheduler-FIHv2-kJ.js.map +0 -1
- package/dist/settings-Dk2il2Hf.js.map +0 -1
- package/dist/src-DoGNJ4Ud.js.map +0 -1
- package/dist/tool-CxKsvxjm.js.map +0 -1
- package/dist/tool-DkT_DJBm.js.map +0 -1
- package/dist/websockets-C6SJtWCJ.js.map +0 -1
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
u as LifecycleRouteAddress,
|
|
9
9
|
v as LifecycleJobOutcome,
|
|
10
10
|
x as Connection
|
|
11
|
-
} from "./capability-runner-
|
|
11
|
+
} from "./capability-runner-uFOdSANC.js";
|
|
12
12
|
import { t as RetryOptions } from "./retries-CV6AkXmQ.js";
|
|
13
13
|
import {
|
|
14
14
|
r as LifecycleRouteEnvelope,
|
|
15
15
|
t as Lifecycle
|
|
16
|
-
} from "./durable-object-lifecycle-
|
|
17
|
-
import { n as CurrentAgentContext } from "./current-agent-
|
|
16
|
+
} from "./durable-object-lifecycle-CRCA6O0W.js";
|
|
17
|
+
import { n as CurrentAgentContext } from "./current-agent-DShbQHDO.js";
|
|
18
18
|
import { t as AgentEmail } from "./internal_context-BlxFEWfn.js";
|
|
19
19
|
import { r as EmailResolver, s as SendEmailOptions } from "./email-7TatiTnl.js";
|
|
20
20
|
import { r as InternalHostMessage } from "./internal-hosts-Kfp5A392.js";
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
n as ObservabilityEvent,
|
|
24
24
|
t as Observability
|
|
25
25
|
} from "./emitter-BJZtCVjQ.js";
|
|
26
|
-
import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-
|
|
26
|
+
import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-BsT8-vtd.js";
|
|
27
27
|
import {
|
|
28
28
|
i as McpClientOptions,
|
|
29
29
|
o as TransportType,
|
|
@@ -36,10 +36,10 @@ import {
|
|
|
36
36
|
i as Schedule,
|
|
37
37
|
o as ScheduleOptions,
|
|
38
38
|
t as Scheduler
|
|
39
|
-
} from "./scheduler-
|
|
39
|
+
} from "./scheduler-CTpR0Ct0.js";
|
|
40
40
|
import { i as QueueItem } from "./types-BA4anrjI.js";
|
|
41
|
-
import { l as TaskHandlers, r as Tasks } from "./tasks-
|
|
42
|
-
import { t as State } from "./index-
|
|
41
|
+
import { l as TaskHandlers, r as Tasks } from "./tasks-Cs8ilctE.js";
|
|
42
|
+
import { t as State } from "./index-Cs7Ed9la.js";
|
|
43
43
|
import { t as CallableMetadata } from "./callable-decorator-DP__HhBA.js";
|
|
44
44
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
45
45
|
import {
|
|
@@ -77,7 +77,8 @@ import {
|
|
|
77
77
|
StreamableHTTPReconnectionOptions,
|
|
78
78
|
Tool,
|
|
79
79
|
Transport,
|
|
80
|
-
TransportSendOptions
|
|
80
|
+
TransportSendOptions,
|
|
81
|
+
UnauthorizedError
|
|
81
82
|
} from "@modelcontextprotocol/client";
|
|
82
83
|
|
|
83
84
|
//#region src/observability/tracing/tracer.d.ts
|
|
@@ -273,7 +274,12 @@ type DynamicAgentConnectionMeta = {
|
|
|
273
274
|
requestHeaders?: [string, string][];
|
|
274
275
|
};
|
|
275
276
|
type DynamicAgentConnectionBridgeLike = {
|
|
276
|
-
send(
|
|
277
|
+
send(
|
|
278
|
+
message: string | ArrayBuffer | ArrayBufferView
|
|
279
|
+
): void | Promise<void> /** Sends `messages` in order, in one call. */;
|
|
280
|
+
sendMany(
|
|
281
|
+
messages: ReadonlyArray<string | ArrayBuffer | ArrayBufferView>
|
|
282
|
+
): void | Promise<void>;
|
|
277
283
|
close(code?: number, reason?: string): void | Promise<void>;
|
|
278
284
|
setState(state: unknown): unknown | Promise<unknown>;
|
|
279
285
|
broadcast(
|
|
@@ -366,6 +372,10 @@ type RootFacetRpcSurface = {
|
|
|
366
372
|
connectionId: string,
|
|
367
373
|
message: string | ArrayBuffer | ArrayBufferView
|
|
368
374
|
): Promise<void>;
|
|
375
|
+
_cf_sendManyToSubAgentConnection(
|
|
376
|
+
connectionId: string,
|
|
377
|
+
messages: ReadonlyArray<string | ArrayBuffer | ArrayBufferView>
|
|
378
|
+
): Promise<void>;
|
|
369
379
|
_cf_closeSubAgentConnection(
|
|
370
380
|
connectionId: string,
|
|
371
381
|
code?: number,
|
|
@@ -405,6 +415,9 @@ declare class DynamicAgentConnectionBridge
|
|
|
405
415
|
) => void | Promise<void>
|
|
406
416
|
);
|
|
407
417
|
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
418
|
+
sendMany(
|
|
419
|
+
messages: ReadonlyArray<string | ArrayBuffer | ArrayBufferView>
|
|
420
|
+
): void;
|
|
408
421
|
close(code?: number, reason?: string): void;
|
|
409
422
|
setState(state: unknown): unknown;
|
|
410
423
|
broadcast(
|
|
@@ -757,6 +770,16 @@ declare class DynamicAgentsInternal extends LifecycleCapability {
|
|
|
757
770
|
operationName: DynamicAgentConnectionOperationName,
|
|
758
771
|
operation: (bridge: DynamicAgentConnectionBridgeLike) => unknown
|
|
759
772
|
): void;
|
|
773
|
+
/**
|
|
774
|
+
* Route a virtual sub-agent connection send. A send that would wait behind
|
|
775
|
+
* another operation joins the waiting send batch instead, so a burst (such
|
|
776
|
+
* as a stream replay) costs one root call, not one per frame (#2820).
|
|
777
|
+
* Order is unchanged: a batch only ever holds consecutive sends.
|
|
778
|
+
*/
|
|
779
|
+
routeConnectionSend(
|
|
780
|
+
connectionId: string,
|
|
781
|
+
message: string | ArrayBuffer | ArrayBufferView
|
|
782
|
+
): void;
|
|
760
783
|
/**
|
|
761
784
|
* Route a facet broadcast after every older connection operation.
|
|
762
785
|
*
|
|
@@ -787,6 +810,10 @@ declare class DynamicAgentsInternal extends LifecycleCapability {
|
|
|
787
810
|
connectionId: string,
|
|
788
811
|
message: string | ArrayBuffer | ArrayBufferView
|
|
789
812
|
): Promise<void>;
|
|
813
|
+
sendManyToConnection(
|
|
814
|
+
connectionId: string,
|
|
815
|
+
messages: ReadonlyArray<string | ArrayBuffer | ArrayBufferView>
|
|
816
|
+
): Promise<void>;
|
|
790
817
|
closeConnection(
|
|
791
818
|
connectionId: string,
|
|
792
819
|
code?: number,
|
|
@@ -991,6 +1018,18 @@ declare class DynamicAgents {
|
|
|
991
1018
|
}>;
|
|
992
1019
|
}
|
|
993
1020
|
//#endregion
|
|
1021
|
+
//#region src/core/events.d.ts
|
|
1022
|
+
interface Disposable {
|
|
1023
|
+
dispose(): void;
|
|
1024
|
+
}
|
|
1025
|
+
type Event<T> = (listener: (e: T) => void) => Disposable;
|
|
1026
|
+
declare class Emitter<T> implements Disposable {
|
|
1027
|
+
private _listeners;
|
|
1028
|
+
readonly event: Event<T>;
|
|
1029
|
+
fire(data: T): void;
|
|
1030
|
+
dispose(): void;
|
|
1031
|
+
}
|
|
1032
|
+
//#endregion
|
|
994
1033
|
//#region src/mcp/rpc.d.ts
|
|
995
1034
|
/**
|
|
996
1035
|
* Structural shape of a Durable Object that serves MCP over RPC, such as
|
|
@@ -1030,18 +1069,6 @@ declare class RPCClientTransport implements Transport {
|
|
|
1030
1069
|
): Promise<void>;
|
|
1031
1070
|
}
|
|
1032
1071
|
//#endregion
|
|
1033
|
-
//#region src/core/events.d.ts
|
|
1034
|
-
interface Disposable {
|
|
1035
|
-
dispose(): void;
|
|
1036
|
-
}
|
|
1037
|
-
type Event<T> = (listener: (e: T) => void) => Disposable;
|
|
1038
|
-
declare class Emitter<T> implements Disposable {
|
|
1039
|
-
private _listeners;
|
|
1040
|
-
readonly event: Event<T>;
|
|
1041
|
-
fire(data: T): void;
|
|
1042
|
-
dispose(): void;
|
|
1043
|
-
}
|
|
1044
|
-
//#endregion
|
|
1045
1072
|
//#region src/mcp/client/connection.d.ts
|
|
1046
1073
|
/**
|
|
1047
1074
|
* Connection state machine for MCP client connections.
|
|
@@ -1075,6 +1102,12 @@ type MCPTransportOptions = (
|
|
|
1075
1102
|
) & {
|
|
1076
1103
|
authProvider?: AgentMcpOAuthProvider;
|
|
1077
1104
|
type?: TransportType;
|
|
1105
|
+
/**
|
|
1106
|
+
* Headers sent with every HTTP request, for servers that take a static
|
|
1107
|
+
* credential instead of OAuth. Stored with the server, so restored
|
|
1108
|
+
* connections send them too.
|
|
1109
|
+
*/
|
|
1110
|
+
headers?: HeadersInit;
|
|
1078
1111
|
};
|
|
1079
1112
|
/** Result of discovering server capabilities. */
|
|
1080
1113
|
type MCPDiscoveryResult =
|
|
@@ -1132,12 +1165,25 @@ declare class MCPClientConnection {
|
|
|
1132
1165
|
*/
|
|
1133
1166
|
private _pendingAuthTransport?;
|
|
1134
1167
|
private _restoredListSubscription?;
|
|
1168
|
+
/**
|
|
1169
|
+
* Whether the last connect or discovery failed because authorization was
|
|
1170
|
+
* refused in a way retrying cannot change: a 403 from the server, or an
|
|
1171
|
+
* OAuth error such as `invalid_target` from the authorization server. The
|
|
1172
|
+
* manager stops reconnecting such a server instead of asking again.
|
|
1173
|
+
*/
|
|
1174
|
+
accessRefused: boolean;
|
|
1175
|
+
/** Keeps concurrent `401`s from starting interleaved OAuth flows. */
|
|
1176
|
+
private readonly _authorizationTurns;
|
|
1135
1177
|
prompts: Prompt[];
|
|
1136
1178
|
resources: Resource[];
|
|
1137
1179
|
resourceTemplates: ResourceTemplateType[];
|
|
1138
1180
|
serverCapabilities: ServerCapabilities | undefined;
|
|
1139
1181
|
/** True when resuming a streamable-http session without cached capabilities */
|
|
1140
1182
|
private _probingCapabilities;
|
|
1183
|
+
/** Whether init() is connecting: its client must not be replaced. */
|
|
1184
|
+
private _connecting;
|
|
1185
|
+
/** The elicitation capability `client` was built to advertise, as JSON. */
|
|
1186
|
+
private _advertisedElicitation;
|
|
1141
1187
|
/** Tracks in-flight discovery to allow cancellation */
|
|
1142
1188
|
private _discoveryAbortController;
|
|
1143
1189
|
private readonly _onObservabilityEvent;
|
|
@@ -1180,6 +1226,14 @@ declare class MCPClientConnection {
|
|
|
1180
1226
|
* connections keep their negotiated capabilities until they reconnect.
|
|
1181
1227
|
*/
|
|
1182
1228
|
configureElicitationHandlers(handlers?: MCPElicitationHandlers): void;
|
|
1229
|
+
/** What a client built now would advertise for elicitation, as JSON. */
|
|
1230
|
+
private elicitationToAdvertise;
|
|
1231
|
+
/**
|
|
1232
|
+
* Connect, and connect again when the elicitation handlers changed during
|
|
1233
|
+
* the handshake: apps configure them in `onStart`, while a restored
|
|
1234
|
+
* server is already connecting.
|
|
1235
|
+
*/
|
|
1236
|
+
private connectWithCurrentHandlers;
|
|
1183
1237
|
/**
|
|
1184
1238
|
* Initialize a client connection, if authentication is required, the connection will be in the AUTHENTICATING state
|
|
1185
1239
|
* Sets connection state based on the result and emits observability events
|
|
@@ -2028,6 +2082,11 @@ declare class MCPClientConnection {
|
|
|
2028
2082
|
signal?: AbortSignal
|
|
2029
2083
|
): Promise<ElicitResult>;
|
|
2030
2084
|
private isResumedStreamableHttpSession;
|
|
2085
|
+
/**
|
|
2086
|
+
* @internal The transport of the open session, if any. Each connect opens
|
|
2087
|
+
* a new one, and init() drops it before reconnecting.
|
|
2088
|
+
*/
|
|
2089
|
+
get session(): object | undefined;
|
|
2031
2090
|
get sessionId(): string | undefined;
|
|
2032
2091
|
/** @internal Clear a restored session before reconnecting. */
|
|
2033
2092
|
clearResumedSession(): void;
|
|
@@ -2044,10 +2103,37 @@ declare class MCPClientConnection {
|
|
|
2044
2103
|
getTransport(
|
|
2045
2104
|
transportType: BaseTransportType
|
|
2046
2105
|
): RPCClientTransport | StreamableHTTPClientTransport | SSEClientTransport;
|
|
2106
|
+
/**
|
|
2107
|
+
* Take an HTTP transport's OAuth flows one at a time: a `401` waits for the
|
|
2108
|
+
* authorization an earlier one started, so concurrent requests share one
|
|
2109
|
+
* client registration and one pending link.
|
|
2110
|
+
*/
|
|
2111
|
+
/** Transport options whose `fetch` records the token each 401 carried. */
|
|
2112
|
+
private authorizationTurnOptions;
|
|
2113
|
+
private withAuthorizationTurns;
|
|
2047
2114
|
private tryConnect;
|
|
2048
2115
|
private _capabilityErrorHandler;
|
|
2049
2116
|
}
|
|
2050
2117
|
//#endregion
|
|
2118
|
+
//#region src/mcp/client/ai-tools.d.ts
|
|
2119
|
+
/** One MCP tool converted for the AI SDK. */
|
|
2120
|
+
type MCPAITool = {
|
|
2121
|
+
description?: string;
|
|
2122
|
+
title?: string;
|
|
2123
|
+
execute: (
|
|
2124
|
+
args: Record<string, unknown>,
|
|
2125
|
+
options?: unknown
|
|
2126
|
+
) => Promise<unknown>;
|
|
2127
|
+
inputSchema: z.ZodType;
|
|
2128
|
+
outputSchema?: z.ZodType;
|
|
2129
|
+
};
|
|
2130
|
+
/**
|
|
2131
|
+
* Structural tool set returned by {@link MCPClientManager.getAITools}.
|
|
2132
|
+
* Compatible with the AI SDK without importing its types into the core
|
|
2133
|
+
* `agents` declaration graph.
|
|
2134
|
+
*/
|
|
2135
|
+
type MCPAIToolSet = Record<string, MCPAITool>;
|
|
2136
|
+
//#endregion
|
|
2051
2137
|
//#region src/mcp/client/storage.d.ts
|
|
2052
2138
|
/**
|
|
2053
2139
|
* Represents a row in the cf_agents_mcp_servers table.
|
|
@@ -2098,52 +2184,9 @@ type PersistedMcpServerOptions = {
|
|
|
2098
2184
|
capabilities?: ClientCapabilities;
|
|
2099
2185
|
};
|
|
2100
2186
|
//#endregion
|
|
2101
|
-
//#region src/mcp/client/
|
|
2102
|
-
type MCPAITool = {
|
|
2103
|
-
description?: string;
|
|
2104
|
-
title?: string;
|
|
2105
|
-
execute: (
|
|
2106
|
-
args: Record<string, unknown>,
|
|
2107
|
-
options?: unknown
|
|
2108
|
-
) => Promise<unknown>;
|
|
2109
|
-
inputSchema: z.ZodType;
|
|
2110
|
-
outputSchema?: z.ZodType;
|
|
2111
|
-
};
|
|
2112
|
-
/**
|
|
2113
|
-
* Structural tool set returned by {@link MCPClientManager.getAITools}.
|
|
2114
|
-
* Compatible with the AI SDK without importing its types into the core
|
|
2115
|
-
* `agents` declaration graph.
|
|
2116
|
-
*/
|
|
2117
|
-
type MCPAIToolSet = Record<string, MCPAITool>;
|
|
2118
|
-
/** Maximum length of a normalized MCP server id. */
|
|
2119
|
-
declare const MCP_SERVER_ID_MAX_LENGTH = 64;
|
|
2120
|
-
/**
|
|
2121
|
-
* Normalize a caller-supplied MCP server id into a stable, storage- and
|
|
2122
|
-
* tool-name-safe form.
|
|
2123
|
-
*
|
|
2124
|
-
* The id is surfaced in several places where the character set matters:
|
|
2125
|
-
* - as the primary key in the `cf_agents_mcp_servers` SQLite table
|
|
2126
|
-
* - embedded in AI SDK tool names as `` `tool_${id.replace(/-/g, "")}_${tool}` ``
|
|
2127
|
-
* (tool names must match `/^[A-Za-z0-9_]+$/`)
|
|
2128
|
-
* - as a key on the `mcpConnections` map and OAuth provider storage
|
|
2129
|
-
*
|
|
2130
|
-
* Rules:
|
|
2131
|
-
* 1. Lowercase.
|
|
2132
|
-
* 2. Replace any run of disallowed characters with a single `-`.
|
|
2133
|
-
* 3. Collapse repeated `-` and trim leading/trailing `-`/`_`.
|
|
2134
|
-
* 4. Prefix with `id-` if the result is empty or doesn't start with a letter.
|
|
2135
|
-
* 5. Truncate to {@link MCP_SERVER_ID_MAX_LENGTH} characters.
|
|
2136
|
-
*
|
|
2137
|
-
* @example
|
|
2138
|
-
* normalizeServerId("my-supplied-id"); // "my-supplied-id"
|
|
2139
|
-
* normalizeServerId("GitHub MCP!"); // "github-mcp"
|
|
2140
|
-
* normalizeServerId("42-things"); // "id-42-things"
|
|
2141
|
-
*/
|
|
2142
|
-
declare function normalizeServerId(input: string): string;
|
|
2187
|
+
//#region src/mcp/client/types.d.ts
|
|
2143
2188
|
type MCPServerOptions = PersistedMcpServerOptions;
|
|
2144
|
-
/**
|
|
2145
|
-
* Result of an OAuth callback request
|
|
2146
|
-
*/
|
|
2189
|
+
/** Result of an OAuth callback request. */
|
|
2147
2190
|
type MCPOAuthCallbackResult =
|
|
2148
2191
|
| {
|
|
2149
2192
|
serverId: string;
|
|
@@ -2155,9 +2198,7 @@ type MCPOAuthCallbackResult =
|
|
|
2155
2198
|
authSuccess: false;
|
|
2156
2199
|
authError: string;
|
|
2157
2200
|
};
|
|
2158
|
-
/**
|
|
2159
|
-
* Options for registering an MCP server
|
|
2160
|
-
*/
|
|
2201
|
+
/** Options for registering an MCP server. */
|
|
2161
2202
|
type RegisterServerOptions = {
|
|
2162
2203
|
url: string;
|
|
2163
2204
|
name: string;
|
|
@@ -2185,33 +2226,48 @@ type MCPConnectionResult =
|
|
|
2185
2226
|
| {
|
|
2186
2227
|
state: typeof MCPConnectionState.CONNECTED;
|
|
2187
2228
|
};
|
|
2229
|
+
/**
|
|
2230
|
+
* @internal Where a server ended up after `connectAndDiscover()`,
|
|
2231
|
+
* `settleServer()` or `reconnectServer()`: ready, waiting for the user to
|
|
2232
|
+
* authorize (with the link when one is usable), failed in a named phase, or
|
|
2233
|
+
* removed meanwhile.
|
|
2234
|
+
*/
|
|
2235
|
+
type MCPServerSettlement =
|
|
2236
|
+
| {
|
|
2237
|
+
readonly state: typeof MCPConnectionState.READY;
|
|
2238
|
+
}
|
|
2239
|
+
| {
|
|
2240
|
+
readonly state: typeof MCPConnectionState.AUTHENTICATING;
|
|
2241
|
+
readonly authUrl: string | undefined;
|
|
2242
|
+
}
|
|
2243
|
+
| {
|
|
2244
|
+
readonly state: typeof MCPConnectionState.FAILED;
|
|
2245
|
+
readonly phase: "connect" | "discover";
|
|
2246
|
+
readonly error: string;
|
|
2247
|
+
/**
|
|
2248
|
+
* Authorization was refused in a way retrying cannot change: a 401 no
|
|
2249
|
+
* link could answer, a 403, or a refusing OAuth error.
|
|
2250
|
+
*/
|
|
2251
|
+
readonly refused?: true;
|
|
2252
|
+
}
|
|
2253
|
+
| {
|
|
2254
|
+
readonly state: "removed";
|
|
2255
|
+
};
|
|
2188
2256
|
/**
|
|
2189
2257
|
* Result of discovering server capabilities.
|
|
2190
2258
|
* success indicates whether discovery completed successfully.
|
|
2191
2259
|
* state is the current connection state at time of return.
|
|
2192
2260
|
* error is present when success is false.
|
|
2261
|
+
* authUrl is present when discovery needs the user to authorize: the server
|
|
2262
|
+
* answered a catalog request with 401 and the connection is `authenticating`.
|
|
2193
2263
|
*/
|
|
2194
2264
|
type MCPDiscoverResult = {
|
|
2195
2265
|
success: boolean;
|
|
2196
2266
|
state: MCPConnectionState;
|
|
2197
|
-
error?: string
|
|
2267
|
+
error?: string /** Authorization URL to send the user to, when `state` is `authenticating`. */;
|
|
2268
|
+
authUrl?: string /** OAuth client id for `authUrl`, when known. */;
|
|
2269
|
+
clientId?: string;
|
|
2198
2270
|
};
|
|
2199
|
-
type MCPClientOAuthCallbackConfig = {
|
|
2200
|
-
successRedirect?: string;
|
|
2201
|
-
errorRedirect?: string;
|
|
2202
|
-
customHandler?: (result: MCPClientOAuthResult) => Response;
|
|
2203
|
-
};
|
|
2204
|
-
type MCPClientOAuthResult =
|
|
2205
|
-
| {
|
|
2206
|
-
serverId: string;
|
|
2207
|
-
authSuccess: true;
|
|
2208
|
-
authError?: undefined;
|
|
2209
|
-
}
|
|
2210
|
-
| {
|
|
2211
|
-
serverId?: string;
|
|
2212
|
-
authSuccess: false /** May contain untrusted content from external OAuth providers. Escape appropriately for your output context. */;
|
|
2213
|
-
authError: string;
|
|
2214
|
-
};
|
|
2215
2271
|
type MCPClientElicitationHandler = (
|
|
2216
2272
|
request: ElicitRequest,
|
|
2217
2273
|
serverId: string /** Aborts when the originating MCP operation is cancelled. */,
|
|
@@ -2222,7 +2278,7 @@ type MCPClientElicitationHandlers = {
|
|
|
2222
2278
|
form?: MCPClientElicitationHandler;
|
|
2223
2279
|
url?: MCPClientElicitationHandler;
|
|
2224
2280
|
};
|
|
2225
|
-
/** Dependencies used by
|
|
2281
|
+
/** Dependencies used by `MCPClientManager` across Durable Object wakes. */
|
|
2226
2282
|
type MCPClientManagerOptions = {
|
|
2227
2283
|
/**
|
|
2228
2284
|
* Runtime bindings used to restore persisted RPC MCP connections.
|
|
@@ -2244,24 +2300,75 @@ type MCPServerFilter = {
|
|
|
2244
2300
|
| string[] /** Include only connections currently in this state (or states). */;
|
|
2245
2301
|
state?: MCPConnectionState | MCPConnectionState[];
|
|
2246
2302
|
};
|
|
2303
|
+
//#endregion
|
|
2304
|
+
//#region src/mcp/client/catalog.d.ts
|
|
2305
|
+
type NamespacedData = {
|
|
2306
|
+
tools: (Tool & {
|
|
2307
|
+
serverId: string;
|
|
2308
|
+
})[];
|
|
2309
|
+
prompts: (Prompt & {
|
|
2310
|
+
serverId: string;
|
|
2311
|
+
})[];
|
|
2312
|
+
resources: (Resource & {
|
|
2313
|
+
serverId: string;
|
|
2314
|
+
})[];
|
|
2315
|
+
resourceTemplates: (ResourceTemplateType & {
|
|
2316
|
+
serverId: string;
|
|
2317
|
+
})[];
|
|
2318
|
+
};
|
|
2319
|
+
/** One catalog of every given connection, each entry tagged with its server. */
|
|
2320
|
+
declare function getNamespacedData<T extends keyof NamespacedData>(
|
|
2321
|
+
mcpClients: Record<string, MCPClientConnection>,
|
|
2322
|
+
type: T
|
|
2323
|
+
): NamespacedData[T];
|
|
2324
|
+
//#endregion
|
|
2325
|
+
//#region src/mcp/client/oauth-callback.d.ts
|
|
2326
|
+
/** Configures how the manager answers an OAuth callback request. */
|
|
2327
|
+
type MCPClientOAuthCallbackConfig = {
|
|
2328
|
+
/** Redirect target after a successful callback. */ successRedirect?: string /** Redirect target after a failed callback; `error` is appended. */;
|
|
2329
|
+
errorRedirect?: string /** Build the response yourself; takes precedence over the redirects. */;
|
|
2330
|
+
customHandler?: (result: MCPClientOAuthResult) => Response;
|
|
2331
|
+
};
|
|
2332
|
+
/** Outcome of an OAuth callback request. */
|
|
2333
|
+
type MCPClientOAuthResult =
|
|
2334
|
+
| {
|
|
2335
|
+
serverId: string;
|
|
2336
|
+
authSuccess: true;
|
|
2337
|
+
authError?: undefined;
|
|
2338
|
+
}
|
|
2339
|
+
| {
|
|
2340
|
+
serverId?: string;
|
|
2341
|
+
authSuccess: false /** May contain untrusted content from external OAuth providers. Escape appropriately for your output context. */;
|
|
2342
|
+
authError: string;
|
|
2343
|
+
};
|
|
2344
|
+
//#endregion
|
|
2345
|
+
//#region src/mcp/client/legacy-connect.d.ts
|
|
2346
|
+
/** Options for the deprecated `MCPClientManager.connect()`. */
|
|
2347
|
+
type LegacyConnectOptions = {
|
|
2348
|
+
/** Reconnect an existing server id, optionally completing OAuth with a code. */ reconnect?: {
|
|
2349
|
+
id: string;
|
|
2350
|
+
oauthClientId?: string;
|
|
2351
|
+
oauthCode?: string;
|
|
2352
|
+
} /** Transport options, including the OAuth provider whose auth URL is read. */;
|
|
2353
|
+
transport?: MCPTransportOptions /** MCP SDK client options. */;
|
|
2354
|
+
client?: McpClientOptions;
|
|
2355
|
+
};
|
|
2356
|
+
//#endregion
|
|
2357
|
+
//#region src/mcp/client/manager.d.ts
|
|
2247
2358
|
/**
|
|
2248
2359
|
* A Durable Object capability that persists and aggregates MCP client
|
|
2249
2360
|
* connections. Install it on any Lifecycle, or use `agent.mcp` on an Agent.
|
|
2361
|
+
*
|
|
2362
|
+
* The manager is the public API and the Lifecycle hooks. Behind it:
|
|
2363
|
+
* - {@link ServerController}: each server's connection life, and what
|
|
2364
|
+
* happens after a failure
|
|
2365
|
+
* - {@link AuthorizationController}: authorization links, OAuth callbacks
|
|
2366
|
+
* and re-authorization during requests
|
|
2250
2367
|
*/
|
|
2251
2368
|
declare class MCPClientManager extends LifecycleCapability {
|
|
2369
|
+
#private;
|
|
2252
2370
|
private readonly _name;
|
|
2253
|
-
private readonly _version;
|
|
2254
2371
|
mcpConnections: Record<string, MCPClientConnection>;
|
|
2255
|
-
/** Cache only the current catalog so old schema graphs are not retained. */
|
|
2256
|
-
private readonly _aiToolSchemas;
|
|
2257
|
-
private _didWarnAboutUnstableGetAITools;
|
|
2258
|
-
private _oauthCallbackConfig?;
|
|
2259
|
-
private _connectionDisposables;
|
|
2260
|
-
private readonly _env;
|
|
2261
|
-
private readonly _createAuthProviderFn;
|
|
2262
|
-
private _isRestored;
|
|
2263
|
-
private _pendingConnections;
|
|
2264
|
-
private _elicitationHandlers?;
|
|
2265
2372
|
/** @internal Protected for testing purposes. */
|
|
2266
2373
|
protected readonly _onObservabilityEvent: Emitter<MCPObservabilityEvent>;
|
|
2267
2374
|
readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
|
|
@@ -2271,166 +2378,31 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2271
2378
|
* This is useful for broadcasting server state to clients.
|
|
2272
2379
|
*/
|
|
2273
2380
|
readonly onServerStateChanged: Event<void>;
|
|
2381
|
+
private readonly _lanes;
|
|
2382
|
+
private _isRestored;
|
|
2383
|
+
private readonly aiTools;
|
|
2384
|
+
private didWarnAboutUnstableGetAITools;
|
|
2385
|
+
private readonly ctx;
|
|
2386
|
+
private readonly status;
|
|
2387
|
+
private readonly elicitation;
|
|
2388
|
+
private readonly authorization;
|
|
2389
|
+
private readonly servers;
|
|
2274
2390
|
/**
|
|
2275
2391
|
* Construct a reusable Durable Object MCP client capability.
|
|
2276
2392
|
*
|
|
2277
|
-
* @param
|
|
2278
|
-
* @param
|
|
2393
|
+
* @param name - MCP client implementation name sent during negotiation.
|
|
2394
|
+
* @param version - MCP client implementation version sent during negotiation.
|
|
2279
2395
|
* @param options - Optional runtime bindings and OAuth configuration.
|
|
2280
2396
|
*/
|
|
2281
2397
|
constructor(
|
|
2282
2398
|
_name: string,
|
|
2283
|
-
|
|
2399
|
+
version: string,
|
|
2284
2400
|
options?: MCPClientManagerOptions
|
|
2285
2401
|
);
|
|
2286
2402
|
/** Restore persisted HTTP and RPC connections before the host handles work. */
|
|
2287
2403
|
onStart(): Promise<void>;
|
|
2288
2404
|
/** Intercept a registered MCP OAuth callback request. */
|
|
2289
2405
|
onRequest(context: CapabilityRequestContext): Promise<Response | undefined>;
|
|
2290
|
-
private oauthCallbackResponse;
|
|
2291
|
-
/**
|
|
2292
|
-
* Scope the manager-level elicitation handler to a single connection.
|
|
2293
|
-
* Returns undefined when no handler is configured so the connection keeps
|
|
2294
|
-
* its default throwing behavior.
|
|
2295
|
-
*/
|
|
2296
|
-
private scopedElicitationHandlers;
|
|
2297
|
-
private sql;
|
|
2298
|
-
private saveServerToStorage;
|
|
2299
|
-
private removeServerFromStorage;
|
|
2300
|
-
/**
|
|
2301
|
-
* Rename a server's id, in-place, across every place the id is used as a
|
|
2302
|
-
* key. Used to JIT-migrate servers that were originally registered under an
|
|
2303
|
-
* auto-generated nanoid to a caller-supplied stable id (see
|
|
2304
|
-
* `Agent.addMcpServer`'s `{ id }` option).
|
|
2305
|
-
*
|
|
2306
|
-
* Migrates:
|
|
2307
|
-
* - the `cf_agents_mcp_servers` row (primary key)
|
|
2308
|
-
* - the in-memory `mcpConnections` map key
|
|
2309
|
-
* - the connection disposables map key
|
|
2310
|
-
* - the attached `authProvider.serverId`, if any
|
|
2311
|
-
* - OAuth-related storage keys under `/{clientName}/{oldId}/...`
|
|
2312
|
-
*
|
|
2313
|
-
* Safe to call when no OAuth keys exist (RPC / bearer-token HTTP servers).
|
|
2314
|
-
* If `oldId === newId` this is a no-op. If a row already exists under
|
|
2315
|
-
* `newId`, throws — the caller is expected to have verified uniqueness.
|
|
2316
|
-
*
|
|
2317
|
-
* @internal Exposed for `Agent.addMcpServer` JIT-migration.
|
|
2318
|
-
*/
|
|
2319
|
-
migrateServerId(
|
|
2320
|
-
oldId: string,
|
|
2321
|
-
newId: string,
|
|
2322
|
-
clientName: string
|
|
2323
|
-
): Promise<void>;
|
|
2324
|
-
private _renameInMemoryConnection;
|
|
2325
|
-
private getServersFromStorage;
|
|
2326
|
-
private filterConnections;
|
|
2327
|
-
/**
|
|
2328
|
-
* Get the parsed server_options for a stored server, if any.
|
|
2329
|
-
*/
|
|
2330
|
-
private getStoredServerOptions;
|
|
2331
|
-
/**
|
|
2332
|
-
* Clear the capabilities persisted on a stored server row. Called once a
|
|
2333
|
-
* seeded connection's handshake completes (see `createConnection`): the
|
|
2334
|
-
* stamp is valid for one successful restore — sessions that configure
|
|
2335
|
-
* handlers re-stamp every row, so a deploy that stops configuring them
|
|
2336
|
-
* stops advertising stale modes after its first connected wake instead of
|
|
2337
|
-
* forever, while wakes that never handshake don't burn the stamp.
|
|
2338
|
-
*/
|
|
2339
|
-
private clearStoredCapabilities;
|
|
2340
|
-
/**
|
|
2341
|
-
* Get the retry options for a server from stored server_options
|
|
2342
|
-
*/
|
|
2343
|
-
private getServerRetryOptions;
|
|
2344
|
-
private clearServerAuthUrl;
|
|
2345
|
-
private updateStoredSession;
|
|
2346
|
-
private failConnection;
|
|
2347
|
-
private isAuthAcceptedConnection;
|
|
2348
|
-
private oauthCallbackSuccess;
|
|
2349
|
-
private runWithCodeVerifierState;
|
|
2350
|
-
private hasRedeemableOAuthState;
|
|
2351
|
-
private ignoreUnverifiedCallback;
|
|
2352
|
-
private consumeStaleOAuthState;
|
|
2353
|
-
private completeAuthorizationAndCleanupVerifier;
|
|
2354
|
-
/**
|
|
2355
|
-
* Create an auth provider for a server
|
|
2356
|
-
* @internal
|
|
2357
|
-
*/
|
|
2358
|
-
private createAuthProvider;
|
|
2359
|
-
/** Get saved RPC servers from storage (servers with `rpc://` URLs). */
|
|
2360
|
-
getRpcServersFromStorage(): MCPServerRow[];
|
|
2361
|
-
/**
|
|
2362
|
-
* Save an RPC server to storage for hibernation recovery.
|
|
2363
|
-
* The binding name is stored so this manager can resolve the namespace from
|
|
2364
|
-
* its runtime environment during restore.
|
|
2365
|
-
*/
|
|
2366
|
-
saveRpcServerToStorage(
|
|
2367
|
-
id: string,
|
|
2368
|
-
name: string,
|
|
2369
|
-
normalizedName: string,
|
|
2370
|
-
bindingName: string,
|
|
2371
|
-
props?: Record<string, unknown>
|
|
2372
|
-
): void;
|
|
2373
|
-
/**
|
|
2374
|
-
* Restore persisted HTTP MCP connections.
|
|
2375
|
-
*
|
|
2376
|
-
* @param clientName - Durable Object identity used to scope OAuth state.
|
|
2377
|
-
*/
|
|
2378
|
-
restoreConnectionsFromStorage(clientName: string): Promise<void>;
|
|
2379
|
-
/**
|
|
2380
|
-
* Track a pending connection promise for a server.
|
|
2381
|
-
* The promise is removed from the map when it settles.
|
|
2382
|
-
*/
|
|
2383
|
-
private _trackConnection;
|
|
2384
|
-
/**
|
|
2385
|
-
* Wait for all in-flight connection and discovery operations to settle.
|
|
2386
|
-
* This is useful when you need MCP tools to be available before proceeding,
|
|
2387
|
-
* e.g. before calling getAITools() after the agent wakes from hibernation.
|
|
2388
|
-
*
|
|
2389
|
-
* Returns once every pending connection has either connected and discovered,
|
|
2390
|
-
* failed, or timed out. Never rejects.
|
|
2391
|
-
*
|
|
2392
|
-
* @param options.timeout - Maximum time in milliseconds to wait.
|
|
2393
|
-
* `0` returns immediately without waiting.
|
|
2394
|
-
* `undefined` (default) waits indefinitely.
|
|
2395
|
-
*/
|
|
2396
|
-
waitForConnections(options?: { timeout?: number }): Promise<void>;
|
|
2397
|
-
private _connectWithRetry;
|
|
2398
|
-
/**
|
|
2399
|
-
* Internal method to restore a single server connection and discovery
|
|
2400
|
-
*/
|
|
2401
|
-
private _restoreServer;
|
|
2402
|
-
/**
|
|
2403
|
-
* Connect to and register an MCP server
|
|
2404
|
-
*
|
|
2405
|
-
* @deprecated This method is maintained for backward compatibility.
|
|
2406
|
-
* For new code, use registerServer() and connectToServer() separately.
|
|
2407
|
-
*
|
|
2408
|
-
* @param url Server URL
|
|
2409
|
-
* @param options Connection options
|
|
2410
|
-
* @returns Object with server ID, auth URL (if OAuth), and client ID (if OAuth)
|
|
2411
|
-
*/
|
|
2412
|
-
connect(
|
|
2413
|
-
url: string,
|
|
2414
|
-
options?: {
|
|
2415
|
-
reconnect?: {
|
|
2416
|
-
id: string;
|
|
2417
|
-
oauthClientId?: string;
|
|
2418
|
-
oauthCode?: string;
|
|
2419
|
-
};
|
|
2420
|
-
transport?: MCPTransportOptions;
|
|
2421
|
-
client?: McpClientOptions;
|
|
2422
|
-
}
|
|
2423
|
-
): Promise<{
|
|
2424
|
-
id: string;
|
|
2425
|
-
authUrl?: string;
|
|
2426
|
-
clientId?: string;
|
|
2427
|
-
}>;
|
|
2428
|
-
/**
|
|
2429
|
-
* Create an in-memory connection object and set up observability
|
|
2430
|
-
* Does NOT save to storage - use registerServer() for that
|
|
2431
|
-
* @returns The connection object (existing or newly created)
|
|
2432
|
-
*/
|
|
2433
|
-
private createConnection;
|
|
2434
2406
|
/**
|
|
2435
2407
|
* Register an MCP server connection without connecting
|
|
2436
2408
|
* Creates the connection object, sets up observability, and saves to storage
|
|
@@ -2440,8 +2412,6 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2440
2412
|
* @returns Server ID
|
|
2441
2413
|
*/
|
|
2442
2414
|
registerServer(id: string, options: RegisterServerOptions): Promise<string>;
|
|
2443
|
-
/** Persist and emit an OAuth continuation produced by connect or discovery. */
|
|
2444
|
-
private persistAuthContinuation;
|
|
2445
2415
|
/**
|
|
2446
2416
|
* Connect to an already registered MCP server and initialize the connection.
|
|
2447
2417
|
*
|
|
@@ -2457,17 +2427,13 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2457
2427
|
* @returns Connection result with current state and OAuth info (if applicable)
|
|
2458
2428
|
*/
|
|
2459
2429
|
connectToServer(id: string): Promise<MCPConnectionResult>;
|
|
2460
|
-
private extractServerIdFromState;
|
|
2461
|
-
isCallbackRequest(req: Request): boolean;
|
|
2462
|
-
private validateCallbackRequest;
|
|
2463
|
-
handleCallbackRequest(req: Request): Promise<MCPOAuthCallbackResult>;
|
|
2464
2430
|
/**
|
|
2465
2431
|
* Discover server capabilities if connection is in CONNECTED or READY state.
|
|
2466
2432
|
* Transitions to DISCOVERING then READY (or CONNECTED on error).
|
|
2467
2433
|
* Can be called to refresh server capabilities (e.g., from a UI refresh button).
|
|
2468
2434
|
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2435
|
+
* Runs after any connection work already queued for the same server, so a
|
|
2436
|
+
* call made during another discovery waits for it and then refreshes again.
|
|
2471
2437
|
*
|
|
2472
2438
|
* @param serverId The server ID to discover
|
|
2473
2439
|
* @param options Optional configuration
|
|
@@ -2480,8 +2446,6 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2480
2446
|
timeoutMs?: number;
|
|
2481
2447
|
}
|
|
2482
2448
|
): Promise<MCPDiscoverResult | undefined>;
|
|
2483
|
-
private _toDiscoverResult;
|
|
2484
|
-
private _recoverStaleSession;
|
|
2485
2449
|
/**
|
|
2486
2450
|
* Establish connection in the background after OAuth completion.
|
|
2487
2451
|
* This method connects to the server and discovers its capabilities.
|
|
@@ -2490,98 +2454,152 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2490
2454
|
* @param serverId The server ID to establish connection for
|
|
2491
2455
|
*/
|
|
2492
2456
|
establishConnection(serverId: string): Promise<void>;
|
|
2493
|
-
private _doEstablishConnection;
|
|
2494
2457
|
/**
|
|
2495
|
-
*
|
|
2496
|
-
*
|
|
2458
|
+
* @internal Connect a registered server and discover its capabilities, as
|
|
2459
|
+
* one unit of lane work. A failure is recorded.
|
|
2497
2460
|
*/
|
|
2498
|
-
|
|
2461
|
+
connectAndDiscover(id: string): Promise<MCPServerSettlement>;
|
|
2499
2462
|
/**
|
|
2500
|
-
*
|
|
2463
|
+
* @internal Bring an already-registered server to a settled state once the
|
|
2464
|
+
* work queued for it has run, for `addMcpServer()`. Never retries a failed
|
|
2465
|
+
* server.
|
|
2466
|
+
*/
|
|
2467
|
+
settleServer(id: string): Promise<MCPServerSettlement>;
|
|
2468
|
+
/**
|
|
2469
|
+
* @internal Try a server again because someone asked: forget a recorded
|
|
2470
|
+
* failure, its link and the step-up budget, and connect now.
|
|
2471
|
+
*/
|
|
2472
|
+
reconnectServer(id: string): Promise<MCPServerSettlement>;
|
|
2473
|
+
/**
|
|
2474
|
+
* Restore persisted HTTP MCP connections. Runs once per wake.
|
|
2501
2475
|
*
|
|
2502
|
-
*
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
*
|
|
2476
|
+
* @param clientName - Durable Object identity used to scope OAuth state.
|
|
2477
|
+
*/
|
|
2478
|
+
restoreConnectionsFromStorage(clientName: string): Promise<void>;
|
|
2479
|
+
/**
|
|
2480
|
+
* Wait for all in-flight connection and discovery operations to settle.
|
|
2481
|
+
* This is useful when you need MCP tools to be available before proceeding,
|
|
2482
|
+
* e.g. before calling getAITools() after the agent wakes from hibernation.
|
|
2507
2483
|
*
|
|
2508
|
-
*
|
|
2509
|
-
*
|
|
2510
|
-
* even when this is called later in the wake-up (e.g. from onStart) — the
|
|
2511
|
-
* handlers attach to the live connections as soon as this runs.
|
|
2484
|
+
* Returns once every pending connection has either connected and discovered,
|
|
2485
|
+
* failed, or timed out. Never rejects.
|
|
2512
2486
|
*
|
|
2513
|
-
*
|
|
2487
|
+
* @param options.timeout - Maximum time in milliseconds to wait.
|
|
2488
|
+
* `0` returns immediately without waiting.
|
|
2489
|
+
* `undefined` (default) waits indefinitely.
|
|
2490
|
+
*/
|
|
2491
|
+
waitForConnections(options?: { timeout?: number }): Promise<void>;
|
|
2492
|
+
/**
|
|
2493
|
+
* Rename a server's id, in-place, across every place the id is used as a
|
|
2494
|
+
* key: its row, its connection, its provider, its OAuth storage keys under
|
|
2495
|
+
* `/{clientName}/{oldId}/...`. Used to migrate a
|
|
2496
|
+
* server registered under an auto-generated id to a caller-supplied
|
|
2497
|
+
* stable id (see `Agent.addMcpServer`'s `{ id }` option).
|
|
2514
2498
|
*
|
|
2515
|
-
*
|
|
2499
|
+
* A no-op when `oldId === newId`. Throws when a row already exists under
|
|
2500
|
+
* `newId`; the caller is expected to have verified uniqueness.
|
|
2501
|
+
*
|
|
2502
|
+
* @internal Exposed for `Agent.addMcpServer` JIT-migration.
|
|
2516
2503
|
*/
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2504
|
+
migrateServerId(
|
|
2505
|
+
oldId: string,
|
|
2506
|
+
newId: string,
|
|
2507
|
+
clientName: string
|
|
2508
|
+
): Promise<void>;
|
|
2520
2509
|
/**
|
|
2521
|
-
*
|
|
2522
|
-
*
|
|
2523
|
-
* themselves are reconfigured.
|
|
2510
|
+
* Closes a connection to an MCP server
|
|
2511
|
+
* @param id The id of the connection to close
|
|
2524
2512
|
*/
|
|
2525
|
-
|
|
2513
|
+
closeConnection(id: string): Promise<void>;
|
|
2526
2514
|
/**
|
|
2527
|
-
*
|
|
2528
|
-
*
|
|
2515
|
+
* Closes every in-memory connection. Servers stay stored, and their
|
|
2516
|
+
* callback URLs still match incoming OAuth requests; use removeServer()
|
|
2517
|
+
* to delete a server.
|
|
2529
2518
|
*/
|
|
2530
|
-
|
|
2519
|
+
closeAllConnections(): Promise<void>;
|
|
2531
2520
|
/**
|
|
2532
|
-
*
|
|
2533
|
-
* @returns namespaced list of tools
|
|
2521
|
+
* Remove an MCP server - closes connection if active and removes from storage.
|
|
2534
2522
|
*/
|
|
2535
|
-
|
|
2523
|
+
removeServer(serverId: string): Promise<void>;
|
|
2536
2524
|
/**
|
|
2537
|
-
*
|
|
2538
|
-
* while a live connection retains the same catalog array and schema-source
|
|
2539
|
-
* identities; tool records and execute closures are rebuilt on every call.
|
|
2540
|
-
*
|
|
2541
|
-
* @param filter - Optional filter to scope results to specific servers
|
|
2542
|
-
* @returns a set of tools that you can use with the AI SDK
|
|
2525
|
+
* List all MCP servers from storage
|
|
2543
2526
|
*/
|
|
2544
|
-
|
|
2527
|
+
listServers(): MCPServerRow[];
|
|
2528
|
+
/** Get saved RPC servers from storage (servers with `rpc://` URLs). */
|
|
2529
|
+
getRpcServersFromStorage(): MCPServerRow[];
|
|
2545
2530
|
/**
|
|
2546
|
-
*
|
|
2547
|
-
*
|
|
2548
|
-
*
|
|
2531
|
+
* Save an RPC server to storage for hibernation recovery.
|
|
2532
|
+
* The binding name is stored so this manager can resolve the namespace from
|
|
2533
|
+
* its runtime environment during restore.
|
|
2549
2534
|
*/
|
|
2550
|
-
|
|
2535
|
+
saveRpcServerToStorage(
|
|
2536
|
+
id: string,
|
|
2537
|
+
name: string,
|
|
2538
|
+
normalizedName: string,
|
|
2539
|
+
bindingName: string,
|
|
2540
|
+
props?: Record<string, unknown>
|
|
2541
|
+
): void;
|
|
2551
2542
|
/**
|
|
2552
|
-
*
|
|
2543
|
+
* Connect to and register an MCP server
|
|
2553
2544
|
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2556
|
-
* URLs will still match incoming OAuth requests.
|
|
2545
|
+
* @deprecated This method is maintained for backward compatibility.
|
|
2546
|
+
* For new code, use registerServer() and connectToServer() separately.
|
|
2557
2547
|
*
|
|
2558
|
-
*
|
|
2559
|
-
*
|
|
2548
|
+
* @param url Server URL
|
|
2549
|
+
* @param options Connection options
|
|
2550
|
+
* @returns Object with server ID, auth URL (if OAuth), and client ID (if OAuth)
|
|
2560
2551
|
*/
|
|
2561
|
-
|
|
2562
|
-
|
|
2552
|
+
connect(
|
|
2553
|
+
url: string,
|
|
2554
|
+
options?: LegacyConnectOptions
|
|
2555
|
+
): Promise<{
|
|
2556
|
+
id: string;
|
|
2557
|
+
authUrl?: string;
|
|
2558
|
+
clientId?: string;
|
|
2559
|
+
}>;
|
|
2560
|
+
/** Whether a request is an OAuth callback for one of this manager's servers. */
|
|
2561
|
+
isCallbackRequest(req: Request): boolean;
|
|
2563
2562
|
/**
|
|
2564
|
-
*
|
|
2565
|
-
*
|
|
2563
|
+
* Complete the OAuth flow a callback request belongs to: verify its state,
|
|
2564
|
+
* exchange its code, and leave the connection ready to reconnect. A
|
|
2565
|
+
* callback for a flow that was already accepted is consumed as a stale
|
|
2566
|
+
* success; one whose state cannot be verified changes nothing.
|
|
2566
2567
|
*/
|
|
2567
|
-
|
|
2568
|
+
handleCallbackRequest(req: Request): Promise<MCPOAuthCallbackResult>;
|
|
2568
2569
|
/**
|
|
2569
|
-
*
|
|
2570
|
+
* Configure OAuth callback handling
|
|
2571
|
+
* @param config OAuth callback configuration
|
|
2570
2572
|
*/
|
|
2571
|
-
|
|
2573
|
+
configureOAuthCallback(config: MCPClientOAuthCallbackConfig): void;
|
|
2572
2574
|
/**
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
+
* Get the current OAuth callback configuration
|
|
2576
|
+
* @returns The current OAuth callback configuration
|
|
2575
2577
|
*/
|
|
2576
|
-
|
|
2578
|
+
getOAuthCallbackConfig(): MCPClientOAuthCallbackConfig | undefined;
|
|
2577
2579
|
/**
|
|
2578
|
-
*
|
|
2580
|
+
* Configure handling for server-initiated `elicitation/create` requests.
|
|
2581
|
+
*
|
|
2582
|
+
* The handler is held in memory only and applied to every MCP connection
|
|
2583
|
+
* created or restored by this manager. Call this before registering
|
|
2584
|
+
* connections when you want the initial MCP handshake to advertise
|
|
2585
|
+
* handler-driven form- and url-mode elicitation. Existing active connections
|
|
2586
|
+
* keep their negotiated capabilities until they reconnect.
|
|
2587
|
+
*
|
|
2588
|
+
* The advertised modes are persisted with each stored server, so
|
|
2589
|
+
* connections restored after hibernation re-advertise them at the handshake
|
|
2590
|
+
* even when this is called later in the wake-up (e.g. from onStart) — the
|
|
2591
|
+
* handlers attach to the live connections as soon as this runs.
|
|
2592
|
+
*
|
|
2593
|
+
* Pass undefined to clear the handler.
|
|
2594
|
+
*
|
|
2595
|
+
* @param handlers Elicitation handlers keyed by mode, each scoped with the server id that sent the request
|
|
2579
2596
|
*/
|
|
2580
|
-
|
|
2597
|
+
configureElicitationHandlers(handlers?: MCPClientElicitationHandlers): void;
|
|
2581
2598
|
/**
|
|
2582
|
-
*
|
|
2599
|
+
* @param filter - Optional filter to scope results to specific servers
|
|
2600
|
+
* @returns namespaced list of tools
|
|
2583
2601
|
*/
|
|
2584
|
-
|
|
2602
|
+
listTools(filter?: MCPServerFilter): NamespacedData["tools"];
|
|
2585
2603
|
/**
|
|
2586
2604
|
* @param filter - Optional filter to scope results to specific servers
|
|
2587
2605
|
* @returns namespaced list of prompts
|
|
@@ -2599,6 +2617,21 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2599
2617
|
listResourceTemplates(
|
|
2600
2618
|
filter?: MCPServerFilter
|
|
2601
2619
|
): NamespacedData["resourceTemplates"];
|
|
2620
|
+
/**
|
|
2621
|
+
* Convert connected MCP tools for the AI SDK. Converted schemas are reused
|
|
2622
|
+
* while a live connection retains the same catalog array and schema-source
|
|
2623
|
+
* identities; tool records and execute closures are rebuilt on every call.
|
|
2624
|
+
*
|
|
2625
|
+
* @param filter - Optional filter to scope results to specific servers
|
|
2626
|
+
* @returns a set of tools that you can use with the AI SDK
|
|
2627
|
+
*/
|
|
2628
|
+
getAITools(filter?: MCPServerFilter): MCPAIToolSet;
|
|
2629
|
+
/**
|
|
2630
|
+
* @deprecated this has been renamed to getAITools(), and unstable_getAITools will be removed in the next major version
|
|
2631
|
+
* @param filter - Optional filter to scope results to specific servers
|
|
2632
|
+
* @returns a set of tools that you can use with the AI SDK
|
|
2633
|
+
*/
|
|
2634
|
+
unstable_getAITools(filter?: MCPServerFilter): MCPAIToolSet;
|
|
2602
2635
|
/**
|
|
2603
2636
|
* Namespaced version of callTool
|
|
2604
2637
|
*/
|
|
@@ -2827,25 +2860,97 @@ declare class MCPClientManager extends LifecycleCapability {
|
|
|
2827
2860
|
| undefined;
|
|
2828
2861
|
description?: string | undefined;
|
|
2829
2862
|
}>;
|
|
2863
|
+
/**
|
|
2864
|
+
* Dispose the manager and all resources.
|
|
2865
|
+
*/
|
|
2866
|
+
dispose(): Promise<void>;
|
|
2867
|
+
private connectionsFor;
|
|
2868
|
+
}
|
|
2869
|
+
//#endregion
|
|
2870
|
+
//#region src/mcp/client/errors.d.ts
|
|
2871
|
+
/**
|
|
2872
|
+
* Thrown by `MCPClientManager.callTool()` (and `readResource()` /
|
|
2873
|
+
* `getPrompt()`) when a request on a ready connection needs the user to
|
|
2874
|
+
* authorize again: a `403 insufficient_scope` step-up, or a `401` whose token
|
|
2875
|
+
* refresh failed. The MCP SDK has already built a new authorization URL; the
|
|
2876
|
+
* manager has moved the connection to `authenticating` and persisted
|
|
2877
|
+
* `authUrl`, so sending the user to `authUrl` completes through the normal
|
|
2878
|
+
* OAuth callback. Retry the request once the connection is `ready` again.
|
|
2879
|
+
*
|
|
2880
|
+
* Extends the SDK's `UnauthorizedError`, which these calls threw before, and
|
|
2881
|
+
* keeps its `name`, so existing `instanceof UnauthorizedError` and
|
|
2882
|
+
* `name === "UnauthorizedError"` checks keep matching. Use
|
|
2883
|
+
* `instanceof MCPAuthorizationRequiredError` to read `authUrl`.
|
|
2884
|
+
*/
|
|
2885
|
+
declare class MCPAuthorizationRequiredError extends UnauthorizedError {
|
|
2886
|
+
/** Stable discriminant for this error. */
|
|
2887
|
+
readonly _tag: "MCPAuthorizationRequiredError";
|
|
2888
|
+
/** The MCP server that needs authorization. */
|
|
2889
|
+
readonly serverId: string;
|
|
2890
|
+
/** The authorization URL to send the user to; also persisted as `auth_url`. */
|
|
2891
|
+
readonly authUrl: string;
|
|
2892
|
+
/** The OAuth client id used for the authorization request, when known. */
|
|
2893
|
+
readonly clientId?: string;
|
|
2894
|
+
/**
|
|
2895
|
+
* @param serverId - The MCP server that needs authorization.
|
|
2896
|
+
* @param authUrl - The authorization URL the SDK built for the new flow.
|
|
2897
|
+
* @param options - The OAuth client id and the original unauthorized error.
|
|
2898
|
+
*/
|
|
2899
|
+
constructor(
|
|
2900
|
+
serverId: string,
|
|
2901
|
+
authUrl: string,
|
|
2902
|
+
options?: {
|
|
2903
|
+
clientId?: string;
|
|
2904
|
+
cause?: unknown;
|
|
2905
|
+
}
|
|
2906
|
+
);
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Thrown by `MCPClientManager.callTool()`, `readResource()` and `getPrompt()`
|
|
2910
|
+
* when no connection exists for `serverId`: the id was never registered, the
|
|
2911
|
+
* server was removed, or a restore has not created the connection yet.
|
|
2912
|
+
*/
|
|
2913
|
+
declare class MCPConnectionNotFoundError extends Error {
|
|
2914
|
+
readonly serverId: string;
|
|
2915
|
+
/** Stable discriminant for this error. */
|
|
2916
|
+
readonly _tag: "MCPConnectionNotFoundError";
|
|
2917
|
+
/**
|
|
2918
|
+
* @param serverId - The server id that has no connection.
|
|
2919
|
+
*/
|
|
2920
|
+
constructor(serverId: string);
|
|
2830
2921
|
}
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2922
|
+
//#endregion
|
|
2923
|
+
//#region src/mcp/client/url-policy.d.ts
|
|
2924
|
+
/**
|
|
2925
|
+
* Rules for the identifiers and URLs the MCP client manager accepts: stable
|
|
2926
|
+
* server ids, and the SSRF policy that keeps HTTP connections off private
|
|
2927
|
+
* and internal networks.
|
|
2928
|
+
*/
|
|
2929
|
+
/** Maximum length of a normalized MCP server id. */
|
|
2930
|
+
declare const MCP_SERVER_ID_MAX_LENGTH = 64;
|
|
2931
|
+
/**
|
|
2932
|
+
* Normalize a caller-supplied MCP server id into a stable, storage- and
|
|
2933
|
+
* tool-name-safe form.
|
|
2934
|
+
*
|
|
2935
|
+
* The id is surfaced in several places where the character set matters:
|
|
2936
|
+
* - as the primary key in the `cf_agents_mcp_servers` SQLite table
|
|
2937
|
+
* - embedded in AI SDK tool names as `` `tool_${id.replace(/-/g, "")}_${tool}` ``
|
|
2938
|
+
* (tool names must match `/^[A-Za-z0-9_]+$/`)
|
|
2939
|
+
* - as a key on the `mcpConnections` map and OAuth provider storage
|
|
2940
|
+
*
|
|
2941
|
+
* Rules:
|
|
2942
|
+
* 1. Lowercase.
|
|
2943
|
+
* 2. Replace any run of disallowed characters with a single `-`.
|
|
2944
|
+
* 3. Collapse repeated `-` and trim leading/trailing `-`/`_`.
|
|
2945
|
+
* 4. Prefix with `id-` if the result is empty or doesn't start with a letter.
|
|
2946
|
+
* 5. Truncate to {@link MCP_SERVER_ID_MAX_LENGTH} characters.
|
|
2947
|
+
*
|
|
2948
|
+
* @example
|
|
2949
|
+
* normalizeServerId("my-supplied-id"); // "my-supplied-id"
|
|
2950
|
+
* normalizeServerId("GitHub MCP!"); // "github-mcp"
|
|
2951
|
+
* normalizeServerId("42-things"); // "id-42-things"
|
|
2952
|
+
*/
|
|
2953
|
+
declare function normalizeServerId(input: string): string;
|
|
2849
2954
|
//#endregion
|
|
2850
2955
|
//#region src/workflow-types.d.ts
|
|
2851
2956
|
type AgentWorkflowPathStep = AgentPathStep;
|
|
@@ -3813,6 +3918,18 @@ type AddRpcMcpServerOptions = {
|
|
|
3813
3918
|
id?: string /** Props to pass to the McpAgent instance */;
|
|
3814
3919
|
props?: Record<string, unknown>;
|
|
3815
3920
|
};
|
|
3921
|
+
/** What `addMcpServer` resolves with for an HTTP or RPC server. */
|
|
3922
|
+
type AddMcpServerResult =
|
|
3923
|
+
| {
|
|
3924
|
+
id: string;
|
|
3925
|
+
state: typeof MCPConnectionState.AUTHENTICATING;
|
|
3926
|
+
authUrl: string;
|
|
3927
|
+
}
|
|
3928
|
+
| {
|
|
3929
|
+
id: string;
|
|
3930
|
+
state: typeof MCPConnectionState.READY;
|
|
3931
|
+
authUrl?: undefined;
|
|
3932
|
+
};
|
|
3816
3933
|
/**
|
|
3817
3934
|
* Default options for Agent configuration.
|
|
3818
3935
|
* Child classes can override specific options without spreading.
|
|
@@ -4029,6 +4146,26 @@ declare class Agent<
|
|
|
4029
4146
|
onStart(_props?: Props): void | Promise<void>;
|
|
4030
4147
|
/** Handle an HTTP request not claimed by a lifecycle component. */
|
|
4031
4148
|
onRequest(_request: Request): Response | Promise<Response>;
|
|
4149
|
+
/**
|
|
4150
|
+
* Choose the response for a request or WebSocket upgrade whose handling
|
|
4151
|
+
* threw, including a failed `onStart`. The error is already logged.
|
|
4152
|
+
*
|
|
4153
|
+
* Return a `Response` to send it, or nothing to send the default, which
|
|
4154
|
+
* never carries the error: `500 Internal Server Error`, or for an upgrade a
|
|
4155
|
+
* socket that closes with 1011. For an upgrade, return either an HTTP
|
|
4156
|
+
* error response or a `101` response with your own `WebSocketPair`.
|
|
4157
|
+
*
|
|
4158
|
+
* Errors from `onStart`, `onRequest`, and `onConnect` pass through
|
|
4159
|
+
* `onError` first. If `onError` throws, `error` is what it threw;
|
|
4160
|
+
* otherwise it is the original error. Avoid sending an error's message or
|
|
4161
|
+
* stack to callers you do not trust. If this hook throws, the default is
|
|
4162
|
+
* sent. Whether it returns nothing or throws, an original thrown value
|
|
4163
|
+
* that is not an `Error` is rethrown instead.
|
|
4164
|
+
*/
|
|
4165
|
+
onFetchError(
|
|
4166
|
+
_request: Request,
|
|
4167
|
+
_error: unknown
|
|
4168
|
+
): Response | void | Promise<Response | void>;
|
|
4032
4169
|
/** Handle a newly accepted hibernating WebSocket connection. */
|
|
4033
4170
|
onConnect(
|
|
4034
4171
|
_connection: Connection,
|
|
@@ -4197,7 +4334,7 @@ declare class Agent<
|
|
|
4197
4334
|
* @example
|
|
4198
4335
|
* ```typescript
|
|
4199
4336
|
* const workersai = createWorkersAI({ binding: this.env.AI });
|
|
4200
|
-
* const model = workersai("@cf/
|
|
4337
|
+
* const model = workersai("@cf/deepseek-ai/deepseek-v4.1-flash-1017", {
|
|
4201
4338
|
* sessionAffinity: this.sessionAffinity,
|
|
4202
4339
|
* });
|
|
4203
4340
|
* ```
|
|
@@ -5037,6 +5174,10 @@ declare class Agent<
|
|
|
5037
5174
|
connectionId: string,
|
|
5038
5175
|
message: string | ArrayBuffer | ArrayBufferView
|
|
5039
5176
|
): Promise<void>;
|
|
5177
|
+
_cf_sendManyToSubAgentConnection(
|
|
5178
|
+
connectionId: string,
|
|
5179
|
+
messages: ReadonlyArray<string | ArrayBuffer | ArrayBufferView>
|
|
5180
|
+
): Promise<void>;
|
|
5040
5181
|
_cf_closeSubAgentConnection(
|
|
5041
5182
|
connectionId: string,
|
|
5042
5183
|
code?: number,
|
|
@@ -6167,8 +6308,28 @@ declare class Agent<
|
|
|
6167
6308
|
state: typeof MCPConnectionState.READY;
|
|
6168
6309
|
}
|
|
6169
6310
|
>;
|
|
6170
|
-
|
|
6171
|
-
|
|
6311
|
+
/**
|
|
6312
|
+
* Bring an already-registered server to a result for `addMcpServer`. Work
|
|
6313
|
+
* already queued for it (restore, an OAuth callback, a concurrent
|
|
6314
|
+
* `addMcpServer`) runs first, so a half-connected server is never reported
|
|
6315
|
+
* as ready.
|
|
6316
|
+
*/
|
|
6317
|
+
private _resumeMcpServer;
|
|
6318
|
+
/** Connect a registered server and discover its capabilities. */
|
|
6319
|
+
private _connectAndDiscoverMcpServer;
|
|
6320
|
+
/** Translate where a server settled into `addMcpServer`'s result or error. */
|
|
6321
|
+
private _mcpServerResult;
|
|
6322
|
+
/**
|
|
6323
|
+
* Try an MCP server again, for example from a "Reconnect" button: forgets
|
|
6324
|
+
* why it failed (unreachable, authorization refused, step-up limit
|
|
6325
|
+
* reached) and its pending link, then connects now with the quick
|
|
6326
|
+
* attempts. The only way to retry a failed server or get a new link;
|
|
6327
|
+
* `addMcpServer()` for a registered server reports its state as is.
|
|
6328
|
+
*
|
|
6329
|
+
* @returns The same result as `addMcpServer()`: `ready`, or
|
|
6330
|
+
* `authenticating` with a new `authUrl`. Throws when the attempt fails.
|
|
6331
|
+
*/
|
|
6332
|
+
reconnectMcpServer(id: string): Promise<AddMcpServerResult>;
|
|
6172
6333
|
removeMcpServer(id: string): Promise<void>;
|
|
6173
6334
|
getMcpServers(): MCPServersState;
|
|
6174
6335
|
/**
|
|
@@ -6384,11 +6545,11 @@ declare function getAgentByName<
|
|
|
6384
6545
|
//#endregion
|
|
6385
6546
|
export {
|
|
6386
6547
|
ChatCapableAgentClass as $,
|
|
6387
|
-
|
|
6548
|
+
MCPElicitationHandlers as $t,
|
|
6388
6549
|
getCurrentAgent as A,
|
|
6389
6550
|
ElicitRequest$1 as At,
|
|
6390
6551
|
AgentToolFailure as B,
|
|
6391
|
-
|
|
6552
|
+
MCPClientElicitationHandler as Bt,
|
|
6392
6553
|
MCPServersState as C,
|
|
6393
6554
|
WorkflowInfo as Ct,
|
|
6394
6555
|
StartFiberResult as D,
|
|
@@ -6396,104 +6557,107 @@ export {
|
|
|
6396
6557
|
StartFiberOptions as E,
|
|
6397
6558
|
WorkflowQueryCriteria as Et,
|
|
6398
6559
|
AgentToolDisplayMetadata as F,
|
|
6399
|
-
|
|
6560
|
+
MCPConnectionNotFoundError as Ft,
|
|
6400
6561
|
AgentToolProgressSnapshot as G,
|
|
6401
|
-
|
|
6562
|
+
MCPOAuthCallbackResult as Gt,
|
|
6402
6563
|
AgentToolLifecycleResult as H,
|
|
6403
|
-
|
|
6564
|
+
MCPClientManagerOptions as Ht,
|
|
6404
6565
|
AgentToolEvent as I,
|
|
6405
6566
|
MCPClientManager as It,
|
|
6406
6567
|
AgentToolRunPart as J,
|
|
6407
|
-
|
|
6568
|
+
MCPServerSettlement as Jt,
|
|
6408
6569
|
AgentToolRunInfo as K,
|
|
6409
|
-
|
|
6570
|
+
MCPServerFilter as Kt,
|
|
6410
6571
|
AgentToolEventDelivery as L,
|
|
6411
|
-
|
|
6572
|
+
MCPClientOAuthCallbackConfig as Lt,
|
|
6412
6573
|
AGENT_TOOL_MILESTONE_PART as M,
|
|
6413
|
-
|
|
6574
|
+
MCP_SERVER_ID_MAX_LENGTH as Mt,
|
|
6414
6575
|
AGENT_TOOL_PROGRESS_PART as N,
|
|
6415
|
-
|
|
6576
|
+
normalizeServerId as Nt,
|
|
6416
6577
|
StateUpdateMessage as O,
|
|
6417
6578
|
WorkflowStatus as Ot,
|
|
6418
6579
|
AgentToolChildAdapter as P,
|
|
6419
|
-
|
|
6580
|
+
MCPAuthorizationRequiredError as Pt,
|
|
6420
6581
|
AgentToolTerminalStatus as Q,
|
|
6421
|
-
|
|
6582
|
+
MCPElicitationHandler as Qt,
|
|
6422
6583
|
AgentToolEventMessage as R,
|
|
6423
|
-
|
|
6584
|
+
MCPClientOAuthResult as Rt,
|
|
6424
6585
|
MCPServerMessage as S,
|
|
6425
6586
|
WorkflowEventPayload as St,
|
|
6426
6587
|
RPCResponse as T,
|
|
6427
6588
|
WorkflowProgressCallback as Tt,
|
|
6428
6589
|
AgentToolMilestone as U,
|
|
6429
|
-
|
|
6590
|
+
MCPConnectionResult as Ut,
|
|
6430
6591
|
AgentToolInterruptedReason as V,
|
|
6431
|
-
|
|
6592
|
+
MCPClientElicitationHandlers as Vt,
|
|
6432
6593
|
AgentToolProgress as W,
|
|
6433
|
-
|
|
6594
|
+
MCPDiscoverResult as Wt,
|
|
6434
6595
|
AgentToolRunStatus as X,
|
|
6435
|
-
|
|
6596
|
+
MCPAITool as Xt,
|
|
6436
6597
|
AgentToolRunState as Y,
|
|
6437
|
-
|
|
6598
|
+
RegisterServerOptions as Yt,
|
|
6438
6599
|
AgentToolStoredChunk as Z,
|
|
6439
|
-
|
|
6600
|
+
MCPAIToolSet as Zt,
|
|
6440
6601
|
FiberRecoveryContext as _,
|
|
6602
|
+
withInvocationScope as _n,
|
|
6441
6603
|
WorkflowCallbackBase as _t,
|
|
6442
6604
|
routeAgentRequest as a,
|
|
6443
|
-
|
|
6605
|
+
DynamicAgentStub as an,
|
|
6444
6606
|
isPositionlessAgentToolChunk as at,
|
|
6445
6607
|
ListFibersOptions as b,
|
|
6446
6608
|
WorkflowErrorCallback as bt,
|
|
6447
6609
|
Agent as c,
|
|
6448
|
-
|
|
6610
|
+
SUB_PREFIX as cn,
|
|
6449
6611
|
AgentWorkflowOrigin as ct,
|
|
6450
6612
|
AgentStaticOptions as d,
|
|
6451
|
-
|
|
6613
|
+
buildAgentUrl as dn,
|
|
6452
6614
|
AgentWorkflowStep as dt,
|
|
6453
|
-
|
|
6615
|
+
McpRpcAgent as en,
|
|
6454
6616
|
DetachedAgentToolConfig as et,
|
|
6455
6617
|
DEFAULT_AGENT_STATIC_OPTIONS as f,
|
|
6456
|
-
|
|
6618
|
+
buildSubAgentPath as fn,
|
|
6457
6619
|
ApprovalEventPayload as ft,
|
|
6458
6620
|
FiberInspection as g,
|
|
6621
|
+
routeSubAgentRequest as gn,
|
|
6459
6622
|
WorkflowCallback as gt,
|
|
6460
6623
|
FiberContext as h,
|
|
6624
|
+
parseSubAgentPath as hn,
|
|
6461
6625
|
WaitForApprovalOptions as ht,
|
|
6462
6626
|
getAgentByName as i,
|
|
6463
|
-
|
|
6627
|
+
DynamicAgentClass as in,
|
|
6464
6628
|
isAgentToolLifecycleChunk as it,
|
|
6465
6629
|
routeAgentEmail as j,
|
|
6466
6630
|
ElicitResult$1 as jt,
|
|
6467
6631
|
StreamingResponse as k,
|
|
6468
6632
|
WorkflowTrackingRow as kt,
|
|
6469
6633
|
AgentContext as l,
|
|
6470
|
-
|
|
6634
|
+
SubAgentPathMatch as ln,
|
|
6471
6635
|
AgentWorkflowParams as lt,
|
|
6472
6636
|
EmailRoutingOptions as m,
|
|
6473
|
-
|
|
6637
|
+
getSubAgentByName as mn,
|
|
6474
6638
|
RunWorkflowOptions as mt,
|
|
6475
6639
|
AgentOptions as n,
|
|
6476
|
-
|
|
6640
|
+
RPCClientTransportOptions as nn,
|
|
6477
6641
|
RunAgentToolOptions as nt,
|
|
6478
6642
|
AddMcpServerOptions as o,
|
|
6479
|
-
|
|
6643
|
+
AgentPathStep as on,
|
|
6480
6644
|
AgentWorkflowEvent as ot,
|
|
6481
6645
|
DeleteFibersOptions as p,
|
|
6482
|
-
|
|
6646
|
+
buildSubAgentPathUnchecked as pn,
|
|
6483
6647
|
DefaultProgress as pt,
|
|
6484
6648
|
AgentToolRunInspection as q,
|
|
6485
|
-
|
|
6649
|
+
MCPServerOptions as qt,
|
|
6486
6650
|
RoutingRetryOptions as r,
|
|
6487
|
-
|
|
6651
|
+
RPC_DO_PREFIX as rn,
|
|
6488
6652
|
RunAgentToolResult as rt,
|
|
6489
6653
|
AddRpcMcpServerOptions as s,
|
|
6490
|
-
|
|
6654
|
+
BuildAgentPathOptions as sn,
|
|
6491
6655
|
AgentWorkflowInternalParams as st,
|
|
6492
6656
|
AgentGetOptions as t,
|
|
6493
|
-
|
|
6657
|
+
RPCClientTransport as tn,
|
|
6494
6658
|
DetachedRunAgentToolResult as tt,
|
|
6495
6659
|
AgentNamespace as u,
|
|
6496
|
-
|
|
6660
|
+
buildAgentPath as un,
|
|
6497
6661
|
AgentWorkflowPathStep as ut,
|
|
6498
6662
|
FiberRecoveryResult as v,
|
|
6499
6663
|
WorkflowCallbackType as vt,
|
|
@@ -6504,6 +6668,6 @@ export {
|
|
|
6504
6668
|
FiberStatus as y,
|
|
6505
6669
|
WorkflowCompleteCallback as yt,
|
|
6506
6670
|
AgentToolEventState as z,
|
|
6507
|
-
|
|
6671
|
+
getNamespacedData as zt
|
|
6508
6672
|
};
|
|
6509
|
-
//# sourceMappingURL=agent-routing-
|
|
6673
|
+
//# sourceMappingURL=agent-routing-BSoZzNiP.d.ts.map
|