The Django Migrations MCP Service is a practical tool that makes it easier to manage Django migrations in distributed environments by wrapping Django's migration commands into MCP endpoints. This service simplifies migration management across multiple services and integrates well with CI/CD pipelines.
git clone https://github.com/mrrobotke/django-migrations-mcp.git
cd django-migrations-mcp
pip install -r requirements.txt
Set the necessary environment variables:
export DJANGO_SETTINGS_MODULE="your_project.settings"
export MCP_SERVICE_PORT=8000 # Optional, defaults to 8000
You can run the service either directly with Python or using Docker:
Python method:
python -m migrations_mcp.service
Docker method:
docker build -t django-migrations-mcp .
docker run -e DJANGO_SETTINGS_MODULE=your_project.settings \
-v /path/to/your/django/project:/app/project \
-p 8000:8000 \
django-migrations-mcp
The service provides several endpoints that correspond to Django's migration commands:
To check the current migration status (equivalent to Django's showmigrations
):
from mcp import MCPClient
client = MCPClient()
migrations = await client.call("show_migrations")
To create new migrations with validation:
result = await client.call("make_migrations", {
"app_labels": ["myapp"], # Optional
"dry_run": True # Optional
})
To apply migrations with safety checks:
result = await client.call("migrate", {
"app_label": "myapp", # Optional
"migration_name": "0001", # Optional
"fake": False, # Optional
"plan": True # Optional
})
You can also access the service using HTTP requests:
Show Migrations:
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{"method": "show_migrations"}'
Make Migrations:
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{"method": "make_migrations", "params": {"apps": ["your_app"]}}'
Apply Migrations:
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{"method": "migrate", "params": {"app": "your_app"}}'
Here's an example GitHub Actions workflow for migration checks:
name: Django Migrations Check
on:
pull_request:
paths:
- '*/migrations/*.py'
- '*/models.py'
jobs:
check-migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Start MCP service
run: |
python -m migrations_mcp.service &
- name: Check migrations
run: |
python ci/check_migrations.py
Example migration check script:
import asyncio
from mcp import MCPClient
async def check_migrations():
client = MCPClient()
# Check current status
migrations = await client.call("show_migrations")
# Try making migrations
result = await client.call("make_migrations", {"dry_run": True})
if not result.success:
print(f"Error: {result.message}")
exit(1)
print("Migration check passed!")
if __name__ == "__main__":
asyncio.run(check_migrations())
docker run -d \
--name django-migrations-mcp \
-e DJANGO_SETTINGS_MODULE=your_project.settings \
-e MCP_SERVICE_PORT=8000 \
-v /path/to/your/django/project:/app/project \
-p 8000:8000 \
django-migrations-mcp
docker run -d \
--name django-migrations-mcp \
-e DJANGO_SETTINGS_MODULE=your_project.settings \
-e MCP_SERVICE_PORT=8000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
-v /path/to/your/django/project:/app/project \
-p 8000:8000 \
--network host \
django-migrations-mcp
docker run -d \
--name django-migrations-mcp \
-e DJANGO_SETTINGS_MODULE=your_project.settings \
-e MCP_SERVICE_PORT=8000 \
-e REDIS_URL=redis://your-redis-host:6379 \
-v /path/to/your/django/project:/app/project \
-p 8000:8000 \
--restart unless-stopped \
--network your-network \
django-migrations-mcp
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "django-migrations-mcp" '{"command":"docker","args":["run","-d","--name","django-migrations-mcp","-e","DJANGO_SETTINGS_MODULE=your_project.settings","-e","MCP_SERVICE_PORT=8000","-v","/path/to/your/django/project:/app/project","-p","8000:8000","django-migrations-mcp"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"django-migrations-mcp": {
"command": "docker",
"args": [
"run",
"-d",
"--name",
"django-migrations-mcp",
"-e",
"DJANGO_SETTINGS_MODULE=your_project.settings",
"-e",
"MCP_SERVICE_PORT=8000",
"-v",
"/path/to/your/django/project:/app/project",
"-p",
"8000:8000",
"django-migrations-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"django-migrations-mcp": {
"command": "docker",
"args": [
"run",
"-d",
"--name",
"django-migrations-mcp",
"-e",
"DJANGO_SETTINGS_MODULE=your_project.settings",
"-e",
"MCP_SERVICE_PORT=8000",
"-v",
"/path/to/your/django/project:/app/project",
"-p",
"8000:8000",
"django-migrations-mcp"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect