agents 0.0.0-74a8c74 → 0.0.0-7bd597a
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 +22 -3
- package/dist/ai-chat-agent.js +127 -64
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.js +39 -22
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +5 -0
- package/dist/{chunk-SZEXGW6W.js → chunk-HD4VEHBA.js} +175 -147
- package/dist/chunk-HD4VEHBA.js.map +1 -0
- package/dist/chunk-HMLY7DHA.js +16 -0
- package/dist/chunk-HMLY7DHA.js.map +1 -0
- package/dist/chunk-Q5ZBHY4Z.js +456 -0
- package/dist/chunk-Q5ZBHY4Z.js.map +1 -0
- package/dist/client.js +43 -43
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +18 -12
- package/dist/index.js +7 -7
- package/dist/mcp/client.d.ts +138 -36
- package/dist/mcp/client.js +4 -780
- 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 +39 -6
- package/dist/mcp/index.js +736 -62
- 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 +25 -5
- package/src/index.ts +38 -15
- 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.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\",\n party: agentNamespace,\n room: opts.name || \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A,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,15 @@
|
|
|
1
1
|
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
2
2
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { MCPClientManager } from "./mcp/client.js";
|
|
4
|
+
import "zod";
|
|
5
|
+
import "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import "./mcp/do-oauth-client-provider.js";
|
|
9
|
+
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
10
|
+
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
11
|
+
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
12
|
+
import "ai";
|
|
5
13
|
|
|
6
14
|
/**
|
|
7
15
|
* RPC request message from client
|
|
@@ -60,10 +68,6 @@ declare function unstable_callable(
|
|
|
60
68
|
target: (this: This, ...args: Args) => Return,
|
|
61
69
|
context: ClassMethodDecoratorContext
|
|
62
70
|
) => (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
71
|
/**
|
|
68
72
|
* Represents a scheduled task within an Agent
|
|
69
73
|
* @template T Type of the payload data
|
|
@@ -99,11 +103,13 @@ type Schedule<T = string> = {
|
|
|
99
103
|
cron: string;
|
|
100
104
|
}
|
|
101
105
|
);
|
|
102
|
-
declare
|
|
103
|
-
|
|
106
|
+
declare function getCurrentAgent<
|
|
107
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
|
|
108
|
+
>(): {
|
|
109
|
+
agent: T | undefined;
|
|
104
110
|
connection: Connection | undefined;
|
|
105
|
-
request: Request | undefined;
|
|
106
|
-
}
|
|
111
|
+
request: Request<unknown, CfProperties<unknown>> | undefined;
|
|
112
|
+
};
|
|
107
113
|
/**
|
|
108
114
|
* Base class for creating Agent implementations
|
|
109
115
|
* @template Env Environment type containing bindings
|
|
@@ -111,6 +117,7 @@ declare const unstable_context: AsyncLocalStorage<{
|
|
|
111
117
|
*/
|
|
112
118
|
declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
113
119
|
#private;
|
|
120
|
+
mcp: MCPClientManager;
|
|
114
121
|
/**
|
|
115
122
|
* Initial state for the Agent
|
|
116
123
|
* Override to provide default state values
|
|
@@ -299,10 +306,9 @@ export {
|
|
|
299
306
|
type Schedule,
|
|
300
307
|
type StateUpdateMessage,
|
|
301
308
|
StreamingResponse,
|
|
302
|
-
WorkflowEntrypoint,
|
|
303
309
|
getAgentByName,
|
|
310
|
+
getCurrentAgent,
|
|
304
311
|
routeAgentEmail,
|
|
305
312
|
routeAgentRequest,
|
|
306
313
|
unstable_callable,
|
|
307
|
-
unstable_context,
|
|
308
314
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
-
WorkflowEntrypoint,
|
|
5
4
|
getAgentByName,
|
|
5
|
+
getCurrentAgent,
|
|
6
6
|
routeAgentEmail,
|
|
7
7
|
routeAgentRequest,
|
|
8
|
-
unstable_callable
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
unstable_callable
|
|
9
|
+
} from "./chunk-HD4VEHBA.js";
|
|
10
|
+
import "./chunk-Q5ZBHY4Z.js";
|
|
11
|
+
import "./chunk-HMLY7DHA.js";
|
|
11
12
|
export {
|
|
12
13
|
Agent,
|
|
13
14
|
StreamingResponse,
|
|
14
|
-
WorkflowEntrypoint,
|
|
15
15
|
getAgentByName,
|
|
16
|
+
getCurrentAgent,
|
|
16
17
|
routeAgentEmail,
|
|
17
18
|
routeAgentRequest,
|
|
18
|
-
unstable_callable
|
|
19
|
-
unstable_context
|
|
19
|
+
unstable_callable
|
|
20
20
|
};
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
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 { ToolSet } from 'ai';
|
|
8
|
+
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
9
|
+
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
6
10
|
|
|
7
11
|
declare class MCPClientConnection {
|
|
8
|
-
|
|
12
|
+
url: URL;
|
|
13
|
+
options: {
|
|
14
|
+
transport: SSEClientTransportOptions & {
|
|
15
|
+
authProvider?: AgentsOAuthProvider;
|
|
16
|
+
};
|
|
17
|
+
client: ConstructorParameters<typeof Client>[1];
|
|
18
|
+
capabilities: ClientCapabilities;
|
|
19
|
+
};
|
|
9
20
|
client: Client;
|
|
10
|
-
|
|
11
|
-
connected: boolean;
|
|
21
|
+
connectionState: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
|
|
12
22
|
instructions?: string;
|
|
13
23
|
tools: Tool[];
|
|
14
|
-
prompts: Prompt
|
|
24
|
+
prompts: Prompt[];
|
|
15
25
|
resources: Resource[];
|
|
16
26
|
resourceTemplates: ResourceTemplate[];
|
|
17
27
|
serverCapabilities: ServerCapabilities | undefined;
|
|
18
|
-
constructor(url: URL, info: ConstructorParameters<typeof Client>[0],
|
|
19
|
-
transport: SSEClientTransportOptions
|
|
28
|
+
constructor(url: URL, info: ConstructorParameters<typeof Client>[0], options?: {
|
|
29
|
+
transport: SSEClientTransportOptions & {
|
|
30
|
+
authProvider?: AgentsOAuthProvider;
|
|
31
|
+
};
|
|
20
32
|
client: ConstructorParameters<typeof Client>[1];
|
|
21
33
|
capabilities: ClientCapabilities;
|
|
22
34
|
});
|
|
23
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Initialize a client connection
|
|
37
|
+
*
|
|
38
|
+
* @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
init(code?: string, clientId?: string): Promise<void>;
|
|
24
42
|
/**
|
|
25
43
|
* Notification handler registration
|
|
26
44
|
*/
|
|
27
45
|
registerTools(): Promise<Tool[]>;
|
|
28
46
|
registerResources(): Promise<Resource[]>;
|
|
29
|
-
registerPrompts(): Promise<Prompt
|
|
47
|
+
registerPrompts(): Promise<Prompt[]>;
|
|
30
48
|
registerResourceTemplates(): Promise<ResourceTemplate[]>;
|
|
31
49
|
fetchTools(): Promise<{
|
|
32
50
|
[x: string]: unknown;
|
|
@@ -42,10 +60,10 @@ declare class MCPClientConnection {
|
|
|
42
60
|
}[]>;
|
|
43
61
|
fetchResources(): Promise<{
|
|
44
62
|
[x: string]: unknown;
|
|
45
|
-
name: string;
|
|
46
63
|
uri: string;
|
|
47
|
-
|
|
64
|
+
name: string;
|
|
48
65
|
mimeType?: string | undefined;
|
|
66
|
+
description?: string | undefined;
|
|
49
67
|
}[]>;
|
|
50
68
|
fetchPrompts(): Promise<{
|
|
51
69
|
[x: string]: unknown;
|
|
@@ -62,8 +80,8 @@ declare class MCPClientConnection {
|
|
|
62
80
|
[x: string]: unknown;
|
|
63
81
|
name: string;
|
|
64
82
|
uriTemplate: string;
|
|
65
|
-
description?: string | undefined;
|
|
66
83
|
mimeType?: string | undefined;
|
|
84
|
+
description?: string | undefined;
|
|
67
85
|
}[]>;
|
|
68
86
|
}
|
|
69
87
|
|
|
@@ -71,7 +89,16 @@ declare class MCPClientConnection {
|
|
|
71
89
|
* Utility class that aggregates multiple MCP clients into one
|
|
72
90
|
*/
|
|
73
91
|
declare class MCPClientManager {
|
|
92
|
+
private name;
|
|
93
|
+
private version;
|
|
74
94
|
mcpConnections: Record<string, MCPClientConnection>;
|
|
95
|
+
private callbackUrls;
|
|
96
|
+
/**
|
|
97
|
+
* @param name Name of the MCP client
|
|
98
|
+
* @param version Version of the MCP Client
|
|
99
|
+
* @param auth Auth paramters if being used to create a DurableObjectOAuthClientProvider
|
|
100
|
+
*/
|
|
101
|
+
constructor(name: string, version: string);
|
|
75
102
|
/**
|
|
76
103
|
* Connect to and register an MCP server
|
|
77
104
|
*
|
|
@@ -79,15 +106,42 @@ declare class MCPClientManager {
|
|
|
79
106
|
* @param clientConfig Client config
|
|
80
107
|
* @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
|
|
81
108
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
109
|
+
connect(url: string, options?: {
|
|
110
|
+
reconnect?: {
|
|
111
|
+
id: string;
|
|
112
|
+
oauthClientId?: string;
|
|
113
|
+
oauthCode?: string;
|
|
114
|
+
};
|
|
115
|
+
transport?: SSEClientTransportOptions & {
|
|
116
|
+
authProvider?: AgentsOAuthProvider;
|
|
117
|
+
};
|
|
118
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
119
|
+
capabilities?: ClientCapabilities;
|
|
120
|
+
}): Promise<{
|
|
121
|
+
id: string;
|
|
122
|
+
authUrl: string | undefined;
|
|
123
|
+
}>;
|
|
124
|
+
isCallbackRequest(req: Request): boolean;
|
|
125
|
+
handleCallbackRequest(req: Request): Promise<{
|
|
126
|
+
serverId: string;
|
|
127
|
+
}>;
|
|
87
128
|
/**
|
|
88
129
|
* @returns namespaced list of tools
|
|
89
130
|
*/
|
|
90
131
|
listTools(): NamespacedData["tools"];
|
|
132
|
+
/**
|
|
133
|
+
* @returns a set of tools that you can use with the AI SDK
|
|
134
|
+
*/
|
|
135
|
+
unstable_getAITools(): ToolSet;
|
|
136
|
+
/**
|
|
137
|
+
* Closes all connections to MCP servers
|
|
138
|
+
*/
|
|
139
|
+
closeAllConnections(): Promise<void[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Closes a connection to an MCP server
|
|
142
|
+
* @param id The id of the connection to close
|
|
143
|
+
*/
|
|
144
|
+
closeConnection(id: string): Promise<void>;
|
|
91
145
|
/**
|
|
92
146
|
* @returns namespaced list of prompts
|
|
93
147
|
*/
|
|
@@ -104,10 +158,10 @@ declare class MCPClientManager {
|
|
|
104
158
|
* Namespaced version of callTool
|
|
105
159
|
*/
|
|
106
160
|
callTool(params: CallToolRequest["params"] & {
|
|
107
|
-
|
|
108
|
-
}, resultSchema
|
|
161
|
+
serverId: string;
|
|
162
|
+
}, resultSchema?: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema, options?: RequestOptions): Promise<zod.objectOutputType<{
|
|
109
163
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
110
|
-
}
|
|
164
|
+
} & {
|
|
111
165
|
content: zod.ZodArray<zod.ZodUnion<[zod.ZodObject<{
|
|
112
166
|
type: zod.ZodLiteral<"text">;
|
|
113
167
|
text: zod.ZodString;
|
|
@@ -129,6 +183,18 @@ declare class MCPClientManager {
|
|
|
129
183
|
type: zod.ZodLiteral<"image">;
|
|
130
184
|
data: zod.ZodString;
|
|
131
185
|
mimeType: zod.ZodString;
|
|
186
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
187
|
+
type: zod.ZodLiteral<"audio">;
|
|
188
|
+
data: zod.ZodString;
|
|
189
|
+
mimeType: zod.ZodString;
|
|
190
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
191
|
+
type: zod.ZodLiteral<"audio">;
|
|
192
|
+
data: zod.ZodString;
|
|
193
|
+
mimeType: zod.ZodString;
|
|
194
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
195
|
+
type: zod.ZodLiteral<"audio">;
|
|
196
|
+
data: zod.ZodString;
|
|
197
|
+
mimeType: zod.ZodString;
|
|
132
198
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
133
199
|
type: zod.ZodLiteral<"resource">;
|
|
134
200
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -230,19 +296,19 @@ declare class MCPClientManager {
|
|
|
230
296
|
}>, zod.ZodTypeAny, "passthrough">>]>;
|
|
231
297
|
}, zod.ZodTypeAny, "passthrough">>]>, "many">;
|
|
232
298
|
isError: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
|
|
233
|
-
}
|
|
299
|
+
}, zod.ZodTypeAny, "passthrough"> | zod.objectOutputType<{
|
|
234
300
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
235
|
-
}
|
|
301
|
+
} & {
|
|
236
302
|
toolResult: zod.ZodUnknown;
|
|
237
|
-
}
|
|
303
|
+
}, zod.ZodTypeAny, "passthrough">>;
|
|
238
304
|
/**
|
|
239
305
|
* Namespaced version of readResource
|
|
240
306
|
*/
|
|
241
307
|
readResource(params: ReadResourceRequest["params"] & {
|
|
242
|
-
|
|
243
|
-
}, options: RequestOptions): Promise<zod.objectOutputType<
|
|
308
|
+
serverId: string;
|
|
309
|
+
}, options: RequestOptions): Promise<zod.objectOutputType<{
|
|
244
310
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
245
|
-
}
|
|
311
|
+
} & {
|
|
246
312
|
contents: zod.ZodArray<zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
247
313
|
uri: zod.ZodString;
|
|
248
314
|
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
@@ -274,15 +340,15 @@ declare class MCPClientManager {
|
|
|
274
340
|
}, {
|
|
275
341
|
blob: zod.ZodString;
|
|
276
342
|
}>, zod.ZodTypeAny, "passthrough">>]>, "many">;
|
|
277
|
-
}
|
|
343
|
+
}, zod.ZodTypeAny, "passthrough">>;
|
|
278
344
|
/**
|
|
279
345
|
* Namespaced version of getPrompt
|
|
280
346
|
*/
|
|
281
347
|
getPrompt(params: GetPromptRequest["params"] & {
|
|
282
|
-
|
|
283
|
-
}, options: RequestOptions): Promise<zod.objectOutputType<
|
|
348
|
+
serverId: string;
|
|
349
|
+
}, options: RequestOptions): Promise<zod.objectOutputType<{
|
|
284
350
|
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
285
|
-
}
|
|
351
|
+
} & {
|
|
286
352
|
description: zod.ZodOptional<zod.ZodString>;
|
|
287
353
|
messages: zod.ZodArray<zod.ZodObject<{
|
|
288
354
|
role: zod.ZodEnum<["user", "assistant"]>;
|
|
@@ -307,6 +373,18 @@ declare class MCPClientManager {
|
|
|
307
373
|
type: zod.ZodLiteral<"image">;
|
|
308
374
|
data: zod.ZodString;
|
|
309
375
|
mimeType: zod.ZodString;
|
|
376
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
377
|
+
type: zod.ZodLiteral<"audio">;
|
|
378
|
+
data: zod.ZodString;
|
|
379
|
+
mimeType: zod.ZodString;
|
|
380
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
381
|
+
type: zod.ZodLiteral<"audio">;
|
|
382
|
+
data: zod.ZodString;
|
|
383
|
+
mimeType: zod.ZodString;
|
|
384
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
385
|
+
type: zod.ZodLiteral<"audio">;
|
|
386
|
+
data: zod.ZodString;
|
|
387
|
+
mimeType: zod.ZodString;
|
|
310
388
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
311
389
|
type: zod.ZodLiteral<"resource">;
|
|
312
390
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -430,6 +508,18 @@ declare class MCPClientManager {
|
|
|
430
508
|
type: zod.ZodLiteral<"image">;
|
|
431
509
|
data: zod.ZodString;
|
|
432
510
|
mimeType: zod.ZodString;
|
|
511
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
512
|
+
type: zod.ZodLiteral<"audio">;
|
|
513
|
+
data: zod.ZodString;
|
|
514
|
+
mimeType: zod.ZodString;
|
|
515
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
516
|
+
type: zod.ZodLiteral<"audio">;
|
|
517
|
+
data: zod.ZodString;
|
|
518
|
+
mimeType: zod.ZodString;
|
|
519
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
520
|
+
type: zod.ZodLiteral<"audio">;
|
|
521
|
+
data: zod.ZodString;
|
|
522
|
+
mimeType: zod.ZodString;
|
|
433
523
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
434
524
|
type: zod.ZodLiteral<"resource">;
|
|
435
525
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -553,6 +643,18 @@ declare class MCPClientManager {
|
|
|
553
643
|
type: zod.ZodLiteral<"image">;
|
|
554
644
|
data: zod.ZodString;
|
|
555
645
|
mimeType: zod.ZodString;
|
|
646
|
+
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
647
|
+
type: zod.ZodLiteral<"audio">;
|
|
648
|
+
data: zod.ZodString;
|
|
649
|
+
mimeType: zod.ZodString;
|
|
650
|
+
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
651
|
+
type: zod.ZodLiteral<"audio">;
|
|
652
|
+
data: zod.ZodString;
|
|
653
|
+
mimeType: zod.ZodString;
|
|
654
|
+
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
655
|
+
type: zod.ZodLiteral<"audio">;
|
|
656
|
+
data: zod.ZodString;
|
|
657
|
+
mimeType: zod.ZodString;
|
|
556
658
|
}, zod.ZodTypeAny, "passthrough">>, zod.ZodObject<{
|
|
557
659
|
type: zod.ZodLiteral<"resource">;
|
|
558
660
|
resource: zod.ZodUnion<[zod.ZodObject<zod.objectUtil.extendShape<{
|
|
@@ -654,20 +756,20 @@ declare class MCPClientManager {
|
|
|
654
756
|
}>, zod.ZodTypeAny, "passthrough">>]>;
|
|
655
757
|
}, zod.ZodTypeAny, "passthrough">>]>;
|
|
656
758
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
657
|
-
}
|
|
759
|
+
}, zod.ZodTypeAny, "passthrough">>;
|
|
658
760
|
}
|
|
659
761
|
type NamespacedData = {
|
|
660
762
|
tools: (Tool & {
|
|
661
|
-
|
|
763
|
+
serverId: string;
|
|
662
764
|
})[];
|
|
663
765
|
prompts: (Prompt & {
|
|
664
|
-
|
|
766
|
+
serverId: string;
|
|
665
767
|
})[];
|
|
666
768
|
resources: (Resource & {
|
|
667
|
-
|
|
769
|
+
serverId: string;
|
|
668
770
|
})[];
|
|
669
771
|
resourceTemplates: (ResourceTemplate & {
|
|
670
|
-
|
|
772
|
+
serverId: string;
|
|
671
773
|
})[];
|
|
672
774
|
};
|
|
673
775
|
declare function getNamespacedData<T extends keyof NamespacedData>(mcpClients: Record<string, MCPClientConnection>, type: T): NamespacedData[T];
|