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 main transfer invoke

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

Overview

Concrete tool for routing MCP server-initiated sampling and elicitation requests from the main process to the renderer, and routing command picker selections to the chat window, provided by the tuui Electron application.

Description

The samplingTransferInvoke and elicitationTransferInvoke functions create Promise-based request/response channels using UUID-based response channel names. They call listenOnceForRendererResponse to register a one-time ipcMain.once handler, then send the request to the renderer via mainWindow.webContents.send. The commandSelectionInvoke function navigates the main window to the chat route, shows it, and sends the command request to the renderer. The mcpServersProcessCallback sends MCP init progress updates to the renderer.

Usage

Import these functions when: an MCP server requests sampling or elicitation (called from the client request handlers in client.ts), the command picker result needs to be routed to the chat window, or MCP init progress needs to be reported to the renderer.

Code Reference

Source Location

  • Repository: tuui
  • File: src/main/index.ts

Signature

export function samplingTransferInvoke(
  request: SamplingRequest
): Promise<SamplingResponse>

export function elicitationTransferInvoke(
  request: ElicitRequest
): Promise<ElicitResponse>

export async function commandSelectionInvoke(
  request: CommandRequest
): Promise<void>

export async function mcpServersProcessCallback(
  callback: McpProgressCallbackObject
): Promise<void>

// Also: registerShortcuts bootstrap
const registerShortcuts = async (): Promise<void>

Import

import {
  samplingTransferInvoke,
  elicitationTransferInvoke,
  commandSelectionInvoke,
  mcpServersProcessCallback
} from './index'

I/O Contract

Inputs

Name Type Required Description
request SamplingRequest Yes (samplingTransferInvoke) MCP sampling request object
request ElicitRequest Yes (elicitationTransferInvoke) MCP elicitation request object
request CommandRequest Yes (commandSelectionInvoke) { prompt: string, input: string }
callback McpProgressCallbackObject Yes (mcpServersProcessCallback) { name, message, status }

Outputs

Name Type Description
samplingTransferInvoke Promise<SamplingResponse> Resolves when renderer sends response on UUID channel; null if window destroyed
elicitationTransferInvoke Promise<ElicitResponse> Resolves when renderer sends response on UUID channel; null if window destroyed
commandSelectionInvoke Promise<void> Main window navigated to #/chat and request sent
side effect webContents.send IPC events sent to renderer

Usage Examples

Sampling Roundtrip

import { samplingTransferInvoke } from './index'

// Called from MCP client request handler:
const response = await samplingTransferInvoke({
  messages: [{ role: 'user', content: { type: 'text', text: 'Summarize this' } }],
  systemPrompt: 'You are a summarizer.',
  maxTokens: 500
})
// response = { role: 'assistant', content: { type: 'text', text: 'Summary...' }, model: '...' }

Route Command Picker to Chat

import { commandSelectionInvoke } from './index'

await commandSelectionInvoke({
  prompt: 'Translate to French',
  input: 'Hello, world!'
})
// Main window navigates to #/chat and renderer receives the command

Related Pages

Implements Principle

Requires Environment

Page Connections

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