Implementation:AI QL Tuui loadConfigFile
| 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.)