agents 0.0.0-74a8c74 → 0.0.0-7b22285
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/dist/ai-chat-agent.d.ts +0 -1
- package/dist/ai-chat-agent.js +60 -63
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.js +18 -9
- package/dist/ai-react.js.map +1 -1
- package/dist/chunk-HMLY7DHA.js +16 -0
- package/dist/chunk-HMLY7DHA.js.map +1 -0
- package/dist/{chunk-SZEXGW6W.js → chunk-XG52S6YY.js} +151 -140
- package/dist/chunk-XG52S6YY.js.map +1 -0
- package/dist/client.js +43 -43
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +2 -3
- package/dist/mcp/client.d.ts +110 -22
- package/dist/mcp/client.js +193 -571
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +41 -0
- package/dist/mcp/do-oauth-client-provider.js +107 -0
- package/dist/mcp/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/index.d.ts +8 -4
- package/dist/mcp/index.js +268 -54
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.js +36 -27
- package/dist/react.js.map +1 -1
- package/dist/schedule.js +2 -0
- package/dist/schedule.js.map +1 -1
- package/package.json +7 -4
- package/src/index.ts +0 -7
- package/dist/chunk-EZ76ZGDB.js +0 -1721
- package/dist/chunk-EZ76ZGDB.js.map +0 -1
- package/dist/chunk-SZEXGW6W.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__privateAdd,
|
|
3
|
+
__privateGet,
|
|
4
|
+
__privateSet
|
|
5
|
+
} from "./chunk-HMLY7DHA.js";
|
|
6
|
+
|
|
1
7
|
// src/client.ts
|
|
2
8
|
import {
|
|
3
9
|
PartySocket
|
|
4
10
|
} from "partysocket";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
static fetch(_opts) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
"AgentClient.fetch is not implemented, use agentFetch instead"
|
|
12
|
-
);
|
|
11
|
+
function camelCaseToKebabCase(str) {
|
|
12
|
+
if (str === str.toUpperCase() && str !== str.toLowerCase()) {
|
|
13
|
+
return str.toLowerCase().replace(/_/g, "-");
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let kebabified = str.replace(
|
|
16
|
+
/[A-Z]/g,
|
|
17
|
+
(letter) => `-${letter.toLowerCase()}`
|
|
18
|
+
);
|
|
19
|
+
kebabified = kebabified.startsWith("-") ? kebabified.slice(1) : kebabified;
|
|
20
|
+
return kebabified.replace(/_/g, "-").replace(/-$/, "");
|
|
21
|
+
}
|
|
22
|
+
var _options, _pendingCalls;
|
|
23
|
+
var AgentClient = class extends PartySocket {
|
|
18
24
|
constructor(options) {
|
|
25
|
+
const agentNamespace = camelCaseToKebabCase(options.agent);
|
|
19
26
|
super({
|
|
20
27
|
prefix: "agents",
|
|
21
|
-
party:
|
|
28
|
+
party: agentNamespace,
|
|
22
29
|
room: options.name || "default",
|
|
23
30
|
...options
|
|
24
31
|
});
|
|
25
|
-
this
|
|
32
|
+
__privateAdd(this, _options);
|
|
33
|
+
__privateAdd(this, _pendingCalls, /* @__PURE__ */ new Map());
|
|
34
|
+
this.agent = agentNamespace;
|
|
26
35
|
this.name = options.name || "default";
|
|
27
|
-
this
|
|
28
|
-
if (this.agent !== this.agent.toLowerCase()) {
|
|
29
|
-
console.warn(
|
|
30
|
-
`Agent name: ${this.agent} should probably be in lowercase. Received: ${this.agent}`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
if (this.name !== this.name.toLowerCase()) {
|
|
34
|
-
console.warn(
|
|
35
|
-
`Agent instance name: ${this.name} should probably be in lowercase. Received: ${this.name}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
36
|
+
__privateSet(this, _options, options);
|
|
38
37
|
this.addEventListener("message", (event) => {
|
|
39
38
|
if (typeof event.data === "string") {
|
|
40
39
|
let parsedMessage;
|
|
@@ -44,38 +43,46 @@ var AgentClient = class extends PartySocket {
|
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
46
45
|
if (parsedMessage.type === "cf_agent_state") {
|
|
47
|
-
this
|
|
46
|
+
__privateGet(this, _options).onStateUpdate?.(parsedMessage.state, "server");
|
|
48
47
|
return;
|
|
49
48
|
}
|
|
50
49
|
if (parsedMessage.type === "rpc") {
|
|
51
50
|
const response = parsedMessage;
|
|
52
|
-
const pending = this
|
|
51
|
+
const pending = __privateGet(this, _pendingCalls).get(response.id);
|
|
53
52
|
if (!pending) return;
|
|
54
53
|
if (!response.success) {
|
|
55
54
|
pending.reject(new Error(response.error));
|
|
56
|
-
this
|
|
55
|
+
__privateGet(this, _pendingCalls).delete(response.id);
|
|
57
56
|
pending.stream?.onError?.(response.error);
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
if ("done" in response) {
|
|
61
60
|
if (response.done) {
|
|
62
61
|
pending.resolve(response.result);
|
|
63
|
-
this
|
|
62
|
+
__privateGet(this, _pendingCalls).delete(response.id);
|
|
64
63
|
pending.stream?.onDone?.(response.result);
|
|
65
64
|
} else {
|
|
66
65
|
pending.stream?.onChunk?.(response.result);
|
|
67
66
|
}
|
|
68
67
|
} else {
|
|
69
68
|
pending.resolve(response.result);
|
|
70
|
-
this
|
|
69
|
+
__privateGet(this, _pendingCalls).delete(response.id);
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use agentFetch instead
|
|
77
|
+
*/
|
|
78
|
+
static fetch(_opts) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
"AgentClient.fetch is not implemented, use agentFetch instead"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
76
83
|
setState(state) {
|
|
77
84
|
this.send(JSON.stringify({ type: "cf_agent_state", state }));
|
|
78
|
-
this
|
|
85
|
+
__privateGet(this, _options).onStateUpdate?.(state, "client");
|
|
79
86
|
}
|
|
80
87
|
/**
|
|
81
88
|
* Call a method on the Agent
|
|
@@ -87,7 +94,7 @@ var AgentClient = class extends PartySocket {
|
|
|
87
94
|
async call(method, args = [], streamOptions) {
|
|
88
95
|
return new Promise((resolve, reject) => {
|
|
89
96
|
const id = Math.random().toString(36).slice(2);
|
|
90
|
-
this
|
|
97
|
+
__privateGet(this, _pendingCalls).set(id, {
|
|
91
98
|
resolve: (value) => resolve(value),
|
|
92
99
|
reject,
|
|
93
100
|
stream: streamOptions,
|
|
@@ -103,21 +110,14 @@ var AgentClient = class extends PartySocket {
|
|
|
103
110
|
});
|
|
104
111
|
}
|
|
105
112
|
};
|
|
113
|
+
_options = new WeakMap();
|
|
114
|
+
_pendingCalls = new WeakMap();
|
|
106
115
|
function agentFetch(opts, init) {
|
|
107
|
-
|
|
108
|
-
console.warn(
|
|
109
|
-
`Agent name: ${opts.agent} should probably be in lowercase. Received: ${opts.agent}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
if (opts.name && opts.name !== opts.name.toLowerCase()) {
|
|
113
|
-
console.warn(
|
|
114
|
-
`Agent instance name: ${opts.name} should probably be in lowercase. Received: ${opts.name}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
116
|
+
const agentNamespace = camelCaseToKebabCase(opts.agent);
|
|
117
117
|
return PartySocket.fetch(
|
|
118
118
|
{
|
|
119
119
|
prefix: "agents",
|
|
120
|
-
party:
|
|
120
|
+
party: agentNamespace,
|
|
121
121
|
room: opts.name || "default",
|
|
122
122
|
...opts
|
|
123
123
|
},
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {\n PartySocket,\n type PartySocketOptions,\n type PartyFetchOptions,\n} from \"partysocket\";\nimport type { RPCRequest, RPCResponse } from \"./\";\n\n/**\n * Options for creating an AgentClient\n */\nexport type AgentClientOptions<State = unknown> = Omit<\n PartySocketOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n /** Called when the Agent's state is updated */\n onStateUpdate?: (state: State, source: \"server\" | \"client\") => void;\n};\n\n/**\n * Options for streaming RPC calls\n */\nexport type StreamOptions = {\n /** Called when a chunk of data is received */\n onChunk?: (chunk: unknown) => void;\n /** Called when the stream ends */\n onDone?: (finalChunk: unknown) => void;\n /** Called when an error occurs */\n onError?: (error: string) => void;\n};\n\n/**\n * Options for the agentFetch function\n */\nexport type AgentClientFetchOptions = Omit<\n PartyFetchOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n};\n\n/**\n * WebSocket client for connecting to an Agent\n */\nexport class AgentClient<State = unknown> extends PartySocket {\n /**\n * @deprecated Use agentFetch instead\n */\n static fetch(_opts: PartyFetchOptions): Promise<Response> {\n throw new Error(\n \"AgentClient.fetch is not implemented, use agentFetch instead\"\n );\n }\n agent: string;\n name: string;\n #options: AgentClientOptions<State>;\n #pendingCalls = new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n stream?: StreamOptions;\n type?: unknown;\n }\n >();\n\n constructor(options: AgentClientOptions<State>) {\n super({\n prefix: \"agents\",\n party:
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {\n PartySocket,\n type PartySocketOptions,\n type PartyFetchOptions,\n} from \"partysocket\";\nimport type { RPCRequest, RPCResponse } from \"./\";\n\n/**\n * Options for creating an AgentClient\n */\nexport type AgentClientOptions<State = unknown> = Omit<\n PartySocketOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n /** Called when the Agent's state is updated */\n onStateUpdate?: (state: State, source: \"server\" | \"client\") => void;\n};\n\n/**\n * Options for streaming RPC calls\n */\nexport type StreamOptions = {\n /** Called when a chunk of data is received */\n onChunk?: (chunk: unknown) => void;\n /** Called when the stream ends */\n onDone?: (finalChunk: unknown) => void;\n /** Called when an error occurs */\n onError?: (error: string) => void;\n};\n\n/**\n * Options for the agentFetch function\n */\nexport type AgentClientFetchOptions = Omit<\n PartyFetchOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n};\n\n/**\n * Convert a camelCase string to a kebab-case string\n * @param str The string to convert\n * @returns The kebab-case string\n */\nfunction camelCaseToKebabCase(str: string): string {\n // If string is all uppercase, convert to lowercase\n if (str === str.toUpperCase() && str !== str.toLowerCase()) {\n return str.toLowerCase().replace(/_/g, \"-\");\n }\n\n // Otherwise handle camelCase to kebab-case\n let kebabified = str.replace(\n /[A-Z]/g,\n (letter) => `-${letter.toLowerCase()}`\n );\n kebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n // Convert any remaining underscores to hyphens and remove trailing -'s\n return kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n\n/**\n * WebSocket client for connecting to an Agent\n */\nexport class AgentClient<State = unknown> extends PartySocket {\n /**\n * @deprecated Use agentFetch instead\n */\n static fetch(_opts: PartyFetchOptions): Promise<Response> {\n throw new Error(\n \"AgentClient.fetch is not implemented, use agentFetch instead\"\n );\n }\n agent: string;\n name: string;\n #options: AgentClientOptions<State>;\n #pendingCalls = new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n stream?: StreamOptions;\n type?: unknown;\n }\n >();\n\n constructor(options: AgentClientOptions<State>) {\n const agentNamespace = camelCaseToKebabCase(options.agent);\n super({\n prefix: \"agents\",\n party: agentNamespace,\n room: options.name || \"default\",\n ...options,\n });\n this.agent = agentNamespace;\n this.name = options.name || \"default\";\n this.#options = options;\n\n this.addEventListener(\"message\", (event) => {\n if (typeof event.data === \"string\") {\n let parsedMessage: Record<string, unknown>;\n try {\n parsedMessage = JSON.parse(event.data);\n } catch (error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (parsedMessage.type === \"cf_agent_state\") {\n this.#options.onStateUpdate?.(parsedMessage.state as State, \"server\");\n return;\n }\n if (parsedMessage.type === \"rpc\") {\n const response = parsedMessage as RPCResponse;\n const pending = this.#pendingCalls.get(response.id);\n if (!pending) return;\n\n if (!response.success) {\n pending.reject(new Error(response.error));\n this.#pendingCalls.delete(response.id);\n pending.stream?.onError?.(response.error);\n return;\n }\n\n // Handle streaming responses\n if (\"done\" in response) {\n if (response.done) {\n pending.resolve(response.result);\n this.#pendingCalls.delete(response.id);\n pending.stream?.onDone?.(response.result);\n } else {\n pending.stream?.onChunk?.(response.result);\n }\n } else {\n // Non-streaming response\n pending.resolve(response.result);\n this.#pendingCalls.delete(response.id);\n }\n }\n }\n });\n }\n\n setState(state: State) {\n this.send(JSON.stringify({ type: \"cf_agent_state\", state }));\n this.#options.onStateUpdate?.(state, \"client\");\n }\n\n /**\n * Call a method on the Agent\n * @param method Name of the method to call\n * @param args Arguments to pass to the method\n * @param streamOptions Options for handling streaming responses\n * @returns Promise that resolves with the method's return value\n */\n async call<T = unknown>(\n method: string,\n args: unknown[] = [],\n streamOptions?: StreamOptions\n ): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const id = Math.random().toString(36).slice(2);\n this.#pendingCalls.set(id, {\n resolve: (value: unknown) => resolve(value as T),\n reject,\n stream: streamOptions,\n type: null as T,\n });\n\n const request: RPCRequest = {\n type: \"rpc\",\n id,\n method,\n args,\n };\n\n this.send(JSON.stringify(request));\n });\n }\n}\n\n/**\n * Make an HTTP request to an Agent\n * @param opts Connection options\n * @param init Request initialization options\n * @returns Promise resolving to a Response\n */\nexport function agentFetch(opts: AgentClientFetchOptions, init?: RequestInit) {\n const agentNamespace = camelCaseToKebabCase(opts.agent);\n\n return PartySocket.fetch(\n {\n prefix: \"agents\",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AK,UAAU,OAAO,CAAC;AAAA,IACnC,CAAC;AAAA,EACH;AACF;AAxGE;AACA;AA+GK,SAAS,WAAW,MAA+B,MAAoB;AAC5E,QAAM,iBAAiB,qBAAqB,KAAK,KAAK;AAEtD,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,MAAM,KAAK,QAAQ;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
2
2
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
import { WorkflowEntrypoint as WorkflowEntrypoint$1 } from "cloudflare:workers";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* RPC request message from client
|
|
@@ -60,10 +59,6 @@ declare function unstable_callable(
|
|
|
60
59
|
target: (this: This, ...args: Args) => Return,
|
|
61
60
|
context: ClassMethodDecoratorContext
|
|
62
61
|
) => (this: This, ...args: Args) => Return;
|
|
63
|
-
/**
|
|
64
|
-
* A class for creating workflow entry points that can be used with Cloudflare Workers
|
|
65
|
-
*/
|
|
66
|
-
declare class WorkflowEntrypoint extends WorkflowEntrypoint$1 {}
|
|
67
62
|
/**
|
|
68
63
|
* Represents a scheduled task within an Agent
|
|
69
64
|
* @template T Type of the payload data
|
|
@@ -299,7 +294,6 @@ export {
|
|
|
299
294
|
type Schedule,
|
|
300
295
|
type StateUpdateMessage,
|
|
301
296
|
StreamingResponse,
|
|
302
|
-
WorkflowEntrypoint,
|
|
303
297
|
getAgentByName,
|
|
304
298
|
routeAgentEmail,
|
|
305
299
|
routeAgentRequest,
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
-
WorkflowEntrypoint,
|
|
5
4
|
getAgentByName,
|
|
6
5
|
routeAgentEmail,
|
|
7
6
|
routeAgentRequest,
|
|
8
7
|
unstable_callable,
|
|
9
8
|
unstable_context
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XG52S6YY.js";
|
|
10
|
+
import "./chunk-HMLY7DHA.js";
|
|
11
11
|
export {
|
|
12
12
|
Agent,
|
|
13
13
|
StreamingResponse,
|
|
14
|
-
WorkflowEntrypoint,
|
|
15
14
|
getAgentByName,
|
|
16
15
|
routeAgentEmail,
|
|
17
16
|
routeAgentRequest,
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
1
|
import * as zod from 'zod';
|
|
2
|
-
import { Tool, Prompt
|
|
2
|
+
import { ClientCapabilities, Tool, Prompt, Resource, ResourceTemplate, ServerCapabilities, CallToolRequest, CallToolResultSchema, CompatibilityCallToolResultSchema, ReadResourceRequest, GetPromptRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
5
|
+
import { AgentsOAuthProvider } from './do-oauth-client-provider.js';
|
|
5
6
|
import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
7
|
+
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
8
|
+
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
6
9
|
|
|
7
10
|
declare class MCPClientConnection {
|
|
8
|
-
|
|
11
|
+
url: URL;
|
|
12
|
+
options: {
|
|
13
|
+
transport: SSEClientTransportOptions & {
|
|
14
|
+
authProvider?: AgentsOAuthProvider;
|
|
15
|
+
};
|
|
16
|
+
client: ConstructorParameters<typeof Client>[1];
|
|
17
|
+
capabilities: ClientCapabilities;
|
|
18
|
+
};
|
|
9
19
|
client: Client;
|
|
10
|
-
|
|
11
|
-
connected: boolean;
|
|
20
|
+
connectionState: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
|
|
12
21
|
instructions?: string;
|
|
13
22
|
tools: Tool[];
|
|
14
|
-
prompts: Prompt
|
|
23
|
+
prompts: Prompt[];
|
|
15
24
|
resources: Resource[];
|
|
16
25
|
resourceTemplates: ResourceTemplate[];
|
|
17
26
|
serverCapabilities: ServerCapabilities | undefined;
|
|
18
|
-
constructor(url: URL, info: ConstructorParameters<typeof Client>[0],
|
|
19
|
-
transport: SSEClientTransportOptions
|
|
27
|
+
constructor(url: URL, info: ConstructorParameters<typeof Client>[0], options?: {
|
|
28
|
+
transport: SSEClientTransportOptions & {
|
|
29
|
+
authProvider?: AgentsOAuthProvider;
|
|
30
|
+
};
|
|
20
31
|
client: ConstructorParameters<typeof Client>[1];
|
|
21
32
|
capabilities: ClientCapabilities;
|
|
22
33
|
});
|
|
23
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Initialize a client connection
|
|
36
|
+
*
|
|
37
|
+
* @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
init(code?: string, clientId?: string): Promise<void>;
|
|
24
41
|
/**
|
|
25
42
|
* Notification handler registration
|
|
26
43
|
*/
|
|
27
44
|
registerTools(): Promise<Tool[]>;
|
|
28
45
|
registerResources(): Promise<Resource[]>;
|
|
29
|
-
registerPrompts(): Promise<Prompt
|
|
46
|
+
registerPrompts(): Promise<Prompt[]>;
|
|
30
47
|
registerResourceTemplates(): Promise<ResourceTemplate[]>;
|
|
31
48
|
fetchTools(): Promise<{
|
|
32
49
|
[x: string]: unknown;
|
|
@@ -71,7 +88,16 @@ declare class MCPClientConnection {
|
|
|
71
88
|
* Utility class that aggregates multiple MCP clients into one
|
|
72
89
|
*/
|
|
73
90
|
declare class MCPClientManager {
|
|
91
|
+
private name;
|
|
92
|
+
private version;
|
|
74
93
|
mcpConnections: Record<string, MCPClientConnection>;
|
|
94
|
+
private callbackUrls;
|
|
95
|
+
/**
|
|
96
|
+
* @param name Name of the MCP client
|
|
97
|
+
* @param version Version of the MCP Client
|
|
98
|
+
* @param auth Auth paramters if being used to create a DurableObjectOAuthClientProvider
|
|
99
|
+
*/
|
|
100
|
+
constructor(name: string, version: string);
|
|
75
101
|
/**
|
|
76
102
|
* Connect to and register an MCP server
|
|
77
103
|
*
|
|
@@ -79,11 +105,25 @@ declare class MCPClientManager {
|
|
|
79
105
|
* @param clientConfig Client config
|
|
80
106
|
* @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
|
|
81
107
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
connect(url: string, options?: {
|
|
109
|
+
reconnect?: {
|
|
110
|
+
id: string;
|
|
111
|
+
oauthClientId?: string;
|
|
112
|
+
oauthCode?: string;
|
|
113
|
+
};
|
|
114
|
+
transport?: SSEClientTransportOptions & {
|
|
115
|
+
authProvider?: AgentsOAuthProvider;
|
|
116
|
+
};
|
|
117
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
118
|
+
capabilities?: ClientCapabilities;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
id: string;
|
|
121
|
+
authUrl: string | undefined;
|
|
122
|
+
}>;
|
|
123
|
+
isCallbackRequest(req: Request): boolean;
|
|
124
|
+
handleCallbackRequest(req: Request): Promise<{
|
|
125
|
+
serverId: string;
|
|
126
|
+
}>;
|
|
87
127
|
/**
|
|
88
128
|
* @returns namespaced list of tools
|
|
89
129
|
*/
|
|
@@ -104,7 +144,7 @@ declare class MCPClientManager {
|
|
|
104
144
|
* Namespaced version of callTool
|
|
105
145
|
*/
|
|
106
146
|
callTool(params: CallToolRequest["params"] & {
|
|
107
|
-
|
|
147
|
+
serverId: string;
|
|
108
148
|
}, resultSchema: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema, options: RequestOptions): Promise<zod.objectOutputType<zod.objectUtil.extendShape<{
|
|
109
149
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
110
150
|
}, {
|
|
@@ -129,6 +169,18 @@ declare class MCPClientManager {
|
|
|
129
169
|
type: zod.ZodLiteral<"image">;
|
|
130
170
|
data: zod.ZodString;
|
|
131
171
|
mimeType: zod.ZodString;
|
|
172
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
173
|
+
type: zod.ZodLiteral<"audio">;
|
|
174
|
+
data: zod.ZodString;
|
|
175
|
+
mimeType: zod.ZodString;
|
|
176
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
177
|
+
type: zod.ZodLiteral<"audio">;
|
|
178
|
+
data: zod.ZodString;
|
|
179
|
+
mimeType: zod.ZodString;
|
|
180
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
181
|
+
type: zod.ZodLiteral<"audio">;
|
|
182
|
+
data: zod.ZodString;
|
|
183
|
+
mimeType: zod.ZodString;
|
|
132
184
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
133
185
|
type: zod.ZodLiteral<"resource">;
|
|
134
186
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -239,7 +291,7 @@ declare class MCPClientManager {
|
|
|
239
291
|
* Namespaced version of readResource
|
|
240
292
|
*/
|
|
241
293
|
readResource(params: ReadResourceRequest["params"] & {
|
|
242
|
-
|
|
294
|
+
serverId: string;
|
|
243
295
|
}, options: RequestOptions): Promise<zod.objectOutputType<zod.objectUtil.extendShape<{
|
|
244
296
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
245
297
|
}, {
|
|
@@ -279,7 +331,7 @@ declare class MCPClientManager {
|
|
|
279
331
|
* Namespaced version of getPrompt
|
|
280
332
|
*/
|
|
281
333
|
getPrompt(params: GetPromptRequest["params"] & {
|
|
282
|
-
|
|
334
|
+
serverId: string;
|
|
283
335
|
}, options: RequestOptions): Promise<zod.objectOutputType<zod.objectUtil.extendShape<{
|
|
284
336
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
285
337
|
}, {
|
|
@@ -307,6 +359,18 @@ declare class MCPClientManager {
|
|
|
307
359
|
type: zod.ZodLiteral<"image">;
|
|
308
360
|
data: zod.ZodString;
|
|
309
361
|
mimeType: zod.ZodString;
|
|
362
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
363
|
+
type: zod.ZodLiteral<"audio">;
|
|
364
|
+
data: zod.ZodString;
|
|
365
|
+
mimeType: zod.ZodString;
|
|
366
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
367
|
+
type: zod.ZodLiteral<"audio">;
|
|
368
|
+
data: zod.ZodString;
|
|
369
|
+
mimeType: zod.ZodString;
|
|
370
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
371
|
+
type: zod.ZodLiteral<"audio">;
|
|
372
|
+
data: zod.ZodString;
|
|
373
|
+
mimeType: zod.ZodString;
|
|
310
374
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
311
375
|
type: zod.ZodLiteral<"resource">;
|
|
312
376
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -430,6 +494,18 @@ declare class MCPClientManager {
|
|
|
430
494
|
type: zod.ZodLiteral<"image">;
|
|
431
495
|
data: zod.ZodString;
|
|
432
496
|
mimeType: zod.ZodString;
|
|
497
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
498
|
+
type: zod.ZodLiteral<"audio">;
|
|
499
|
+
data: zod.ZodString;
|
|
500
|
+
mimeType: zod.ZodString;
|
|
501
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
502
|
+
type: zod.ZodLiteral<"audio">;
|
|
503
|
+
data: zod.ZodString;
|
|
504
|
+
mimeType: zod.ZodString;
|
|
505
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
506
|
+
type: zod.ZodLiteral<"audio">;
|
|
507
|
+
data: zod.ZodString;
|
|
508
|
+
mimeType: zod.ZodString;
|
|
433
509
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
434
510
|
type: zod.ZodLiteral<"resource">;
|
|
435
511
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -553,6 +629,18 @@ declare class MCPClientManager {
|
|
|
553
629
|
type: zod.ZodLiteral<"image">;
|
|
554
630
|
data: zod.ZodString;
|
|
555
631
|
mimeType: zod.ZodString;
|
|
632
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
633
|
+
type: zod.ZodLiteral<"audio">;
|
|
634
|
+
data: zod.ZodString;
|
|
635
|
+
mimeType: zod.ZodString;
|
|
636
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
637
|
+
type: zod.ZodLiteral<"audio">;
|
|
638
|
+
data: zod.ZodString;
|
|
639
|
+
mimeType: zod.ZodString;
|
|
640
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
641
|
+
type: zod.ZodLiteral<"audio">;
|
|
642
|
+
data: zod.ZodString;
|
|
643
|
+
mimeType: zod.ZodString;
|
|
556
644
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
557
645
|
type: zod.ZodLiteral<"resource">;
|
|
558
646
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -658,16 +746,16 @@ declare class MCPClientManager {
|
|
|
658
746
|
}
|
|
659
747
|
type NamespacedData = {
|
|
660
748
|
tools: (Tool & {
|
|
661
|
-
|
|
749
|
+
serverId: string;
|
|
662
750
|
})[];
|
|
663
751
|
prompts: (Prompt & {
|
|
664
|
-
|
|
752
|
+
serverId: string;
|
|
665
753
|
})[];
|
|
666
754
|
resources: (Resource & {
|
|
667
|
-
|
|
755
|
+
serverId: string;
|
|
668
756
|
})[];
|
|
669
757
|
resourceTemplates: (ResourceTemplate & {
|
|
670
|
-
|
|
758
|
+
serverId: string;
|
|
671
759
|
})[];
|
|
672
760
|
};
|
|
673
761
|
declare function getNamespacedData<T extends keyof NamespacedData>(mcpClients: Record<string, MCPClientConnection>, type: T): NamespacedData[T];
|