FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
c15r
c15rChat
Public
Like
Chat
Home
Code
12
backend
1
frontend
6
shared
1
test
4
IMPLEMENTATION-SUMMARY.md
NextSteps-Examples.md
NextSteps-README.md
README.md
ResourceViewer-README.md
TESTING.md
package.json
H
test-runner.ts
Branches
1
Pull requests
Remixes
1
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ€“ all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
6/20/2025
Viewing readonly version of main branch: v960
View latest version
README.md

Anthropic Streaming Chat with MCP

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

๐Ÿš€ Key Features

  • ๐Ÿš€ 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)
  • ๐Ÿ’ฌ Inline User Input - Sophisticated ask_user tool with text, multiline, choice, and confirm inputs
  • ๐Ÿงฎ Built-in Calculator - Mathematical expression evaluation tool
  • ๐Ÿ”„ 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
  • ๐ŸŽฏ Command Palette - Quick access to MCP tools and prompts via / commands
  • ๐Ÿ’พ 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

๐Ÿ—๏ธ Architecture Improvements

Centralized Client Management

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);

Performance Optimizations

  • โœ… 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

Before vs After Consolidation

Before

  • โŒ Multiple client instances per server (4 separate creation points)
  • โŒ Duplicate connection logic across components
  • โŒ ResourceViewer reload loops due to unstable references
  • โŒ Inconsistent error handling

After

  • โœ… 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

Streaming Implementation

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
  • Error handling and keep-alive support
  • Token usage tracking
  • Support for all delta types (text, JSON, thinking)

Project Structure

โ”œโ”€โ”€ 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
โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”‚   โ””โ”€โ”€ useAnthropicStream.tsx # Streaming chat hook
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ mcpTesting.ts   # Frontend MCP server testing
โ”‚   โ”‚   โ””โ”€โ”€ mcpPrompts.ts   # Frontend MCP prompt fetching
โ”‚   โ””โ”€โ”€ style.css           # Custom styles with streaming animations
โ”œโ”€โ”€ shared/
โ”‚   โ””โ”€โ”€ types.ts            # Shared TypeScript types for streaming
โ”œโ”€โ”€ 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

Configuration

The app stores configuration and chat history in localStorage:

  • anthropic_api_key: Your Anthropic API key
  • selected_model: The chosen Claude model (defaults to claude-3-5-sonnet-20241022)
  • mcp_servers: Array of configured MCP servers
  • chat_messages: Complete chat history (persists between page loads)
  • auto_execute_next_steps: Global setting for NextSteps auto-execution (defaults to true)

Development

Testing

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.

API Endpoints

  • GET / - Main application (serves frontend)
  • GET /frontend/* - Frontend static files
  • GET /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.

Usage

  1. Open the app at the provided URL
  2. Click "Settings" in the footer to configure your Anthropic API key and select your preferred Claude model
  3. Add/remove/toggle MCP servers as needed
  4. Use the "Test" button next to each MCP server to verify connectivity (shows โœ… for success, โŒ for errors)
  5. Configure NextSteps auto-execution in settings (enabled by default)
  6. Start chatting with Claude and watch responses stream in real-time!
  7. Use the stop button (โน๏ธ) to interrupt streaming at any time
  8. Switch models anytime in settings without losing your chat history
  9. Your chat history and settings will be automatically saved and restored when you return
  10. When MCP tools return NextSteps proposals, they'll appear as interactive pills that can auto-execute or require manual selection

Default MCP Server

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)

Features in Detail

  • ๐ŸŽจ 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
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesVersion controlCLIAI agentsCode intelligenceSlack integrationsGTMPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
ยฉ 2025 Val Town, Inc.