laibaaaimran/phase3-chatbot-backend
0
Todo Evolution Backend - Phase 3
Hugging Face Spaces Deployment
This is the backend for the Todo Evolution application, designed for deployment on Hugging Face Spaces using Docker. This backend supports AI chatbot integration via Model Context Protocol (MCP).
Environment Variables Required
You need to set the following environment variables:
DATABASE_URL: PostgreSQL database URL (e.g., your Neon database URL)JWT_SECRETorBETTER_AUTH_SECRET: Secret for JWT token verification (should match frontend)CORS_ORIGINS: Comma-separated list of allowed origins (e.g., your frontend URL, Hugging Face Space URL)COHERE_API_KEY: Your Cohere API key for AI chatbot functionalityPORT: Port number (default: 8000)
API Endpoints
Task Management
GET /health- Health check endpointGET /api/tasks- Get user's tasksPOST /api/tasks- Create a new taskPUT /api/tasks/{id}- Update a taskPATCH /api/tasks/{id}/complete- Toggle task completion statusDELETE /api/tasks/{id}- Delete a task
MCP (Model Context Protocol) Server for AI Chatbot
GET /mcp/tools- Get available tools for the AI agentPOST /mcp/call-tools- Execute tools requested by the AI agent
Authentication
The backend uses JWT tokens from Better Auth for authentication. The tokens are verified using the shared secret.
MCP Server Capabilities
The MCP server exposes the following tools to the AI chatbot:
add_task: Add a new task to the user's listget_tasks: Retrieve the user's tasksupdate_task: Update an existing taskdelete_task: Delete a taskmark_complete: Toggle the completion status of a task
Hugging Face Spaces Setup
- Create a new Space on Hugging Face with the "Docker" SDK option
- Set the required environment variables in the Space settings
- Add the following files to your repository:
Dockerfilerequirements.txtmain.pymcp/directory containing the MCP server implementation- The Space will automatically build and deploy the application
Docker Build
To build the Docker image locally:
docker build -t todo-backend .To run locally:
docker run -p 8000:8000 \
-e DATABASE_URL="your_db_url" \
-e JWT_SECRET="your_secret" \
-e COHERE_API_KEY="your_cohere_key" \
-e CORS_ORIGINS="http://localhost:3000,https://your-frontend-url.vercel.app" \
todo-backend