Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI QL Tuui initClients

From Leeroopedia
Knowledge Sources
Domains MCP, Initialization, Orchestration
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for orchestrating MCP client initialization across stdio and MCPB manifest server types, provided by the tuui Electron application.

Description

The initClients function dispatches initialization based on metadata type: metadata__stdio_config entries call initSingleClient directly with the stdio config; metadata__mcpb_manifest entries first resolve the manifest to a stdio config via getMcpConfigForDxt, then call initSingleClient. initSingleClient calls initializeClient (which spawns the stdio transport and connects). The loadConfig helper loads the default MCP config file and maps entries to McpClientObject arrays.

Usage

Import initClients when re-initializing all MCP servers from a metadata map. Import loadConfig when loading the default MCP server config. Import initSingleClient when spawning a single MCP server from a resolved config.

Code Reference

Source Location

  • Repository: tuui
  • File: src/main/mcp/init.ts

Signature

export async function loadConfig(): Promise<McpClientObject[]>

export async function initClients(
  metadata: McpMetadataConfig,
  callback?: McpProgressCallback
): Promise<McpClientObject[]>

export async function initSingleClient(
  name: string,
  serverConfig: McpServerConfig,
  callback?: McpProgressCallback
): Promise<McpClientObject>

Import

import { initClients, initSingleClient, loadConfig } from './mcp/init'

I/O Contract

Inputs

Name Type Required Description
metadata McpMetadataConfig Yes (initClients) Map of server names to { type, config, user_config? }
callback McpProgressCallback No (name, message, status) progress reporter
name string Yes (initSingleClient) Server name
serverConfig McpServerConfig Yes (initSingleClient) StdioServerParameters

Outputs

Name Type Description
initClients McpClientObject[] Connected clients; failed inits return { name } without connection
initSingleClient McpClientObject { name, connection: McpClientTransport, configJson }
loadConfig McpClientObject[] Config entries mapped to { name, configJson } (no connection)

Usage Examples

Initialize Clients from Metadata

import { initClients } from './mcp/init'

const metadata = {
  'my-stdio-server': {
    type: 'metadata__stdio_config',
    config: { command: 'npx', args: ['-y', '@mcp/server'] }
  },
  'my-bundled-server': {
    type: 'metadata__mcpb_manifest',
    config: validatedManifest,
    user_config: { API_KEY: 'xxx' }
  }
}

const clients = await initClients(metadata, (name, msg, status) => {
  console.log(`[${status}] ${name}: ${msg}`)
})
// clients = [
//   { name: 'my-stdio-server', connection: {...}, configJson: {...} },
//   { name: 'my-bundled-server', connection: {...}, configJson: {...} }
// ]

Load Default Config

import { loadConfig } from './mcp/init'

const configs = await loadConfig()
// configs = [{ name: 'default-server', configJson: { command: '...' } }]

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment