$git clone https://github.com/gts360/django-mcp-serverDjango MCP Server is an implementation of the Model Context Protocol (MCP) extension for Django. This module allows MCP Clients and AI agents to interact with any Django application seamlessly.
| 1 | # Django MCP Server |
| 2 | |
| 3 | [](https://pypi.org/project/django-mcp-server/) |
| 4 |  |
| 5 | [](https://djangopackages.org/packages/p/django-mcp-server/) |
| 6 |  |
| 7 | [](https://pypi.org/project/django-mcp-server/) |
| 8 | |
| 9 | **Django MCP Server** is an implementation of the **Model Context Protocol (MCP)** extension for Django. This module allows **MCP Clients** and **AI agents** to interact with **any Django application** seamlessly. |
| 10 | |
| 11 | 🚀 Django-Style declarative style tools to allow AI Agents and MCP clients tool to interact with Django.<br/> |
| 12 | 🚀 Expose Django models for AI Agents and MCP Tools to query in 2 lines of code in a safe way.<br/> |
| 13 | 🚀 Convert Django Rest Framework APIs to MCP tools with one annotation.<br/> |
| 14 | ✅ Working on both WSGI and ASGI without infrastructure change.<br/> |
| 15 | ✅ Validated as a Remote Integration with Claude AI.<br/> |
| 16 | 🤖 Any MCP Client or AI Agent supporting MCP , (Google Agent Developement Kit, Claude AI, Claude Desktop ...) can interact with your application. |
| 17 | |
| 18 | Many thanks 🙏 to [all the contributor community](https://github.com/omarbenhamid/django-mcp-server/graphs/contributors) |
| 19 | |
| 20 | Maintained ✨ with care by [Smart GTS software engineering](https://www.smart-gts.com/#contact). |
| 21 | |
| 22 | Licensed under the **MIT License**. |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## Features |
| 27 | |
| 28 | - Expose Django models and logic as **MCP tools**. |
| 29 | - Serve an MCP endpoint inside your Django app. |
| 30 | - Easily integrate with AI agents, MCP Clients, or tools like Google ADK. |
| 31 | |
| 32 | --- |
| 33 | |
| 34 | ## Quick Start |
| 35 | |
| 36 | ### 1️⃣ Install |
| 37 | |
| 38 | ```bash |
| 39 | pip install django-mcp-server |
| 40 | ``` |
| 41 | |
| 42 | Or directly from GitHub: |
| 43 | |
| 44 | ```bash |
| 45 | pip install git+https://github.com/omarbenhamid/django-mcp-server.git |
| 46 | ``` |
| 47 | |
| 48 | --- |
| 49 | |
| 50 | ### 2️⃣ Configure Django |
| 51 | |
| 52 | ✅ Add `mcp_server` to your `INSTALLED_APPS`: |
| 53 | |
| 54 | ```python |
| 55 | INSTALLED_APPS = [ |
| 56 | # your apps... |
| 57 | 'mcp_server', |
| 58 | ] |
| 59 | ``` |
| 60 | |
| 61 | ✅ Add the **MCP endpoint** to your `urls.py`: |
| 62 | |
| 63 | ```python |
| 64 | from django.urls import path, include |
| 65 | |
| 66 | urlpatterns = [ |
| 67 | # your urls... |
| 68 | path("", include('mcp_server.urls')), |
| 69 | ] |
| 70 | ``` |
| 71 | |
| 72 | By default, the MCP endpoint will be available at `/mcp`. |
| 73 | |
| 74 | --- |
| 75 | |
| 76 | ### 3️⃣ Define MCP Tools |
| 77 | |
| 78 | In mcp.py create a subclass of `ModelQueryToolset` to give access to a model : |
| 79 | |
| 80 | ```python |
| 81 | from mcp_server import ModelQueryToolset |
| 82 | from .models import * |
| 83 | |
| 84 | |
| 85 | class BirdQueryTool(ModelQueryToolset): |
| 86 | model = Bird |
| 87 | |
| 88 | def get_queryset(self): |
| 89 | """self.request can be used to filter the queryset""" |
| 90 | return super().get_queryset().filter(location__isnull=False) |
| 91 | |
| 92 | class LocationTool(ModelQueryToolset): |
| 93 | model = Location |
| 94 | |
| 95 | class CityTool(ModelQueryToolset): |
| 96 | model = City |
| 97 | |
| 98 | ``` |
| 99 | |
| 100 | Or create a sub class of `MCPToolset` to publish generic methods (private _ methods are not published) |
| 101 | |
| 102 | Example: |
| 103 | ```python |
| 104 | from mcp_server import MCPToolset |
| 105 | from django.core.mail import send_mail |
| 106 | |
| 107 | class MyAITools(MCPToolset): |
| 108 | def add(self, a: int, b: int) -> list[dict]: |
| 109 | """A service to add two numbers together""" |
| 110 | return a+b |
| 111 | |
| 112 | def send_email(self, to_email: str, subject: str, body: str): |
| 113 | """ A tool to send emails""" |
| 114 | |
| 115 | send_mail( |
| 116 | subject=subject, |
| 117 | message=body, |
| 118 | from_email='your_email@example.com', |
| 119 | recipient_list=[to_email], |
| 120 | fail_silently=False, |
| 121 | ) |
| 122 | ``` |
| 123 | |
| 124 | --- |
| 125 | |
| 126 | ### Verify with MCP Inspect |
| 127 | |
| 128 | Use the management commande mcp_inspect to ensure your tools are correctly declared : |
| 129 | |
| 130 | ```bash |
| 131 | python manage.py mcp_inspect |
| 132 | ``` |
| 133 | |
| 134 | ### Use the MCP with any MCP Client |
| 135 | |
| 136 | The mcp tool is now published on your Django App at `/mcp` endpoint. |
| 137 | |
| 138 | **IMPORTANT** For production setup, on non-public data, consider enabling |
| 139 | authorization through : DJANGO_MCP_AUTHENTICATION_CLASSES |
| 140 | |
| 141 | ### Test with MCP Python SDK |
| 142 | |
| 143 | Y |