Components

MomcpTUI (Main App)

The main Textual application that orchestrates everything.

Responsibilities:

  • Compose the TUI layout (header, chat, input, footer)
  • Handle user input and command routing
  • Manage chat history and display
  • Coordinate LLM calls and tool execution

LLMClient

Handles communication with LLM provider APIs.

Features:

  • Streaming SSE response parsing
  • Tool call streaming with argument buffering
  • Thinking/reasoning content extraction
  • API key management per provider
  • Special header handling for MiMo (api-key vs Authorization)

MCPManager

Manages connections to MCP servers.

Features:

  • Register stdio and HTTP MCP servers
  • Lazy connection (connects on first tool call)
  • Thread-safe async bridge
  • Tool discovery and invocation

Config

Configuration management.

Features:

  • Load/save configuration file
  • Built-in model registry (9 providers)
  • Custom model support
  • Provider API key URL mapping

MomcpServer

The built-in MCP server providing file and command tools.

Built-in tools:

  • fs_list, fs_read, fs_write, fs_mkdir, fs_delete
  • code_replace, code_write
  • run_command

Utilities

ModulePurpose
CompressionToken estimation and conversation compression
CancellationThread-safe cancellation tokens
ClipboardCross-platform clipboard access
PromptsSystem prompt generation
Localei18n translation strings (zh/en)

Data Flow

User Input

MomcpTUI.on_input_submitted()

Thread: _request_llm_reply_stream()

compress_messages() → estimate tokens

LLMClient.chat_tools_stream() → SSE stream

[If tool call] MCPManager.call_tool() → MCP Server

[Loop back to LLM with tool result]

Final response → UI update