Skip to main content
Glama
mrrobotke

Django Migrations MCP Service

by mrrobotke

Django 마이그레이션 MCP 서비스

분산 환경에서 Django 마이그레이션을 관리하기 위한 모델 컨텍스트 프로토콜(MCP) 서비스입니다. 이 서비스는 Django 마이그레이션 명령을 래핑하여 MCP 엔드포인트로 노출하므로 여러 서비스 간의 마이그레이션을 쉽게 관리하고 CI/CD 파이프라인과 통합할 수 있습니다.

특징

  • 마이그레이션 상태 확인( showmigrations 와 동일)

  • 검증을 통해 새로운 마이그레이션을 생성합니다( makemigrations 와 동일)

  • 안전 검사를 사용하여 마이그레이션 적용( migrate 와 동일)

  • 추가 검증 및 안전 점검:

    • 순차적 마이그레이션 순서 확인

    • 충돌 감지

    • 종속성 검증

    • 이주 작업의 안전 분석

Related MCP server: mcp-dbs

설치

지역 개발

  1. 저장소를 복제합니다.

지엑스피1

  1. 종속성 설치:

pip install -r requirements.txt

구성

다음 환경 변수를 설정하세요.

export DJANGO_SETTINGS_MODULE="your_project.settings" export MCP_SERVICE_PORT=8000 # Optional, defaults to 8000

용법

서비스 실행

  1. Python을 사용하여 직접:

python -m migrations_mcp.service
  1. 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 엔드포인트

  1. 마이그레이션 표시:

from mcp import MCPClient client = MCPClient() migrations = await client.call("show_migrations")
  1. 마이그레이션을 수행합니다.

result = await client.call("make_migrations", { "app_labels": ["myapp"], # Optional "dry_run": True # Optional })
  1. 마이그레이션 적용:

result = await client.call("migrate", { "app_label": "myapp", # Optional "migration_name": "0001", # Optional "fake": False, # Optional "plan": True # Optional })

CI/CD 통합

GitHub Actions 워크플로 예시:

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

check_migrations.py 스크립트 예시:

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())

개발

테스트 실행

pytest migrations_mcp/tests/

코드 스타일

이 프로젝트는 PEP 8 가이드라인을 따릅니다. 다음을 사용하여 코드 형식을 지정하세요.

black migrations_mcp/ isort migrations_mcp/

특허

MIT 라이선스. 자세한 내용은 라이선스 파일을 참조하세요.

기여하다

  1. 저장소를 포크하세요

  2. 기능 브랜치를 생성합니다( git checkout -b feature/amazing-feature )

  3. 변경 사항을 커밋하세요( git commit -m 'Add amazing feature' )

  4. 브랜치에 푸시( git push origin feature/amazing-feature )

  5. 풀 리퀘스트 열기

Docker 사용법

이 프로젝트에는 다양한 배포 시나리오에 맞는 구조화된 명령을 제공하는 docker-commands.json 파일이 포함되어 있습니다. 이러한 명령을 직접 사용하거나 스크립트에서 구문 분석할 수 있습니다.

사용 가능한 Docker 구성

  1. Redis MCP 서버

# Run Redis MCP server docker run -i --rm mcp/redis redis://host.docker.internal:6379
  1. Django 마이그레이션 MCP 서버

# Basic setup 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 # With Redis integration 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
  1. 개발 환경

# Using docker-compose docker-compose up -d --build
  1. 테스트 환경

# Run tests in container docker run --rm \ -e DJANGO_SETTINGS_MODULE=your_project.settings \ -e PYTHONPATH=/app \ -v ${PWD}:/app \ django-migrations-mcp \ pytest
  1. 프로덕션 환경

# Production setup with health check 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

프로그래밍 방식으로 명령 사용

명령을 프로그래밍 방식으로 구문 분석하고 사용할 수 있습니다.

import json import subprocess # Load commands with open('docker-commands.json') as f: commands = json.load(f) # Run Redis MCP server redis_config = commands['mcpServers']['redis'] subprocess.run([redis_config['command']] + redis_config['args']) # Run Django Migrations MCP server django_config = commands['mcpServers']['djangoMigrations'] subprocess.run([django_config['command']] + django_config['args'])

네트워크 설정

  1. 개발 네트워크

docker network create mcp-dev-network
  1. 제작 네트워크

docker network create --driver overlay --attachable mcp-prod-network

MCP 도구 사용

이 서비스는 curl이나 모든 HTTP 클라이언트를 통해 액세스할 수 있는 여러 엔드포인트를 제공합니다.

  1. 마이그레이션 표시

curl -X POST http://localhost:8000/mcp \ -H "Content-Type: application/json" \ -d '{"method": "show_migrations"}'
  1. 마이그레이션을 만드세요

curl -X POST http://localhost:8000/mcp \ -H "Content-Type: application/json" \ -d '{"method": "make_migrations", "params": {"apps": ["your_app"]}}'
  1. 마이그레이션 적용

curl -X POST http://localhost:8000/mcp \ -H "Content-Type: application/json" \ -d '{"method": "migrate", "params": {"app": "your_app"}}'
-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mrrobotke/django-migrations-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server