agents 0.0.0-197e86a → 0.0.0-1a3d226

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +255 -10
  2. package/dist/ai-chat-agent.d.ts +238 -31
  3. package/dist/ai-chat-agent.js +1118 -260
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.d.ts +155 -0
  6. package/dist/ai-chat-v5-migration.js +155 -0
  7. package/dist/ai-chat-v5-migration.js.map +1 -0
  8. package/dist/ai-react.d.ts +197 -86
  9. package/dist/ai-react.js +574 -199
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/ai-types-0OnT3FHg.d.ts +127 -0
  12. package/dist/ai-types-DEtF_8Km.js +28 -0
  13. package/dist/ai-types-DEtF_8Km.js.map +1 -0
  14. package/dist/ai-types.d.ts +6 -74
  15. package/dist/ai-types.js +3 -1
  16. package/dist/cli/index.d.ts +1 -0
  17. package/dist/cli/index.js +28 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/client-BINtT7y-.d.ts +834 -0
  20. package/dist/client-CdM5I962.d.ts +104 -0
  21. package/dist/client-DjTPRM8-.js +117 -0
  22. package/dist/client-DjTPRM8-.js.map +1 -0
  23. package/dist/client-QZa2Rq0l.js +1105 -0
  24. package/dist/client-QZa2Rq0l.js.map +1 -0
  25. package/dist/client.d.ts +10 -92
  26. package/dist/client.js +3 -11
  27. package/dist/codemode/ai.d.ts +27 -0
  28. package/dist/codemode/ai.js +151 -0
  29. package/dist/codemode/ai.js.map +1 -0
  30. package/dist/context-BkKbAa1R.js +8 -0
  31. package/dist/context-BkKbAa1R.js.map +1 -0
  32. package/dist/context-DcbQ8o7k.d.ts +24 -0
  33. package/dist/context.d.ts +6 -0
  34. package/dist/context.js +3 -0
  35. package/dist/do-oauth-client-provider--To1Tsjj.d.ts +70 -0
  36. package/dist/do-oauth-client-provider-B1fVIshX.js +155 -0
  37. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  38. package/dist/{index-BCJclX6q.d.ts → index-CfZ2mfMI.d.ts} +131 -170
  39. package/dist/index-DLuxm_9W.d.ts +58 -0
  40. package/dist/index.d.ts +66 -40
  41. package/dist/index.js +7 -28
  42. package/dist/mcp/client.d.ts +2 -11
  43. package/dist/mcp/client.js +4 -9
  44. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  45. package/dist/mcp/do-oauth-client-provider.js +3 -7
  46. package/dist/mcp/index.d.ts +197 -109
  47. package/dist/mcp/index.js +1429 -942
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/mcp/x402.d.ts +34 -0
  50. package/dist/mcp/x402.js +198 -0
  51. package/dist/mcp/x402.js.map +1 -0
  52. package/dist/mcp-CPSfGUgd.d.ts +61 -0
  53. package/dist/observability/index.d.ts +2 -14
  54. package/dist/observability/index.js +7 -10
  55. package/dist/react.d.ts +48 -35
  56. package/dist/react.js +183 -110
  57. package/dist/react.js.map +1 -1
  58. package/dist/schedule.d.ts +61 -38
  59. package/dist/schedule.js +46 -21
  60. package/dist/schedule.js.map +1 -1
  61. package/dist/serializable-Crsj26mx.d.ts +39 -0
  62. package/dist/serializable.d.ts +7 -32
  63. package/dist/serializable.js +1 -1
  64. package/dist/src-BZDh910Z.js +1181 -0
  65. package/dist/src-BZDh910Z.js.map +1 -0
  66. package/package.json +93 -29
  67. package/dist/ai-types.js.map +0 -1
  68. package/dist/chunk-HY7ZLHJB.js +0 -598
  69. package/dist/chunk-HY7ZLHJB.js.map +0 -1
  70. package/dist/chunk-JXN5WZFQ.js +0 -1287
  71. package/dist/chunk-JXN5WZFQ.js.map +0 -1
  72. package/dist/chunk-KUH345EY.js +0 -116
  73. package/dist/chunk-KUH345EY.js.map +0 -1
  74. package/dist/chunk-PVQZBKN7.js +0 -106
  75. package/dist/chunk-PVQZBKN7.js.map +0 -1
  76. package/dist/client-DgyzBU_8.d.ts +0 -4601
  77. package/dist/client.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/mcp/client.js.map +0 -1
  80. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  81. package/dist/observability/index.js.map +0 -1
  82. package/dist/serializable.js.map +0 -1
  83. package/src/index.ts +0 -1917
package/dist/index.d.ts CHANGED
@@ -1,41 +1,67 @@
1
- import "cloudflare:workers";
2
- import "@modelcontextprotocol/sdk/client/index.js";
3
- import "@modelcontextprotocol/sdk/types.js";
4
- export { Connection, ConnectionContext, WSMessage } from "partyserver";
5
- import "./client-DgyzBU_8.js";
1
+ import { n as AgentEmail } from "./context-DcbQ8o7k.js";
2
+ import { h as TransportType } from "./client-BINtT7y-.js";
3
+ import "./ai-types-0OnT3FHg.js";
4
+ import {
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,
23
+ n as AgentContext,
24
+ o as Connection,
25
+ p as MCPServersState,
26
+ r as AgentNamespace,
27
+ s as ConnectionContext,
28
+ t as Agent,
29
+ u as EmailSendOptions,
30
+ v as StateUpdateMessage,
31
+ w as createHeaderBasedEmailResolver,
32
+ x as callable,
33
+ y as StreamingResponse
34
+ } from "./index-CfZ2mfMI.js";
6
35
  export {
7
- A as Agent,
8
- a as AgentContext,
9
- p as AgentEmail,
10
- i as AgentNamespace,
11
- j as AgentOptions,
12
- C as CallableMetadata,
13
- E as EmailResolver,
14
- n as EmailRoutingOptions,
15
- q as EmailSendOptions,
16
- f as MCPServer,
17
- e as MCPServerMessage,
18
- M as MCPServersState,
19
- Q as QueueItem,
20
- R as RPCRequest,
21
- c as RPCResponse,
22
- d as Schedule,
23
- S as StateUpdateMessage,
24
- t as StreamingResponse,
25
- l as createAddressBasedEmailResolver,
26
- m as createCatchAllEmailResolver,
27
- k as createHeaderBasedEmailResolver,
28
- s as getAgentByName,
29
- h as getCurrentAgent,
30
- o as routeAgentEmail,
31
- r as routeAgentRequest,
32
- u as unstable_callable
33
- } from "./index-BCJclX6q.js";
34
- import "zod";
35
- import "@modelcontextprotocol/sdk/shared/protocol.js";
36
- import "ai";
37
- import "@modelcontextprotocol/sdk/client/sse.js";
38
- import "@modelcontextprotocol/sdk/client/streamableHttp.js";
39
- import "./mcp/do-oauth-client-provider.js";
40
- import "@modelcontextprotocol/sdk/client/auth.js";
41
- import "@modelcontextprotocol/sdk/shared/auth.js";
36
+ Agent,
37
+ AgentContext,
38
+ AgentEmail,
39
+ AgentNamespace,
40
+ AgentOptions,
41
+ CallableMetadata,
42
+ Connection,
43
+ ConnectionContext,
44
+ EmailResolver,
45
+ EmailRoutingOptions,
46
+ EmailSendOptions,
47
+ MCPServer,
48
+ MCPServerMessage,
49
+ MCPServersState,
50
+ QueueItem,
51
+ RPCRequest,
52
+ RPCResponse,
53
+ Schedule,
54
+ StateUpdateMessage,
55
+ StreamingResponse,
56
+ TransportType,
57
+ WSMessage,
58
+ callable,
59
+ createAddressBasedEmailResolver,
60
+ createCatchAllEmailResolver,
61
+ createHeaderBasedEmailResolver,
62
+ getAgentByName,
63
+ getCurrentAgent,
64
+ routeAgentEmail,
65
+ routeAgentRequest,
66
+ unstable_callable
67
+ };
package/dist/index.js CHANGED
@@ -1,28 +1,7 @@
1
- import {
2
- Agent,
3
- StreamingResponse,
4
- createAddressBasedEmailResolver,
5
- createCatchAllEmailResolver,
6
- createHeaderBasedEmailResolver,
7
- getAgentByName,
8
- getCurrentAgent,
9
- routeAgentEmail,
10
- routeAgentRequest,
11
- unstable_callable
12
- } from "./chunk-JXN5WZFQ.js";
13
- import "./chunk-HY7ZLHJB.js";
14
- import "./chunk-PVQZBKN7.js";
15
- import "./chunk-KUH345EY.js";
16
- export {
17
- Agent,
18
- StreamingResponse,
19
- createAddressBasedEmailResolver,
20
- createCatchAllEmailResolver,
21
- createHeaderBasedEmailResolver,
22
- getAgentByName,
23
- getCurrentAgent,
24
- routeAgentEmail,
25
- routeAgentRequest,
26
- unstable_callable
27
- };
28
- //# sourceMappingURL=index.js.map
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
+
7
+ export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
@@ -1,11 +1,2 @@
1
- import 'zod';
2
- import '@modelcontextprotocol/sdk/client/index.js';
3
- import '@modelcontextprotocol/sdk/shared/protocol.js';
4
- import '@modelcontextprotocol/sdk/types.js';
5
- import 'ai';
6
- export { M as MCPClientManager, g as getNamespacedData } from '../client-DgyzBU_8.js';
7
- import '@modelcontextprotocol/sdk/client/sse.js';
8
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
9
- import './do-oauth-client-provider.js';
10
- import '@modelcontextprotocol/sdk/client/auth.js';
11
- import '@modelcontextprotocol/sdk/shared/auth.js';
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-BINtT7y-.js";
2
+ export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
@@ -1,9 +1,4 @@
1
- import {
2
- MCPClientManager,
3
- getNamespacedData
4
- } from "../chunk-HY7ZLHJB.js";
5
- export {
6
- MCPClientManager,
7
- getNamespacedData
8
- };
9
- //# sourceMappingURL=client.js.map
1
+ import { n as getNamespacedData, t as MCPClientManager } from "../client-QZa2Rq0l.js";
2
+ import "../do-oauth-client-provider-B1fVIshX.js";
3
+
4
+ export { MCPClientManager, getNamespacedData };
@@ -1,41 +1,2 @@
1
- import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
2
- import { OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
3
-
4
- interface AgentsOAuthProvider extends OAuthClientProvider {
5
- authUrl: string | undefined;
6
- clientId: string | undefined;
7
- serverId: string | undefined;
8
- }
9
- declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
10
- storage: DurableObjectStorage;
11
- clientName: string;
12
- baseRedirectUrl: string;
13
- private _authUrl_;
14
- private _serverId_;
15
- private _clientId_;
16
- constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
- get clientMetadata(): OAuthClientMetadata;
18
- get redirectUrl(): string;
19
- get clientId(): string;
20
- set clientId(clientId_: string);
21
- get serverId(): string;
22
- set serverId(serverId_: string);
23
- keyPrefix(clientId: string): string;
24
- clientInfoKey(clientId: string): string;
25
- clientInformation(): Promise<OAuthClientInformation | undefined>;
26
- saveClientInformation(clientInformation: OAuthClientInformationFull): Promise<void>;
27
- tokenKey(clientId: string): string;
28
- tokens(): Promise<OAuthTokens | undefined>;
29
- saveTokens(tokens: OAuthTokens): Promise<void>;
30
- get authUrl(): string | undefined;
31
- /**
32
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
33
- * and require user interact to initiate the redirect flow
34
- */
35
- redirectToAuthorization(authUrl: URL): Promise<void>;
36
- codeVerifierKey(clientId: string): string;
37
- saveCodeVerifier(verifier: string): Promise<void>;
38
- codeVerifier(): Promise<string>;
39
- }
40
-
41
- export { type AgentsOAuthProvider, DurableObjectOAuthClientProvider };
1
+ import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider--To1Tsjj.js";
2
+ export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,7 +1,3 @@
1
- import {
2
- DurableObjectOAuthClientProvider
3
- } from "../chunk-PVQZBKN7.js";
4
- export {
5
- DurableObjectOAuthClientProvider
6
- };
7
- //# sourceMappingURL=do-oauth-client-provider.js.map
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B1fVIshX.js";
2
+
3
+ export { DurableObjectOAuthClientProvider };
@@ -1,112 +1,200 @@
1
- import { M as MCPClientManager } from '../client-DgyzBU_8.js';
2
- export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-DgyzBU_8.js';
3
- import { DurableObject } from 'cloudflare:workers';
4
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
- import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
7
- export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
8
- import { Connection, WSMessage } from 'partyserver';
9
- import 'zod';
10
- import '@modelcontextprotocol/sdk/client/index.js';
11
- import '@modelcontextprotocol/sdk/shared/protocol.js';
12
- import 'ai';
13
- import '@modelcontextprotocol/sdk/client/sse.js';
14
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
15
- import './do-oauth-client-provider.js';
16
- import '@modelcontextprotocol/sdk/client/auth.js';
17
- import '@modelcontextprotocol/sdk/shared/auth.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-BINtT7y-.js";
3
+ import "../ai-types-0OnT3FHg.js";
4
+ import { o as Connection, s as ConnectionContext, t as Agent } from "../index-CfZ2mfMI.js";
5
+ import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
6
+ import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
7
+ import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
8
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
+ import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
18
11
 
19
- interface CORSOptions {
20
- origin?: string;
21
- methods?: string;
22
- headers?: string;
23
- maxAge?: number;
24
- exposeHeaders?: string;
12
+ //#region src/mcp/client-transports.d.ts
13
+ /**
14
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
15
+ */
16
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
17
+ constructor(url: URL, options: SSEClientTransportOptions);
25
18
  }
26
- type MaybePromise<T> = T | Promise<T>;
27
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
28
- private _status;
29
- private _transport?;
30
- private _transportType;
31
- private _requestIdToConnectionId;
32
- /**
33
- * Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
34
- * to the outer class: initialState/state/setState/onStateUpdate/sql
35
- */
36
- private _agent;
37
- get mcp(): MCPClientManager;
38
- protected constructor(ctx: DurableObjectState, env: Env);
39
- /**
40
- * Agents API allowlist
41
- */
42
- initialState: State;
43
- get state(): State;
44
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
45
- setState(state: State): void;
46
- /**
47
- * Elicit user input with a message and schema
48
- */
49
- elicitInput(params: {
50
- message: string;
51
- requestedSchema: unknown;
52
- }): Promise<ElicitResult>;
53
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
54
- onStart(): Promise<void>;
55
- /**
56
- * McpAgent API
57
- */
58
- abstract server: MaybePromise<McpServer | Server>;
59
- props: Props;
60
- initRun: boolean;
61
- abstract init(): Promise<void>;
62
- /**
63
- * Handle errors that occur during initialization or operation.
64
- * Override this method to provide custom error handling.
65
- * @param error - The error that occurred
66
- * @returns An error response object with status code and message
67
- */
68
- onError(error: Error): {
69
- status: number;
70
- message: string;
71
- };
72
- _init(props: Props): Promise<void>;
73
- setInitialized(): Promise<void>;
74
- isInitialized(): Promise<boolean>;
75
- updateProps(props: Props): Promise<void>;
76
- private _initialize;
77
- fetch(request: Request): Promise<Response>;
78
- getWebSocket(): WebSocket | null;
79
- getWebSocketForResponseID(id: string): WebSocket | null;
80
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
81
- /**
82
- * Wait for elicitation response through storage polling
83
- */
84
- private _waitForElicitationResponse;
85
- /**
86
- * Handle elicitation responses */
87
- private _handleElicitationResponse;
88
- onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
89
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
90
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
91
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
92
- static mount(path: string, { binding, corsOptions }?: {
93
- binding?: string;
94
- corsOptions?: CORSOptions;
95
- }): {
96
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
97
- };
98
- static serveSSE(path: string, { binding, corsOptions }?: {
99
- binding?: string;
100
- corsOptions?: CORSOptions;
101
- }): {
102
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
103
- };
104
- static serve(path: string, { binding, corsOptions }?: {
105
- binding?: string;
106
- corsOptions?: CORSOptions;
107
- }): {
108
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
109
- };
19
+ /**
20
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
21
+ */
22
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
23
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
110
24
  }
111
-
112
- export { McpAgent };
25
+ //#endregion
26
+ //#region src/mcp/worker-transport.d.ts
27
+ interface MCPStorageApi {
28
+ get(): Promise<TransportState | undefined> | TransportState | undefined;
29
+ set(state: TransportState): Promise<void> | void;
30
+ }
31
+ interface TransportState {
32
+ sessionId?: string;
33
+ initialized: boolean;
34
+ }
35
+ interface WorkerTransportOptions {
36
+ sessionIdGenerator?: () => string;
37
+ /**
38
+ * Enable traditional Request/Response mode, this will disable streaming.
39
+ */
40
+ enableJsonResponse?: boolean;
41
+ onsessioninitialized?: (sessionId: string) => void;
42
+ corsOptions?: CORSOptions;
43
+ /**
44
+ * Optional storage api for persisting transport state.
45
+ * Use this to store session state in Durable Object/Agent storage
46
+ * so it survives hibernation/restart.
47
+ */
48
+ storage?: MCPStorageApi;
49
+ }
50
+ declare class WorkerTransport implements Transport {
51
+ started: boolean;
52
+ private initialized;
53
+ private sessionIdGenerator?;
54
+ private enableJsonResponse;
55
+ private onsessioninitialized?;
56
+ private standaloneSseStreamId;
57
+ private streamMapping;
58
+ private requestToStreamMapping;
59
+ private requestResponseMap;
60
+ private corsOptions?;
61
+ private storage?;
62
+ private stateRestored;
63
+ sessionId?: string;
64
+ onclose?: () => void;
65
+ onerror?: (error: Error) => void;
66
+ onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
67
+ constructor(options?: WorkerTransportOptions);
68
+ /**
69
+ * Restore transport state from persistent storage.
70
+ * This is automatically called on start.
71
+ */
72
+ private restoreState;
73
+ /**
74
+ * Persist current transport state to storage.
75
+ */
76
+ private saveState;
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
+ */
91
+ private validateProtocolVersion;
92
+ private getHeaders;
93
+ handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
94
+ private handleGetRequest;
95
+ private handlePostRequest;
96
+ private handleDeleteRequest;
97
+ private handleOptionsRequest;
98
+ private handleUnsupportedRequest;
99
+ private validateSession;
100
+ close(): Promise<void>;
101
+ send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
102
+ }
103
+ //#endregion
104
+ //#region src/mcp/auth-context.d.ts
105
+ interface McpAuthContext {
106
+ props: Record<string, unknown>;
107
+ }
108
+ declare function getMcpAuthContext(): McpAuthContext | undefined;
109
+ //#endregion
110
+ //#region src/mcp/handler.d.ts
111
+ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
112
+ /**
113
+ * The route path that this MCP handler should respond to.
114
+ * If specified, the handler will only process requests that match this route.
115
+ * @default "/mcp"
116
+ */
117
+ route?: string;
118
+ /**
119
+ * An optional auth context to use for handling MCP requests.
120
+ * If not provided, the handler will look for props in the execution context.
121
+ */
122
+ authContext?: McpAuthContext;
123
+ /**
124
+ * An optional transport to use for handling MCP requests.
125
+ * If not provided, a WorkerTransport will be created with the provided WorkerTransportOptions.
126
+ */
127
+ transport?: WorkerTransport;
128
+ }
129
+ declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
130
+ /**
131
+ * @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
132
+ */
133
+ declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
134
+ //#endregion
135
+ //#region src/mcp/index.d.ts
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> {
137
+ private _transport?;
138
+ props?: Props;
139
+ abstract server: MaybePromise<McpServer | Server>;
140
+ abstract init(): Promise<void>;
141
+ setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
142
+ getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
143
+ /** Read the transport type for this agent.
144
+ * This relies on the naming scheme being `sse:${sessionId}`
145
+ * or `streamable-http:${sessionId}`.
146
+ */
147
+ getTransportType(): BaseTransportType;
148
+ /** Read the sessionId for this agent.
149
+ * This relies on the naming scheme being `sse:${sessionId}`
150
+ * or `streamable-http:${sessionId}`.
151
+ */
152
+ getSessionId(): string;
153
+ /** Get the unique WebSocket. SSE transport only. */
154
+ getWebSocket(): Connection<unknown> | null;
155
+ /** Returns a new transport matching the type of the Agent. */
156
+ private initTransport;
157
+ /** Update and store the props */
158
+ updateProps(props?: Props): Promise<void>;
159
+ reinitializeServer(): Promise<void>;
160
+ /** Sets up the MCP transport and server every time the Agent is started.*/
161
+ onStart(props?: Props): Promise<void>;
162
+ /** Validates new WebSocket connections. */
163
+ onConnect(conn: Connection, {
164
+ request: req
165
+ }: ConnectionContext): Promise<void>;
166
+ /** Handles MCP Messages for the legacy SSE transport. */
167
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown, extraInfo?: MessageExtraInfo): Promise<Error | null>;
168
+ /** Elicit user input with a message and schema */
169
+ elicitInput(params: {
170
+ message: string;
171
+ requestedSchema: unknown;
172
+ }): Promise<ElicitResult$1>;
173
+ /** Wait for elicitation response through storage polling */
174
+ private _waitForElicitationResponse;
175
+ /** Handle elicitation responses */
176
+ private _handleElicitationResponse;
177
+ /** Return a handler for the given path for this MCP.
178
+ * Defaults to Streamable HTTP transport.
179
+ */
180
+ static serve(path: string, {
181
+ binding,
182
+ corsOptions,
183
+ transport,
184
+ jurisdiction
185
+ }?: ServeOptions): {
186
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
187
+ };
188
+ /**
189
+ * Legacy api
190
+ **/
191
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
192
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
193
+ };
194
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
195
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
196
+ };
197
+ }
198
+ //#endregion
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 };
200
+ //# sourceMappingURL=index.d.ts.map