MCP-todo-client-server

namanbarkiya/MCP-todo-client-server

3.2

If you are the rightful owner of MCP-todo-client-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This document provides a comprehensive overview of a Model Context Protocol (MCP) server implementation using FastAPI and Next.js, designed to demonstrate an API-first approach for managing todos.

Tools
5
Resources
0
Prompts
0

MCP AI Todo

An end-to-end demo showing an API-first MCP approach: a FastAPI backend exposes both a REST API and an MCP endpoint; a Next.js client consumes the REST API for UI and can orchestrate via MCP for tool-driven actions.

Why API-first MCP?

  • The backend (FastAPI) owns the source of truth and exposes capabilities as REST endpoints and MCP tools.
  • The frontend (Next.js) stays thin and calls the API, while MCP can automate workflows via the same backend.
  • Assistants in MCP-compatible clients can invoke the same server-side tools used by the UI.

Architecture

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚        Next.js Frontend       β”‚
                 β”‚  (Tabs: Todos | MCP | Chat)   β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
              fetch /app/api/mcp β”‚                      fetch /app/api/chat
                                 β”‚                                  β”‚
                                 β–Ό                                  β–Ό
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚ MCP API Routes             β”‚   β”‚   Chat API Route     β”‚
                     β”‚ /api/mcp/tools             β”‚   β”‚ (LLM + tool-calling) β”‚
                     β”‚ /api/mcp/tool (invoke)     β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚ /api/mcp/resources/prompts β”‚                 β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚ server-side
                                    β”‚                               β–Ό
                                    β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚                    β”‚  MCP Client SDK (JS)   β”‚
                                    β”‚                    β”‚ @modelcontextprotocol  β”‚
                                    β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚                                  β”‚ HTTP
                                    β–Ό                                  β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β–Ό
                         β”‚   MCP Server (FastAPI)     β”‚        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚   Endpoint: POST /mcp      β”‚        β”‚   LLM (Gemini)β”‚
                         β”‚   Exposes MCP Tools:       β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚   - list_todos             β”‚         function calls
                         β”‚   - get_todo               β”‚
                         β”‚   - create_todo            β”‚
                         β”‚   - update_todo            β”‚
                         β”‚   - delete_todo            β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                        REST       β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                         FastAPI REST                         β”‚
    β”‚   GET/POST /todos/  |  PUT/DELETE /todos/{id}                β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                    β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       writes/reads      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  CSV Service (CRUD)  │────────────────────────►│ todos.csv β”‚
         β”‚ load/save/next id    │◄────────────────────────│           β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        data returned    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

mcp-ai-todo/
β”œβ”€β”€ .cursor/          # Cursor config for MCP tools
β”œβ”€β”€ backend/          # FastAPI REST API + MCP endpoint; CSV storage for todos
β”œβ”€β”€ frontend/         # Next.js client (shadcn/ui, Tailwind) with multi-tab UI
└── README.md         # This file

Backend (FastAPI + MCP)

Start the API server:

cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8080

Key endpoints:

  • REST: GET/POST /todos/, PUT/DELETE /todos/{id}/
  • MCP: POST /mcp (Model Context Protocol endpoint)

Data store: backend/data/todos.csv via a simple CSV service.

Frontend (Next.js)

Start the web client:

cd frontend
npm install
npm run dev

Environment variables:

  • NEXT_PUBLIC_API_BASE (optional): defaults to http://localhost:8080. Set if your backend runs elsewhere.

UI highlights (single-page, multi-tab):

  • Todos: CRUD against FastAPI endpoints; inline edit, toggle, delete
  • MCP Tools: lists available server tools exposed via MCP
  • Chat: improved chat window; each response shows collapsible tool-call details

Tech:

  • Next.js App Router, Tailwind CSS (v3), shadcn/ui components
  • MCP client (@modelcontextprotocol/sdk) configured in frontend/lib/mcpClient.ts

Using MCP with this project

MCP is exposed at http://localhost:8080/mcp. Any MCP-compatible client can connect and discover available tools. Typical flows:

  • Ask the assistant to list/create/update/delete todos; the assistant calls MCP tools that use the same backend logic as the REST API.
  • In the UI Chat tab, tool calls and results appear under each assistant response.

Example assistant prompts:

  • β€œList all todos.”
  • β€œCreate a todo β€˜Buy groceries’.”
  • β€œMark todo 3 as completed.”

Development Tips

  • Keep server logic in the backend; expose as both REST and MCP tools.
  • The UI should remain a thin client; avoid duplicating server logic in the frontend.
  • To change styles, use shadcn/ui primitives and Tailwind utilities (no custom component boilerplate).

URLs

  • Frontend: http://localhost:3000
  • API: http://localhost:8080
  • MCP: http://localhost:8080/mcp