
mrrobotke/django-migrations-mcp
Developer toolsЭта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал
A Model Context Protocol (MCP) service for managing Django migrations in distributed environments.
Обзор
A Model Context Protocol (MCP) service for managing Django migrations in distributed environments. This service wraps Django's migration commands and exposes them as MCP endpoints, making it easy to manage migrations across multiple services and integrate with CI/CD pipelines. - Check migration status (equivalent to showmigrations) - Create new migrations with validation (equivalent to makemigrations) - Apply migrations with safety checks (equivalent to migrate) - Additional validation and safety checks: - Sequential migration order verification - Conflict detection - Dependency validation - Safety analysis of migration operations Set the following environment variables: The project follows PEP 8 guidelines. Format your code using: MIT License. See LICENSE file for details. 1. Fork the repository 2. Create your feature branch (git checkout -b feature/amazing-feature) 3. Commit your changes (git commit -m 'Add amazing feature') 4.
README
Показан фрагмент оригинального README. Открыть оригинал.
Django Migrations MCP Service
A Model Context Protocol (MCP) service for managing Django migrations in distributed environments. This service wraps Django’s migration commands and exposes them as MCP endpoints, making it easy to manage migrations across multiple services and integrate with CI/CD pipelines.
Features
- Check migration status (equivalent to
showmigrations) - Create new migrations with validation (equivalent to
makemigrations) - Apply migrations with safety checks (equivalent to
migrate) - Additional validation and safety checks:
- Sequential migration order verification
- Conflict detection
- Dependency validation
- Safety analysis of migration operations
Installation
Local Development
- Clone the repository:
git clone https://github.com/mrrobotke/django-migrations-mcp.git
cd django-migrations-mcp
- Install dependencies:
pip install -r requirements.txt
Configuration
Set the following environment variables:
export DJANGO_SETTINGS_MODULE="your_project.settings"
export MCP_SERVICE_PORT=8000 # Optional, defaults to 8000
Usage
Running the Service
- Directly with Python:
python -m migrations_mcp.service
- Using Docker:
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
MCP Endpoints
- Show Migrations:
from mcp import MCPClient
client = MCPClient()
migrations = await client.call("show_migrations")
- Make Migrations:
result = await client.call("make_migrations", {
"app_labels": ["myapp"], # Optional
"dry_run": True # Optional
})
- Apply Migrations:
result = await client.call("migrate", {
"app_label": "myapp", # Optional
"migration_name": "0001", # Optional
"fake": False, # Optional
"plan": True # Optional
})
CI/CD Integration
Example GitHub Actions workflow:
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 check_migrations.py script:
import asyncio
from mcp import MCPClient
async def check_migrations():
client = MCPClient()
Установка
docker run -e DJANGO_SETTINGS_MODULE=your_project.settings \