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 loadConfigFile

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

Overview

Concrete tool for loading MCP server configuration from JSON files with file-watching support, provided by the tuui Electron application.

Description

The loadConfigFile function reads an MCP server configuration JSON file, parses it into a Record<string, McpServerConfig> mapping, and registers a debounced file watcher for hot-reload. It handles missing files gracefully (returns empty object with notification) and surfaces JSON parse errors to the user via Electron notifications. The config file must contain an mcpServers top-level key.

Usage

Import this function when you need to load MCP server definitions from a JSON config file at application startup or during a server re-initialization cycle. Also use loadLlmFile when loading LLM, popup, or startup JSON configs.

Code Reference

Source Location

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

Signature

export function loadConfigFile(
  configPath: string
): Record<string, McpServerConfig>

// Also exported:
export function loadLlmFile(
  llmPath: string
): Record<string, any> | {}

Import

import { loadConfigFile, loadLlmFile } from './mcp/config'

I/O Contract

Inputs

Name Type Required Description
configPath string Yes Absolute or relative path to the MCP config JSON file

Outputs

Name Type Description
return Record<string, McpServerConfig> Mapping of server names to StdioServerParameters; empty object on missing file or no mcpServers key
side effect fs.watch Registers a debounced file watcher (500ms) on the config path
side effect Notification Shows Electron notification on missing file or parse error

Usage Examples

Load MCP Config at Startup

import { loadConfigFile } from './mcp/config'
import Constants from '../utils/Constants'

// Load the default MCP server config shipped as an asset
const servers = loadConfigFile(Constants.ASSETS_PATH.mcp)

if (Object.keys(servers).length > 0) {
  console.log('Loaded servers:', Object.keys(servers))
  // servers is { "server-name": { command: "...", args: [...], env: {...} } }
} else {
  console.log('No MCP servers configured')
}

Load LLM Provider Config

import { loadLlmFile } from './mcp/config'
import Constants from '../utils/Constants'

// Load the default LLM chatbot provider configs
const llmConfig = loadLlmFile(Constants.ASSETS_PATH.llm)
// llmConfig contains chatbot provider definitions (url, model, apiKey, etc.)

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

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