Client for connecting to multiple MCP servers and loading LangChain-compatible tools.

Constructors

  • Create a new MultiServerMCPClient.

    Parameters

    • config: Record<string, {
          args: string[];
          command: string;
          cwd?: string;
          encoding?: string;
          env?: Record<string, string>;
          restart?: {
              delayMs?: number;
              enabled?: boolean;
              maxAttempts?: number;
          };
          stderr?:
              | "overlapped"
              | "pipe"
              | "ignore"
              | "inherit";
          transport?: "stdio";
          type?: "stdio";
      } & {
          defaultToolTimeout?: number;
          outputHandling?: "content" | "artifact" | {
              audio: undefined | "content" | "artifact";
              image: undefined | "content" | "artifact";
              resource: undefined | "content" | "artifact";
              text: undefined | "content" | "artifact";
          };
      } | {
          authProvider?: OAuthClientProvider;
          automaticSSEFallback?: boolean;
          headers?: Record<string, string>;
          reconnect?: {
              delayMs?: number;
              enabled?: boolean;
              maxAttempts?: number;
          };
          transport?: "http" | "sse";
          type?: "http" | "sse";
          url: string;
      } & {
          defaultToolTimeout?: number;
          outputHandling?: "content" | "artifact" | {
              audio: undefined | "content" | "artifact";
              image: undefined | "content" | "artifact";
              resource: undefined | "content" | "artifact";
              text: undefined | "content" | "artifact";
          };
      }> | {
          additionalToolNamePrefix?: string;
          mcpServers: Record<string, {
              args: string[];
              command: string;
              cwd?: string;
              encoding?: string;
              env?: Record<string, string>;
              restart?: {
                  delayMs?: number;
                  enabled?: boolean;
                  maxAttempts?: number;
              };
              stderr?:
                  | "overlapped"
                  | "pipe"
                  | "ignore"
                  | "inherit";
              transport?: "stdio";
              type?: "stdio";
          } & {
              defaultToolTimeout?: number;
              outputHandling?: "content" | "artifact" | {
                  audio: undefined | "content" | "artifact";
                  image: undefined | "content" | "artifact";
                  resource: undefined | "content" | "artifact";
                  text: undefined | "content" | "artifact";
              };
          } | {
              authProvider?: OAuthClientProvider;
              automaticSSEFallback?: boolean;
              headers?: Record<string, string>;
              reconnect?: {
                  delayMs?: number;
                  enabled?: boolean;
                  maxAttempts?: number;
              };
              transport?: "http" | "sse";
              type?: "http" | "sse";
              url: string;
          } & {
              defaultToolTimeout?: number;
              outputHandling?: "content" | "artifact" | {
                  audio: undefined | "content" | "artifact";
                  image: undefined | "content" | "artifact";
                  resource: undefined | "content" | "artifact";
                  text: undefined | "content" | "artifact";
              };
          }>;
          prefixToolNameWithServerName?: boolean;
          throwOnLoadError?: boolean;
          useStandardContentBlocks?: boolean;
      } & {
          defaultToolTimeout?: number;
          outputHandling?: "content" | "artifact" | {
              audio: undefined | "content" | "artifact";
              image: undefined | "content" | "artifact";
              resource: undefined | "content" | "artifact";
              text: undefined | "content" | "artifact";
          };
      }

      Configuration object

    Returns MultiServerMCPClient

Accessors

  • get config(): {
        additionalToolNamePrefix?: string;
        mcpServers: Record<string, {
            args: string[];
            command: string;
            cwd?: string;
            encoding?: string;
            env?: Record<string, string>;
            restart?: {
                delayMs?: number;
                enabled?: boolean;
                maxAttempts?: number;
            };
            stderr?:
                | "overlapped"
                | "pipe"
                | "ignore"
                | "inherit";
            transport?: "stdio";
            type?: "stdio";
        } & {
            defaultToolTimeout?: number;
            outputHandling?: "content" | "artifact" | {
                audio: undefined | "content" | "artifact";
                image: undefined | "content" | "artifact";
                resource: undefined | "content" | "artifact";
                text: undefined | "content" | "artifact";
            };
        } | {
            authProvider?: OAuthClientProvider;
            automaticSSEFallback?: boolean;
            headers?: Record<string, string>;
            reconnect?: {
                delayMs?: number;
                enabled?: boolean;
                maxAttempts?: number;
            };
            transport?: "http" | "sse";
            type?: "http" | "sse";
            url: string;
        } & {
            defaultToolTimeout?: number;
            outputHandling?: "content" | "artifact" | {
                audio: undefined | "content" | "artifact";
                image: undefined | "content" | "artifact";
                resource: undefined | "content" | "artifact";
                text: undefined | "content" | "artifact";
            };
        }>;
        prefixToolNameWithServerName?: boolean;
        throwOnLoadError?: boolean;
        useStandardContentBlocks?: boolean;
    } & {
        defaultToolTimeout?: number;
        outputHandling?: "content" | "artifact" | {
            audio: undefined | "content" | "artifact";
            image: undefined | "content" | "artifact";
            resource: undefined | "content" | "artifact";
            text: undefined | "content" | "artifact";
        };
    }
  • Returns clone of server config for inspection purposes.

    Client does not support config modifications.

    Returns {
        additionalToolNamePrefix?: string;
        mcpServers: Record<string, {
            args: string[];
            command: string;
            cwd?: string;
            encoding?: string;
            env?: Record<string, string>;
            restart?: {
                delayMs?: number;
                enabled?: boolean;
                maxAttempts?: number;
            };
            stderr?:
                | "overlapped"
                | "pipe"
                | "ignore"
                | "inherit";
            transport?: "stdio";
            type?: "stdio";
        } & {
            defaultToolTimeout?: number;
            outputHandling?: "content" | "artifact" | {
                audio: undefined | "content" | "artifact";
                image: undefined | "content" | "artifact";
                resource: undefined | "content" | "artifact";
                text: undefined | "content" | "artifact";
            };
        } | {
            authProvider?: OAuthClientProvider;
            automaticSSEFallback?: boolean;
            headers?: Record<string, string>;
            reconnect?: {
                delayMs?: number;
                enabled?: boolean;
                maxAttempts?: number;
            };
            transport?: "http" | "sse";
            type?: "http" | "sse";
            url: string;
        } & {
            defaultToolTimeout?: number;
            outputHandling?: "content" | "artifact" | {
                audio: undefined | "content" | "artifact";
                image: undefined | "content" | "artifact";
                resource: undefined | "content" | "artifact";
                text: undefined | "content" | "artifact";
            };
        }>;
        prefixToolNameWithServerName?: boolean;
        throwOnLoadError?: boolean;
        useStandardContentBlocks?: boolean;
    } & {
        defaultToolTimeout?: number;
        outputHandling?: "content" | "artifact" | {
            audio: undefined | "content" | "artifact";
            image: undefined | "content" | "artifact";
            resource: undefined | "content" | "artifact";
            text: undefined | "content" | "artifact";
        };
    }

Methods

  • Get a the MCP client for a specific server. Useful for fetching prompts or resources from that server.

    Parameters

    • serverName: string

      The name of the server

    Returns Promise<undefined | Client<{
        method: string;
        params?: {};
    }, {
        method: string;
        params?: {};
    }, {}>>

    The client for the server, or undefined if the server is not connected

  • Get tools from specified servers as a flattened array.

    Parameters

    • Rest...servers: string[]

      Optional array of server names to filter tools by. If not provided, returns tools from all servers.

    Returns Promise<DynamicStructuredTool<ToolInputSchemaBase, any, any, any>[]>

    A flattened array of tools from the specified servers (or all servers)

  • Proactively initialize connections to all servers. This will be called automatically when methods requiring an active connection (like getTools or getClient) are called, but you can call it directly to ensure all connections are established before using the tools.

    Returns Promise<Record<string, DynamicStructuredTool<ToolInputSchemaBase, any, any, any>[]>>

    A map of server names to arrays of tools

    If initialization fails