@mcp-z/client
    Preparing search index...

    Function createServerRegistry

    • Create a registry of MCP servers from configuration.

      Fast start: Returns immediately after processes are created. Use registry.connect() for lazy MCP connection.

      Parameters

      • serversConfig: ServersConfig

        Map of server names to their configurations

      • Optionaloptions: CreateServerRegistryOptions

        Options for registry creation

        Options for creating a server registry.

        • Optionalcwd?: string

          Working directory for spawned processes (default: process.cwd())

        • Optionaldialects?: Dialect[]

          Dialects controlling which servers to spawn.

          • ['servers']: Spawn stdio servers only (default, Claude Code compatible)
          • ['start']: Only spawn servers with start blocks (HTTP servers)
          • ['servers', 'start']: Spawn both stdio servers and start blocks
          ['servers']
          
        • Optionalenv?: Record<string, string>

          Base environment for all servers. If provided, process.env is NOT included (caller has full control). If omitted, process.env is used as the base (default behavior).

      Returns ServerRegistry

      ServerRegistry instance with config, server map, connect method, and close function

      // Fast server start (does NOT wait for readiness)
      const registry = createServerRegistry({
      'echo': { command: 'node', args: ['server.ts'] },
      });

      // Connect when needed (waits for MCP handshake)
      const client = await registry.connect('echo');

      // Cleanup (closes all clients AND processes)
      await registry.close();
      // Start HTTP servers with start blocks
      const registry = createServerRegistry(
      {
      'http-server': {
      url: 'http://localhost:8080/mcp',
      start: { command: 'node', args: ['http.ts', '--port', '8080'] }
      },
      },
      { dialects: ['start'] }
      );
      // Using await using for automatic close
      await using registry = createServerRegistry(config);
      const client = await registry.connect('server');
      // Auto-disposed when scope exits