Skip to main content

MCP server providing a stateful Django shell for AI assistants.

Project description

mcp-django-shell

PyPI PyPI - Python Version Django Version

A Model Context Protocol (MCP) server providing a stateful Django shell for AI assistants to interact with Django projects.

Requirements

  • Python 3.10, 3.11, 3.12, 3.13
  • Django 4.2, 5.1, 5.2

Installation

  1. Install the package from PyPI.

    python -m pip install mcp-django-shell
    
    # or if you like the new hotness
    
    uv add mcp-django-shell
    uv sync
    
  2. Add to your Django project's INSTALLED_APPS:

    DEBUG = ...
    
    if DEBUG:
        INSTALLED_APPS.append("mcp_django_shell")
    

[!WARNING]

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.

Getting Started

mcp-django-shell provides a Django management command that MCP clients can connect to. Configure your client using one of the examples below.

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

Claude Code

{
  "mcpServers": {
    "django_shell": {
      "command": "python",
      "args": ["manage.py", "mcp_shell"],
      "cwd": "/path/to/your/django/project"
    }
  }
}

Opencode

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "django_shell": {
      "type": "local",
      "command": ["python", "manage.py", "mcp_shell"],
      "enabled": true
    }
  }
}

Usage

mcp-django-shell provides an MCP server with a stateful Django shell for AI assistants. It sets up Django, maintains session state between calls, and lets the AI write and execute Python code directly against your project.

The MCP server comes with just two tools:

  • 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, so the AI can work iteratively - exploring your models, testing queries, debugging issues.

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

  • 🐚 One tool - 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
  • 🚀 Zero configuration - No schemas, no settings, just Django
  • 🤖 LLM-friendly - Designed for AI 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.

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-shell is licensed under the MIT license. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_django_shell-0.3.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_django_shell-0.3.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_django_shell-0.3.0.tar.gz.

File metadata

  • Download URL: mcp_django_shell-0.3.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.12

File hashes

Hashes for mcp_django_shell-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ec69be3b6bd070a627d517b1406b0041aa1dd7591c8616317d5ee0904a9df937
MD5 7c8f8e8284cefffbc2cd0adf2e995150
BLAKE2b-256 7cced0d5eb85d262228db1f7aecb87097de941026e7c16de8b6e55f6ea36ae61

See more details on using hashes here.

File details

Details for the file mcp_django_shell-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_django_shell-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10ddf57c1988465a850264a9a0eceff1bf49ff352a9f56035cb0a70b0a88a4e9
MD5 9e1f630e5ba693228091d75cf36ea891
BLAKE2b-256 a545a09a3ba57d5652c684f3cd2f6d0faaf4efda808b451ed52b1ae69a33413a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page