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 のガイドから始めましょう →