|
1 | | -# Python Todo List App with MCP Integration |
| 1 | +# Todo MCP Agent with Azure AI |
2 | 2 |
|
3 | | -A Flask-based todo list application that exposes operations as MCP (Model Context Protocol) tools over HTTP and can be deployed to Azure App Service. |
| 3 | +A FastAPI-based todo list application with Azure AI Agents integration and Model Context Protocol (MCP) server functionality. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | | -- ✅ **CRUD Operations**: Create, read, update, delete todos |
8 | | -- 🎯 **Priority Management**: Set priority levels (low, medium, high) |
9 | | -- ✅ **Mark Complete/Incomplete**: Toggle completion status |
10 | | -- 🌐 **Web Interface**: Clean, responsive Bootstrap UI |
11 | | -- 💬 **Chat Interface**: Placeholder for future LLM integration |
12 | | -- 🔧 **MCP Tools**: HTTP-accessible tools for external integrations |
13 | | -- ☁️ **Azure Ready**: Optimized for Azure App Service deployment |
| 7 | +- 🤖 **AI-Powered Chat**: Azure AI Agents with GPT-4o for natural language todo management |
| 8 | +- 🔧 **MCP Integration**: Model Context Protocol server for AI tool access |
| 9 | +- ✅ **Todo Management**: Full CRUD operations with priority levels |
| 10 | +- 🌐 **Web Interface**: Clean, responsive UI with chat functionality |
| 11 | +- ☁️ **Azure Deployment**: Ready for Azure App Service with AI Foundry |
14 | 12 |
|
15 | | -## MCP Tools Available |
16 | | - |
17 | | -The application exposes the following MCP tools over HTTP: |
18 | | - |
19 | | -- `create_todo(title, description, priority)` - Create a new todo item |
20 | | -- `list_todos(filter_completed)` - Get all todos with optional filtering |
21 | | -- `update_todo(id, title, description, priority, completed)` - Update existing todo |
22 | | -- `delete_todo(id)` - Delete a todo item |
23 | | -- `mark_todo_complete(id, completed)` - Mark todo as complete/incomplete |
24 | | - |
25 | | -## Local Development |
| 13 | +## Quick Start |
26 | 14 |
|
27 | 15 | ### Prerequisites |
28 | 16 |
|
29 | | -- Python 3.12+ |
30 | | -- Virtual environment (venv) |
| 17 | +- Python 3.11+ |
| 18 | +- Azure subscription (for AI features) |
| 19 | +- Azure Developer CLI (azd) |
31 | 20 |
|
32 | | -### Setup |
| 21 | +### Local Development |
33 | 22 |
|
34 | | -1. **Clone and setup environment**: |
| 23 | +1. **Clone and setup**: |
35 | 24 | ```bash |
36 | | - git clone <repository-url> |
| 25 | + git clone <your-repo-url> |
37 | 26 | cd python-todo-mcp-agent |
38 | 27 | python -m venv .venv |
39 | 28 | .venv\Scripts\activate # Windows |
40 | | - # or |
41 | | - source .venv/bin/activate # Linux/Mac |
42 | | - ``` |
43 | | - |
44 | | -2. **Install dependencies**: |
45 | | - ```bash |
46 | 29 | pip install -r requirements.txt |
47 | 30 | ``` |
48 | 31 |
|
49 | | -3. **Set environment variables** (optional): |
50 | | - ```bash |
51 | | - set SECRET_KEY=your-secret-key-here |
52 | | - set DATABASE_URL=sqlite:///todos.db |
53 | | - ``` |
54 | | - |
55 | | -4. **Run the application**: |
| 32 | +2. **Run locally**: |
56 | 33 | ```bash |
57 | 34 | python main.py |
58 | 35 | ``` |
59 | 36 |
|
60 | | -5. **Access the application**: |
61 | | - - Web Interface: http://localhost:8000 |
62 | | - - Chat Interface: http://localhost:8000/chat |
| 37 | +3. **Access the app**: |
| 38 | + - Todo List: http://localhost:8000 |
| 39 | + - AI Chat: http://localhost:8000/chat |
63 | 40 | - Health Check: http://localhost:8000/health |
64 | | - - MCP Endpoint: http://localhost:8000/mcp |
65 | | - - MCP Tools: http://localhost:8000/mcp/tools/* |
66 | | - |
67 | | -## Azure Deployment |
68 | 41 |
|
69 | | -### Prerequisites |
| 42 | +### Azure Deployment |
70 | 43 |
|
71 | | -- Azure CLI installed and logged in |
72 | | -- Azure Developer CLI (azd) installed |
| 44 | +Deploy with one command: |
73 | 45 |
|
74 | | -### Deploy with AZD |
| 46 | +```bash |
| 47 | +azd up |
| 48 | +``` |
75 | 49 |
|
76 | | -1. **Initialize AZD**: |
77 | | - ```bash |
78 | | - azd init |
79 | | - ``` |
| 50 | +This creates: |
| 51 | +- Azure AI Foundry resource with GPT-4o |
| 52 | +- Azure AI Foundry project |
| 53 | +- App Service with managed identity |
| 54 | +- All necessary role assignments |
80 | 55 |
|
81 | | -2. **Set environment variables**: |
82 | | - ```bash |
83 | | - azd env set SECRET_KEY "your-production-secret-key" |
84 | | - azd env set DATABASE_URL "sqlite:///todos.db" |
85 | | - ``` |
| 56 | +## How It Works |
86 | 57 |
|
87 | | -3. **Deploy to Azure**: |
88 | | - ```bash |
89 | | - azd up |
90 | | - ``` |
| 58 | +The application combines three key components: |
91 | 59 |
|
92 | | -### Infrastructure |
| 60 | +1. **Todo Management**: Standard CRUD operations for managing tasks |
| 61 | +2. **MCP Server**: Exposes todo operations as tools that AI agents can use |
| 62 | +3. **AI Chat Interface**: Azure AI Agents that can interact with your todos through natural language |
93 | 63 |
|
94 | | -The deployment creates: |
| 64 | +### Example Chat Interactions |
95 | 65 |
|
96 | | -- **App Service Plan**: P0V3 (Premium V3, Linux) |
97 | | -- **App Service**: Python 3.12 runtime |
98 | | -- **Managed Identity**: Secure Azure resource access |
| 66 | +- "Create a high priority todo to finish the project" |
| 67 | +- "Show me all my incomplete todos" |
| 68 | +- "Mark the project todo as complete" |
| 69 | +- "What todos do I have for today?" |
99 | 70 |
|
100 | 71 | ## Architecture |
101 | 72 |
|
102 | 73 | ``` |
103 | 74 | ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ |
104 | | -│ Web Browser │────│ Flask App │────│ SQLite DB │ |
105 | | -│ (Todo UI) │ │ (CRUD API) │ │ (Data Store) │ |
| 75 | +│ Chat UI │────│ FastAPI App │────│ In-Memory │ |
| 76 | +│ (AI Agent) │ │ + MCP Server │ │ Todo Store │ |
106 | 77 | └─────────────────┘ └──────────────────┘ └─────────────────┘ |
107 | 78 | │ |
108 | 79 | ┌──────────────────┐ |
109 | | - │ MCP Server │ |
110 | | - │ (HTTP Tools) │ |
111 | | - └──────────────────┘ |
112 | | - │ |
113 | | - ┌──────────────────┐ |
114 | | - │ External Tools │ |
115 | | - │ & Integrations │ |
| 80 | + │ Azure AI │ |
| 81 | + │ Foundry + │ |
| 82 | + │ GPT-4o │ |
116 | 83 | └──────────────────┘ |
117 | 84 | ``` |
118 | 85 |
|
| 86 | +## MCP Tools |
| 87 | + |
| 88 | +The application exposes these tools for AI agents: |
| 89 | + |
| 90 | +- `create_todo` - Create new todos |
| 91 | +- `list_todos` - List all or filtered todos |
| 92 | +- `update_todo` - Update existing todos |
| 93 | +- `delete_todo` - Delete todos |
| 94 | +- `mark_todo_complete` - Toggle completion status |
| 95 | + |
119 | 96 | ## API Endpoints |
120 | 97 |
|
| 98 | +### Web Interface |
| 99 | +- `GET /` - Todo list page |
| 100 | +- `GET /chat` - AI chat interface |
| 101 | +- `GET /health` - Health check |
| 102 | + |
121 | 103 | ### REST API |
122 | | -- `GET /api/todos` - List all todos |
123 | | -- `POST /api/todos` - Create new todo |
124 | | -- `GET /api/todos/{id}` - Get specific todo |
| 104 | +- `GET /api/todos` - List todos |
| 105 | +- `POST /api/todos` - Create todo |
125 | 106 | - `PUT /api/todos/{id}` - Update todo |
126 | 107 | - `DELETE /api/todos/{id}` - Delete todo |
127 | | -- `PATCH /api/todos/{id}/complete` - Toggle completion |
128 | | - |
129 | | -### MCP Integration |
130 | | -- `GET /mcp` - MCP server info and available tools |
131 | | -- `POST /mcp` - MCP protocol endpoint (JSON-RPC 2.0) |
132 | | -- `GET/POST /mcp/tools/create_todo` - Direct tool access |
133 | | -- `GET/POST /mcp/tools/list_todos` - Direct tool access |
134 | | -- `POST /mcp/tools/update_todo` - Direct tool access |
135 | | -- `POST /mcp/tools/delete_todo` - Direct tool access |
136 | | -- `POST /mcp/tools/mark_todo_complete` - Direct tool access |
137 | | - |
138 | | -## Environment Variables |
139 | | - |
140 | | -| Variable | Description | Default | |
141 | | -|----------|-------------|---------| |
142 | | -| `SECRET_KEY` | Flask secret key for sessions | `dev-secret-key` | |
143 | | -| `DATABASE_URL` | Database connection string | `sqlite:///todos.db` | |
144 | | - |
145 | | -## Development Notes |
146 | | - |
147 | | -- **Database**: Uses SQLite for simplicity (can be upgraded to Azure SQL) |
148 | | -- **Styling**: Bootstrap 5 with Font Awesome icons |
149 | | -- **Frontend**: Vanilla JavaScript with fetch API |
150 | | -- **Backend**: Flask with SQLAlchemy ORM |
151 | | -- **MCP**: Native JSON-RPC 2.0 implementation in Flask |
152 | | -- **Security**: HTTPS only, managed identity, CORS enabled |
153 | | - |
154 | | -## Future Enhancements |
155 | | - |
156 | | -- 🤖 **LLM Integration**: Connect chat interface to language models |
157 | | -- 🗄️ **Database Upgrade**: Migrate to Azure SQL Database |
158 | | -- 🔐 **Authentication**: Add user accounts and auth |
159 | | -- 📱 **Mobile App**: React Native or Flutter companion |
160 | | -- 🔍 **Search**: Full-text search capabilities |
161 | | -- 📊 **Analytics**: Usage metrics and insights |
162 | | - |
163 | | -## Contributing |
164 | | - |
165 | | -1. Fork the repository |
166 | | -2. Create a feature branch |
167 | | -3. Make your changes |
168 | | -4. Add tests if applicable |
169 | | -5. Submit a pull request |
| 108 | + |
| 109 | +### AI Chat API |
| 110 | +- `POST /api/chat/session` - Create chat session |
| 111 | +- `POST /api/chat/message` - Send message to AI agent |
| 112 | + |
| 113 | +### MCP Server |
| 114 | +- `GET /mcp/stream` - MCP server info |
| 115 | +- `POST /mcp/stream` - MCP JSON-RPC endpoint |
| 116 | + |
| 117 | +## Configuration |
| 118 | + |
| 119 | +Environment variables are automatically configured during Azure deployment: |
| 120 | + |
| 121 | +- `AZURE_AI_PROJECT_ENDPOINT` - AI Foundry endpoint |
| 122 | +- `AZURE_OPENAI_DEPLOYMENT_NAME` - GPT-4o deployment name |
| 123 | +- `AZURE_APP_SERVICE_URL` - App service URL for MCP |
| 124 | + |
| 125 | +## Development |
| 126 | + |
| 127 | +The app uses: |
| 128 | +- **FastAPI** for the web framework |
| 129 | +- **Azure AI Agents** for AI functionality |
| 130 | +- **Bootstrap 5** for UI styling |
| 131 | +- **In-memory storage** for simplicity (easily upgradeable) |
170 | 132 |
|
171 | 133 | ## License |
172 | 134 |
|
173 | | -This project is licensed under the MIT License. |
| 135 | +MIT License |
0 commit comments