UNPKG

@langchain/mcp-adapters

Version:
1,217 lines (1,215 loc) 434 kB
import { State, ToolHooks } from "./hooks.js"; import { z } from "zod/v3"; import { ContentBlock as ContentBlock$1, MessageStructure, ToolMessage as ToolMessage$1 } from "@langchain/core/messages"; import { Command as Command$1 } from "@langchain/langgraph"; import { RunnableConfig as RunnableConfig$1 } from "@langchain/core/runnables"; import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js"; //#region src/types.d.ts declare const outputHandlingSchema: z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>; /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ type OutputHandling = z.output<typeof outputHandlingSchema>; /** * Stdio transport connection */ declare const stdioConnectionSchema: z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ transport: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ type: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * The executable to run the server (e.g. `node`, `npx`, etc) */ command: z.ZodString; /** * Array of command line arguments to pass to the executable */ args: z.ZodArray<z.ZodString, "many">; /** * Environment variables to set when spawning the process. */ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * The encoding to use when reading from the process */ encoding: z.ZodOptional<z.ZodString>; /** * How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn` * * The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr. * * @default "inherit" */ stderr: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"overlapped">, z.ZodLiteral<"pipe">, z.ZodLiteral<"ignore">, z.ZodLiteral<"inherit">]>>>; /** * The working directory to use when spawning the process. */ cwd: z.ZodOptional<z.ZodString>; /** * Additional restart settings */ restart: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically restart the process if it exits */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of restart attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between restart attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; }, "strip", z.ZodTypeAny, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr: "ignore" | "inherit" | "overlapped" | "pipe"; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr?: "ignore" | "inherit" | "overlapped" | "pipe" | undefined; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>; /** * Streamable HTTP transport connection */ declare const streamableHttpConnectionSchema: z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ transport: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * The URL to connect to */ url: z.ZodString; /** * Additional headers to send with the request, useful for authentication */ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * OAuth client provider for automatic authentication handling. * When provided, the transport will automatically handle token refresh, * 401 error retries, and OAuth 2.0 flows according to RFC 6750. * This is the recommended approach for authentication instead of manual headers. */ authProvider: z.ZodOptional<z.ZodType<OAuthClientProvider, z.ZodTypeDef, OAuthClientProvider>>; /** * Additional reconnection settings. */ reconnect: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically reconnect if the connection is lost */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of reconnection attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between reconnection attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; /** * Whether to automatically fallback to SSE if Streamable HTTP is not available or not supported * * @default true */ automaticSSEFallback: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, "strip", z.ZodTypeAny, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback: boolean; }, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback?: boolean | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>; /** * Create combined schema for all transport connection types */ declare const connectionSchema: z.ZodUnion<[z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ transport: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ type: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * The executable to run the server (e.g. `node`, `npx`, etc) */ command: z.ZodString; /** * Array of command line arguments to pass to the executable */ args: z.ZodArray<z.ZodString, "many">; /** * Environment variables to set when spawning the process. */ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * The encoding to use when reading from the process */ encoding: z.ZodOptional<z.ZodString>; /** * How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn` * * The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr. * * @default "inherit" */ stderr: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"overlapped">, z.ZodLiteral<"pipe">, z.ZodLiteral<"ignore">, z.ZodLiteral<"inherit">]>>>; /** * The working directory to use when spawning the process. */ cwd: z.ZodOptional<z.ZodString>; /** * Additional restart settings */ restart: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically restart the process if it exits */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of restart attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between restart attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; }, "strip", z.ZodTypeAny, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr: "ignore" | "inherit" | "overlapped" | "pipe"; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr?: "ignore" | "inherit" | "overlapped" | "pipe" | undefined; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>, z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ transport: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * The URL to connect to */ url: z.ZodString; /** * Additional headers to send with the request, useful for authentication */ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * OAuth client provider for automatic authentication handling. * When provided, the transport will automatically handle token refresh, * 401 error retries, and OAuth 2.0 flows according to RFC 6750. * This is the recommended approach for authentication instead of manual headers. */ authProvider: z.ZodOptional<z.ZodType<OAuthClientProvider, z.ZodTypeDef, OAuthClientProvider>>; /** * Additional reconnection settings. */ reconnect: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically reconnect if the connection is lost */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of reconnection attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between reconnection attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; /** * Whether to automatically fallback to SSE if Streamable HTTP is not available or not supported * * @default true */ automaticSSEFallback: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, "strip", z.ZodTypeAny, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback: boolean; }, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback?: boolean | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>]>; declare const notifications: z.ZodObject<{ /** * Called when a log message is received. * * @param logMessage - The log message * @param logMessage.message - The log message * @param logMessage.level - The log level * @param logMessage.timestamp - The log timestamp * @param source - The source of the log message * @param source.server - The server of the source, e.g. "my-server" * @param source.option - The connection options of the source, e.g. `{ transport: "stdio", command: "node", args: ["server.js"] }` * @returns The log message * * @example * ```ts * const client = new MultiServerMCPClient({ * // ... * onLog: (logMessage) => { * console.log(logMessage); * }, * }); * ``` */ onMessage: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodObject<{ /** * The severity of this log message. */ level: z.ZodEnum<["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]>; /** * An optional name of the logger issuing this message. */ logger: z.ZodOptional<z.ZodString>; /** * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. */ data: z.ZodUnknown; }, "strip", z.ZodTypeAny, { level: "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning"; logger?: string | undefined; data?: unknown; }, { level: "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning"; logger?: string | undefined; data?: unknown; }>, z.ZodObject<{ server: z.ZodString; options: z.ZodUnion<[z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ transport: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * Optional transport type, inferred from the structure of the config if not provided. Included * for compatibility with common MCP client config file formats. */ type: z.ZodOptional<z.ZodLiteral<"stdio">>; /** * The executable to run the server (e.g. `node`, `npx`, etc) */ command: z.ZodString; /** * Array of command line arguments to pass to the executable */ args: z.ZodArray<z.ZodString, "many">; /** * Environment variables to set when spawning the process. */ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * The encoding to use when reading from the process */ encoding: z.ZodOptional<z.ZodString>; /** * How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn` * * The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr. * * @default "inherit" */ stderr: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"overlapped">, z.ZodLiteral<"pipe">, z.ZodLiteral<"ignore">, z.ZodLiteral<"inherit">]>>>; /** * The working directory to use when spawning the process. */ cwd: z.ZodOptional<z.ZodString>; /** * Additional restart settings */ restart: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically restart the process if it exits */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of restart attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between restart attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; }, "strip", z.ZodTypeAny, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr: "ignore" | "inherit" | "overlapped" | "pipe"; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }, { transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr?: "ignore" | "inherit" | "overlapped" | "pipe" | undefined; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>, z.ZodIntersection<z.ZodObject<{ /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ transport: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * Optional transport type, inferred from the structure of the config. If "sse", will not attempt * to connect using streamable HTTP. */ type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>>; /** * The URL to connect to */ url: z.ZodString; /** * Additional headers to send with the request, useful for authentication */ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; /** * OAuth client provider for automatic authentication handling. * When provided, the transport will automatically handle token refresh, * 401 error retries, and OAuth 2.0 flows according to RFC 6750. * This is the recommended approach for authentication instead of manual headers. */ authProvider: z.ZodOptional<z.ZodType<OAuthClientProvider, z.ZodTypeDef, OAuthClientProvider>>; /** * Additional reconnection settings. */ reconnect: z.ZodOptional<z.ZodObject<{ /** * Whether to automatically reconnect if the connection is lost */ enabled: z.ZodOptional<z.ZodBoolean>; /** * Maximum number of reconnection attempts */ maxAttempts: z.ZodOptional<z.ZodNumber>; /** * Delay in milliseconds between reconnection attempts */ delayMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }, { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; }>>; /** * Whether to automatically fallback to SSE if Streamable HTTP is not available or not supported * * @default true */ automaticSSEFallback: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, "strip", z.ZodTypeAny, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback: boolean; }, { transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback?: boolean | undefined; }>, z.ZodObject<{ /** * Defines where to place each tool output type in the LangChain ToolMessage. * * Can be set to `content` or `artifact` to send all tool output into the ToolMessage.content or * ToolMessage.artifact array, respectively, or you can assign an object that maps each content type * to `content` or `artifact`. * * @default { * "text": "content", * "image": "content", * "audio": "content", * "resource": "artifact" * } * * Items in the `content` field will be used as input context for the LLM, while the artifact field is * used for capturing tool output that won't be shown to the model, to be used in some later workflow * step. * * For example, imagine that you have a SQL query tool that can return huge result sets. Rather than * sending these large outputs directly to the model, perhaps you want the model to be able to inspect * the output in a code execution environment. In this case, you would set the output handling for the * `resource` type to `artifact` (its default value), and then upon initialization of your code * execution environment, you would look through your message history for `ToolMessage`s with the * `artifact` field set to `resource`, and use the `content` field during initialization of the * environment. */ outputHandling: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>, z.ZodObject<{ audio: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; image: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; resource_link: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; text: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"content">, z.ZodLiteral<"artifact">]>>; }, "strip", z.ZodTypeAny, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }, { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; }>]>>; /** * Default timeout in milliseconds for tool execution. Must be greater than 0. * If not specified, tools will use their own configured timeout values. */ defaultToolTimeout: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }, { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }>>]>; }, "strip", z.ZodTypeAny, { server: string; options: ({ transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr: "ignore" | "inherit" | "overlapped" | "pipe"; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; } & { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }) | ({ transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback: boolean; } & { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }); }, { server: string; options: ({ transport?: "stdio" | undefined; type?: "stdio" | undefined; command: string; args: string[]; env?: Record<string, string> | undefined; encoding?: string | undefined; stderr?: "ignore" | "inherit" | "overlapped" | "pipe" | undefined; cwd?: string | undefined; restart?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; } & { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }) | ({ transport?: "http" | "sse" | undefined; type?: "http" | "sse" | undefined; url: string; headers?: Record<string, string> | undefined; authProvider?: OAuthClientProvider | undefined; reconnect?: { enabled?: boolean | undefined; maxAttempts?: number | undefined; delayMs?: number | undefined; } | undefined; automaticSSEFallback?: boolean | undefined; } & { outputHandling?: "artifact" | "content" | { audio?: "artifact" | "content" | undefined; image?: "artifact" | "content" | undefined; resource?: "artifact" | "content" | undefined; resource_link?: "artifact" | "content" | undefined; text?: "artifact" | "content" | undefined; } | undefined; defaultToolTimeout?: number | undefined; }); }>], z.ZodUnknown>, z.ZodUnion<[z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>; /** * Called when a progress message is received. * * @param progress - The progress message * @param progress.message - The progress message * @param progress.percentage - The progress percentage * @param progress.timestamp - The progress timestamp * @param source - The source of the progress message * @param source.type - The type of the source, e.g. "tool" * @param source.server - The server of the source, e.g. "my-server" * @param source.name - The name of the source, e.g. "my-name" * @param source.args - The arguments of the source, e.g. { a: 1, b: 2 } * @returns The progress message * * @example * ```ts * const client = new MultiServerMCPClient({ * // ... * onProgress: (progress, source) => { * if (source.type === "tool") { * console.log(progress); * }, * }); * ``` */ onProgress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodObject<{ /** * The progress thus far. This should increase every time progress is made, even if the total is unknown. */ progress: z.ZodNumber; /** * Total number of items to process (or total progress required), if known. */ total: z.ZodOptional<z.ZodNumber>; /** * An optional message describing the current progress. */ message: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { progress: number; total?: number | undefined; message?: string | undefined; }, { progress: number; total?: number | undefined; message?: string | undefined; }>, z.ZodUnion<[z.ZodObject<{ type: z.ZodLiteral<"tool">; name: z.ZodString; args: z.ZodUnknown; server: z.ZodString; }, "strip", z.ZodTypeAny, { type: "tool"; name: string; args?: unknown; server: string; }, { type: "tool"; name: string; args?: unknown; server: string; }>, z.ZodObject<{ type: z.ZodLiteral<"unknown">; }, "strip", z.ZodTypeAny, { type: "unknown"; }, { type: "unknown"; }>]>], z.ZodUnknown>, z.ZodUnion<[z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>; onCancelled: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodObject<{ /** * The ID of the request to cancel. * * This MUST correspond to the ID of a request previously issued in the same direction. */ requestId: z.ZodUn