agents 0.0.0-293b546 → 0.0.0-29938d4
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 +121 -0
- package/dist/ai-chat-agent.d.ts +158 -24
- package/dist/ai-chat-agent.js +380 -60
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.js +154 -2
- package/dist/ai-chat-v5-migration.js.map +1 -0
- package/dist/ai-react.d.ts +136 -16
- package/dist/ai-react.js +252 -74
- package/dist/ai-react.js.map +1 -1
- package/dist/{ai-types-81H_-Uxh.d.ts → ai-types-0OnT3FHg.d.ts} +26 -2
- package/dist/{ai-types-CrMqkwc_.js → ai-types-DEtF_8Km.js} +5 -1
- package/dist/ai-types-DEtF_8Km.js.map +1 -0
- package/dist/ai-types.d.ts +1 -1
- package/dist/ai-types.js +1 -1
- 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-BAQA84dr.d.ts → client-CdM5I962.d.ts} +2 -2
- package/dist/client-DFotUKH_.d.ts +834 -0
- package/dist/{client-B3SR12TQ.js → client-DjTPRM8-.js} +2 -2
- package/dist/{client-B3SR12TQ.js.map → client-DjTPRM8-.js.map} +1 -1
- package/dist/{client-C8VrzljV.js → client-QZa2Rq0l.js} +371 -187
- package/dist/client-QZa2Rq0l.js.map +1 -0
- package/dist/client.d.ts +1 -2
- package/dist/client.js +1 -2
- package/dist/codemode/ai.js +6 -6
- package/dist/codemode/ai.js.map +1 -1
- package/dist/context-BkKbAa1R.js +8 -0
- package/dist/context-BkKbAa1R.js.map +1 -0
- package/dist/context-DcbQ8o7k.d.ts +24 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +3 -0
- package/dist/{do-oauth-client-provider-C2CHH5x-.d.ts → do-oauth-client-provider--To1Tsjj.d.ts} +20 -5
- package/dist/{do-oauth-client-provider-CwqK5SXm.js → do-oauth-client-provider-B1fVIshX.js} +69 -8
- package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
- package/dist/{index-7kI1zprE.d.ts → index-CT2tCrLr.d.ts} +59 -60
- package/dist/{index-BUle9RiP.d.ts → index-DLuxm_9W.d.ts} +2 -2
- package/dist/index.d.ts +31 -34
- package/dist/index.js +5 -5
- package/dist/mcp/client.d.ts +2 -4
- package/dist/mcp/client.js +2 -2
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +19 -12
- package/dist/mcp/index.js +55 -60
- package/dist/mcp/index.js.map +1 -1
- package/dist/{mcp-BwPscEiF.d.ts → mcp-CPSfGUgd.d.ts} +1 -1
- package/dist/observability/index.d.ts +1 -2
- package/dist/observability/index.js +5 -5
- package/dist/react.d.ts +134 -10
- package/dist/react.js +56 -56
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +18 -72
- package/dist/{serializable-faDkMCai.d.ts → serializable-Crsj26mx.d.ts} +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{src-xjQt2wBU.js → src-BZDh910Z.js} +26 -25
- package/dist/src-BZDh910Z.js.map +1 -0
- package/package.json +29 -14
- package/dist/ai-chat-v5-migration-BSiGZmYU.js +0 -155
- package/dist/ai-chat-v5-migration-BSiGZmYU.js.map +0 -1
- package/dist/ai-types-CrMqkwc_.js.map +0 -1
- package/dist/cli.d.ts +0 -8
- package/dist/cli.js.map +0 -1
- package/dist/client-BG2wUgN5.d.ts +0 -1462
- package/dist/client-C8VrzljV.js.map +0 -1
- package/dist/do-oauth-client-provider-CwqK5SXm.js.map +0 -1
- package/dist/react-9nVfoERh.d.ts +0 -113
- package/dist/src-xjQt2wBU.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { n as AgentEmail } from "./context-DcbQ8o7k.js";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./client-
|
|
6
|
-
import { t as Observability } from "./index-
|
|
7
|
-
import { n as MessageType } from "./ai-types-
|
|
3
|
+
h as TransportType,
|
|
4
|
+
t as MCPClientManager,
|
|
5
|
+
u as MCPConnectionState
|
|
6
|
+
} from "./client-DFotUKH_.js";
|
|
7
|
+
import { t as Observability } from "./index-DLuxm_9W.js";
|
|
8
|
+
import { n as MessageType } from "./ai-types-0OnT3FHg.js";
|
|
8
9
|
import {
|
|
9
10
|
Connection,
|
|
10
11
|
Connection as Connection$1,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
ServerCapabilities,
|
|
21
22
|
Tool
|
|
22
23
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
23
|
-
import { env } from "cloudflare:workers";
|
|
24
24
|
|
|
25
25
|
//#region src/index.d.ts
|
|
26
26
|
|
|
@@ -90,7 +90,7 @@ declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
|
90
90
|
type QueueItem<T = string> = {
|
|
91
91
|
id: string;
|
|
92
92
|
payload: T;
|
|
93
|
-
callback: keyof Agent<
|
|
93
|
+
callback: keyof Agent<Cloudflare.Env>;
|
|
94
94
|
created_at: number;
|
|
95
95
|
};
|
|
96
96
|
/**
|
|
@@ -158,7 +158,7 @@ type MCPServer = {
|
|
|
158
158
|
capabilities: ServerCapabilities | null;
|
|
159
159
|
};
|
|
160
160
|
declare function getCurrentAgent<
|
|
161
|
-
T extends Agent<
|
|
161
|
+
T extends Agent<Cloudflare.Env> = Agent<Cloudflare.Env>
|
|
162
162
|
>(): {
|
|
163
163
|
agent: T | undefined;
|
|
164
164
|
connection: Connection | undefined;
|
|
@@ -171,7 +171,7 @@ declare function getCurrentAgent<
|
|
|
171
171
|
* @template State State type to store within the Agent
|
|
172
172
|
*/
|
|
173
173
|
declare class Agent<
|
|
174
|
-
Env =
|
|
174
|
+
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
175
175
|
State = unknown,
|
|
176
176
|
Props extends Record<string, unknown> = Record<string, unknown>
|
|
177
177
|
> extends Server<Env, Props> {
|
|
@@ -331,7 +331,7 @@ declare class Agent<
|
|
|
331
331
|
/**
|
|
332
332
|
* Cancel a scheduled task
|
|
333
333
|
* @param id ID of the task to cancel
|
|
334
|
-
* @returns true if the task was cancelled, false
|
|
334
|
+
* @returns true if the task was cancelled, false if the task was not found
|
|
335
335
|
*/
|
|
336
336
|
cancelSchedule(id: string): Promise<boolean>;
|
|
337
337
|
private _scheduleNextAlarm;
|
|
@@ -361,7 +361,8 @@ declare class Agent<
|
|
|
361
361
|
* @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
|
|
362
362
|
* @param agentsPrefix agents routing prefix if not using `agents`
|
|
363
363
|
* @param options MCP client and transport options
|
|
364
|
-
* @returns authUrl
|
|
364
|
+
* @returns Server id and state - either "authenticating" with authUrl, or "ready"
|
|
365
|
+
* @throws If connection or discovery fails
|
|
365
366
|
*/
|
|
366
367
|
addMcpServer(
|
|
367
368
|
serverName: string,
|
|
@@ -375,10 +376,18 @@ declare class Agent<
|
|
|
375
376
|
type?: TransportType;
|
|
376
377
|
};
|
|
377
378
|
}
|
|
378
|
-
): Promise<
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
379
|
+
): Promise<
|
|
380
|
+
| {
|
|
381
|
+
id: string;
|
|
382
|
+
state: typeof MCPConnectionState.AUTHENTICATING;
|
|
383
|
+
authUrl: string;
|
|
384
|
+
}
|
|
385
|
+
| {
|
|
386
|
+
id: string;
|
|
387
|
+
state: typeof MCPConnectionState.READY;
|
|
388
|
+
authUrl?: undefined;
|
|
389
|
+
}
|
|
390
|
+
>;
|
|
382
391
|
removeMcpServer(id: string): Promise<void>;
|
|
383
392
|
getMcpServers(): MCPServersState;
|
|
384
393
|
private broadcastMcpServers;
|
|
@@ -407,8 +416,9 @@ declare class Agent<
|
|
|
407
416
|
/**
|
|
408
417
|
* Namespace for creating Agent instances
|
|
409
418
|
* @template Agentic Type of the Agent class
|
|
419
|
+
* @deprecated Use DurableObjectNamespace instead
|
|
410
420
|
*/
|
|
411
|
-
type AgentNamespace<Agentic extends Agent<
|
|
421
|
+
type AgentNamespace<Agentic extends Agent<Cloudflare.Env>> =
|
|
412
422
|
DurableObjectNamespace<Agentic>;
|
|
413
423
|
/**
|
|
414
424
|
* Agent's durable context
|
|
@@ -475,21 +485,11 @@ type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
|
475
485
|
* @param options The options for routing the email
|
|
476
486
|
* @returns A promise that resolves when the email has been routed
|
|
477
487
|
*/
|
|
478
|
-
declare function routeAgentEmail<Env>(
|
|
488
|
+
declare function routeAgentEmail<Env extends Cloudflare.Env = Cloudflare.Env>(
|
|
479
489
|
email: ForwardableEmailMessage,
|
|
480
490
|
env: Env,
|
|
481
491
|
options: EmailRoutingOptions<Env>
|
|
482
492
|
): Promise<void>;
|
|
483
|
-
type AgentEmail = {
|
|
484
|
-
from: string;
|
|
485
|
-
to: string;
|
|
486
|
-
getRaw: () => Promise<Uint8Array>;
|
|
487
|
-
headers: Headers;
|
|
488
|
-
rawSize: number;
|
|
489
|
-
setReject: (reason: string) => void;
|
|
490
|
-
forward: (rcptTo: string, headers?: Headers) => Promise<void>;
|
|
491
|
-
reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
|
|
492
|
-
};
|
|
493
493
|
type EmailSendOptions = {
|
|
494
494
|
to: string;
|
|
495
495
|
subject: string;
|
|
@@ -511,11 +511,11 @@ type EmailSendOptions = {
|
|
|
511
511
|
* @returns Promise resolving to an Agent instance stub
|
|
512
512
|
*/
|
|
513
513
|
declare function getAgentByName<
|
|
514
|
-
Env,
|
|
515
|
-
T extends Agent<Env>,
|
|
514
|
+
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
515
|
+
T extends Agent<Env> = Agent<Env>,
|
|
516
516
|
Props extends Record<string, unknown> = Record<string, unknown>
|
|
517
517
|
>(
|
|
518
|
-
namespace:
|
|
518
|
+
namespace: DurableObjectNamespace<T>,
|
|
519
519
|
name: string,
|
|
520
520
|
options?: {
|
|
521
521
|
jurisdiction?: DurableObjectJurisdiction;
|
|
@@ -544,35 +544,34 @@ declare class StreamingResponse {
|
|
|
544
544
|
}
|
|
545
545
|
//#endregion
|
|
546
546
|
export {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
getCurrentAgent as
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
RPCRequest as
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
MCPServersState as m,
|
|
547
|
+
createCatchAllEmailResolver as C,
|
|
548
|
+
routeAgentEmail as D,
|
|
549
|
+
getCurrentAgent as E,
|
|
550
|
+
routeAgentRequest as O,
|
|
551
|
+
createAddressBasedEmailResolver as S,
|
|
552
|
+
getAgentByName as T,
|
|
553
|
+
Schedule as _,
|
|
554
|
+
CallableMetadata as a,
|
|
555
|
+
WSMessage as b,
|
|
556
|
+
EmailResolver as c,
|
|
557
|
+
MCPServer as d,
|
|
558
|
+
MCPServerMessage as f,
|
|
559
|
+
RPCResponse as g,
|
|
560
|
+
RPCRequest as h,
|
|
561
|
+
AgentOptions as i,
|
|
562
|
+
unstable_callable as k,
|
|
563
|
+
EmailRoutingOptions as l,
|
|
564
|
+
QueueItem as m,
|
|
566
565
|
AgentContext as n,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
566
|
+
Connection$1 as o,
|
|
567
|
+
MCPServersState as p,
|
|
568
|
+
AgentNamespace as r,
|
|
569
|
+
ConnectionContext as s,
|
|
571
570
|
Agent as t,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
571
|
+
EmailSendOptions as u,
|
|
572
|
+
StateUpdateMessage as v,
|
|
573
|
+
createHeaderBasedEmailResolver as w,
|
|
574
|
+
callable as x,
|
|
575
|
+
StreamingResponse as y
|
|
577
576
|
};
|
|
578
|
-
//# sourceMappingURL=index-
|
|
577
|
+
//# sourceMappingURL=index-CT2tCrLr.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as BaseEvent, t as MCPObservabilityEvent } from "./mcp-
|
|
1
|
+
import { n as BaseEvent, t as MCPObservabilityEvent } from "./mcp-CPSfGUgd.js";
|
|
2
2
|
|
|
3
3
|
//#region src/observability/agent.d.ts
|
|
4
4
|
|
|
@@ -55,4 +55,4 @@ export {
|
|
|
55
55
|
genericObservability as r,
|
|
56
56
|
Observability as t
|
|
57
57
|
};
|
|
58
|
-
//# sourceMappingURL=index-
|
|
58
|
+
//# sourceMappingURL=index-DLuxm_9W.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import "./index-BUle9RiP.js";
|
|
5
|
-
import "./ai-types-81H_-Uxh.js";
|
|
1
|
+
import { n as AgentEmail } from "./context-DcbQ8o7k.js";
|
|
2
|
+
import { h as TransportType } from "./client-DFotUKH_.js";
|
|
3
|
+
import "./ai-types-0OnT3FHg.js";
|
|
6
4
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
m as MCPServersState,
|
|
5
|
+
C as createCatchAllEmailResolver,
|
|
6
|
+
D as routeAgentEmail,
|
|
7
|
+
E as getCurrentAgent,
|
|
8
|
+
O as routeAgentRequest,
|
|
9
|
+
S as createAddressBasedEmailResolver,
|
|
10
|
+
T as getAgentByName,
|
|
11
|
+
_ as Schedule,
|
|
12
|
+
a as CallableMetadata,
|
|
13
|
+
b as WSMessage,
|
|
14
|
+
c as EmailResolver,
|
|
15
|
+
d as MCPServer,
|
|
16
|
+
f as MCPServerMessage,
|
|
17
|
+
g as RPCResponse,
|
|
18
|
+
h as RPCRequest,
|
|
19
|
+
i as AgentOptions,
|
|
20
|
+
k as unstable_callable,
|
|
21
|
+
l as EmailRoutingOptions,
|
|
22
|
+
m as QueueItem,
|
|
26
23
|
n as AgentContext,
|
|
27
|
-
o as
|
|
28
|
-
p as
|
|
29
|
-
r as
|
|
30
|
-
s as
|
|
24
|
+
o as Connection,
|
|
25
|
+
p as MCPServersState,
|
|
26
|
+
r as AgentNamespace,
|
|
27
|
+
s as ConnectionContext,
|
|
31
28
|
t as Agent,
|
|
32
|
-
u as
|
|
33
|
-
v as
|
|
34
|
-
w as
|
|
35
|
-
x as
|
|
36
|
-
y as
|
|
37
|
-
} from "./index-
|
|
29
|
+
u as EmailSendOptions,
|
|
30
|
+
v as StateUpdateMessage,
|
|
31
|
+
w as createHeaderBasedEmailResolver,
|
|
32
|
+
x as callable,
|
|
33
|
+
y as StreamingResponse
|
|
34
|
+
} from "./index-CT2tCrLr.js";
|
|
38
35
|
export {
|
|
39
36
|
Agent,
|
|
40
37
|
AgentContext,
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./client-
|
|
3
|
-
import "./client-
|
|
4
|
-
import "./do-oauth-client-provider-
|
|
5
|
-
import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-
|
|
1
|
+
import "./context-BkKbAa1R.js";
|
|
2
|
+
import "./client-DjTPRM8-.js";
|
|
3
|
+
import "./client-QZa2Rq0l.js";
|
|
4
|
+
import "./do-oauth-client-provider-B1fVIshX.js";
|
|
5
|
+
import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-BZDh910Z.js";
|
|
6
6
|
|
|
7
7
|
export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import { a as MCPConnectionResult, c as
|
|
2
|
-
|
|
3
|
-
import "../do-oauth-client-provider-C2CHH5x-.js";
|
|
4
|
-
export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
|
|
1
|
+
import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-DFotUKH_.js";
|
|
2
|
+
export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
|
package/dist/mcp/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getNamespacedData, t as MCPClientManager } from "../client-
|
|
2
|
-
import "../do-oauth-client-provider-
|
|
1
|
+
import { n as getNamespacedData, t as MCPClientManager } from "../client-QZa2Rq0l.js";
|
|
2
|
+
import "../do-oauth-client-provider-B1fVIshX.js";
|
|
3
3
|
|
|
4
4
|
export { MCPClientManager, getNamespacedData };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider
|
|
1
|
+
import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider--To1Tsjj.js";
|
|
2
2
|
export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../index-
|
|
5
|
-
import "../ai-types-81H_-Uxh.js";
|
|
6
|
-
import { c as ConnectionContext, s as Connection, t as Agent } from "../index-7kI1zprE.js";
|
|
1
|
+
import "../context-DcbQ8o7k.js";
|
|
2
|
+
import { a as MCPConnectionResult, d as BaseTransportType, f as CORSOptions, i as MCPClientOAuthResult, m as ServeOptions, o as MCPDiscoverResult, p as MaybePromise, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions } from "../client-DFotUKH_.js";
|
|
3
|
+
import "../ai-types-0OnT3FHg.js";
|
|
4
|
+
import { o as Connection, s as ConnectionContext, t as Agent } from "../index-CT2tCrLr.js";
|
|
7
5
|
import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
6
|
import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
7
|
import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
|
|
@@ -26,8 +24,6 @@ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTran
|
|
|
26
24
|
}
|
|
27
25
|
//#endregion
|
|
28
26
|
//#region src/mcp/worker-transport.d.ts
|
|
29
|
-
declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-03-26", "2025-06-18"];
|
|
30
|
-
type ProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];
|
|
31
27
|
interface MCPStorageApi {
|
|
32
28
|
get(): Promise<TransportState | undefined> | TransportState | undefined;
|
|
33
29
|
set(state: TransportState): Promise<void> | void;
|
|
@@ -35,7 +31,6 @@ interface MCPStorageApi {
|
|
|
35
31
|
interface TransportState {
|
|
36
32
|
sessionId?: string;
|
|
37
33
|
initialized: boolean;
|
|
38
|
-
protocolVersion?: ProtocolVersion;
|
|
39
34
|
}
|
|
40
35
|
interface WorkerTransportOptions {
|
|
41
36
|
sessionIdGenerator?: () => string;
|
|
@@ -63,7 +58,6 @@ declare class WorkerTransport implements Transport {
|
|
|
63
58
|
private requestToStreamMapping;
|
|
64
59
|
private requestResponseMap;
|
|
65
60
|
private corsOptions?;
|
|
66
|
-
private protocolVersion?;
|
|
67
61
|
private storage?;
|
|
68
62
|
private stateRestored;
|
|
69
63
|
sessionId?: string;
|
|
@@ -81,6 +75,19 @@ declare class WorkerTransport implements Transport {
|
|
|
81
75
|
*/
|
|
82
76
|
private saveState;
|
|
83
77
|
start(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
80
|
+
*
|
|
81
|
+
* This performs a simple check: if a version header is present, it must be
|
|
82
|
+
* in the SUPPORTED_PROTOCOL_VERSIONS list. We do not track the negotiated
|
|
83
|
+
* version or enforce version consistency across requests - the SDK handles
|
|
84
|
+
* version negotiation during initialization, and we simply reject any
|
|
85
|
+
* explicitly unsupported versions.
|
|
86
|
+
*
|
|
87
|
+
* - Header present and supported: Accept
|
|
88
|
+
* - Header present and unsupported: 400 Bad Request
|
|
89
|
+
* - Header missing: Accept (version validation is optional)
|
|
90
|
+
*/
|
|
84
91
|
private validateProtocolVersion;
|
|
85
92
|
private getHeaders;
|
|
86
93
|
handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
|
|
@@ -126,7 +133,7 @@ declare function createMcpHandler(server: McpServer | Server, options?: CreateMc
|
|
|
126
133
|
declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
127
134
|
//#endregion
|
|
128
135
|
//#region src/mcp/index.d.ts
|
|
129
|
-
declare abstract class McpAgent<Env =
|
|
136
|
+
declare abstract class McpAgent<Env extends Cloudflare.Env = Cloudflare.Env, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
|
|
130
137
|
private _transport?;
|
|
131
138
|
props?: Props;
|
|
132
139
|
abstract server: MaybePromise<McpServer | Server>;
|
|
@@ -189,5 +196,5 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
189
196
|
};
|
|
190
197
|
}
|
|
191
198
|
//#endregion
|
|
192
|
-
export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, type MCPConnectionResult, type MCPServerOptions, McpAgent, type McpAuthContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, type TransportState, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
|
199
|
+
export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, type MCPConnectionResult, type MCPDiscoverResult, type MCPServerOptions, McpAgent, type McpAuthContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, type TransportState, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
|
193
200
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import "../client-
|
|
4
|
-
import "../
|
|
5
|
-
import
|
|
1
|
+
import "../context-BkKbAa1R.js";
|
|
2
|
+
import { t as MessageType } from "../ai-types-DEtF_8Km.js";
|
|
3
|
+
import "../client-DjTPRM8-.js";
|
|
4
|
+
import "../client-QZa2Rq0l.js";
|
|
5
|
+
import "../do-oauth-client-provider-B1fVIshX.js";
|
|
6
|
+
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-BZDh910Z.js";
|
|
6
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
8
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
9
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
|
-
import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
|
|
10
11
|
|
|
11
12
|
//#region src/mcp/utils.ts
|
|
12
13
|
/**
|
|
@@ -592,19 +593,35 @@ var StreamableHTTPServerTransport = class {
|
|
|
592
593
|
if (Array.isArray(rawMessage)) messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
593
594
|
else messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
594
595
|
const hasRequests = messages.some(isJSONRPCRequest);
|
|
595
|
-
if (!hasRequests) for (const message of messages)
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
596
|
+
if (!hasRequests) for (const message of messages) {
|
|
597
|
+
if (this.messageInterceptor) {
|
|
598
|
+
if (await this.messageInterceptor(message, {
|
|
599
|
+
authInfo,
|
|
600
|
+
requestInfo
|
|
601
|
+
})) continue;
|
|
602
|
+
}
|
|
603
|
+
this.onmessage?.(message, {
|
|
604
|
+
authInfo,
|
|
605
|
+
requestInfo
|
|
606
|
+
});
|
|
607
|
+
}
|
|
599
608
|
else if (hasRequests) {
|
|
600
609
|
const { connection } = getCurrentAgent();
|
|
601
610
|
if (!connection) throw new Error("Connection was not found in handlePostRequest");
|
|
602
611
|
const requestIds = messages.filter(isJSONRPCRequest).map((message) => message.id);
|
|
603
612
|
connection.setState({ requestIds });
|
|
604
|
-
for (const message of messages)
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
613
|
+
for (const message of messages) {
|
|
614
|
+
if (this.messageInterceptor) {
|
|
615
|
+
if (await this.messageInterceptor(message, {
|
|
616
|
+
authInfo,
|
|
617
|
+
requestInfo
|
|
618
|
+
})) continue;
|
|
619
|
+
}
|
|
620
|
+
this.onmessage?.(message, {
|
|
621
|
+
authInfo,
|
|
622
|
+
requestInfo
|
|
623
|
+
});
|
|
624
|
+
}
|
|
608
625
|
}
|
|
609
626
|
}
|
|
610
627
|
async close() {
|
|
@@ -677,8 +694,6 @@ var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransp
|
|
|
677
694
|
|
|
678
695
|
//#endregion
|
|
679
696
|
//#region src/mcp/worker-transport.ts
|
|
680
|
-
const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
|
|
681
|
-
const DEFAULT_PROTOCOL_VERSION = "2025-03-26";
|
|
682
697
|
const MCP_PROTOCOL_VERSION_HEADER = "MCP-Protocol-Version";
|
|
683
698
|
var WorkerTransport = class {
|
|
684
699
|
constructor(options) {
|
|
@@ -706,7 +721,6 @@ var WorkerTransport = class {
|
|
|
706
721
|
if (state) {
|
|
707
722
|
this.sessionId = state.sessionId;
|
|
708
723
|
this.initialized = state.initialized;
|
|
709
|
-
this.protocolVersion = state.protocolVersion;
|
|
710
724
|
}
|
|
711
725
|
this.stateRestored = true;
|
|
712
726
|
}
|
|
@@ -717,8 +731,7 @@ var WorkerTransport = class {
|
|
|
717
731
|
if (!this.storage) return;
|
|
718
732
|
const state = {
|
|
719
733
|
sessionId: this.sessionId,
|
|
720
|
-
initialized: this.initialized
|
|
721
|
-
protocolVersion: this.protocolVersion
|
|
734
|
+
initialized: this.initialized
|
|
722
735
|
};
|
|
723
736
|
await Promise.resolve(this.storage.set(state));
|
|
724
737
|
}
|
|
@@ -726,44 +739,26 @@ var WorkerTransport = class {
|
|
|
726
739
|
if (this.started) throw new Error("Transport already started");
|
|
727
740
|
this.started = true;
|
|
728
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
744
|
+
*
|
|
745
|
+
* This performs a simple check: if a version header is present, it must be
|
|
746
|
+
* in the SUPPORTED_PROTOCOL_VERSIONS list. We do not track the negotiated
|
|
747
|
+
* version or enforce version consistency across requests - the SDK handles
|
|
748
|
+
* version negotiation during initialization, and we simply reject any
|
|
749
|
+
* explicitly unsupported versions.
|
|
750
|
+
*
|
|
751
|
+
* - Header present and supported: Accept
|
|
752
|
+
* - Header present and unsupported: 400 Bad Request
|
|
753
|
+
* - Header missing: Accept (version validation is optional)
|
|
754
|
+
*/
|
|
729
755
|
validateProtocolVersion(request) {
|
|
730
|
-
const
|
|
731
|
-
if (!
|
|
732
|
-
if (!this.protocolVersion || this.protocolVersion === DEFAULT_PROTOCOL_VERSION) return;
|
|
733
|
-
return new Response(JSON.stringify({
|
|
734
|
-
jsonrpc: "2.0",
|
|
735
|
-
error: {
|
|
736
|
-
code: -32e3,
|
|
737
|
-
message: `Bad Request: ${MCP_PROTOCOL_VERSION_HEADER} header is required`
|
|
738
|
-
},
|
|
739
|
-
id: null
|
|
740
|
-
}), {
|
|
741
|
-
status: 400,
|
|
742
|
-
headers: {
|
|
743
|
-
"Content-Type": "application/json",
|
|
744
|
-
...this.getHeaders()
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(versionHeader)) return new Response(JSON.stringify({
|
|
749
|
-
jsonrpc: "2.0",
|
|
750
|
-
error: {
|
|
751
|
-
code: -32e3,
|
|
752
|
-
message: `Bad Request: Unsupported ${MCP_PROTOCOL_VERSION_HEADER}: ${versionHeader}. Supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")}`
|
|
753
|
-
},
|
|
754
|
-
id: null
|
|
755
|
-
}), {
|
|
756
|
-
status: 400,
|
|
757
|
-
headers: {
|
|
758
|
-
"Content-Type": "application/json",
|
|
759
|
-
...this.getHeaders()
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
if (this.protocolVersion && versionHeader !== this.protocolVersion) return new Response(JSON.stringify({
|
|
756
|
+
const protocolVersion = request.headers.get(MCP_PROTOCOL_VERSION_HEADER);
|
|
757
|
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) return new Response(JSON.stringify({
|
|
763
758
|
jsonrpc: "2.0",
|
|
764
759
|
error: {
|
|
765
760
|
code: -32e3,
|
|
766
|
-
message: `Bad Request:
|
|
761
|
+
message: `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`
|
|
767
762
|
},
|
|
768
763
|
id: null
|
|
769
764
|
}), {
|
|
@@ -966,12 +961,6 @@ var WorkerTransport = class {
|
|
|
966
961
|
...this.getHeaders()
|
|
967
962
|
}
|
|
968
963
|
});
|
|
969
|
-
const initRequest = messages.find(isInitializeRequest);
|
|
970
|
-
if (initRequest?.params) {
|
|
971
|
-
const version = initRequest.params.protocolVersion;
|
|
972
|
-
if (version && SUPPORTED_PROTOCOL_VERSIONS.includes(version)) this.protocolVersion = version;
|
|
973
|
-
else this.protocolVersion = DEFAULT_PROTOCOL_VERSION;
|
|
974
|
-
}
|
|
975
964
|
this.sessionId = this.sessionIdGenerator?.();
|
|
976
965
|
this.initialized = true;
|
|
977
966
|
await this.saveState();
|
|
@@ -1258,7 +1247,13 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1258
1247
|
initTransport() {
|
|
1259
1248
|
switch (this.getTransportType()) {
|
|
1260
1249
|
case "sse": return new McpSSETransport();
|
|
1261
|
-
case "streamable-http":
|
|
1250
|
+
case "streamable-http": {
|
|
1251
|
+
const transport = new StreamableHTTPServerTransport({});
|
|
1252
|
+
transport.messageInterceptor = async (message) => {
|
|
1253
|
+
return this._handleElicitationResponse(message);
|
|
1254
|
+
};
|
|
1255
|
+
return transport;
|
|
1256
|
+
}
|
|
1262
1257
|
}
|
|
1263
1258
|
}
|
|
1264
1259
|
/** Update and store the props */
|