Implementation:AI QL Tuui mcpStore
| Knowledge Sources | |
|---|---|
| Domains | MCP, State_Management, Content_Translation |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for managing MCP server registry state, listing and calling MCP tools, and translating MCP content to OpenAI format, provided by the tuui Electron application.
Description
The useMcpStore Pinia store is the renderer-side hub for MCP server interaction. It merges preload-exposed server APIs with user-edited stdio configs via getServers(), lists tools across all or filtered servers via listTools() / listServerTools(), resolves tool-to-server mappings via getTool(), invokes tools via callTool(), and translates MCP content types (text/image/resource) to OpenAI-compatible format via convertItem().
Usage
Import this store when you need to: list available MCP tools for an LLM request, call an MCP tool by name, translate MCP content to OpenAI message format, or watch for server registry changes.
Code Reference
Source Location
- Repository: tuui
- File: src/renderer/store/mcp.ts
Signature
export function getServers(): McpServerApi
export function useMcpStore(): {
// State
version: number
serverTools: any[]
loading: boolean
checkList: string[]
selected: string[] | undefined
selectedChips: Record<string, number>
// Actions
watchServerUpdate(): void
listServerTools(serverNames?: string[]): Promise<FunctionType[]>
listTools(): Promise<FunctionType[] | null>
getTool(toolName: string): Promise<{ server: string, tool: McpToolType } | null>
callTool(toolName: string, toolArgs: string): Promise<CallToolResult | null>
convertItem(item: ChatCompletionPromptMessage['content']): ChatCompletionRequestContent
packReturn(string: string): { content: [{ type: 'text', text: string }] }
}
export interface FunctionType {
type: 'function'
function: { name: string, description: string, parameters: any }
}
Import
import { useMcpStore, getServers, type FunctionType } from '@/renderer/store/mcp'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| serverNames | string[] | No (listServerTools) | Filter to specific servers; defaults to selected server |
| toolName | string | Yes (getTool/callTool) | MCP tool name to find or invoke |
| toolArgs | string | Yes (callTool) | JSON string of tool arguments |
| item | ChatCompletionPromptMessage['content'] | Yes (convertItem) | MCP content item (text/image/resource) |
Outputs
| Name | Type | Description |
|---|---|---|
| listTools/listServerTools | FunctionType[] | Array of OpenAI tool format: { type: 'function', function: { name, description, parameters } } |
| getTool | null | Resolved server + tool definition |
| callTool | null | MCP tool call result with content array |
| convertItem | ChatCompletionRequestContent | OpenAI content format (text or image_url) |
Usage Examples
List All Available Tools
import { useMcpStore } from '@/renderer/store/mcp'
const mcpStore = useMcpStore()
const tools = await mcpStore.listTools()
// tools = [{ type: 'function', function: { name: 'read_file', description: '...', parameters: {...} } }, ...]
Call a Tool by Name
const mcpStore = useMcpStore()
const result = await mcpStore.callTool('read_file', '{"path": "/tmp/test.txt"}')
// result.content = [{ type: 'text', text: 'file contents...' }]
Convert MCP Content to OpenAI Format
const mcpStore = useMcpStore()
// Text content passes through
const textItem = mcpStore.convertItem({ type: 'text', text: 'hello' })
// → { type: 'text', text: 'hello' }
// Image content becomes base64 data URL
const imageItem = mcpStore.convertItem({ type: 'image', mimeType: 'image/png', data: 'base64...' })
// → { type: 'image_url', image_url: { url: 'data:image/png;base64,base64...' } }
// Resource content becomes JSON text
const resourceItem = mcpStore.convertItem({ type: 'resource', resource: { uri: 'file:///x' } })
// → { type: 'text', text: '{...JSON...}' }
Related Pages
Implements Principle
- Principle:AI_QL_Tuui_MCP_Server_Lifecycle
- Principle:AI_QL_Tuui_Agentic_Tool_Loop
- Principle:AI_QL_Tuui_MCP_OpenAI_Content_Translation
- Principle:AI_QL_Tuui_MCP_Sampling