MCP-CLI now features an enhanced compact streaming display system that provides content-aware, real-time feedback during LLM response generation.
- Automatically detects content type (code, markdown, tables, queries, JSON, etc.)
- Adapts phase messages based on detected content
- Provides syntax-appropriate preview styling
- Smooth spinner animation
- Real-time character and time statistics
- Progressive phase messages that update based on response length
- Content type indicator in status line
- Response Mode: For assistant responses with content-type detection
- Tool Mode: For tool execution with appropriate status messages
- Thinking Mode: For analysis and reasoning steps
from mcp_cli.ui.streaming_display import StreamingContext
from rich.console import Console
console = Console()
# Use as a context manager
with StreamingContext(console=console, title="🤖 Assistant") as ctx:
for chunk in response_chunks:
ctx.update(chunk)# Tool execution mode
with StreamingContext(
console=console,
title="⚙️ Database Query",
mode="tool",
refresh_per_second=8,
transient=True
) as ctx:
for chunk in tool_output:
ctx.update(chunk)The streaming display is integrated into:
StreamingHandler: Handles async streaming from LLM providersUIManager: Manages overall UI state during streamingConversationProcessor: Orchestrates streaming during chat
-
CompactStreamingDisplay: Main display class
- Content type detection
- Preview generation
- Progress tracking
- Panel rendering
-
StreamingContext: Context manager wrapper
- Manages
rich.Livedisplay - Handles cleanup and final panel display
- Provides simple update interface
- Manages
-
Helper Functions:
tokenize_text(): Converts text to streamable tokens
- Content arrives in chunks
- Display detects content type from early chunks
- Preview is captured from first few lines
- Progress panel updates with each chunk
- Final panel renders with full formatted content
See the examples/ directory for complete demos:
streaming_simple.py: Basic usage examplesmcp_cli_streaming_demo_v2.py: Comprehensive feature showcasemcp_cli_clean_demo_new.py: Full integration example
- Optimized refresh rate (8 Hz) for smooth updates without flicker
- Transient display that cleanly replaces with final panel
- Minimal overhead with efficient content accumulation
- Fixed panel height prevents terminal jumping