Django MCP Server

Django MCP Server

Enables LLM assistants to explore Django project structure through read-only resources and optionally execute Python code in a stateful Django shell environment. Provides access to project configuration, app details, model information, and interactive development capabilities.

Category
访问服务器

README

mcp-django

<!-- [[[cog import subprocess import cog

from noxfile import DJ_VERSIONS from noxfile import PY_VERSIONS

cog.outl("PyPI - mcp-django") cog.outl("PyPI - mcp-django-shell") cog.outl("PyPI - Python Version") cog.outl(f"Django Version") ]]] --> PyPI - mcp-django PyPI - mcp-django-shell PyPI - Python Version Django Version <!-- [[[end]]] -->

A Model Context Protocol (MCP) server providing Django project exploration resources and optional stateful shell access for LLM assistants to interact with Django projects.

Requirements

<!-- [[[cog import subprocess import cog

from noxfile import DJ_VERSIONS from noxfile import PY_VERSIONS

cog.outl(f"- Python {', '.join([version for version in PY_VERSIONS])}") cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version != 'main'])}") ]]] -->

  • Python 3.10, 3.11, 3.12, 3.13
  • Django 4.2, 5.1, 5.2 <!-- [[[end]]] -->

Installation

Choose the installation option that fits your use case:

Core

Provides read-only Django project exploration resources (django://project, django://apps, django://models).

# Read-only resources only - no shell access
pip install mcp-django

# Or with uv
uv add mcp-django

Shell

⚠️ DO NOT use in production!

Adds django_shell and django_reset tools for executing Python code.

# Includes shell tools for code execution
pip install "mcp-django[shell]"

# Or with uv
uv add "mcp-django[shell]"

[!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.

All

# Currently same as [shell]
pip install "mcp-django[all]"

# Or with uv
uv add "mcp-django[all]"

Getting Started

Run the MCP server directly from your Django project directory:

python -m mcp_django

# With explicit settings module
python -m mcp_django --settings myproject.settings

# With debug logging
python -m mcp_django --debug

Or using 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.

There's also a Django management command if you prefer, but that requires adding mcp-django to INSTALLED_APPS:

python manage.py mcp

Transport

The server supports multiple transport protocols:

# Default: STDIO
python -m mcp_django

# HTTP
python -m mcp_django --transport http --host 127.0.0.1 --port 8000

# SSE
python -m mcp_django --transport sse --host 127.0.0.1 --port 8000

Client Configuration

Configure your MCP client using one of the examples below. The command is the same for all clients, just expressed in annoyingly different JSON soup.

Don't see your client? Submit a PR with setup instructions.

Claude Code

{
  "mcpServers": {
    "django": {
      "command": "python",
      "args": ["-m", "mcp_django"],
      "cwd": "/path/to/your/django/project",
      "env": {
        "DJANGO_SETTINGS_MODULE": "myproject.settings"
      }
    }
  }
}

Opencode

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "django": {
      "type": "local",
      "command": ["python", "-m", "mcp_django"],
      "enabled": true,
      "environment": {
        "DJANGO_SETTINGS_MODULE": "myproject.settings"
      }
    }
  }
}

Features

mcp-django provides an MCP server with Django project exploration resources and optional shell access for LLM assistants. The base package offers safe, read-only resources while the shell extra adds stateful code execution capabilities.

It wouldn't be an MCP server README without a gratuitous list of features punctuated by emojis, so:

Core (mcp-django):

  • 🔍 Project exploration - MCP resources for discovering apps, models, and configuration
  • 🚀 Zero configuration - No schemas, no settings, just Django
  • 🔒 Safe by default - Read-only resources, no code execution
  • 🌐 Multiple transports - STDIO, HTTP, SSE support

Shell (mcp-django[shell]):

  • 🐚 Stateful shell - django_shell executes Python code in your Django environment
  • 🔄 Persistent state - Imports and variables stick around between calls
  • 🧹 Reset when needed - django_reset clears the session when things get weird
  • 🤖 LLM-friendly - Designed for LLM assistants that already know Python
  • 📦 Minimal dependencies - Just FastMCP and Django (you already have Django)
  • 🎯 Does one thing well - Runs code. That's it. That's the feature.

Inspired by Armin Ronacher's Your MCP Doesn't Need 30 Tools: It Needs Code.

Resources (mcp-django)

Read-only resources are provided for project exploration without executing code (note that resource support varies across MCP clients):

  • django://project - Python environment and Django configuration details
  • django://apps - All installed Django applications with their models
  • django://models - Detailed model information with import paths and field types

The idea is to give just enough information about the project to hopefully guide the LLM assistant and prevent needless shell exploration, allowing it to get straight to work.

Tools (mcp-django-shell)

When installed with the shell extra, two tools handle shell operations and session management:

  • django_shell - Execute Python code in a persistent Django shell session
  • django_reset - Reset the session, clearing all variables and imports

Imports and variables persist between calls within the shell tool, so the LLM can work iteratively - exploring your models, testing queries, debugging issues.

Development

For detailed instructions on setting up a development environment and contributing to this project, see CONTRIBUTING.md.

For release procedures, see RELEASING.md.

License

mcp-django is licensed under the MIT license. See the LICENSE file for more information.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选