A WSGI- and ASGI-compatible Django implementation of the Model Context Protocol server
Project description
Django MCP Server
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.
✅ Works inside your existing WSGI application.
🚀 Streamable HTTP transport (stateless) is implemented.
🛣️ Stateful transport and Server-Sent Events (SSE) responses are on the roadmap (requires ASGI).
Licensed under the MIT License.
Features
- Expose Django models and logic as MCP tools.
- Serve an MCP endpoint inside your Django app.
- Easily integrate with AI agents, MCP Clients, or tools like Google ADK.
Quick Start
1️⃣ Install
pip install django-mcp-server
Or directly from GitHub:
pip install git+https://github.com/omarbenhamid/django-mcp-server.git
2️⃣ Configure Django
✅ Add mcp_server to your INSTALLED_APPS:
INSTALLED_APPS = [
# your apps...
'mcp_server',
]
✅ Add the MCP endpoint to your urls.py:
from django.urls import path, include
urlpatterns = [
# your urls...
path("", include('mcp_server.urls')),
]
By default, the MCP endpoint will be available at /mcp.
3️⃣ Define MCP Tools
Create a file mcp.py in your Django app.
Example:
from mcp_server import mcp_server as mcp
from .models import Bird
print("Defining tools")
@mcp.tool()
async def get_species_count(name: str) -> int:
'''Find the ID of a bird species by name (partial match). Returns the count.'''
ret = await Bird.objects.filter(species__icontains=name).afirst()
if ret is None:
ret = await Bird.objects.acreate(species=name)
return ret.count
@mcp.tool()
async def increment_species(name: str, amount: int = 1) -> int:
'''
Increment the count of a bird species by a specified amount.
Returns the new count.
'''
ret = await Bird.objects.filter(species__icontains=name).afirst()
if ret is None:
ret = await Bird.objects.acreate(species=name)
ret.count += amount
await ret.asave()
return ret.count
⚠️ Important: Always use Django's async ORM API.
Testing
By default, your MCP Server will be available as a stateless streamable http transport endpoint at <your_django_server>/mcp (ex. http://localhost:8000/mcp) (*without / at the end !).
There are many ways to test :
- Using the test MCP Client script : test/test_mcp_client.py
- You can test using MCP Inspector tool
- or any compatible MCP Client.
Integration with Agentic Frameworks and MCP Clients
You can easily plug your MCP server endpoint into any agentic framework supporting MCP streamable http servers. Refer to this list of clients
Roadmap
- ✅ Stateless streamable HTTP transport (implemented)
- 🔜 STDIO transport integration for dev configuration (ex. Claude Desktop)
- 🔜 ****
- 🔜 Stateful streamable HTTP transport using Django sessions
- 🔜 SSE endpoint integration (requires ASGI)
- 🔜 Improved error management and logging
Issues
If you encounter bugs or have feature requests, please open an issue on GitHub Issues.
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: django_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
466430bd44ab1d7f5fe64ab39028b3dcefbb04b2e4ad202860962659508fbb81
|
|
| MD5 |
9038eea3b21575257149bb9a3c313dcb
|
|
| BLAKE2b-256 |
cfc51b964670766e7727b3b259eb2f692e368381e486351e31e4a4478a1a797e
|
File details
Details for the file django_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bcce575440b8555543973d26471c0fa8bcabd167b50a413db2332c1306e205e
|
|
| MD5 |
37778eee5751f79fe9dc3ac8b54c90ca
|
|
| BLAKE2b-256 |
c62005f9256d9a4674eb5403c8333413cbea9e75b6c27a35b591d8060c89ae58
|