A mobile-optimized single page chat application that uses the Anthropic Messages API with real-time streaming and MCP (Model Context Protocol) server support, featuring centralized client management and performance optimizations.
Source: https://www.val.town/x/c15r/Chat
Live server: https://chat.parc.land
Bundles Contextual MCP server by default: https://contextual.parc.land/mcp
- đ Real-time streaming responses - See Claude's responses appear word-by-word as they're generated
- âšī¸ Stream control - Stop streaming at any time with the stop button
- đ§ Client-side Tools - Interactive tools that run in the browser (ask_user, calculator, js_exec)
- đ¨ UI Affordance Framework - Dynamic UI component registration system for rich interactions
- đŦ Inline User Input - Sophisticated ask_user tool with text, multiline, choice, and confirm inputs
- đ§Ž Built-in Calculator - Mathematical expression evaluation tool
- đ¨ UI Affordance System - Register custom UI components in overlays, sidebars, headers, footers, and inline
- đ NextSteps Auto-Execution - MCP tools can propose follow-up actions with automatic or manual execution
- đ Resource Viewer - MCP tools can display file content with syntax highlighting and fullscreen support
- đ§ Centralized Client Pool - Unified MCP client management for optimal performance and reliability
- đ Performance Optimizations - Memoized rendering, stable references, and efficient connection reuse
- đ Automatic MCP Server Status Checking - Real-time server health monitoring with detailed diagnostics
- đ¯ Enhanced Command Palette - Quick access to MCP tools, prompts, and client-side tools via
/commands with:- Auto-execution for prompts - Prompts execute immediately without manual submission
- Focused dialog experience - Main input is disabled when argument dialogs are shown
- Streamlined UX - No confusion between input methods during tool/prompt execution
- đž Persistent Storage - Chat history and settings saved locally with automatic restoration
- đ¨ Exquisite Design System - Sophisticated visual design with glassmorphism, smooth animations, and depth
- đą Mobile-First Experience - Optimized for mobile viewports with touch-friendly interactions
- ⨠Smooth Animations - Delightful micro-interactions and transitions throughout the interface
- đ Advanced Theming - Comprehensive design tokens with CSS custom properties
- âŋ Accessibility First - Full keyboard navigation, screen reader support, and reduced motion preferences
The application now uses a unified MCPClientPool that eliminates duplicate connections and provides consistent access to MCP operations:
// Single source of truth for all MCP operations
const clientPool = new MCPClientPool(connectedClients, serverConfigs);
// Unified API across all components
await clientPool.testServer(serverName);
await clientPool.fetchTools();
await clientPool.callTool(serverName, toolName, args);
- â No Duplicate Client Connections: Single client instance per server
- â Memoized Client Resolution: Cached lookups prevent unnecessary re-renders
- â Stable Reference Management: Arrays memoized to prevent reload loops
- â Optimized useEffect Dependencies: Minimal effect re-executions
- â Connection Reuse: Existing connections used for all operations
- â Multiple client instances per server (4 separate creation points)
- â Duplicate connection logic across components
- â ResourceViewer reload loops due to unstable references
- â Inconsistent error handling
- â Single client instance per server via centralized pool
- â Unified connection logic in MCPClientPool
- â Stable component rendering with memoized references
- â Consistent error handling across all components
This app implements Anthropic's official streaming guide using:
- Server-Sent Events (SSE) for real-time communication
- Proper event parsing (
message_start,content_block_delta,message_stop, etc.) - Content block reassembly for text, tool use, and thinking responses
- Immediate message visibility: Completed streaming responses are immediately added to chat history during tool execution cycles
- Error handling and keep-alive support
- Token usage tracking
- Support for all delta types (text, JSON, thinking)
The streaming implementation has been enhanced to provide better user experience during tool execution:
- Immediate Message Addition: Each completed streaming response is immediately added to the visible chat history
- Preserved Context: Previous messages remain visible throughout tool execution cycles
- Live Streaming Preview: Only the currently streaming content uses the live preview system
- Seamless Tool Execution: Interactive tools (like
ask_user) maintain full conversation context
This ensures users never lose sight of previous responses during long tool execution sequences.
âââ backend/
â âââ index.ts # Hono server with static file serving
âââ frontend/
â âââ index.html # Main HTML template
â âââ index.tsx # React app entry point
â âââ components/
â â âââ App.tsx # Main app component
â â âââ StreamingChat.tsx # Real-time streaming chat interface
â â âââ Settings.tsx # Settings flyout
â â âââ MCPStatus.tsx # MCP server status dashboard with progressive disclosure
â â âââ CommandPalette.tsx # MCP prompt command palette
â â âââ HTMLRenderer.tsx # HTML output renderer with MCP context
â â âââ NextSteps.tsx # NextSteps auto-execution component
â â âââ ResourceViewer.tsx # File/resource viewer with syntax highlighting
â â âââ Message.tsx # Individual message component
â â âââ affordances/ # UI affordance components (empty - create your own)
â âââ hooks/
â â âââ useAnthropicStream.tsx # Streaming chat hook
â âââ utils/
â â âââ clientTools.ts # Client-side tools utility with dynamic tool management
â â âââ affordanceManager.ts # UI affordance registration framework
â â âââ containers/ # Affordance container managers
â â â âââ overlayContainer.ts # Modal/popup containers
â â â âââ sidebarContainer.ts # Collapsible side panels
â â â âââ headerContainer.ts # Fixed header extensions
â â â âââ footerContainer.ts # Footer extensions
â â â âââ inlineContainer.ts # Chat-embedded components
â â âââ mcpTesting.ts # Frontend MCP server testing
â â âââ mcpPrompts.ts # Frontend MCP prompt fetching
â â âââ mcpTools.ts # MCP tools fetching with caching
â â âââ mcpClientPool.ts # Centralized MCP client pool
â â âââ MCPClient.ts # Individual MCP client wrapper
â âââ style.css # Custom styles with streaming animations
âââ shared/
â âââ types.ts # Shared TypeScript types for streaming
â âââ affordance-types.ts # UI affordance framework types
âââ test/ # Test suite
â âââ components/ # Component tests
â â âââ Message.test.tsx # Message component tests
â âââ utils/ # Test utilities and helpers
â â âââ test-helpers.ts # Common test utilities
â âââ setup.ts # Global test setup and configuration
â âââ README.md # Test-specific documentation
âââ package.json # NPM configuration with test scripts
âââ TESTING.md # Comprehensive testing guide
âââ README.md
The application includes a powerful UI Affordance Registration Framework that allows the assistant to dynamically create and control custom UI components. This system provides:
- Overlay: Modal/popup containers with backdrop support
- Sidebar: Collapsible side panels (left/right positioning)
- Header: Fixed header extensions with priority ordering
- Footer: Footer extensions alongside existing controls
- Inline: Components embedded directly in the chat flow
attach_affordance: Attach new UI components from file keys with optional persistencecall_affordance_method: Invoke methods on attached componentsdetach_affordance: Remove attached componentslist_affordances: List all active affordancesget_affordance_errors: Get runtime errors from affordance componentsclear_affordance_errors: Clear/acknowledge affordance errorsget_affordance_logs: Get captured console logs from affordance componentsclear_affordance_logs: Clear captured logs from affordance componentsrestore_affordances: Manually restore persistent affordances from localStorageclear_persisted_affordances: Clear all saved affordance configurationsget_persisted_affordances_info: View information about saved affordances
// Attach a custom affordance component in the sidebar
const counterId = await attach_affordance('sidebar',
'my-custom-component.tsx', // Your component file (from MCP or local)
{
title: 'My Component',
position: 'right',
width: '250px',
persistent: true // Will be restored on next session
}
);
// Get available methods and their schemas
const methods = await call_affordance_method(counterId, 'getPublicMethods', []);
console.log('Available methods:', methods);
// Interact with your component (methods are called directly on the component)
await call_affordance_method(counterId, 'someMethod', ['param1', 'param2']);
const result = await call_affordance_method(counterId, 'getResult', []);
// Check for any errors
const errors = await get_affordance_errors(counterId);
if (errors.length > 0) {
console.log('Component has errors:', errors);
// Clear the errors after handling
await clear_affordance_errors(counterId);
}
// Check for any logs
const logs = await get_affordance_logs(counterId);
if (logs.length > 0) {
console.log('Component logs:', logs);
// Clear the logs after reviewing
await clear_affordance_logs(counterId);
}
// View persistent affordances info
const info = await get_persisted_affordances_info();
console.log(`${info.count} affordances will be restored on next session`);
For detailed documentation, see AFFORDANCE-FRAMEWORK.md. For component development guide, see AFFORDANCE-COMPONENT-GUIDE.md.
The affordance framework supports automatic persistence across sessions:
- Persistent Affordances: Set
persistent: truein the affordance config to automatically save and restore across browser sessions - Automatic Restoration: Persistent affordances are automatically restored when the app starts and MCP clients are ready
- State Management: Components can implement optional
getState()andsetState()methods to preserve internal state - Replacement Logic: Attaching an affordance with the same
fileKeyandtypeautomatically replaces the existing one (prevents duplicates) - Error Recovery: Failed restorations are logged but don't break the app startup
Storage Location: Persistent affordances are saved in localStorage under the key affordance_registrations.
The app stores configuration and chat history in localStorage:
anthropic_api_key: Your Anthropic API keyselected_model: The chosen Claude model (defaults to claude-3-5-sonnet-20241022)mcp_servers: Array of configured MCP serverschat_messages: Complete chat history (persists between page loads)auto_execute_next_steps: Global setting for NextSteps auto-execution (defaults to true)
The project includes a comprehensive test suite using Deno Test and React Testing Library:
# Run all tests npm test # Run tests in watch mode npm run test:watch # Run tests with coverage npm run test:coverage # Generate HTML coverage report npm run test:coverage-report
For detailed testing information, see TESTING.md.
GET /- Main application (serves frontend)GET /frontend/*- Frontend static filesGET /shared/*- Shared utility files
Note: MCP server testing and prompt fetching are now handled directly on the frontend for improved performance and reduced server load.
- Open the app at the provided URL
- Click "Settings" in the footer to configure your Anthropic API key and select your preferred Claude model
- Add/remove/toggle MCP servers as needed
- Use the "Test" button next to each MCP server to verify connectivity (shows â for success, â for errors)
- Configure NextSteps auto-execution in settings (enabled by default)
- Start chatting with Claude and watch responses stream in real-time!
- Use the stop button (âšī¸) to interrupt streaming at any time
- Switch models anytime in settings without losing your chat history
- Your chat history and settings will be automatically saved and restored when you return
- When MCP tools return NextSteps proposals, they'll appear as interactive pills that can auto-execute or require manual selection
The app comes pre-configured with the Val Town MCP server:
- Name: Val Town MCP
- URL:
https://c15r--81c497c63c0a11f081e29e149126039e.web.val.run/mcp - Status: Enabled by default (you'll need to add your authorization token)
- đ¨ Exquisite Design System: Sophisticated visual design featuring:
- Glassmorphism Effects: Translucent surfaces with backdrop blur for depth
- Smooth Animations: Delightful micro-interactions and state transitions
- Advanced Typography: Carefully crafted font hierarchy and spacing
- Color Psychology: Harmonious color palette designed for extended use
- Depth & Shadows: Multi-layered shadow system for visual hierarchy
- Responsive Design: Fluid layouts that adapt beautifully to any screen size
- đą Mobile-First Experience: Optimized for mobile devices with:
- Touch-Friendly Controls: Generous tap targets and gesture support
- Adaptive Layouts: Content reflows intelligently on smaller screens
- Performance Optimized: Smooth 60fps animations on mobile devices
- iOS/Android Polish: Native-feeling interactions and visual cues
- Real-time Streaming: Watch Claude's responses appear word-by-word as they're generated
- Stream Control: Stop streaming responses at any time with the stop button
- Client-side Tools: Interactive tools that run directly in the browser:
- ask_user: Sophisticated user input with text, multiline, multiple choice, and confirmation dialogs
- calculate: Mathematical expression evaluator for quick calculations
- NextSteps Auto-Execution: MCP tools can propose follow-up actions that execute automatically after a countdown or require manual selection. See NextSteps-README.md for implementation details.
- Resource Viewer: MCP tools can display file and resource content with syntax highlighting, fullscreen support, and intelligent rendering based on file type
- MCP Integration: Support for multiple Model Context Protocol servers
- Enhanced MCP Display: Collapsible sections for tool calls and results with proper JSON formatting
- Unobtrusive Footer Controls: Settings (âī¸) and clear chat (đī¸) buttons positioned in the footer alongside the input
- Persistent Chat History: All messages automatically saved to localStorage and restored on page load
- Persistent Settings: All configuration stored in browser localStorage
- Auto-scroll: Messages automatically scroll to bottom during streaming
- Auto-resize: Input field grows with content
- Error Handling: Clear error messages for API issues with stream recovery
- Loading States: Visual feedback during API calls and streaming
- Structured Responses: MCP tool use and results are displayed in organized, collapsible sections
- Clean Interface: Maximized chat area with no header, footer contains all controls
- Streaming Animations: Visual cursor and highlighting for active streaming responses
- âŋ Accessibility Features:
- Keyboard Navigation: Full keyboard support for all interactions
- Screen Reader Support: Semantic HTML and ARIA labels
- Reduced Motion: Respects user's motion preferences
- High Contrast: Supports high contrast mode
- Focus Management: Clear focus indicators and logical tab order