agents 0.0.0-e03246e → 0.0.0-e173b41
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 +257 -27
- package/dist/ai-chat-agent.d.ts +133 -12
- package/dist/ai-chat-agent.js +798 -160
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration-BSiGZmYU.js +155 -0
- package/dist/ai-chat-v5-migration-BSiGZmYU.js.map +1 -0
- package/dist/ai-chat-v5-migration.d.ts +155 -0
- package/dist/ai-chat-v5-migration.js +3 -0
- package/dist/ai-react.d.ts +78 -72
- package/dist/ai-react.js +411 -192
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types-81H_-Uxh.d.ts +103 -0
- package/dist/ai-types-CrMqkwc_.js +24 -0
- package/dist/ai-types-CrMqkwc_.js.map +1 -0
- package/dist/ai-types.d.ts +6 -69
- package/dist/ai-types.js +3 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-B3SR12TQ.js +117 -0
- package/dist/client-B3SR12TQ.js.map +1 -0
- package/dist/client-BAQA84dr.d.ts +104 -0
- package/dist/client-BZq9qau2.js +1093 -0
- package/dist/client-BZq9qau2.js.map +1 -0
- package/dist/client-CsaP9Irq.d.ts +1528 -0
- package/dist/client.d.ts +12 -79
- package/dist/client.js +3 -130
- package/dist/codemode/ai.d.ts +27 -0
- package/dist/codemode/ai.js +151 -0
- package/dist/codemode/ai.js.map +1 -0
- package/dist/do-oauth-client-provider-C2CHH5x-.d.ts +55 -0
- package/dist/do-oauth-client-provider-CwqK5SXm.js +94 -0
- package/dist/do-oauth-client-provider-CwqK5SXm.js.map +1 -0
- package/dist/index-BUle9RiP.d.ts +58 -0
- package/dist/index-Bx5KK3VJ.d.ts +587 -0
- package/dist/index.d.ts +63 -301
- package/dist/index.js +7 -22
- package/dist/mcp/client.d.ts +4 -675
- package/dist/mcp/client.js +3 -267
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -0
- package/dist/mcp/do-oauth-client-provider.js +3 -0
- package/dist/mcp/index.d.ts +191 -43
- package/dist/mcp/index.js +1438 -334
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +34 -0
- package/dist/mcp/x402.js +198 -0
- package/dist/mcp/x402.js.map +1 -0
- package/dist/mcp-BwPscEiF.d.ts +61 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +7 -0
- package/dist/react-CbwD4fBf.d.ts +113 -0
- package/dist/react.d.ts +10 -39
- package/dist/react.js +183 -98
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +89 -12
- package/dist/schedule.js +46 -23
- package/dist/schedule.js.map +1 -1
- package/dist/serializable-faDkMCai.d.ts +39 -0
- package/dist/serializable.d.ts +7 -0
- package/dist/serializable.js +1 -0
- package/dist/src-D_KKH_4c.js +1184 -0
- package/dist/src-D_KKH_4c.js.map +1 -0
- package/package.json +130 -51
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-YMUU7QHV.js +0 -595
- package/dist/chunk-YMUU7QHV.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp/client.js.map +0 -1
- package/src/index.ts +0 -919
package/dist/mcp/client.js
CHANGED
|
@@ -1,268 +1,4 @@
|
|
|
1
|
-
import "../
|
|
1
|
+
import { n as getNamespacedData, t as MCPClientManager } from "../client-BZq9qau2.js";
|
|
2
|
+
import "../do-oauth-client-provider-CwqK5SXm.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
SSEClientTransport
|
|
6
|
-
} from "@modelcontextprotocol/sdk/client/sse.js";
|
|
7
|
-
var SSEEdgeClientTransport = class extends SSEClientTransport {
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
10
|
-
*/
|
|
11
|
-
constructor(url, options) {
|
|
12
|
-
const fetchOverride = (url2, options2 = {}) => {
|
|
13
|
-
const workerOptions = {
|
|
14
|
-
...options2
|
|
15
|
-
};
|
|
16
|
-
delete workerOptions.mode;
|
|
17
|
-
return global.fetch(url2, workerOptions);
|
|
18
|
-
};
|
|
19
|
-
super(url, {
|
|
20
|
-
...options,
|
|
21
|
-
eventSourceInit: {
|
|
22
|
-
fetch: fetchOverride
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
this.url = url;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/mcp/client-connection.ts
|
|
30
|
-
import {
|
|
31
|
-
ToolListChangedNotificationSchema,
|
|
32
|
-
ResourceListChangedNotificationSchema,
|
|
33
|
-
PromptListChangedNotificationSchema
|
|
34
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
35
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
36
|
-
var MCPClientConnection = class {
|
|
37
|
-
constructor(url, info, opts = { transport: {}, client: {}, capabilities: {} }) {
|
|
38
|
-
this.info = info;
|
|
39
|
-
this.transport = new SSEEdgeClientTransport(url, opts.transport);
|
|
40
|
-
this.client = new Client(info, opts.client);
|
|
41
|
-
this.client.registerCapabilities(opts.capabilities);
|
|
42
|
-
this.connected = false;
|
|
43
|
-
this.tools = [];
|
|
44
|
-
this.prompts = [];
|
|
45
|
-
this.resources = [];
|
|
46
|
-
this.resourceTemplates = [];
|
|
47
|
-
}
|
|
48
|
-
async init() {
|
|
49
|
-
await this.client.connect(this.transport);
|
|
50
|
-
this.serverCapabilities = await this.client.getServerCapabilities();
|
|
51
|
-
if (!this.serverCapabilities) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`The MCP Server ${this.info.name} failed to return server capabilities`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
const [instructions, tools, resources, prompts, resourceTemplates] = await Promise.all([
|
|
57
|
-
this.client.getInstructions(),
|
|
58
|
-
this.registerTools(),
|
|
59
|
-
this.registerResources(),
|
|
60
|
-
this.registerPrompts(),
|
|
61
|
-
this.registerResourceTemplates()
|
|
62
|
-
]);
|
|
63
|
-
this.instructions = instructions;
|
|
64
|
-
this.tools = tools;
|
|
65
|
-
this.resources = resources;
|
|
66
|
-
this.prompts = prompts;
|
|
67
|
-
this.resourceTemplates = resourceTemplates;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Notification handler registration
|
|
71
|
-
*/
|
|
72
|
-
async registerTools() {
|
|
73
|
-
if (!this.serverCapabilities || !this.serverCapabilities.tools) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
if (this.serverCapabilities.tools.listChanged) {
|
|
77
|
-
this.client.setNotificationHandler(
|
|
78
|
-
ToolListChangedNotificationSchema,
|
|
79
|
-
async (_notification) => {
|
|
80
|
-
this.tools = await this.fetchTools();
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return this.fetchTools();
|
|
85
|
-
}
|
|
86
|
-
async registerResources() {
|
|
87
|
-
if (!this.serverCapabilities || !this.serverCapabilities.resources) {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
if (this.serverCapabilities.resources.listChanged) {
|
|
91
|
-
this.client.setNotificationHandler(
|
|
92
|
-
ResourceListChangedNotificationSchema,
|
|
93
|
-
async (_notification) => {
|
|
94
|
-
this.resources = await this.fetchResources();
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return this.fetchResources();
|
|
99
|
-
}
|
|
100
|
-
async registerPrompts() {
|
|
101
|
-
if (!this.serverCapabilities || !this.serverCapabilities.prompts) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
if (this.serverCapabilities.prompts.listChanged) {
|
|
105
|
-
this.client.setNotificationHandler(
|
|
106
|
-
PromptListChangedNotificationSchema,
|
|
107
|
-
async (_notification) => {
|
|
108
|
-
this.prompts = await this.fetchPrompts();
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return this.fetchPrompts();
|
|
113
|
-
}
|
|
114
|
-
async registerResourceTemplates() {
|
|
115
|
-
if (!this.serverCapabilities || !this.serverCapabilities.resources) {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
return this.fetchResourceTemplates();
|
|
119
|
-
}
|
|
120
|
-
async fetchTools() {
|
|
121
|
-
let toolsAgg = [];
|
|
122
|
-
let toolsResult = { tools: [] };
|
|
123
|
-
do {
|
|
124
|
-
toolsResult = await this.client.listTools({
|
|
125
|
-
cursor: toolsResult.nextCursor
|
|
126
|
-
});
|
|
127
|
-
toolsAgg = toolsAgg.concat(toolsResult.tools);
|
|
128
|
-
} while (toolsResult.nextCursor);
|
|
129
|
-
return toolsAgg;
|
|
130
|
-
}
|
|
131
|
-
async fetchResources() {
|
|
132
|
-
let resourcesAgg = [];
|
|
133
|
-
let resourcesResult = { resources: [] };
|
|
134
|
-
do {
|
|
135
|
-
resourcesResult = await this.client.listResources({
|
|
136
|
-
cursor: resourcesResult.nextCursor
|
|
137
|
-
});
|
|
138
|
-
resourcesAgg = resourcesAgg.concat(resourcesResult.resources);
|
|
139
|
-
} while (resourcesResult.nextCursor);
|
|
140
|
-
return resourcesAgg;
|
|
141
|
-
}
|
|
142
|
-
async fetchPrompts() {
|
|
143
|
-
let promptsAgg = [];
|
|
144
|
-
let promptsResult = { prompts: [] };
|
|
145
|
-
do {
|
|
146
|
-
promptsResult = await this.client.listPrompts({
|
|
147
|
-
cursor: promptsResult.nextCursor
|
|
148
|
-
});
|
|
149
|
-
promptsAgg = promptsAgg.concat(promptsResult.prompts);
|
|
150
|
-
} while (promptsResult.nextCursor);
|
|
151
|
-
return promptsAgg;
|
|
152
|
-
}
|
|
153
|
-
async fetchResourceTemplates() {
|
|
154
|
-
let templatesAgg = [];
|
|
155
|
-
let templatesResult = {
|
|
156
|
-
resourceTemplates: []
|
|
157
|
-
};
|
|
158
|
-
do {
|
|
159
|
-
templatesResult = await this.client.listResourceTemplates({
|
|
160
|
-
cursor: templatesResult.nextCursor
|
|
161
|
-
});
|
|
162
|
-
templatesAgg = templatesAgg.concat(templatesResult.resourceTemplates);
|
|
163
|
-
} while (templatesResult.nextCursor);
|
|
164
|
-
return templatesAgg;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/mcp/client.ts
|
|
169
|
-
var MCPClientManager = class {
|
|
170
|
-
constructor() {
|
|
171
|
-
this.mcpConnections = {};
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Connect to and register an MCP server
|
|
175
|
-
*
|
|
176
|
-
* @param transportConfig Transport config
|
|
177
|
-
* @param clientConfig Client config
|
|
178
|
-
* @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
|
|
179
|
-
*/
|
|
180
|
-
async connectToServer(url, info, opts = { transport: {}, client: {}, capabilities: {} }) {
|
|
181
|
-
if (info.name in this.mcpConnections) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`An existing MCP client has already been registered under the name "${info.name}". The MCP client name must be unique.`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
this.mcpConnections[info.name] = new MCPClientConnection(url, info, opts);
|
|
187
|
-
await this.mcpConnections[info.name].init();
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* @returns namespaced list of tools
|
|
191
|
-
*/
|
|
192
|
-
listTools() {
|
|
193
|
-
return getNamespacedData(this.mcpConnections, "tools");
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* @returns namespaced list of prompts
|
|
197
|
-
*/
|
|
198
|
-
listPrompts() {
|
|
199
|
-
return getNamespacedData(this.mcpConnections, "prompts");
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @returns namespaced list of tools
|
|
203
|
-
*/
|
|
204
|
-
listResources() {
|
|
205
|
-
return getNamespacedData(this.mcpConnections, "resources");
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* @returns namespaced list of resource templates
|
|
209
|
-
*/
|
|
210
|
-
listResourceTemplates() {
|
|
211
|
-
return getNamespacedData(this.mcpConnections, "resourceTemplates");
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Namespaced version of callTool
|
|
215
|
-
*/
|
|
216
|
-
callTool(params, resultSchema, options) {
|
|
217
|
-
const unqualifiedName = params.name.replace(`${params.serverName}.`, "");
|
|
218
|
-
return this.mcpConnections[params.serverName].client.callTool(
|
|
219
|
-
{
|
|
220
|
-
...params,
|
|
221
|
-
name: unqualifiedName
|
|
222
|
-
},
|
|
223
|
-
resultSchema,
|
|
224
|
-
options
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Namespaced version of readResource
|
|
229
|
-
*/
|
|
230
|
-
readResource(params, options) {
|
|
231
|
-
return this.mcpConnections[params.serverName].client.readResource(
|
|
232
|
-
params,
|
|
233
|
-
options
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Namespaced version of getPrompt
|
|
238
|
-
*/
|
|
239
|
-
getPrompt(params, options) {
|
|
240
|
-
return this.mcpConnections[params.serverName].client.getPrompt(
|
|
241
|
-
params,
|
|
242
|
-
options
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
function getNamespacedData(mcpClients, type) {
|
|
247
|
-
const sets = Object.entries(mcpClients).map(([name, conn]) => {
|
|
248
|
-
return { name, data: conn[type] };
|
|
249
|
-
});
|
|
250
|
-
const namespacedData = sets.flatMap(({ name: serverName, data }) => {
|
|
251
|
-
return data.map((item) => {
|
|
252
|
-
return {
|
|
253
|
-
...item,
|
|
254
|
-
// we add a servername so we can easily pull it out and convert between qualified<->unqualified name
|
|
255
|
-
// just in case the server name or item name includes a "."
|
|
256
|
-
serverName: `${serverName}`,
|
|
257
|
-
// qualified name
|
|
258
|
-
name: `${serverName}.${item.name}`
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
return namespacedData;
|
|
263
|
-
}
|
|
264
|
-
export {
|
|
265
|
-
MCPClientManager,
|
|
266
|
-
getNamespacedData
|
|
267
|
-
};
|
|
268
|
-
//# sourceMappingURL=client.js.map
|
|
4
|
+
export { MCPClientManager, getNamespacedData };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,45 +1,193 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
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-CsaP9Irq.js";
|
|
2
|
+
import "../mcp-BwPscEiF.js";
|
|
3
|
+
import "../do-oauth-client-provider-C2CHH5x-.js";
|
|
4
|
+
import "../index-BUle9RiP.js";
|
|
5
|
+
import "../ai-types-81H_-Uxh.js";
|
|
6
|
+
import { c as ConnectionContext, s as Connection, t as Agent } from "../index-Bx5KK3VJ.js";
|
|
7
|
+
import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
|
+
import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
|
|
12
|
-
#private;
|
|
13
|
-
protected constructor(ctx: DurableObjectState, env: Env);
|
|
14
|
-
/**
|
|
15
|
-
* Agents API allowlist
|
|
16
|
-
*/
|
|
17
|
-
initialState: State;
|
|
18
|
-
get state(): State;
|
|
19
|
-
sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
|
|
20
|
-
setState(state: State): void;
|
|
21
|
-
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
22
|
-
onStart(): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* McpAgent API
|
|
25
|
-
*/
|
|
26
|
-
abstract server: McpServer;
|
|
27
|
-
props: Props;
|
|
28
|
-
initRun: boolean;
|
|
29
|
-
abstract init(): Promise<void>;
|
|
30
|
-
_init(props: Props): Promise<void>;
|
|
31
|
-
fetch(request: Request): Promise<Response>;
|
|
32
|
-
getWebSocket(): WebSocket | null;
|
|
33
|
-
onMCPMessage(sessionId: string, request: Request): Promise<Response>;
|
|
34
|
-
webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
|
|
35
|
-
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
36
|
-
webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
37
|
-
static mount(path: string, { binding, corsOptions, }?: {
|
|
38
|
-
binding?: string;
|
|
39
|
-
corsOptions?: CORSOptions;
|
|
40
|
-
}): {
|
|
41
|
-
fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response | undefined>;
|
|
42
|
-
};
|
|
14
|
+
//#region src/mcp/client-transports.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
|
|
17
|
+
*/
|
|
18
|
+
declare class SSEEdgeClientTransport extends SSEClientTransport {
|
|
19
|
+
constructor(url: URL, options: SSEClientTransportOptions);
|
|
43
20
|
}
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
|
|
23
|
+
*/
|
|
24
|
+
declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
|
|
25
|
+
constructor(url: URL, options: StreamableHTTPClientTransportOptions);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#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
|
+
interface MCPStorageApi {
|
|
32
|
+
get(): Promise<TransportState | undefined> | TransportState | undefined;
|
|
33
|
+
set(state: TransportState): Promise<void> | void;
|
|
34
|
+
}
|
|
35
|
+
interface TransportState {
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
initialized: boolean;
|
|
38
|
+
protocolVersion?: ProtocolVersion;
|
|
39
|
+
}
|
|
40
|
+
interface WorkerTransportOptions {
|
|
41
|
+
sessionIdGenerator?: () => string;
|
|
42
|
+
/**
|
|
43
|
+
* Enable traditional Request/Response mode, this will disable streaming.
|
|
44
|
+
*/
|
|
45
|
+
enableJsonResponse?: boolean;
|
|
46
|
+
onsessioninitialized?: (sessionId: string) => void;
|
|
47
|
+
corsOptions?: CORSOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Optional storage api for persisting transport state.
|
|
50
|
+
* Use this to store session state in Durable Object/Agent storage
|
|
51
|
+
* so it survives hibernation/restart.
|
|
52
|
+
*/
|
|
53
|
+
storage?: MCPStorageApi;
|
|
54
|
+
}
|
|
55
|
+
declare class WorkerTransport implements Transport {
|
|
56
|
+
started: boolean;
|
|
57
|
+
private initialized;
|
|
58
|
+
private sessionIdGenerator?;
|
|
59
|
+
private enableJsonResponse;
|
|
60
|
+
private onsessioninitialized?;
|
|
61
|
+
private standaloneSseStreamId;
|
|
62
|
+
private streamMapping;
|
|
63
|
+
private requestToStreamMapping;
|
|
64
|
+
private requestResponseMap;
|
|
65
|
+
private corsOptions?;
|
|
66
|
+
private protocolVersion?;
|
|
67
|
+
private storage?;
|
|
68
|
+
private stateRestored;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
onclose?: () => void;
|
|
71
|
+
onerror?: (error: Error) => void;
|
|
72
|
+
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
|
73
|
+
constructor(options?: WorkerTransportOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Restore transport state from persistent storage.
|
|
76
|
+
* This is automatically called on start.
|
|
77
|
+
*/
|
|
78
|
+
private restoreState;
|
|
79
|
+
/**
|
|
80
|
+
* Persist current transport state to storage.
|
|
81
|
+
*/
|
|
82
|
+
private saveState;
|
|
83
|
+
start(): Promise<void>;
|
|
84
|
+
private validateProtocolVersion;
|
|
85
|
+
private getHeaders;
|
|
86
|
+
handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
|
|
87
|
+
private handleGetRequest;
|
|
88
|
+
private handlePostRequest;
|
|
89
|
+
private handleDeleteRequest;
|
|
90
|
+
private handleOptionsRequest;
|
|
91
|
+
private handleUnsupportedRequest;
|
|
92
|
+
private validateSession;
|
|
93
|
+
close(): Promise<void>;
|
|
94
|
+
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/mcp/auth-context.d.ts
|
|
98
|
+
interface McpAuthContext {
|
|
99
|
+
props: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
declare function getMcpAuthContext(): McpAuthContext | undefined;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/mcp/handler.d.ts
|
|
104
|
+
interface CreateMcpHandlerOptions extends WorkerTransportOptions {
|
|
105
|
+
/**
|
|
106
|
+
* The route path that this MCP handler should respond to.
|
|
107
|
+
* If specified, the handler will only process requests that match this route.
|
|
108
|
+
* @default "/mcp"
|
|
109
|
+
*/
|
|
110
|
+
route?: string;
|
|
111
|
+
/**
|
|
112
|
+
* An optional auth context to use for handling MCP requests.
|
|
113
|
+
* If not provided, the handler will look for props in the execution context.
|
|
114
|
+
*/
|
|
115
|
+
authContext?: McpAuthContext;
|
|
116
|
+
/**
|
|
117
|
+
* An optional transport to use for handling MCP requests.
|
|
118
|
+
* If not provided, a WorkerTransport will be created with the provided WorkerTransportOptions.
|
|
119
|
+
*/
|
|
120
|
+
transport?: WorkerTransport;
|
|
121
|
+
}
|
|
122
|
+
declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
|
|
125
|
+
*/
|
|
126
|
+
declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/mcp/index.d.ts
|
|
129
|
+
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
|
|
130
|
+
private _transport?;
|
|
131
|
+
props?: Props;
|
|
132
|
+
abstract server: MaybePromise<McpServer | Server>;
|
|
133
|
+
abstract init(): Promise<void>;
|
|
134
|
+
setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
|
|
135
|
+
getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
|
|
136
|
+
/** Read the transport type for this agent.
|
|
137
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
138
|
+
* or `streamable-http:${sessionId}`.
|
|
139
|
+
*/
|
|
140
|
+
getTransportType(): BaseTransportType;
|
|
141
|
+
/** Read the sessionId for this agent.
|
|
142
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
143
|
+
* or `streamable-http:${sessionId}`.
|
|
144
|
+
*/
|
|
145
|
+
getSessionId(): string;
|
|
146
|
+
/** Get the unique WebSocket. SSE transport only. */
|
|
147
|
+
getWebSocket(): Connection<unknown> | null;
|
|
148
|
+
/** Returns a new transport matching the type of the Agent. */
|
|
149
|
+
private initTransport;
|
|
150
|
+
/** Update and store the props */
|
|
151
|
+
updateProps(props?: Props): Promise<void>;
|
|
152
|
+
reinitializeServer(): Promise<void>;
|
|
153
|
+
/** Sets up the MCP transport and server every time the Agent is started.*/
|
|
154
|
+
onStart(props?: Props): Promise<void>;
|
|
155
|
+
/** Validates new WebSocket connections. */
|
|
156
|
+
onConnect(conn: Connection, {
|
|
157
|
+
request: req
|
|
158
|
+
}: ConnectionContext): Promise<void>;
|
|
159
|
+
/** Handles MCP Messages for the legacy SSE transport. */
|
|
160
|
+
onSSEMcpMessage(_sessionId: string, messageBody: unknown, extraInfo?: MessageExtraInfo): Promise<Error | null>;
|
|
161
|
+
/** Elicit user input with a message and schema */
|
|
162
|
+
elicitInput(params: {
|
|
163
|
+
message: string;
|
|
164
|
+
requestedSchema: unknown;
|
|
165
|
+
}): Promise<ElicitResult$1>;
|
|
166
|
+
/** Wait for elicitation response through storage polling */
|
|
167
|
+
private _waitForElicitationResponse;
|
|
168
|
+
/** Handle elicitation responses */
|
|
169
|
+
private _handleElicitationResponse;
|
|
170
|
+
/** Return a handler for the given path for this MCP.
|
|
171
|
+
* Defaults to Streamable HTTP transport.
|
|
172
|
+
*/
|
|
173
|
+
static serve(path: string, {
|
|
174
|
+
binding,
|
|
175
|
+
corsOptions,
|
|
176
|
+
transport,
|
|
177
|
+
jurisdiction
|
|
178
|
+
}?: ServeOptions): {
|
|
179
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Legacy api
|
|
183
|
+
**/
|
|
184
|
+
static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
185
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
186
|
+
};
|
|
187
|
+
static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
188
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
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
|
+
//# sourceMappingURL=index.d.ts.map
|