agents 0.0.0-d7d2876 → 0.0.0-dd6a9e3
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 +2 -6
- package/dist/ai-chat-agent.js +1 -4
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +5 -3
- package/dist/ai-react.js.map +1 -1
- package/dist/mcp.d.ts +58 -0
- package/dist/mcp.js +945 -0
- package/dist/mcp.js.map +1 -0
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -316,18 +316,14 @@ Create meaningful conversations with intelligence:
|
|
|
316
316
|
|
|
317
317
|
```ts
|
|
318
318
|
import { AIChatAgent } from "agents/ai-chat-agent";
|
|
319
|
-
import {
|
|
319
|
+
import { openai } from "@ai-sdk/openai";
|
|
320
320
|
|
|
321
321
|
export class DialogueAgent extends AIChatAgent {
|
|
322
322
|
async onChatMessage(onFinish) {
|
|
323
323
|
return createDataStreamResponse({
|
|
324
324
|
execute: async (dataStream) => {
|
|
325
|
-
const ai = createOpenAI({
|
|
326
|
-
apiKey: this.env.OPENAI_API_KEY,
|
|
327
|
-
});
|
|
328
|
-
|
|
329
325
|
const stream = streamText({
|
|
330
|
-
model:
|
|
326
|
+
model: openai("gpt-4o"),
|
|
331
327
|
messages: this.messages,
|
|
332
328
|
onFinish, // call onFinish so that messages get saved
|
|
333
329
|
});
|
package/dist/ai-chat-agent.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
// src/ai-chat-agent.ts
|
|
10
10
|
import { appendResponseMessages } from "ai";
|
|
11
11
|
var decoder = new TextDecoder();
|
|
12
|
-
var _AIChatAgent_instances,
|
|
12
|
+
var _AIChatAgent_instances, broadcastChatMessage_fn, tryCatch_fn, persistMessages_fn, reply_fn;
|
|
13
13
|
var AIChatAgent = class extends Agent {
|
|
14
14
|
constructor(ctx, env) {
|
|
15
15
|
super(ctx, env);
|
|
@@ -121,9 +121,6 @@ var AIChatAgent = class extends Agent {
|
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
_AIChatAgent_instances = new WeakSet();
|
|
124
|
-
sendChatMessage_fn = function(connection, message) {
|
|
125
|
-
connection.send(JSON.stringify(message));
|
|
126
|
-
};
|
|
127
124
|
broadcastChatMessage_fn = function(message, exclude) {
|
|
128
125
|
this.broadcast(JSON.stringify(message), exclude);
|
|
129
126
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ai-chat-agent.ts"],"sourcesContent":["import { Agent, type AgentContext, type Connection, type WSMessage } from \"./\";\nimport type {\n Message as ChatMessage,\n StreamTextOnFinishCallback,\n ToolSet,\n} from \"ai\";\nimport { appendResponseMessages } from \"ai\";\nimport type { OutgoingMessage, IncomingMessage } from \"./ai-types\";\nconst decoder = new TextDecoder();\n\n/**\n * Extension of Agent with built-in chat capabilities\n * @template Env Environment type containing bindings\n */\nexport class AIChatAgent<Env = unknown, State = unknown> extends Agent<\n Env,\n State\n> {\n /** Array of chat messages for the current conversation */\n messages: ChatMessage[];\n constructor(ctx: AgentContext, env: Env) {\n super(ctx, env);\n this.sql`create table if not exists cf_ai_chat_agent_messages (\n id text primary key,\n message text not null,\n created_at datetime default current_timestamp\n )`;\n this.messages = (\n this.sql`select * from cf_ai_chat_agent_messages` || []\n ).map((row) => {\n return JSON.parse(row.message as string);\n });\n }\n\n #
|
|
1
|
+
{"version":3,"sources":["../src/ai-chat-agent.ts"],"sourcesContent":["import { Agent, type AgentContext, type Connection, type WSMessage } from \"./\";\nimport type {\n Message as ChatMessage,\n StreamTextOnFinishCallback,\n ToolSet,\n} from \"ai\";\nimport { appendResponseMessages } from \"ai\";\nimport type { OutgoingMessage, IncomingMessage } from \"./ai-types\";\nconst decoder = new TextDecoder();\n\n/**\n * Extension of Agent with built-in chat capabilities\n * @template Env Environment type containing bindings\n */\nexport class AIChatAgent<Env = unknown, State = unknown> extends Agent<\n Env,\n State\n> {\n /** Array of chat messages for the current conversation */\n messages: ChatMessage[];\n constructor(ctx: AgentContext, env: Env) {\n super(ctx, env);\n this.sql`create table if not exists cf_ai_chat_agent_messages (\n id text primary key,\n message text not null,\n created_at datetime default current_timestamp\n )`;\n this.messages = (\n this.sql`select * from cf_ai_chat_agent_messages` || []\n ).map((row) => {\n return JSON.parse(row.message as string);\n });\n }\n\n #broadcastChatMessage(message: OutgoingMessage, exclude?: string[]) {\n this.broadcast(JSON.stringify(message), exclude);\n }\n\n override async onMessage(connection: Connection, message: WSMessage) {\n if (typeof message === \"string\") {\n let data: IncomingMessage;\n try {\n data = JSON.parse(message) as IncomingMessage;\n } catch (error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (\n data.type === \"cf_agent_use_chat_request\" &&\n data.init.method === \"POST\"\n ) {\n const {\n method,\n keepalive,\n headers,\n body, // we're reading this\n redirect,\n integrity,\n credentials,\n mode,\n referrer,\n referrerPolicy,\n window,\n // dispatcher,\n // duplex\n } = data.init;\n const { messages } = JSON.parse(body as string);\n this.#broadcastChatMessage(\n {\n type: \"cf_agent_chat_messages\",\n messages,\n },\n [connection.id]\n );\n await this.#persistMessages(messages, [connection.id]);\n return this.#tryCatch(async () => {\n const response = await this.onChatMessage(async ({ response }) => {\n const finalMessages = appendResponseMessages({\n messages,\n responseMessages: response.messages,\n });\n\n await this.#persistMessages(finalMessages, [connection.id]);\n });\n if (response) {\n await this.#reply(data.id, response);\n }\n });\n }\n if (data.type === \"cf_agent_chat_clear\") {\n this.sql`delete from cf_ai_chat_agent_messages`;\n this.messages = [];\n this.#broadcastChatMessage(\n {\n type: \"cf_agent_chat_clear\",\n },\n [connection.id]\n );\n } else if (data.type === \"cf_agent_chat_messages\") {\n // replace the messages with the new ones\n await this.#persistMessages(data.messages, [connection.id]);\n }\n }\n }\n\n override async onRequest(request: Request): Promise<Response> {\n return this.#tryCatch(() => {\n if (request.url.endsWith(\"/get-messages\")) {\n const messages = (\n this.sql`select * from cf_ai_chat_agent_messages` || []\n ).map((row) => {\n return JSON.parse(row.message as string);\n });\n return Response.json(messages);\n }\n return super.onRequest(request);\n });\n }\n\n async #tryCatch<T>(fn: () => T | Promise<T>) {\n try {\n return await fn();\n } catch (e) {\n throw this.onError(e);\n }\n }\n\n /**\n * Handle incoming chat messages and generate a response\n * @param onFinish Callback to be called when the response is finished\n * @returns Response to send to the client or undefined\n */\n async onChatMessage(\n onFinish: StreamTextOnFinishCallback<ToolSet>\n ): Promise<Response | undefined> {\n throw new Error(\n \"recieved a chat message, override onChatMessage and return a Response to send to the client\"\n );\n }\n\n /**\n * Save messages on the server side and trigger AI response\n * @param messages Chat messages to save\n */\n async saveMessages(messages: ChatMessage[]) {\n await this.#persistMessages(messages);\n const response = await this.onChatMessage(async ({ response }) => {\n const finalMessages = appendResponseMessages({\n messages,\n responseMessages: response.messages,\n });\n\n await this.#persistMessages(finalMessages, []);\n });\n if (response) {\n // we're just going to drain the body\n // @ts-ignore TODO: fix this type error\n for await (const chunk of response.body!) {\n decoder.decode(chunk);\n }\n response.body?.cancel();\n }\n }\n\n async #persistMessages(\n messages: ChatMessage[],\n excludeBroadcastIds: string[] = []\n ) {\n this.sql`delete from cf_ai_chat_agent_messages`;\n for (const message of messages) {\n this.sql`insert into cf_ai_chat_agent_messages (id, message) values (${\n message.id\n },${JSON.stringify(message)})`;\n }\n this.messages = messages;\n this.#broadcastChatMessage(\n {\n type: \"cf_agent_chat_messages\",\n messages: messages,\n },\n excludeBroadcastIds\n );\n }\n\n async #reply(id: string, response: Response) {\n // now take chunks out from dataStreamResponse and send them to the client\n return this.#tryCatch(async () => {\n // @ts-expect-error TODO: fix this type error\n for await (const chunk of response.body!) {\n const body = decoder.decode(chunk);\n\n this.#broadcastChatMessage({\n id,\n type: \"cf_agent_use_chat_response\",\n body,\n done: false,\n });\n }\n\n this.#broadcastChatMessage({\n id,\n type: \"cf_agent_use_chat_response\",\n body: \"\",\n done: true,\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;AAMA,SAAS,8BAA8B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AoB;AAClE,OAAK,UAAU,KAAK,UAAU,OAAO,GAAG,OAAO;AACjD;AAoFM,cAAY,eAAC,IAA0B;AAC3C,MAAI;AACF,WAAO,MAAM,GAAG;AAAA,EAClB,SAAS,GAAG;AACV,UAAM,KAAK,QAAQ,CAAC;AAAA,EACtB;AACF;AAuCM,qBAAgB,eACpB,UACA,sBAAgC,CAAC,GACjC;AACA,OAAK;AACL,aAAW,WAAW,UAAU;AAC9B,SAAK,kEACH,QAAQ,EACV,IAAI,KAAK,UAAU,OAAO,CAAC;AAAA,EAC7B;AACA,OAAK,WAAW;AAChB,wBAAK,iDAAL,WACE;AAAA,IACE,MAAM;AAAA,IACN;AAAA,EACF,GACA;AAEJ;AAEM,WAAM,eAAC,IAAY,UAAoB;AAE3C,SAAO,sBAAK,qCAAL,WAAe,YAAY;AAEhC,qBAAiB,SAAS,SAAS,MAAO;AACxC,YAAM,OAAO,QAAQ,OAAO,KAAK;AAEjC,4BAAK,iDAAL,WAA2B;AAAA,QACzB;AAAA,QACA,MAAM;AAAA,QACN;AAAA,QACA,MAAM;AAAA,MACR;AAAA,IACF;AAEA,0BAAK,iDAAL,WAA2B;AAAA,MACzB;AAAA,MACA,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["response"]}
|
package/dist/ai-react.d.ts
CHANGED
|
@@ -14,10 +14,10 @@ type GetInitialMessagesOptions = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Options for the useAgentChat hook
|
|
16
16
|
*/
|
|
17
|
-
type UseAgentChatOptions = Omit<
|
|
17
|
+
type UseAgentChatOptions<State> = Omit<
|
|
18
18
|
Parameters<typeof useChat>[0] & {
|
|
19
19
|
/** Agent connection from useAgent */
|
|
20
|
-
agent: ReturnType<typeof useAgent
|
|
20
|
+
agent: ReturnType<typeof useAgent<State>>;
|
|
21
21
|
getInitialMessages?:
|
|
22
22
|
| undefined
|
|
23
23
|
| null
|
|
@@ -30,7 +30,9 @@ type UseAgentChatOptions = Omit<
|
|
|
30
30
|
* @param options Chat options including the agent connection
|
|
31
31
|
* @returns Chat interface controls and state with added clearHistory method
|
|
32
32
|
*/
|
|
33
|
-
declare function useAgentChat
|
|
33
|
+
declare function useAgentChat<State = unknown>(
|
|
34
|
+
options: UseAgentChatOptions<State>
|
|
35
|
+
): {
|
|
34
36
|
/**
|
|
35
37
|
* Set the chat messages and synchronize with the Agent
|
|
36
38
|
* @param messages New messages to set
|
package/dist/ai-react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ai-react.tsx"],"sourcesContent":["import { useChat } from \"@ai-sdk/react\";\nimport type { Message } from \"ai\";\nimport type { useAgent } from \"./react\";\nimport { useEffect, use } from \"react\";\nimport type { OutgoingMessage } from \"./ai-types\";\n\ntype GetInitialMessagesOptions = {\n agent: string;\n name: string;\n url: string;\n};\n\n/**\n * Options for the useAgentChat hook\n */\ntype UseAgentChatOptions = Omit<\n Parameters<typeof useChat>[0] & {\n /** Agent connection from useAgent */\n agent: ReturnType<typeof useAgent
|
|
1
|
+
{"version":3,"sources":["../src/ai-react.tsx"],"sourcesContent":["import { useChat } from \"@ai-sdk/react\";\nimport type { Message } from \"ai\";\nimport type { useAgent } from \"./react\";\nimport { useEffect, use } from \"react\";\nimport type { OutgoingMessage } from \"./ai-types\";\n\ntype GetInitialMessagesOptions = {\n agent: string;\n name: string;\n url: string;\n};\n\n/**\n * Options for the useAgentChat hook\n */\ntype UseAgentChatOptions<State> = Omit<\n Parameters<typeof useChat>[0] & {\n /** Agent connection from useAgent */\n agent: ReturnType<typeof useAgent<State>>;\n getInitialMessages?:\n | undefined\n | null\n // | (() => Message[])\n | ((options: GetInitialMessagesOptions) => Promise<Message[]>);\n },\n \"fetch\"\n>;\n\n// TODO: clear cache when the agent is unmounted?\nconst requestCache = new Map<string, Promise<Message[]>>();\n\n/**\n * React hook for building AI chat interfaces using an Agent\n * @param options Chat options including the agent connection\n * @returns Chat interface controls and state with added clearHistory method\n */\nexport function useAgentChat<State = unknown>(\n options: UseAgentChatOptions<State>\n) {\n const { agent, getInitialMessages, ...rest } = options;\n const url = `${agent._pkurl\n .replace(\"ws://\", \"http://\")\n .replace(\"wss://\", \"https://\")}`;\n\n async function defaultGetInitialMessagesFetch({\n url,\n }: GetInitialMessagesOptions) {\n const response = await fetch(new Request(`${url}/get-messages`), {\n headers: options.headers,\n credentials: options.credentials,\n });\n return response.json<Message[]>();\n }\n\n const getInitialMessagesFetch =\n getInitialMessages || defaultGetInitialMessagesFetch;\n\n function doGetInitialMessages(\n getInitialMessagesOptions: GetInitialMessagesOptions\n ) {\n if (requestCache.has(url)) {\n return requestCache.get(url)!;\n }\n const promise = getInitialMessagesFetch(getInitialMessagesOptions);\n requestCache.set(url, promise);\n return promise;\n }\n\n const initialMessages =\n getInitialMessages !== null\n ? use(\n doGetInitialMessages({\n agent: agent.agent,\n name: agent.name,\n url,\n })\n )\n : rest.initialMessages;\n\n useEffect(() => {\n return () => {\n requestCache.delete(url);\n };\n }, [url]);\n\n async function aiFetch(\n request: RequestInfo | URL,\n options: RequestInit = {}\n ) {\n // we're going to use a websocket to do the actual \"fetching\"\n // but still satisfy the type signature of the fetch function\n // so we'll return a promise that resolves to a response\n\n const {\n method,\n keepalive,\n headers,\n body,\n redirect,\n integrity,\n signal,\n credentials,\n mode,\n referrer,\n referrerPolicy,\n window,\n // dispatcher, duplex\n } = options;\n const id = crypto.randomUUID();\n const abortController = new AbortController();\n\n signal?.addEventListener(\"abort\", () => {\n abortController.abort();\n });\n\n agent.addEventListener(\n \"message\",\n (event) => {\n let data: OutgoingMessage;\n try {\n data = JSON.parse(event.data) as OutgoingMessage;\n } catch (error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (data.type === \"cf_agent_use_chat_response\") {\n if (data.id === id) {\n controller.enqueue(new TextEncoder().encode(data.body));\n if (data.done) {\n controller.close();\n abortController.abort();\n }\n }\n }\n },\n { signal: abortController.signal }\n );\n\n let controller: ReadableStreamDefaultController;\n\n const stream = new ReadableStream({\n start(c) {\n controller = c;\n },\n });\n\n agent.send(\n JSON.stringify({\n type: \"cf_agent_use_chat_request\",\n id,\n url: request.toString(),\n init: {\n method,\n keepalive,\n headers,\n body,\n redirect,\n integrity,\n credentials,\n mode,\n referrer,\n referrerPolicy,\n window,\n // dispatcher,\n // duplex\n },\n })\n );\n\n return new Response(stream);\n }\n const useChatHelpers = useChat({\n initialMessages,\n sendExtraMessageFields: true,\n fetch: aiFetch,\n ...rest,\n });\n\n useEffect(() => {\n function onClearHistory(event: MessageEvent) {\n if (typeof event.data !== \"string\") {\n return;\n }\n let data: OutgoingMessage;\n try {\n data = JSON.parse(event.data) as OutgoingMessage;\n } catch (error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (data.type === \"cf_agent_chat_clear\") {\n useChatHelpers.setMessages([]);\n }\n }\n\n function onMessages(event: MessageEvent) {\n if (typeof event.data !== \"string\") {\n return;\n }\n let data: OutgoingMessage;\n try {\n data = JSON.parse(event.data) as OutgoingMessage;\n } catch (error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (data.type === \"cf_agent_chat_messages\") {\n useChatHelpers.setMessages(data.messages);\n }\n }\n\n agent.addEventListener(\"message\", onClearHistory);\n agent.addEventListener(\"message\", onMessages);\n\n return () => {\n agent.removeEventListener(\"message\", onClearHistory);\n agent.removeEventListener(\"message\", onMessages);\n };\n }, [\n agent.addEventListener,\n agent.removeEventListener,\n useChatHelpers.setMessages,\n ]);\n\n return {\n ...useChatHelpers,\n /**\n * Set the chat messages and synchronize with the Agent\n * @param messages New messages to set\n */\n setMessages: (messages: Message[]) => {\n useChatHelpers.setMessages(messages);\n agent.send(\n JSON.stringify({\n type: \"cf_agent_chat_messages\",\n messages,\n })\n );\n },\n /**\n * Clear chat history on both client and Agent\n */\n clearHistory: () => {\n useChatHelpers.setMessages([]);\n agent.send(\n JSON.stringify({\n type: \"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,MAAM,IAAI;AAAA,MAC9B,SAAS,OAAO;AAGd;AAAA,MACF;AACA,UAAI,KAAK,SAAS,uBAAuB;AACvC,uBAAe,YAAY,CAAC,CAAC;AAAA,MAC/B;AAAA,IACF;AAEA,aAAS,WAAW,OAAqB;AACvC,UAAI,OAAO,MAAM,SAAS,UAAU;AAClC;AAAA,MACF;AACA,UAAI;AACJ,UAAI;AACF,eAAO,KAAK,MAAM,MAAM,IAAI;AAAA,MAC9B,SAAS,OAAO;AAGd;AAAA,MACF;AACA,UAAI,KAAK,SAAS,0BAA0B;AAC1C,uBAAe,YAAY,KAAK,QAAQ;AAAA,MAC1C;AAAA,IACF;AAEA,UAAM,iBAAiB,WAAW,cAAc;AAChD,UAAM,iBAAiB,WAAW,UAAU;AAE5C,WAAO,MAAM;AACX,YAAM,oBAAoB,WAAW,cAAc;AACnD,YAAM,oBAAoB,WAAW,UAAU;AAAA,IACjD;AAAA,EACF,GAAG;AAAA,IACD,MAAM;AAAA,IACN,MAAM;AAAA,IACN,eAAe;AAAA,EACjB,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH,aAAa,CAAC,aAAwB;AACpC,qBAAe,YAAY,QAAQ;AACnC,YAAM;AAAA,QACJ,KAAK,UAAU;AAAA,UACb,MAAM;AAAA,UACN;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAIA,cAAc,MAAM;AAClB,qBAAe,YAAY,CAAC,CAAC;AAC7B,YAAM;AAAA,QACJ,KAAK,UAAU;AAAA,UACb,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;","names":["url","options"]}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { Connection } from "partyserver";
|
|
4
|
+
|
|
5
|
+
interface CORSOptions {
|
|
6
|
+
origin?: string;
|
|
7
|
+
methods?: string;
|
|
8
|
+
headers?: string;
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
}
|
|
11
|
+
declare abstract class McpAgent<
|
|
12
|
+
Env = unknown,
|
|
13
|
+
State = unknown,
|
|
14
|
+
Props extends Record<string, unknown> = Record<string, unknown>,
|
|
15
|
+
> extends DurableObject {
|
|
16
|
+
#private;
|
|
17
|
+
protected constructor(ctx: DurableObjectState, env: Env);
|
|
18
|
+
/**
|
|
19
|
+
* Agents API allowlist
|
|
20
|
+
*/
|
|
21
|
+
initialState: State;
|
|
22
|
+
get state(): State;
|
|
23
|
+
sql<T = Record<string, string | number | boolean | null>>(
|
|
24
|
+
strings: TemplateStringsArray,
|
|
25
|
+
...values: (string | number | boolean | null)[]
|
|
26
|
+
): T[];
|
|
27
|
+
setState(state: State): void;
|
|
28
|
+
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
29
|
+
/**
|
|
30
|
+
* McpAgent API
|
|
31
|
+
*/
|
|
32
|
+
abstract server: McpServer;
|
|
33
|
+
private transport;
|
|
34
|
+
props: Props;
|
|
35
|
+
initRun: boolean;
|
|
36
|
+
abstract init(): Promise<void>;
|
|
37
|
+
_init(props: Props): Promise<void>;
|
|
38
|
+
onSSE(path: string): Promise<Response>;
|
|
39
|
+
onMCPMessage(request: Request): Promise<Response>;
|
|
40
|
+
static mount(
|
|
41
|
+
path: string,
|
|
42
|
+
{
|
|
43
|
+
binding,
|
|
44
|
+
corsOptions,
|
|
45
|
+
}?: {
|
|
46
|
+
binding?: string;
|
|
47
|
+
corsOptions?: CORSOptions;
|
|
48
|
+
}
|
|
49
|
+
): {
|
|
50
|
+
fetch: (
|
|
51
|
+
request: Request,
|
|
52
|
+
env: Record<string, DurableObjectNamespace<McpAgent>>,
|
|
53
|
+
ctx: ExecutionContext
|
|
54
|
+
) => Promise<Response>;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { McpAgent };
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,945 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent
|
|
3
|
+
} from "./chunk-X6BBKLSC.js";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet,
|
|
7
|
+
__privateSet
|
|
8
|
+
} from "./chunk-HMLY7DHA.js";
|
|
9
|
+
|
|
10
|
+
// src/mcp.ts
|
|
11
|
+
import { DurableObject } from "cloudflare:workers";
|
|
12
|
+
|
|
13
|
+
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
var JSONRPC_VERSION = "2.0";
|
|
16
|
+
var ProgressTokenSchema = z.union([z.string(), z.number().int()]);
|
|
17
|
+
var CursorSchema = z.string();
|
|
18
|
+
var BaseRequestParamsSchema = z.object({
|
|
19
|
+
_meta: z.optional(z.object({
|
|
20
|
+
/**
|
|
21
|
+
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
22
|
+
*/
|
|
23
|
+
progressToken: z.optional(ProgressTokenSchema)
|
|
24
|
+
}).passthrough())
|
|
25
|
+
}).passthrough();
|
|
26
|
+
var RequestSchema = z.object({
|
|
27
|
+
method: z.string(),
|
|
28
|
+
params: z.optional(BaseRequestParamsSchema)
|
|
29
|
+
});
|
|
30
|
+
var BaseNotificationParamsSchema = z.object({
|
|
31
|
+
/**
|
|
32
|
+
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
|
33
|
+
*/
|
|
34
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
35
|
+
}).passthrough();
|
|
36
|
+
var NotificationSchema = z.object({
|
|
37
|
+
method: z.string(),
|
|
38
|
+
params: z.optional(BaseNotificationParamsSchema)
|
|
39
|
+
});
|
|
40
|
+
var ResultSchema = z.object({
|
|
41
|
+
/**
|
|
42
|
+
* This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
|
|
43
|
+
*/
|
|
44
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
45
|
+
}).passthrough();
|
|
46
|
+
var RequestIdSchema = z.union([z.string(), z.number().int()]);
|
|
47
|
+
var JSONRPCRequestSchema = z.object({
|
|
48
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
49
|
+
id: RequestIdSchema
|
|
50
|
+
}).merge(RequestSchema).strict();
|
|
51
|
+
var JSONRPCNotificationSchema = z.object({
|
|
52
|
+
jsonrpc: z.literal(JSONRPC_VERSION)
|
|
53
|
+
}).merge(NotificationSchema).strict();
|
|
54
|
+
var JSONRPCResponseSchema = z.object({
|
|
55
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
56
|
+
id: RequestIdSchema,
|
|
57
|
+
result: ResultSchema
|
|
58
|
+
}).strict();
|
|
59
|
+
var ErrorCode;
|
|
60
|
+
(function(ErrorCode2) {
|
|
61
|
+
ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
62
|
+
ErrorCode2[ErrorCode2["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
63
|
+
ErrorCode2[ErrorCode2["ParseError"] = -32700] = "ParseError";
|
|
64
|
+
ErrorCode2[ErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
65
|
+
ErrorCode2[ErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
66
|
+
ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
67
|
+
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
68
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
69
|
+
var JSONRPCErrorSchema = z.object({
|
|
70
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
71
|
+
id: RequestIdSchema,
|
|
72
|
+
error: z.object({
|
|
73
|
+
/**
|
|
74
|
+
* The error type that occurred.
|
|
75
|
+
*/
|
|
76
|
+
code: z.number().int(),
|
|
77
|
+
/**
|
|
78
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
79
|
+
*/
|
|
80
|
+
message: z.string(),
|
|
81
|
+
/**
|
|
82
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
83
|
+
*/
|
|
84
|
+
data: z.optional(z.unknown())
|
|
85
|
+
})
|
|
86
|
+
}).strict();
|
|
87
|
+
var JSONRPCMessageSchema = z.union([
|
|
88
|
+
JSONRPCRequestSchema,
|
|
89
|
+
JSONRPCNotificationSchema,
|
|
90
|
+
JSONRPCResponseSchema,
|
|
91
|
+
JSONRPCErrorSchema
|
|
92
|
+
]);
|
|
93
|
+
var EmptyResultSchema = ResultSchema.strict();
|
|
94
|
+
var CancelledNotificationSchema = NotificationSchema.extend({
|
|
95
|
+
method: z.literal("notifications/cancelled"),
|
|
96
|
+
params: BaseNotificationParamsSchema.extend({
|
|
97
|
+
/**
|
|
98
|
+
* The ID of the request to cancel.
|
|
99
|
+
*
|
|
100
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
101
|
+
*/
|
|
102
|
+
requestId: RequestIdSchema,
|
|
103
|
+
/**
|
|
104
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
105
|
+
*/
|
|
106
|
+
reason: z.string().optional()
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
var ImplementationSchema = z.object({
|
|
110
|
+
name: z.string(),
|
|
111
|
+
version: z.string()
|
|
112
|
+
}).passthrough();
|
|
113
|
+
var ClientCapabilitiesSchema = z.object({
|
|
114
|
+
/**
|
|
115
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
116
|
+
*/
|
|
117
|
+
experimental: z.optional(z.object({}).passthrough()),
|
|
118
|
+
/**
|
|
119
|
+
* Present if the client supports sampling from an LLM.
|
|
120
|
+
*/
|
|
121
|
+
sampling: z.optional(z.object({}).passthrough()),
|
|
122
|
+
/**
|
|
123
|
+
* Present if the client supports listing roots.
|
|
124
|
+
*/
|
|
125
|
+
roots: z.optional(z.object({
|
|
126
|
+
/**
|
|
127
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
128
|
+
*/
|
|
129
|
+
listChanged: z.optional(z.boolean())
|
|
130
|
+
}).passthrough())
|
|
131
|
+
}).passthrough();
|
|
132
|
+
var InitializeRequestSchema = RequestSchema.extend({
|
|
133
|
+
method: z.literal("initialize"),
|
|
134
|
+
params: BaseRequestParamsSchema.extend({
|
|
135
|
+
/**
|
|
136
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
137
|
+
*/
|
|
138
|
+
protocolVersion: z.string(),
|
|
139
|
+
capabilities: ClientCapabilitiesSchema,
|
|
140
|
+
clientInfo: ImplementationSchema
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
var ServerCapabilitiesSchema = z.object({
|
|
144
|
+
/**
|
|
145
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
146
|
+
*/
|
|
147
|
+
experimental: z.optional(z.object({}).passthrough()),
|
|
148
|
+
/**
|
|
149
|
+
* Present if the server supports sending log messages to the client.
|
|
150
|
+
*/
|
|
151
|
+
logging: z.optional(z.object({}).passthrough()),
|
|
152
|
+
/**
|
|
153
|
+
* Present if the server offers any prompt templates.
|
|
154
|
+
*/
|
|
155
|
+
prompts: z.optional(z.object({
|
|
156
|
+
/**
|
|
157
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
158
|
+
*/
|
|
159
|
+
listChanged: z.optional(z.boolean())
|
|
160
|
+
}).passthrough()),
|
|
161
|
+
/**
|
|
162
|
+
* Present if the server offers any resources to read.
|
|
163
|
+
*/
|
|
164
|
+
resources: z.optional(z.object({
|
|
165
|
+
/**
|
|
166
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
167
|
+
*/
|
|
168
|
+
subscribe: z.optional(z.boolean()),
|
|
169
|
+
/**
|
|
170
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
171
|
+
*/
|
|
172
|
+
listChanged: z.optional(z.boolean())
|
|
173
|
+
}).passthrough()),
|
|
174
|
+
/**
|
|
175
|
+
* Present if the server offers any tools to call.
|
|
176
|
+
*/
|
|
177
|
+
tools: z.optional(z.object({
|
|
178
|
+
/**
|
|
179
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
180
|
+
*/
|
|
181
|
+
listChanged: z.optional(z.boolean())
|
|
182
|
+
}).passthrough())
|
|
183
|
+
}).passthrough();
|
|
184
|
+
var InitializeResultSchema = ResultSchema.extend({
|
|
185
|
+
/**
|
|
186
|
+
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
|
|
187
|
+
*/
|
|
188
|
+
protocolVersion: z.string(),
|
|
189
|
+
capabilities: ServerCapabilitiesSchema,
|
|
190
|
+
serverInfo: ImplementationSchema,
|
|
191
|
+
/**
|
|
192
|
+
* Instructions describing how to use the server and its features.
|
|
193
|
+
*
|
|
194
|
+
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
|
|
195
|
+
*/
|
|
196
|
+
instructions: z.optional(z.string())
|
|
197
|
+
});
|
|
198
|
+
var InitializedNotificationSchema = NotificationSchema.extend({
|
|
199
|
+
method: z.literal("notifications/initialized")
|
|
200
|
+
});
|
|
201
|
+
var PingRequestSchema = RequestSchema.extend({
|
|
202
|
+
method: z.literal("ping")
|
|
203
|
+
});
|
|
204
|
+
var ProgressSchema = z.object({
|
|
205
|
+
/**
|
|
206
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
207
|
+
*/
|
|
208
|
+
progress: z.number(),
|
|
209
|
+
/**
|
|
210
|
+
* Total number of items to process (or total progress required), if known.
|
|
211
|
+
*/
|
|
212
|
+
total: z.optional(z.number())
|
|
213
|
+
}).passthrough();
|
|
214
|
+
var ProgressNotificationSchema = NotificationSchema.extend({
|
|
215
|
+
method: z.literal("notifications/progress"),
|
|
216
|
+
params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
|
|
217
|
+
/**
|
|
218
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
219
|
+
*/
|
|
220
|
+
progressToken: ProgressTokenSchema
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
var PaginatedRequestSchema = RequestSchema.extend({
|
|
224
|
+
params: BaseRequestParamsSchema.extend({
|
|
225
|
+
/**
|
|
226
|
+
* An opaque token representing the current pagination position.
|
|
227
|
+
* If provided, the server should return results starting after this cursor.
|
|
228
|
+
*/
|
|
229
|
+
cursor: z.optional(CursorSchema)
|
|
230
|
+
}).optional()
|
|
231
|
+
});
|
|
232
|
+
var PaginatedResultSchema = ResultSchema.extend({
|
|
233
|
+
/**
|
|
234
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
235
|
+
* If present, there may be more results available.
|
|
236
|
+
*/
|
|
237
|
+
nextCursor: z.optional(CursorSchema)
|
|
238
|
+
});
|
|
239
|
+
var ResourceContentsSchema = z.object({
|
|
240
|
+
/**
|
|
241
|
+
* The URI of this resource.
|
|
242
|
+
*/
|
|
243
|
+
uri: z.string(),
|
|
244
|
+
/**
|
|
245
|
+
* The MIME type of this resource, if known.
|
|
246
|
+
*/
|
|
247
|
+
mimeType: z.optional(z.string())
|
|
248
|
+
}).passthrough();
|
|
249
|
+
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
250
|
+
/**
|
|
251
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
252
|
+
*/
|
|
253
|
+
text: z.string()
|
|
254
|
+
});
|
|
255
|
+
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
256
|
+
/**
|
|
257
|
+
* A base64-encoded string representing the binary data of the item.
|
|
258
|
+
*/
|
|
259
|
+
blob: z.string().base64()
|
|
260
|
+
});
|
|
261
|
+
var ResourceSchema = z.object({
|
|
262
|
+
/**
|
|
263
|
+
* The URI of this resource.
|
|
264
|
+
*/
|
|
265
|
+
uri: z.string(),
|
|
266
|
+
/**
|
|
267
|
+
* A human-readable name for this resource.
|
|
268
|
+
*
|
|
269
|
+
* This can be used by clients to populate UI elements.
|
|
270
|
+
*/
|
|
271
|
+
name: z.string(),
|
|
272
|
+
/**
|
|
273
|
+
* A description of what this resource represents.
|
|
274
|
+
*
|
|
275
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
276
|
+
*/
|
|
277
|
+
description: z.optional(z.string()),
|
|
278
|
+
/**
|
|
279
|
+
* The MIME type of this resource, if known.
|
|
280
|
+
*/
|
|
281
|
+
mimeType: z.optional(z.string())
|
|
282
|
+
}).passthrough();
|
|
283
|
+
var ResourceTemplateSchema = z.object({
|
|
284
|
+
/**
|
|
285
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
286
|
+
*/
|
|
287
|
+
uriTemplate: z.string(),
|
|
288
|
+
/**
|
|
289
|
+
* A human-readable name for the type of resource this template refers to.
|
|
290
|
+
*
|
|
291
|
+
* This can be used by clients to populate UI elements.
|
|
292
|
+
*/
|
|
293
|
+
name: z.string(),
|
|
294
|
+
/**
|
|
295
|
+
* A description of what this template is for.
|
|
296
|
+
*
|
|
297
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
298
|
+
*/
|
|
299
|
+
description: z.optional(z.string()),
|
|
300
|
+
/**
|
|
301
|
+
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
|
|
302
|
+
*/
|
|
303
|
+
mimeType: z.optional(z.string())
|
|
304
|
+
}).passthrough();
|
|
305
|
+
var ListResourcesRequestSchema = PaginatedRequestSchema.extend({
|
|
306
|
+
method: z.literal("resources/list")
|
|
307
|
+
});
|
|
308
|
+
var ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
309
|
+
resources: z.array(ResourceSchema)
|
|
310
|
+
});
|
|
311
|
+
var ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
|
|
312
|
+
method: z.literal("resources/templates/list")
|
|
313
|
+
});
|
|
314
|
+
var ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
315
|
+
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
316
|
+
});
|
|
317
|
+
var ReadResourceRequestSchema = RequestSchema.extend({
|
|
318
|
+
method: z.literal("resources/read"),
|
|
319
|
+
params: BaseRequestParamsSchema.extend({
|
|
320
|
+
/**
|
|
321
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
322
|
+
*/
|
|
323
|
+
uri: z.string()
|
|
324
|
+
})
|
|
325
|
+
});
|
|
326
|
+
var ReadResourceResultSchema = ResultSchema.extend({
|
|
327
|
+
contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
328
|
+
});
|
|
329
|
+
var ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
330
|
+
method: z.literal("notifications/resources/list_changed")
|
|
331
|
+
});
|
|
332
|
+
var SubscribeRequestSchema = RequestSchema.extend({
|
|
333
|
+
method: z.literal("resources/subscribe"),
|
|
334
|
+
params: BaseRequestParamsSchema.extend({
|
|
335
|
+
/**
|
|
336
|
+
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
|
337
|
+
*/
|
|
338
|
+
uri: z.string()
|
|
339
|
+
})
|
|
340
|
+
});
|
|
341
|
+
var UnsubscribeRequestSchema = RequestSchema.extend({
|
|
342
|
+
method: z.literal("resources/unsubscribe"),
|
|
343
|
+
params: BaseRequestParamsSchema.extend({
|
|
344
|
+
/**
|
|
345
|
+
* The URI of the resource to unsubscribe from.
|
|
346
|
+
*/
|
|
347
|
+
uri: z.string()
|
|
348
|
+
})
|
|
349
|
+
});
|
|
350
|
+
var ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
351
|
+
method: z.literal("notifications/resources/updated"),
|
|
352
|
+
params: BaseNotificationParamsSchema.extend({
|
|
353
|
+
/**
|
|
354
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
355
|
+
*/
|
|
356
|
+
uri: z.string()
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
var PromptArgumentSchema = z.object({
|
|
360
|
+
/**
|
|
361
|
+
* The name of the argument.
|
|
362
|
+
*/
|
|
363
|
+
name: z.string(),
|
|
364
|
+
/**
|
|
365
|
+
* A human-readable description of the argument.
|
|
366
|
+
*/
|
|
367
|
+
description: z.optional(z.string()),
|
|
368
|
+
/**
|
|
369
|
+
* Whether this argument must be provided.
|
|
370
|
+
*/
|
|
371
|
+
required: z.optional(z.boolean())
|
|
372
|
+
}).passthrough();
|
|
373
|
+
var PromptSchema = z.object({
|
|
374
|
+
/**
|
|
375
|
+
* The name of the prompt or prompt template.
|
|
376
|
+
*/
|
|
377
|
+
name: z.string(),
|
|
378
|
+
/**
|
|
379
|
+
* An optional description of what this prompt provides
|
|
380
|
+
*/
|
|
381
|
+
description: z.optional(z.string()),
|
|
382
|
+
/**
|
|
383
|
+
* A list of arguments to use for templating the prompt.
|
|
384
|
+
*/
|
|
385
|
+
arguments: z.optional(z.array(PromptArgumentSchema))
|
|
386
|
+
}).passthrough();
|
|
387
|
+
var ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
388
|
+
method: z.literal("prompts/list")
|
|
389
|
+
});
|
|
390
|
+
var ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
391
|
+
prompts: z.array(PromptSchema)
|
|
392
|
+
});
|
|
393
|
+
var GetPromptRequestSchema = RequestSchema.extend({
|
|
394
|
+
method: z.literal("prompts/get"),
|
|
395
|
+
params: BaseRequestParamsSchema.extend({
|
|
396
|
+
/**
|
|
397
|
+
* The name of the prompt or prompt template.
|
|
398
|
+
*/
|
|
399
|
+
name: z.string(),
|
|
400
|
+
/**
|
|
401
|
+
* Arguments to use for templating the prompt.
|
|
402
|
+
*/
|
|
403
|
+
arguments: z.optional(z.record(z.string()))
|
|
404
|
+
})
|
|
405
|
+
});
|
|
406
|
+
var TextContentSchema = z.object({
|
|
407
|
+
type: z.literal("text"),
|
|
408
|
+
/**
|
|
409
|
+
* The text content of the message.
|
|
410
|
+
*/
|
|
411
|
+
text: z.string()
|
|
412
|
+
}).passthrough();
|
|
413
|
+
var ImageContentSchema = z.object({
|
|
414
|
+
type: z.literal("image"),
|
|
415
|
+
/**
|
|
416
|
+
* The base64-encoded image data.
|
|
417
|
+
*/
|
|
418
|
+
data: z.string().base64(),
|
|
419
|
+
/**
|
|
420
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
421
|
+
*/
|
|
422
|
+
mimeType: z.string()
|
|
423
|
+
}).passthrough();
|
|
424
|
+
var EmbeddedResourceSchema = z.object({
|
|
425
|
+
type: z.literal("resource"),
|
|
426
|
+
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
427
|
+
}).passthrough();
|
|
428
|
+
var PromptMessageSchema = z.object({
|
|
429
|
+
role: z.enum(["user", "assistant"]),
|
|
430
|
+
content: z.union([
|
|
431
|
+
TextContentSchema,
|
|
432
|
+
ImageContentSchema,
|
|
433
|
+
EmbeddedResourceSchema
|
|
434
|
+
])
|
|
435
|
+
}).passthrough();
|
|
436
|
+
var GetPromptResultSchema = ResultSchema.extend({
|
|
437
|
+
/**
|
|
438
|
+
* An optional description for the prompt.
|
|
439
|
+
*/
|
|
440
|
+
description: z.optional(z.string()),
|
|
441
|
+
messages: z.array(PromptMessageSchema)
|
|
442
|
+
});
|
|
443
|
+
var PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
444
|
+
method: z.literal("notifications/prompts/list_changed")
|
|
445
|
+
});
|
|
446
|
+
var ToolSchema = z.object({
|
|
447
|
+
/**
|
|
448
|
+
* The name of the tool.
|
|
449
|
+
*/
|
|
450
|
+
name: z.string(),
|
|
451
|
+
/**
|
|
452
|
+
* A human-readable description of the tool.
|
|
453
|
+
*/
|
|
454
|
+
description: z.optional(z.string()),
|
|
455
|
+
/**
|
|
456
|
+
* A JSON Schema object defining the expected parameters for the tool.
|
|
457
|
+
*/
|
|
458
|
+
inputSchema: z.object({
|
|
459
|
+
type: z.literal("object"),
|
|
460
|
+
properties: z.optional(z.object({}).passthrough())
|
|
461
|
+
}).passthrough()
|
|
462
|
+
}).passthrough();
|
|
463
|
+
var ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
464
|
+
method: z.literal("tools/list")
|
|
465
|
+
});
|
|
466
|
+
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
467
|
+
tools: z.array(ToolSchema)
|
|
468
|
+
});
|
|
469
|
+
var CallToolResultSchema = ResultSchema.extend({
|
|
470
|
+
content: z.array(z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])),
|
|
471
|
+
isError: z.boolean().default(false).optional()
|
|
472
|
+
});
|
|
473
|
+
var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
|
|
474
|
+
toolResult: z.unknown()
|
|
475
|
+
}));
|
|
476
|
+
var CallToolRequestSchema = RequestSchema.extend({
|
|
477
|
+
method: z.literal("tools/call"),
|
|
478
|
+
params: BaseRequestParamsSchema.extend({
|
|
479
|
+
name: z.string(),
|
|
480
|
+
arguments: z.optional(z.record(z.unknown()))
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
var ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
484
|
+
method: z.literal("notifications/tools/list_changed")
|
|
485
|
+
});
|
|
486
|
+
var LoggingLevelSchema = z.enum([
|
|
487
|
+
"debug",
|
|
488
|
+
"info",
|
|
489
|
+
"notice",
|
|
490
|
+
"warning",
|
|
491
|
+
"error",
|
|
492
|
+
"critical",
|
|
493
|
+
"alert",
|
|
494
|
+
"emergency"
|
|
495
|
+
]);
|
|
496
|
+
var SetLevelRequestSchema = RequestSchema.extend({
|
|
497
|
+
method: z.literal("logging/setLevel"),
|
|
498
|
+
params: BaseRequestParamsSchema.extend({
|
|
499
|
+
/**
|
|
500
|
+
* The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
|
|
501
|
+
*/
|
|
502
|
+
level: LoggingLevelSchema
|
|
503
|
+
})
|
|
504
|
+
});
|
|
505
|
+
var LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
506
|
+
method: z.literal("notifications/message"),
|
|
507
|
+
params: BaseNotificationParamsSchema.extend({
|
|
508
|
+
/**
|
|
509
|
+
* The severity of this log message.
|
|
510
|
+
*/
|
|
511
|
+
level: LoggingLevelSchema,
|
|
512
|
+
/**
|
|
513
|
+
* An optional name of the logger issuing this message.
|
|
514
|
+
*/
|
|
515
|
+
logger: z.optional(z.string()),
|
|
516
|
+
/**
|
|
517
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
518
|
+
*/
|
|
519
|
+
data: z.unknown()
|
|
520
|
+
})
|
|
521
|
+
});
|
|
522
|
+
var ModelHintSchema = z.object({
|
|
523
|
+
/**
|
|
524
|
+
* A hint for a model name.
|
|
525
|
+
*/
|
|
526
|
+
name: z.string().optional()
|
|
527
|
+
}).passthrough();
|
|
528
|
+
var ModelPreferencesSchema = z.object({
|
|
529
|
+
/**
|
|
530
|
+
* Optional hints to use for model selection.
|
|
531
|
+
*/
|
|
532
|
+
hints: z.optional(z.array(ModelHintSchema)),
|
|
533
|
+
/**
|
|
534
|
+
* How much to prioritize cost when selecting a model.
|
|
535
|
+
*/
|
|
536
|
+
costPriority: z.optional(z.number().min(0).max(1)),
|
|
537
|
+
/**
|
|
538
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
539
|
+
*/
|
|
540
|
+
speedPriority: z.optional(z.number().min(0).max(1)),
|
|
541
|
+
/**
|
|
542
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
543
|
+
*/
|
|
544
|
+
intelligencePriority: z.optional(z.number().min(0).max(1))
|
|
545
|
+
}).passthrough();
|
|
546
|
+
var SamplingMessageSchema = z.object({
|
|
547
|
+
role: z.enum(["user", "assistant"]),
|
|
548
|
+
content: z.union([TextContentSchema, ImageContentSchema])
|
|
549
|
+
}).passthrough();
|
|
550
|
+
var CreateMessageRequestSchema = RequestSchema.extend({
|
|
551
|
+
method: z.literal("sampling/createMessage"),
|
|
552
|
+
params: BaseRequestParamsSchema.extend({
|
|
553
|
+
messages: z.array(SamplingMessageSchema),
|
|
554
|
+
/**
|
|
555
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
556
|
+
*/
|
|
557
|
+
systemPrompt: z.optional(z.string()),
|
|
558
|
+
/**
|
|
559
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
|
|
560
|
+
*/
|
|
561
|
+
includeContext: z.optional(z.enum(["none", "thisServer", "allServers"])),
|
|
562
|
+
temperature: z.optional(z.number()),
|
|
563
|
+
/**
|
|
564
|
+
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
|
|
565
|
+
*/
|
|
566
|
+
maxTokens: z.number().int(),
|
|
567
|
+
stopSequences: z.optional(z.array(z.string())),
|
|
568
|
+
/**
|
|
569
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
570
|
+
*/
|
|
571
|
+
metadata: z.optional(z.object({}).passthrough()),
|
|
572
|
+
/**
|
|
573
|
+
* The server's preferences for which model to select.
|
|
574
|
+
*/
|
|
575
|
+
modelPreferences: z.optional(ModelPreferencesSchema)
|
|
576
|
+
})
|
|
577
|
+
});
|
|
578
|
+
var CreateMessageResultSchema = ResultSchema.extend({
|
|
579
|
+
/**
|
|
580
|
+
* The name of the model that generated the message.
|
|
581
|
+
*/
|
|
582
|
+
model: z.string(),
|
|
583
|
+
/**
|
|
584
|
+
* The reason why sampling stopped.
|
|
585
|
+
*/
|
|
586
|
+
stopReason: z.optional(z.enum(["endTurn", "stopSequence", "maxTokens"]).or(z.string())),
|
|
587
|
+
role: z.enum(["user", "assistant"]),
|
|
588
|
+
content: z.discriminatedUnion("type", [
|
|
589
|
+
TextContentSchema,
|
|
590
|
+
ImageContentSchema
|
|
591
|
+
])
|
|
592
|
+
});
|
|
593
|
+
var ResourceReferenceSchema = z.object({
|
|
594
|
+
type: z.literal("ref/resource"),
|
|
595
|
+
/**
|
|
596
|
+
* The URI or URI template of the resource.
|
|
597
|
+
*/
|
|
598
|
+
uri: z.string()
|
|
599
|
+
}).passthrough();
|
|
600
|
+
var PromptReferenceSchema = z.object({
|
|
601
|
+
type: z.literal("ref/prompt"),
|
|
602
|
+
/**
|
|
603
|
+
* The name of the prompt or prompt template
|
|
604
|
+
*/
|
|
605
|
+
name: z.string()
|
|
606
|
+
}).passthrough();
|
|
607
|
+
var CompleteRequestSchema = RequestSchema.extend({
|
|
608
|
+
method: z.literal("completion/complete"),
|
|
609
|
+
params: BaseRequestParamsSchema.extend({
|
|
610
|
+
ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),
|
|
611
|
+
/**
|
|
612
|
+
* The argument's information
|
|
613
|
+
*/
|
|
614
|
+
argument: z.object({
|
|
615
|
+
/**
|
|
616
|
+
* The name of the argument
|
|
617
|
+
*/
|
|
618
|
+
name: z.string(),
|
|
619
|
+
/**
|
|
620
|
+
* The value of the argument to use for completion matching.
|
|
621
|
+
*/
|
|
622
|
+
value: z.string()
|
|
623
|
+
}).passthrough()
|
|
624
|
+
})
|
|
625
|
+
});
|
|
626
|
+
var CompleteResultSchema = ResultSchema.extend({
|
|
627
|
+
completion: z.object({
|
|
628
|
+
/**
|
|
629
|
+
* An array of completion values. Must not exceed 100 items.
|
|
630
|
+
*/
|
|
631
|
+
values: z.array(z.string()).max(100),
|
|
632
|
+
/**
|
|
633
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
634
|
+
*/
|
|
635
|
+
total: z.optional(z.number().int()),
|
|
636
|
+
/**
|
|
637
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
638
|
+
*/
|
|
639
|
+
hasMore: z.optional(z.boolean())
|
|
640
|
+
}).passthrough()
|
|
641
|
+
});
|
|
642
|
+
var RootSchema = z.object({
|
|
643
|
+
/**
|
|
644
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
645
|
+
*/
|
|
646
|
+
uri: z.string().startsWith("file://"),
|
|
647
|
+
/**
|
|
648
|
+
* An optional name for the root.
|
|
649
|
+
*/
|
|
650
|
+
name: z.optional(z.string())
|
|
651
|
+
}).passthrough();
|
|
652
|
+
var ListRootsRequestSchema = RequestSchema.extend({
|
|
653
|
+
method: z.literal("roots/list")
|
|
654
|
+
});
|
|
655
|
+
var ListRootsResultSchema = ResultSchema.extend({
|
|
656
|
+
roots: z.array(RootSchema)
|
|
657
|
+
});
|
|
658
|
+
var RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
659
|
+
method: z.literal("notifications/roots/list_changed")
|
|
660
|
+
});
|
|
661
|
+
var ClientRequestSchema = z.union([
|
|
662
|
+
PingRequestSchema,
|
|
663
|
+
InitializeRequestSchema,
|
|
664
|
+
CompleteRequestSchema,
|
|
665
|
+
SetLevelRequestSchema,
|
|
666
|
+
GetPromptRequestSchema,
|
|
667
|
+
ListPromptsRequestSchema,
|
|
668
|
+
ListResourcesRequestSchema,
|
|
669
|
+
ListResourceTemplatesRequestSchema,
|
|
670
|
+
ReadResourceRequestSchema,
|
|
671
|
+
SubscribeRequestSchema,
|
|
672
|
+
UnsubscribeRequestSchema,
|
|
673
|
+
CallToolRequestSchema,
|
|
674
|
+
ListToolsRequestSchema
|
|
675
|
+
]);
|
|
676
|
+
var ClientNotificationSchema = z.union([
|
|
677
|
+
CancelledNotificationSchema,
|
|
678
|
+
ProgressNotificationSchema,
|
|
679
|
+
InitializedNotificationSchema,
|
|
680
|
+
RootsListChangedNotificationSchema
|
|
681
|
+
]);
|
|
682
|
+
var ClientResultSchema = z.union([
|
|
683
|
+
EmptyResultSchema,
|
|
684
|
+
CreateMessageResultSchema,
|
|
685
|
+
ListRootsResultSchema
|
|
686
|
+
]);
|
|
687
|
+
var ServerRequestSchema = z.union([
|
|
688
|
+
PingRequestSchema,
|
|
689
|
+
CreateMessageRequestSchema,
|
|
690
|
+
ListRootsRequestSchema
|
|
691
|
+
]);
|
|
692
|
+
var ServerNotificationSchema = z.union([
|
|
693
|
+
CancelledNotificationSchema,
|
|
694
|
+
ProgressNotificationSchema,
|
|
695
|
+
LoggingMessageNotificationSchema,
|
|
696
|
+
ResourceUpdatedNotificationSchema,
|
|
697
|
+
ResourceListChangedNotificationSchema,
|
|
698
|
+
ToolListChangedNotificationSchema,
|
|
699
|
+
PromptListChangedNotificationSchema
|
|
700
|
+
]);
|
|
701
|
+
var ServerResultSchema = z.union([
|
|
702
|
+
EmptyResultSchema,
|
|
703
|
+
InitializeResultSchema,
|
|
704
|
+
CompleteResultSchema,
|
|
705
|
+
GetPromptResultSchema,
|
|
706
|
+
ListPromptsResultSchema,
|
|
707
|
+
ListResourcesResultSchema,
|
|
708
|
+
ListResourceTemplatesResultSchema,
|
|
709
|
+
ReadResourceResultSchema,
|
|
710
|
+
CallToolResultSchema,
|
|
711
|
+
ListToolsResultSchema
|
|
712
|
+
]);
|
|
713
|
+
|
|
714
|
+
// src/lib/sseEdge.ts
|
|
715
|
+
var MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
716
|
+
var SSEEdgeTransport = class {
|
|
717
|
+
/**
|
|
718
|
+
* Creates a new EdgeSSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
719
|
+
*/
|
|
720
|
+
constructor(messageUrl, sessionId) {
|
|
721
|
+
this.messageUrl = messageUrl;
|
|
722
|
+
this.sessionId = sessionId;
|
|
723
|
+
this.controller = null;
|
|
724
|
+
this.closed = false;
|
|
725
|
+
this.stream = new ReadableStream({
|
|
726
|
+
start: (controller) => {
|
|
727
|
+
this.controller = controller;
|
|
728
|
+
},
|
|
729
|
+
cancel: () => {
|
|
730
|
+
this.closed = true;
|
|
731
|
+
this.onclose?.();
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
async start() {
|
|
736
|
+
if (this.closed) {
|
|
737
|
+
throw new Error(
|
|
738
|
+
"SSE transport already closed! If using Server class, note that connect() calls start() automatically."
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
if (!this.controller) {
|
|
742
|
+
throw new Error("Stream controller not initialized");
|
|
743
|
+
}
|
|
744
|
+
const endpointMessage = `event: endpoint
|
|
745
|
+
data: ${encodeURI(this.messageUrl)}?sessionId=${this.sessionId}
|
|
746
|
+
|
|
747
|
+
`;
|
|
748
|
+
this.controller.enqueue(new TextEncoder().encode(endpointMessage));
|
|
749
|
+
}
|
|
750
|
+
get sseResponse() {
|
|
751
|
+
if (!this.stream) {
|
|
752
|
+
throw new Error("Stream not initialized");
|
|
753
|
+
}
|
|
754
|
+
return new Response(this.stream, {
|
|
755
|
+
headers: {
|
|
756
|
+
"Content-Type": "text/event-stream",
|
|
757
|
+
"Cache-Control": "no-cache",
|
|
758
|
+
Connection: "keep-alive"
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Handles incoming Requests
|
|
764
|
+
*/
|
|
765
|
+
async handlePostMessage(req) {
|
|
766
|
+
if (this.closed || !this.controller) {
|
|
767
|
+
const message = "SSE connection not established";
|
|
768
|
+
return new Response(message, { status: 500 });
|
|
769
|
+
}
|
|
770
|
+
try {
|
|
771
|
+
const contentType = req.headers.get("content-type") || "";
|
|
772
|
+
if (!contentType.includes("application/json")) {
|
|
773
|
+
throw new Error(`Unsupported content-type: ${contentType}`);
|
|
774
|
+
}
|
|
775
|
+
const contentLength = Number.parseInt(
|
|
776
|
+
req.headers.get("content-length") || "0",
|
|
777
|
+
10
|
|
778
|
+
);
|
|
779
|
+
if (contentLength > MAXIMUM_MESSAGE_SIZE) {
|
|
780
|
+
throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
781
|
+
}
|
|
782
|
+
const body = await req.json();
|
|
783
|
+
await this.handleMessage(body);
|
|
784
|
+
return new Response("Accepted", { status: 202 });
|
|
785
|
+
} catch (error) {
|
|
786
|
+
this.onerror?.(error);
|
|
787
|
+
return new Response(String(error), { status: 400 });
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
|
792
|
+
*/
|
|
793
|
+
async handleMessage(message) {
|
|
794
|
+
let parsedMessage;
|
|
795
|
+
try {
|
|
796
|
+
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
797
|
+
} catch (error) {
|
|
798
|
+
this.onerror?.(error);
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
this.onmessage?.(parsedMessage);
|
|
802
|
+
}
|
|
803
|
+
async close() {
|
|
804
|
+
if (!this.closed && this.controller) {
|
|
805
|
+
this.controller.close();
|
|
806
|
+
this.stream.cancel();
|
|
807
|
+
this.closed = true;
|
|
808
|
+
this.onclose?.();
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
async send(message) {
|
|
812
|
+
if (this.closed || !this.controller) {
|
|
813
|
+
throw new Error("Not connected");
|
|
814
|
+
}
|
|
815
|
+
const messageText = `event: message
|
|
816
|
+
data: ${JSON.stringify(message)}
|
|
817
|
+
|
|
818
|
+
`;
|
|
819
|
+
this.controller.enqueue(new TextEncoder().encode(messageText));
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
// src/mcp.ts
|
|
824
|
+
function handleCORS(request, corsOptions) {
|
|
825
|
+
const origin = request.headers.get("Origin") || "*";
|
|
826
|
+
const corsHeaders = {
|
|
827
|
+
"Access-Control-Allow-Origin": corsOptions?.origin || origin,
|
|
828
|
+
"Access-Control-Allow-Methods": corsOptions?.methods || "GET, POST, OPTIONS",
|
|
829
|
+
"Access-Control-Allow-Headers": corsOptions?.headers || "Content-Type",
|
|
830
|
+
"Access-Control-Max-Age": (corsOptions?.maxAge || 86400).toString()
|
|
831
|
+
};
|
|
832
|
+
if (request.method === "OPTIONS") {
|
|
833
|
+
return new Response(null, { headers: corsHeaders });
|
|
834
|
+
}
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
var _agent;
|
|
838
|
+
var McpAgent = class extends DurableObject {
|
|
839
|
+
constructor(ctx, env) {
|
|
840
|
+
var _a;
|
|
841
|
+
super(ctx, env);
|
|
842
|
+
/**
|
|
843
|
+
* Since McpAgent's _aren't_ yet real "Agents" (they route differently, don't support
|
|
844
|
+
* websockets, don't support hibernation), let's only expose a couple of the methods
|
|
845
|
+
* to the outer class: initialState/state/setState/onStateUpdate/sql
|
|
846
|
+
*/
|
|
847
|
+
__privateAdd(this, _agent);
|
|
848
|
+
this.initRun = false;
|
|
849
|
+
const self = this;
|
|
850
|
+
__privateSet(this, _agent, new (_a = class extends Agent {
|
|
851
|
+
onStateUpdate(state, source) {
|
|
852
|
+
return self.onStateUpdate(state, source);
|
|
853
|
+
}
|
|
854
|
+
}, _a.options = {
|
|
855
|
+
hibernate: false
|
|
856
|
+
}, _a)(ctx, env));
|
|
857
|
+
}
|
|
858
|
+
get state() {
|
|
859
|
+
if (this.initialState) __privateGet(this, _agent).initialState = this.initialState;
|
|
860
|
+
return __privateGet(this, _agent).state;
|
|
861
|
+
}
|
|
862
|
+
sql(strings, ...values) {
|
|
863
|
+
return __privateGet(this, _agent).sql(strings, ...values);
|
|
864
|
+
}
|
|
865
|
+
setState(state) {
|
|
866
|
+
return __privateGet(this, _agent).setState(state);
|
|
867
|
+
}
|
|
868
|
+
onStateUpdate(state, source) {
|
|
869
|
+
}
|
|
870
|
+
async _init(props) {
|
|
871
|
+
this.props = props;
|
|
872
|
+
if (!this.initRun) {
|
|
873
|
+
this.initRun = true;
|
|
874
|
+
await this.init();
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
async onSSE(path) {
|
|
878
|
+
this.transport = new SSEEdgeTransport(
|
|
879
|
+
`${path}/message`,
|
|
880
|
+
this.ctx.id.toString()
|
|
881
|
+
);
|
|
882
|
+
await this.server.connect(this.transport);
|
|
883
|
+
return this.transport.sseResponse;
|
|
884
|
+
}
|
|
885
|
+
async onMCPMessage(request) {
|
|
886
|
+
return this.transport.handlePostMessage(request);
|
|
887
|
+
}
|
|
888
|
+
static mount(path, {
|
|
889
|
+
binding = "MCP_OBJECT",
|
|
890
|
+
corsOptions
|
|
891
|
+
} = {}) {
|
|
892
|
+
const basePattern = new URLPattern({ pathname: path });
|
|
893
|
+
const messagePattern = new URLPattern({ pathname: `${path}/message` });
|
|
894
|
+
return {
|
|
895
|
+
fetch: async (request, env, ctx) => {
|
|
896
|
+
const corsResponse = handleCORS(request, corsOptions);
|
|
897
|
+
if (corsResponse) return corsResponse;
|
|
898
|
+
const url = new URL(request.url);
|
|
899
|
+
const namespace = env[binding];
|
|
900
|
+
if (request.method === "GET" && basePattern.test(url)) {
|
|
901
|
+
const object = namespace.get(namespace.newUniqueId());
|
|
902
|
+
await object._init(ctx.props);
|
|
903
|
+
const response = await object.onSSE(path);
|
|
904
|
+
const headerObj = {};
|
|
905
|
+
response.headers.forEach((value, key) => {
|
|
906
|
+
headerObj[key] = value;
|
|
907
|
+
});
|
|
908
|
+
headerObj["Access-Control-Allow-Origin"] = corsOptions?.origin || "*";
|
|
909
|
+
return new Response(response.body, {
|
|
910
|
+
status: response.status,
|
|
911
|
+
statusText: response.statusText,
|
|
912
|
+
headers: headerObj
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
if (request.method === "POST" && messagePattern.test(url)) {
|
|
916
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
917
|
+
if (!sessionId) {
|
|
918
|
+
return new Response(
|
|
919
|
+
`Missing sessionId. Expected POST to ${path} to initiate new one`,
|
|
920
|
+
{ status: 400 }
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
const object = namespace.get(namespace.idFromString(sessionId));
|
|
924
|
+
const response = await object.onMCPMessage(request);
|
|
925
|
+
const headerObj = {};
|
|
926
|
+
response.headers.forEach((value, key) => {
|
|
927
|
+
headerObj[key] = value;
|
|
928
|
+
});
|
|
929
|
+
headerObj["Access-Control-Allow-Origin"] = corsOptions?.origin || "*";
|
|
930
|
+
return new Response(response.body, {
|
|
931
|
+
status: response.status,
|
|
932
|
+
statusText: response.statusText,
|
|
933
|
+
headers: headerObj
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
return new Response("Not Found", { status: 404 });
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
_agent = new WeakMap();
|
|
942
|
+
export {
|
|
943
|
+
McpAgent
|
|
944
|
+
};
|
|
945
|
+
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp.ts","../../../node_modules/@modelcontextprotocol/sdk/src/types.ts","../src/lib/sseEdge.ts"],"sourcesContent":["import { DurableObject } from \"cloudflare:workers\";\nimport { Agent } from \"./\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { SSEEdgeTransport } from \"./lib/sseEdge.ts\";\nimport type { Connection } from \"./\";\n\n// CORS helper function\nfunction handleCORS(\n request: Request,\n corsOptions?: CORSOptions\n): Response | null {\n const origin = request.headers.get(\"Origin\") || \"*\";\n const corsHeaders = {\n \"Access-Control-Allow-Origin\": corsOptions?.origin || origin,\n \"Access-Control-Allow-Methods\":\n corsOptions?.methods || \"GET, POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": corsOptions?.headers || \"Content-Type\",\n \"Access-Control-Max-Age\": (corsOptions?.maxAge || 86400).toString(),\n };\n\n if (request.method === \"OPTIONS\") {\n return new Response(null, { headers: corsHeaders });\n }\n\n return null;\n}\n\ninterface CORSOptions {\n origin?: string;\n methods?: string;\n headers?: string;\n maxAge?: number;\n}\n\nexport abstract class McpAgent<\n Env = unknown,\n State = unknown,\n Props extends Record<string, unknown> = Record<string, unknown>,\n> extends DurableObject {\n /**\n * Since McpAgent's _aren't_ yet real \"Agents\" (they route differently, don't support\n * websockets, don't support hibernation), let's only expose a couple of the methods\n * to the outer class: initialState/state/setState/onStateUpdate/sql\n */\n readonly #agent: Agent<Env, State>;\n protected constructor(ctx: DurableObjectState, env: Env) {\n super(ctx, env);\n const self = this;\n\n // Since McpAgent's _aren't_ yet real \"Agents\" (they route differently, they don't support\n // websockets, hibernation, scheduling etc), let's only expose a couple of the methods\n // to the outer class for now.\n this.#agent = new (class extends Agent<Env, State> {\n static options = {\n hibernate: false,\n };\n\n onStateUpdate(state: State | undefined, source: Connection | \"server\") {\n return self.onStateUpdate(state, source);\n }\n })(ctx, env);\n }\n\n /**\n * Agents API allowlist\n */\n initialState!: State;\n get state() {\n if (this.initialState) this.#agent.initialState = this.initialState;\n return this.#agent.state;\n }\n sql<T = Record<string, string | number | boolean | null>>(\n strings: TemplateStringsArray,\n ...values: (string | number | boolean | null)[]\n ) {\n return this.#agent.sql<T>(strings, ...values);\n }\n\n setState(state: State) {\n return this.#agent.setState(state);\n }\n onStateUpdate(state: State | undefined, source: Connection | \"server\") {\n // override this to handle state updates\n }\n\n /**\n * McpAgent API\n */\n abstract server: McpServer;\n private transport!: SSEEdgeTransport;\n props!: Props;\n initRun = false;\n\n abstract init(): Promise<void>;\n\n async _init(props: Props) {\n this.props = props;\n if (!this.initRun) {\n this.initRun = true;\n await this.init();\n }\n }\n\n async onSSE(path: string): Promise<Response> {\n this.transport = new SSEEdgeTransport(\n `${path}/message`,\n this.ctx.id.toString()\n );\n await this.server.connect(this.transport);\n return this.transport.sseResponse;\n }\n\n async onMCPMessage(request: Request): Promise<Response> {\n return this.transport.handlePostMessage(request);\n }\n\n static mount(\n path: string,\n {\n binding = \"MCP_OBJECT\",\n corsOptions,\n }: {\n binding?: string;\n corsOptions?: CORSOptions;\n } = {}\n ) {\n const basePattern = new URLPattern({ pathname: path });\n const messagePattern = new URLPattern({ pathname: `${path}/message` });\n\n return {\n fetch: async (\n request: Request,\n env: Record<string, DurableObjectNamespace<McpAgent>>,\n ctx: ExecutionContext\n ) => {\n // Handle CORS preflight\n const corsResponse = handleCORS(request, corsOptions);\n if (corsResponse) return corsResponse;\n\n const url = new URL(request.url);\n const namespace = env[binding];\n\n if (request.method === \"GET\" && basePattern.test(url)) {\n const object = namespace.get(namespace.newUniqueId());\n // @ts-ignore\n await object._init(ctx.props);\n const response = await object.onSSE(path);\n\n // Convert headers to a plain object\n const headerObj: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headerObj[key] = value;\n });\n headerObj[\"Access-Control-Allow-Origin\"] = corsOptions?.origin || \"*\";\n\n // Clone the response to get a new body stream\n // const clonedResponse = response.clone();\n return new Response(response.body as unknown as BodyInit, {\n status: response.status,\n statusText: response.statusText,\n headers: headerObj,\n });\n }\n\n if (request.method === \"POST\" && messagePattern.test(url)) {\n const sessionId = url.searchParams.get(\"sessionId\");\n if (!sessionId) {\n return new Response(\n `Missing sessionId. Expected POST to ${path} to initiate new one`,\n { status: 400 }\n );\n }\n const object = namespace.get(namespace.idFromString(sessionId));\n const response = await object.onMCPMessage(request);\n\n // Convert headers to a plain object\n const headerObj: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headerObj[key] = value;\n });\n headerObj[\"Access-Control-Allow-Origin\"] = corsOptions?.origin || \"*\";\n\n return new Response(response.body as unknown as BodyInit, {\n status: response.status,\n statusText: response.statusText,\n headers: headerObj,\n });\n }\n\n return new Response(\"Not Found\", { status: 404 });\n },\n };\n }\n}\n",null,"// From https://github.com/modelcontextprotocol/typescript-sdk/blob/77dfb11aadb7f6bca4ffdf6e8e3d628a1d6df3be/src/server/sseEdge.ts\n\nimport type { Transport } from \"@modelcontextprotocol/sdk/shared/transport.js\";\nimport {\n type JSONRPCMessage,\n JSONRPCMessageSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\nconst MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024; // 4MB\n\n/**\n * This transport is compatible with Cloudflare Workers and other edge environments\n */\nexport class SSEEdgeTransport implements Transport {\n private controller: ReadableStreamDefaultController<Uint8Array> | null = null;\n readonly stream: ReadableStream<Uint8Array>;\n private closed = false;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n /**\n * Creates a new EdgeSSETransport, which will direct the MPC client to POST messages to messageUrl\n */\n constructor(\n private messageUrl: string,\n readonly sessionId: string\n ) {\n // Create a readable stream for SSE\n this.stream = new ReadableStream({\n start: (controller) => {\n this.controller = controller;\n },\n cancel: () => {\n this.closed = true;\n this.onclose?.();\n },\n });\n }\n\n async start(): Promise<void> {\n if (this.closed) {\n throw new Error(\n \"SSE transport already closed! If using Server class, note that connect() calls start() automatically.\"\n );\n }\n\n // Make sure the controller exists\n if (!this.controller) {\n throw new Error(\"Stream controller not initialized\");\n }\n\n // Send the endpoint event\n const endpointMessage = `event: endpoint\\ndata: ${encodeURI(this.messageUrl)}?sessionId=${this.sessionId}\\n\\n`;\n this.controller.enqueue(new TextEncoder().encode(endpointMessage));\n }\n\n get sseResponse(): Response {\n // Ensure the stream is properly initialized\n if (!this.stream) {\n throw new Error(\"Stream not initialized\");\n }\n\n // Return a response with the SSE stream\n return new Response(this.stream, {\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n }\n\n /**\n * Handles incoming Requests\n */\n async handlePostMessage(req: Request): Promise<Response> {\n if (this.closed || !this.controller) {\n const message = \"SSE connection not established\";\n return new Response(message, { status: 500 });\n }\n\n try {\n const contentType = req.headers.get(\"content-type\") || \"\";\n if (!contentType.includes(\"application/json\")) {\n throw new Error(`Unsupported content-type: ${contentType}`);\n }\n\n // Check if the request body is too large\n const contentLength = Number.parseInt(\n req.headers.get(\"content-length\") || \"0\",\n 10\n );\n if (contentLength > MAXIMUM_MESSAGE_SIZE) {\n throw new Error(`Request body too large: ${contentLength} bytes`);\n }\n\n // Clone the request before reading the body to avoid stream issues\n const body = await req.json();\n await this.handleMessage(body);\n return new Response(\"Accepted\", { status: 202 });\n } catch (error) {\n this.onerror?.(error as Error);\n return new Response(String(error), { status: 400 });\n }\n }\n\n /**\n * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.\n */\n async handleMessage(message: unknown): Promise<void> {\n let parsedMessage: JSONRPCMessage;\n try {\n parsedMessage = JSONRPCMessageSchema.parse(message);\n } catch (error) {\n this.onerror?.(error as Error);\n throw error;\n }\n\n this.onmessage?.(parsedMessage);\n }\n\n async close(): Promise<void> {\n if (!this.closed && this.controller) {\n this.controller.close();\n this.stream.cancel();\n this.closed = true;\n this.onclose?.();\n }\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (this.closed || !this.controller) {\n throw new Error(\"Not connected\");\n }\n\n const messageText = `event: message\\ndata: ${JSON.stringify(message)}\\n\\n`;\n this.controller.enqueue(new TextEncoder().encode(messageText));\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,qBAAqB;;;ACA9B,SAAS,SAAqB;AASvB,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB,EAAE,MAAM,CAAC,EAAE,OAAM,GAAI,EAAE,OAAM,EAAG,IAAG,CAAE,CAAC;AAKlE,IAAM,eAAe,EAAE,OAAM;AAEpC,IAAM,0BAA0B,EAC7B,OAAO;EACN,OAAO,EAAE,SACP,EACG,OAAO;;;;IAIN,eAAe,EAAE,SAAS,mBAAmB;GAC9C,EACA,YAAW,CAAE;CAEnB,EACA,YAAW;AAEP,IAAM,gBAAgB,EAAE,OAAO;EACpC,QAAQ,EAAE,OAAM;EAChB,QAAQ,EAAE,SAAS,uBAAuB;CAC3C;AAED,IAAM,+BAA+B,EAClC,OAAO;;;;EAIN,OAAO,EAAE,SAAS,EAAE,OAAO,CAAA,CAAE,EAAE,YAAW,CAAE;CAC7C,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AO,IAAI,SAAS,SAAS,MAA6B;AAAA,YACxD,QAAQ,SAAS;AAAA,YACjB,YAAY,SAAS;AAAA,YACrB,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,eAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AACF;AArJW;","names":["ErrorCode"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agents",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-dd6a9e3",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"types": "./dist/schedule.d.ts",
|
|
43
43
|
"require": "./dist/schedule.js",
|
|
44
44
|
"import": "./dist/schedule.js"
|
|
45
|
+
},
|
|
46
|
+
"./mcp": {
|
|
47
|
+
"types": "./dist/mcp.d.ts",
|
|
48
|
+
"require": "./dist/mcp.js",
|
|
49
|
+
"import": "./dist/mcp.js"
|
|
45
50
|
}
|
|
46
51
|
},
|
|
47
52
|
"keywords": [],
|
|
@@ -58,8 +63,11 @@
|
|
|
58
63
|
"description": "A home for your AI agents",
|
|
59
64
|
"dependencies": {
|
|
60
65
|
"cron-schedule": "^5.0.4",
|
|
61
|
-
"nanoid": "^5.1.
|
|
62
|
-
"partyserver": "^0.0.
|
|
66
|
+
"nanoid": "^5.1.5",
|
|
67
|
+
"partyserver": "^0.0.66",
|
|
63
68
|
"partysocket": "0.0.0-548c226"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@modelcontextprotocol/sdk": "^1.7.0"
|
|
64
72
|
}
|
|
65
73
|
}
|