Skip to content

Conversation

@DanielHashmi
Copy link
Owner

@DanielHashmi DanielHashmi commented Dec 15, 2025

Summary

Complete MCP-based AI chatbot implementation for Phase III: Todo management through natural language with stateless architecture and widget streaming.

Architecture Overview

Component Technology Description
Agent Framework OpenAI Agents SDK MCP protocol with stdio transport
Backend FastAPI + SQLModel Stateless server with database persistence
Frontend Next.js 16 + ChatKit React components with CDN integration
Database Neon PostgreSQL Conversation & task storage
Authentication Better Auth JWT Token-based user context

Key Implementation Details

MCP Architecture (Stateless)

  • MCPTaskAgent connects to MCP server via stdio transport
  • Agent has NO internal state - all data persisted to database
  • User messages stored BEFORE agent runs
  • Assistant responses stored AFTER completion
  • Tools accessed via MCP protocol (not direct function calls)

Widget Streaming System

  • Agent instructions enforce widget-only display (no text formatting)
  • Widgets built for: task list, task created, task completed, task deleted, task updated
  • Streaming via ctx.context.stream_widget() during tool execution
  • Frontend receives widgets through SSE stream

Database Integration

  • DatabaseStore implements ChatKit Store contract
  • Conversations persisted with language preference
  • Messages stored with role, content, timestamps
  • Stateless design ensures consistency across requests

Frontend Components

  • ThemedChatWidget with proper CDN script loading
  • FloatingChatWidget for dashboard integration
  • Custom fetch with Authorization header for JWT
  • Global CSS for chat widget styling

Files Changed

New Files (13)

  • backend/src/chatbot/mcp_agent.py - MCP agent implementation
  • backend/src/chatbot/task_tools.py - MCP tool decorators
  • backend/src/mcp_server/ - MCP server with task tools
  • backend/src/services/db_chatkit_store.py - Database store
  • backend/src/services/mcp_chatkit_server.py - ChatKit server
  • frontend/components/chat/ThemedChatWidget.tsx - Themed widget
  • specs/006-todo-ai-chatbot/plan.md - Implementation plan
  • specs/006-todo-ai-chatbot/implementation-status.md - Progress tracking
  • specs/006-todo-ai-chatbot/mcp-research.md - MCP architecture notes

Modified Files (21)

  • Enhanced agent instructions with widget display rules
  • Updated ChatKit API endpoints for MCP integration
  • Frontend dashboard with chat widget
  • Global CSS with chat styling
  • README with MCP architecture documentation
  • Test utilities for JWT and MCP validation

Critical Implementation Rules

STATELESS MANDATE: Server holds NO state between requests
MCP TOOLS: Agent interacts with tasks ONLY through MCP tools
WIDGET STREAMING: Display via stream_widget(), NOT agent text
CDN REQUIRED: ChatKit CDN must load for proper widget rendering
CUSTOM BACKEND: Uses FastAPI backend (not hosted workflows)

Test Plan

  • MCP server starts and exposes tools correctly
  • Agent instructions prevent text formatting of task data
  • Widgets stream properly during tool execution
  • Database persistence works for conversations and messages
  • JWT authentication validates user context
  • Frontend widget renders with proper CDN loading
  • End-to-end task operations (add, list, complete, delete, update)
  • Multi-language support (English/Urdu)
  • Voice command integration

Debugging Guide

Backend Issues

  • Widgets not rendering → Check stream_widget() call in tools
  • Agent outputting JSON → Update agent instructions to prevent formatting
  • Streaming broken → Verify run_streamed() not run_sync
  • CORS errors → Check FastAPI middleware configuration

Frontend Issues

  • Blank widgets → Verify CDN script loaded in layout.tsx
  • Broken widgets → Check widget field structure
  • Auth failures → Verify Authorization header in custom fetch
  • Infinite loading → Check backend response format

Related Documentation

  • Specification: specs/006-todo-ai-chatbot/spec.md
  • Architecture: specs/phase-three-goal.md
  • MCP Research: specs/006-todo-ai-chatbot/mcp-research.md
  • Quickstart: specs/006-todo-ai-chatbot/quickstart.md

🤖 Generated with Claude Code

DanielHashmi and others added 17 commits December 14, 2025 19:00
Add specialized AI agents for full-stack development:
- authentication-specialist: Better Auth integration
- backend-expert: FastAPI and Python patterns
- frontend-expert: Next.js 16+ development
- database-expert: SQLModel and Neon PostgreSQL
- fullstack-architect: System architecture decisions
- ui-ux-expert: Modern UI design
- chatkit engineers: OpenAI ChatKit integration

Add development skills with templates and references:
- better-auth-python/ts: JWT verification patterns
- fastapi: API routing and dependencies
- nextjs: App Router and Server Components
- drizzle-orm: Type-safe database queries
- neon-postgres: Serverless PostgreSQL
- framer-motion: React animations
- shadcn: UI component patterns
- tailwind-css: Utility-first styling
- context7-documentation-retrieval: Library docs

Update slash commands for spec-driven development

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add PowerShell scripts for Windows development:
- check-prerequisites.ps1: Verify development environment
- common.ps1: Shared utility functions
- create-new-feature.ps1: Feature scaffolding
- setup-plan.ps1: Plan file initialization
- update-agent-context.ps1: Agent context management

Add Architecture Decision Records (ADRs):
- 0001: Transition to full-stack web application architecture
- 0002: Authentication with Better Auth and JWT
- 0003: Full-stack technology stack selection
- 0004: Authentication technology stack decisions
- 0005: PWA offline-first architecture

Update constitution.md for Phase II requirements:
- Multi-user authentication support
- Persistent storage with Neon PostgreSQL
- Better Auth for frontend, JWT for backend
- Vertical slice architecture methodology

Update .gitignore for full-stack development

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Backend (FastAPI + Python):
- JWT verification with EdDSA/JWKS from Better Auth
- Protected route middleware and dependencies
- User and session models with SQLModel
- Database migrations and table creation scripts
- Neon PostgreSQL integration with connection pooling
- Task CRUD API with user isolation
- Profile image upload with secure file handling
- Comprehensive test suite for auth flows

Specs and Documentation:
- Feature specification with user stories
- Architecture plan and data models
- API contracts (OpenAPI/YAML format)
- Better Auth integration guide
- Implementation task breakdown
- Requirements checklist

Prompt History Records for traceability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Specifications for full task management:
- Task creation, reading, updating, deletion
- Priority levels (low, medium, high)
- Tag-based categorization
- Search and filter functionality
- Sort by date, priority, status
- Completion status tracking

Implementation plan covering:
- Backend API endpoints
- Frontend components
- State management
- Database schema updates

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Complete UI overhaul with industry-standard design:
- Design system with consistent tokens and variables
- Tailwind CSS configuration with custom theme
- Framer Motion animations and micro-interactions
- Responsive layouts for all screen sizes
- Dark mode support with system preference detection

Components implemented:
- Authentication pages (login, register, forgot password)
- Dashboard with task overview and stats
- Task list with filtering, sorting, and search
- Task detail and edit views
- Profile and settings pages
- Navigation and sidebar components

Design specifications and implementation plan

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Marketing landing page specifications:
- Hero section with animated headlines
- Feature showcase with icon grid
- Testimonials carousel
- Pricing comparison table
- Call-to-action sections
- Mobile-responsive design

Implementation plan with:
- React components structure
- Framer Motion animations
- SEO optimization
- Performance considerations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Progressive Web App (PWA) features:
- Service worker for offline support
- App manifest for installation
- IndexedDB for local data caching
- Background sync for offline changes
- Push notification infrastructure

Profile enhancements:
- Avatar upload with image cropping
- Profile settings management
- Account preferences
- Notification settings
- Data export functionality

ADR for PWA offline-first architecture

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Complete Next.js 16+ frontend with:

Authentication:
- Better Auth integration with email/password
- OAuth social login support (Google, GitHub)
- Session management and JWT handling
- Protected routes and middleware

Task Management UI:
- Dashboard with task overview and stats
- Task list with real-time filtering and sorting
- Task creation, editing, and deletion
- Priority and tag management
- Search functionality

Profile Features:
- User profile page with avatar upload
- Settings and preferences
- Account management

Design System:
- Tailwind CSS with custom theme
- shadcn/ui component library
- Framer Motion animations
- Dark mode support
- Responsive mobile-first design

Landing Page:
- Hero section with animations
- Feature showcase
- Pricing and testimonials

PWA Support:
- Service worker configuration
- Offline caching strategy
- App manifest

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reorganize PHR directory structure:
- Rename console-task-manager to 001-console-task-manager
- Use standardized 4-digit numbering (0001-, 0002-, etc.)

Add constitution PHRs:
- 0001: Initial Python console app constitution
- 0002: Phase II full-stack transition
- 0003: Development methodology updates
- 0004: Multi-phase vertical slice architecture

Add general PHRs:
- Auth user story specification
- Technology research sessions
- Backend analysis and debugging
- Git workflow documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update README.md:
- Add full-stack architecture overview
- Document frontend and backend setup
- Add development quickstart guide
- Include technology stack details

Update CLAUDE.md:
- Add Phase II specialized agents guidance
- Update skill usage recommendations
- Document active technologies per feature

Add phase-two-goal.md:
- Define full-stack web application vision
- Outline feature progression roadmap
- Specify technology requirements

Add root package-lock.json and test utilities

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- 001-auth-integration: Update to 159/180 tasks (88%), mark
  security/testing/documentation items as completed
- 004-landing-page: Mark accessibility and theme tasks completed
- 005-pwa-profile-enhancements: Update to 56/59 tasks (95%),
  remaining: PWA icons generation and Lighthouse audit

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove 001-console-task-manager specs and implementation
- Remove console app Python code (src/cli, src/models, src/services)
- Remove related unit and integration tests
- Add PWA profile enhancements prompt history record
- Prepare branch for 002-web-task-manager implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Introduce Phase III specification for AI-powered todo chatbot with
MCP architecture, OpenAI Agents SDK, and ChatKit integration. Updates
constitution to v3.0.0 with stateless architecture requirements and
global project rules.

Changes:
- Constitution: Add Phase III AI chatbot architecture section
- Constitution: Add Global Project Rules for cross-phase governance
- CLAUDE.md: Refactor and add Phase III agent/skill requirements
- Add Claude skills: chatkit-backend, chatkit-gemini, sqlmodel, mcp-python-sdk
- Add phase-three-goal.md specification
- Add todo-app-feature-requirements.md
- Add PHRs for constitution and skill creation prompts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Complete feature specification for AI-powered chatbot integration:

- 10 user stories covering core chat, Urdu support, and voice commands
- 30 functional requirements (FR-001 to FR-030)
- 17 measurable success criteria
- Clarifications for rate limiting, task matching, speech services
- Edge cases for error handling, multi-language, and voice input

Features specified:
- Natural language task management (CRUD operations)
- Floating widget in bottom-right corner
- Multi-language support (English + Urdu)
- Voice commands with browser Web Speech API
- Conversation persistence and tool chaining

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive planning documentation for Todo AI Chatbot:
- Implementation plan with 4-phase architecture
- Detailed tasks breakdown (37 backend + 8 frontend tasks)
- Data model design with SQLModel schemas
- API contracts for chat endpoint
- Research notes and quickstart guide
- Prompt history records for planning sessions

Also add Context7 MCP tool permissions to settings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implemented production-ready AI chatbot (Lispa) with natural language task management,
voice input, real-time updates, and robust error handling.

Key Features:
- Natural language task operations (add/delete/complete by name)
- Voice input with beautiful UI and error handling
- Real-time task list updates using SWR
- Simplified ChatKit integration (phase-3 reference implementation)
- Multi-step agent workflows with explicit instructions

Critical Fixes:
- Agent tool call workflow: Two-step operations (list → delete/complete)
- Tool schema validation: Changed Optional[str] to str with default
- JWT authentication: Proper token injection in ChatKit fetch
- React hydration: Dynamic import with ssr: false
- UI positioning: Voice button in top-left, no overlaps
- Real-time updates: SWR mutate with 500ms delay for DB commits

Technical Improvements:
- Agent instructions with mandatory language and visual separators
- list_tasks returns task data for agent parsing
- Filtered voice "aborted" errors (expected behavior)
- Switched to Groq LLM provider (free tier)
- Added comprehensive CSS for widget overflow prevention
- Fixed message history append vs replace issue

Files Added:
- backend/src/chatbot/ (agent, tools, widgets, model_factory)
- backend/src/api/chatkit.py (ChatKit protocol endpoint)
- backend/src/services/chat_service.py (conversation/message persistence)
- backend/src/middleware/rate_limit.py (20 msg/min)
- backend/src/models/chat*.py (Conversation, Message, enums)
- backend/migrations/add_chat_tables.py
- frontend/components/chat/ (FloatingChatWidget, VoiceInput)
- frontend/hooks/useAuthToken.ts
- Comprehensive test suite (unit + integration)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…idget streaming

Completed Phase III Todo AI Chatbot with Model Context Protocol (MCP) architecture:

Backend:
- MCPTaskAgent connects to MCP server via stdio transport for tool access
- Stateless design - all state persisted to database via DatabaseStore
- Widget streaming system with builders for task operations
- Enhanced agent instructions with strict widget display rules
- Database-backed ChatKit store for conversation persistence

Frontend:
- ThemedChatWidget component with CDN integration
- Enhanced global CSS for chat widget styling
- Floating chat widget with proper z-index and positioning

Infrastructure:
- MCP server in src/mcp_server with task management tools
- Task tools (add, list, complete, delete, update) via MCP protocol
- JWT authentication and debugging utilities
- Comprehensive test suite for MCP server and authentication

Documentation:
- Updated README with MCP architecture overview
- Implementation status tracking
- MCP research notes and quickstart guide
- Phase III specification and task breakdown

This implementation follows the stateless architecture mandate where:
- Server holds NO state between requests
- User messages stored BEFORE agent runs
- Assistant responses stored AFTER completion
- All task operations via MCP tools as interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@DanielHashmi
Copy link
Owner Author

🚀 Latest Update: MCP Architecture Implementation

Just pushed comprehensive MCP-based chatbot implementation (commit 0c9d3d5).

What's New

Complete MCP Architecture

  • Agent connects to MCP server via stdio transport
  • Stateless design with all state persisted to database
  • Widget streaming system for task operations
  • Database-backed conversation persistence

Key Stats

  • 📦 36 files changed (+3792, -590 lines)
  • ✨ 13 new files (MCP agent, server, tools, store)
  • 🔧 21 files enhanced (agent instructions, API, frontend, tests)

Ready for Testing

  • Backend MCP server operational
  • Agent instructions enforce widget-only display
  • JWT authentication integrated
  • Test suite for MCP validation

Next Steps

  1. Frontend testing with CDN-loaded ChatKit widget
  2. End-to-end task operation validation
  3. Multi-language support verification (English/Urdu)
  4. Voice command integration testing

The implementation follows all Phase III mandates: stateless architecture, MCP tools as interface, widget streaming, and custom backend mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants