Implementation:AI QL Tuui IPCs
| Knowledge Sources | |
|---|---|
| Domains | IPC, MCP, Electron |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for registering and managing Electron IPC handlers between the main and renderer processes, provided by the tuui Electron application.
Description
The IPCs class is the central IPC handler registry. Its initialize() method registers all static handlers (app info, file transfer, command selection, manifest listing, LLM/popup/startup config loading, MCP server init/stop). The registerIpcHandlers standalone function dynamically registers per-server, per-capability IPC handlers by introspecting connected MCP clients. listenOnceForRendererResponse implements the UUID-based one-time response channel pattern used for sampling and elicitation roundtrips.
Usage
Import the IPCs class when bootstrapping the main process (call IPCs.initialize() and IPCs.initializeMCP()). Import registerIpcHandlers when wiring up newly connected MCP clients. Import listenOnceForRendererResponse when implementing async request/response correlation over IPC.
Code Reference
Source Location
- Repository: tuui
- File: src/main/IPCs.ts
Signature
export default class IPCs {
static clients: McpClientObject[]
static currentFeatures: McpFeatureObject[]
static initialize(): void
static updateMCP(newFeatures: McpFeatureObject[]): void
static stopAllServers(): void
static removeAllHandlers(): void
static initializeMCP(initialFeatures: McpFeatureObject[]): void
}
export function listenOnceForRendererResponse(
responseChannel: string,
resolve: (_value: McpClientResponse) => void
): void
export function registerIpcHandlers({
name,
connection,
configJson
}: McpClientObject): McpFeatureObject
Import
import IPCs, {
registerIpcHandlers,
listenOnceForRendererResponse
} from './IPCs'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| metadata | McpMetadataConfig | Yes (msgMcpServersInit) | Map of server names to metadata entries |
| McpClientObject | { name, connection?, configJson? } | Yes (registerIpcHandlers) | Connected MCP client object |
| responseChannel | string | Yes (listenOnceForRendererResponse) | UUID-based IPC channel name |
| resolve | (value) => void | Yes (listenOnceForRendererResponse) | Promise resolver callback |
| IpcFileTransferRequest | { name, data } | Yes (msgFileTransferRequest) | Bundle filename and binary data |
Outputs
| Name | Type | Description |
|---|---|---|
| McpInitResponse | { status: 'error', error } | Result of MCP server initialization |
| McpFeatureObject | { name, config, tools?, prompts?, resources?, description? } | Feature object with IPC event names per capability |
| ManifestResponse | { status, result?, error? } | Result of list-manifests handler |
| IpcFileTransferResponse | { name, success, path?, reason? } | Result of file transfer |
Usage Examples
Initialize IPC Handlers at Startup
import IPCs from './IPCs'
// Register all static IPC handlers
IPCs.initialize()
// Register the list-clients handler with initial features
IPCs.initializeMCP([])
Register Capability-Based IPC Handlers
import { registerIpcHandlers } from './IPCs'
// After connecting an MCP client, register its capability handlers
const feature = registerIpcHandlers({
name: 'my-server',
connection: { client, transport }, // McpClientTransport
configJson: { command: 'node', args: ['server.js'] }
})
// feature now contains IPC event names:
// feature.tools.list = "my-server-tools/list"
// feature.tools.call = "my-server-tools/call"
// feature.prompts.list = "my-server-prompts/list"
// etc.
UUID-Based Response Channel
import { listenOnceForRendererResponse } from './IPCs'
import { v4 as uuidv4 } from 'uuid'
const responseChannel = `msgSamplingTransferResult-${uuidv4()}`
listenOnceForRendererResponse(responseChannel, (response) => {
console.log('Got response from renderer:', response)
})
// Later, renderer sends response on the channel:
// window.mainApi.send(responseChannel, responseData)
Related Pages
Implements Principle
- Principle:AI_QL_Tuui_MCP_Server_Lifecycle
- Principle:AI_QL_Tuui_Capability_Based_IPC_Routing
- Principle:AI_QL_Tuui_UUID_Response_Channel
- Principle:AI_QL_Tuui_MCPB_Bundle_Packaging
- Principle:AI_QL_Tuui_Global_Shortcut_Command_Picker