MD

mrrobotke/django-migrations-mcp

Developer tools

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기

6 stars 5 forks 품질 48 트렌드 14

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

  1. Clone the repository:
git clone https://github.com/mrrobotke/django-migrations-mcp.git
cd django-migrations-mcp
  1. 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

  1. Directly with Python:
python -m migrations_mcp.service
  1. 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

  1. Show Migrations:
from mcp import MCPClient

client = MCPClient()
migrations = await client.call("show_migrations")
  1. Make Migrations:
result = await client.call("make_migrations", {
    "app_labels": ["myapp"],  # Optional
    "dry_run": True  # Optional
})
  1. 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()
GitHub에서 전체 README 보기

설치

docker run -e DJANGO_SETTINGS_MODULE=your_project.settings \
MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →