by joshuadavidthomas
Provides Django project exploration resources and a stateless shell, enabling LLM assistants to query apps, models, routes, settings and execute arbitrary Python code within a Django environment.
Mcp Django offers an MCP server that exposes introspection resources for a Django project (apps, models, routes, settings) and a lightweight, stateless Python shell. It is intended for LLM assistants to programmatically explore and interact with a Django codebase during development.
pip install mcp-django
# or with uv
uv add mcp-django
python -m mcp_django # STDIO (default)
# or HTTP/SSE for remote access
python -m mcp_django --transport http --host 0.0.0.0 --port 8000
INSTALLED_APPS and start via the Django management command:
python manage.py mcp
django://apps, django://model/{app}/{model} and route introspection.execute runs Python code with a fresh environment each call.DJANGO_SETTINGS_MODULE.django-read-only or run the server in an isolated container.mcp_django in INSTALLED_APPS and run python manage.py mcp.A Model Context Protocol (MCP) server providing Django project exploration resources and optional stateful shell access for LLM assistants to interact with Django projects.
pip install mcp-django
# Or with uv
uv add mcp-django
⚠️ DO NOT use in production!
[!WARNING]
Seriously, only enable in development!
Look, it should go without saying, but I will say it anyway - this gives full shell access to your Django project. Only enable and use this in development and in a project that does not have access to any production data.
LLMs can go off the rails, get spooked by some random error, and in trying to fix things drop a production database.
[!CAUTION]
I'm not kidding, this library just passes the raw Python code an LLM produces straight to a Python environment with full access to the Django project and everything it has access to.
Most LLMs have basic safety protections in place if you ask to delete any data and will refuse to delete production data, but it is pretty trivial to bypass. (Hint: Just tell the LLM it's not production, it's in a development environment, and it will be the bull in a china shop deleting anything you want.)
I suggest using something like django-read-only if you need some CYA protection against this. Or, you know, don't use this in any sensitive environments.
Run the MCP server directly from your Django project directory:
python -m mcp_django
# Or with uv
uv run -m mcp_django
The server automatically detects DJANGO_SETTINGS_MODULE from your environment. You can override it with --settings or add to your Python path with --pythonpath:
python -m mcp_django --settings myproject.settings --debug
If you add mcp_django to INSTALLED_APPS, you can run it as a Django management command. This ensures the server runs within your Django project's environment and uses your project's settings:
python manage.py mcp
If you're using Docker and Docker Compose, you can run mcp-django as a separate compose service using HTTP transport. This makes it easier to connect your MCP client (running on your host) to the Django project (running in a container):
# compose.yml
services:
app:
# your existing Django app service
mcp:
build: .
command: python -m mcp_django --transport http --host 0.0.0.0 --port 8000
environment:
DJANGO_SETTINGS_MODULE: myproject.settings
ports:
- "8001:8000"
Then configure your MCP client to connect to http://localhost:8001/mcp (see Client Configuration below).
The server supports multiple transport protocols:
# STDIO (default, for local development)
python -m mcp_django
# HTTP (for Docker or remote access)
python -m mcp_django --transport http --host 127.0.0.1 --port 8000
# SSE (for Docker or remote access)
python -m mcp_django --transport sse --host 127.0.0.1 --port 8000
Configure your MCP client to connect to the server.
Don't see your client? Submit a PR with setup instructions.
For local development, use type: local with the command:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"django": {
"type": "local",
"command": ["python", "-m", "mcp_django"],
"enabled": true,
"environment": {
"DJANGO_SETTINGS_MODULE": "myproject.settings"
}
}
}
}
For Docker development, use type: remote with the URL:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"django": {
"type": "remote",
"url": "http://localhost:8001/mcp",
"enabled": true
}
}
}
For local development, use the command configuration:
{
"mcpServers": {
"django": {
"command": "python",
"args": ["-m", "mcp_django"],
"cwd": "/path/to/your/django/project",
"env": {
"DJANGO_SETTINGS_MODULE": "myproject.settings"
}
}
}
}
For Docker development with HTTP/SSE transport, configuration varies by Claude Code version - consult the MCP client documentation for remote server setup.
mcp-django provides an MCP server with Django project exploration resources and tools for LLM assistants.
It wouldn't be an MCP server README without a gratuitous list of features punctuated by emojis, so:
shell executes Python code with fresh state each callInspired by Armin Ronacher's Your MCP Doesn't Need 30 Tools: It Needs Code.
Read-only resources for project exploration without executing code (note that resource support varies across MCP clients):
| Resource | Description |
|---|---|
django://app/{app_label} |
Details for a specific Django app |
django://app/{app_label}/models |
All models in a specific app |
django://apps |
All installed Django applications with their models |
django://model/{app_label}/{model_name} |
Detailed information about a specific model |
django://models |
Project models with import paths and field types (first-party only) |
django://route/{pattern*} |
Routes matching a specific URL pattern |
django://setting/{key} |
Get a specific Django setting value |
| Resource | Description |
|---|---|
django://package/{slug} |
Detailed information about a specific package |
django://grid/{slug} |
Comparison grid with packages (e.g., "rest-frameworks") |
| Tool | Description |
|---|---|
get_project_info |
Get comprehensive project information including Python environment and Django configuration |
get_setting |
Get a Django setting value by key |
list_apps |
List all installed Django applications with their models |
list_models |
Get detailed information about Django models with optional filtering by app or scope |
list_routes |
Introspect Django URL routes with filtering support for HTTP method, route name, or URL pattern |
| Tool | Description |
|---|---|
execute_command |
Execute Django management commands with arguments and options |
list_commands |
List all available Django management commands with their source apps |
| Tool | Description |
|---|---|
execute |
Execute Python code in a stateless Django shell |
export_history |
Export session history as a Python script |
clear_history |
Clear the session history for a fresh start |
| Tool | Description |
|---|---|
get_grid |
Get a specific comparison grid with all its packages |
get_package |
Get detailed information about a specific Django package |
search |
Search djangopackages.org for third-party packages |
For detailed instructions on setting up a development environment and contributing to this project, see CONTRIBUTING.md.
For release procedures, see RELEASING.md.
mcp-django is licensed under the MIT license. See the LICENSE file for more information.
Please log in to share your review and rating for this MCP.
Explore related MCPs that share similar capabilities and solve comparable challenges
by modelcontextprotocol
A Model Context Protocol server for Git repository interaction and automation.
by zed-industries
A high‑performance, multiplayer code editor designed for speed and collaboration.
by modelcontextprotocol
Model Context Protocol Servers
by modelcontextprotocol
A Model Context Protocol server that provides time and timezone conversion capabilities.
by cline
An autonomous coding assistant that can create and edit files, execute terminal commands, and interact with a browser directly from your IDE, operating step‑by‑step with explicit user permission.
by upstash
Provides up-to-date, version‑specific library documentation and code examples directly inside LLM prompts, eliminating outdated information and hallucinated APIs.
by daytonaio
Provides a secure, elastic infrastructure that creates isolated sandboxes for running AI‑generated code with sub‑90 ms startup, unlimited persistence, and OCI/Docker compatibility.
by continuedev
Enables faster shipping of code by integrating continuous AI agents across IDEs, terminals, and CI pipelines, offering chat, edit, autocomplete, and customizable agent workflows.
by github
Connects AI tools directly to GitHub, enabling natural‑language interactions for repository browsing, issue and pull‑request management, CI/CD monitoring, code‑security analysis, and team collaboration.