Token导航 LogoToken导航TokenDH.com
Django Migrations MCP服务 logo
开发工具stdio官方级别未说明来源级核验

Django Migrations MCP服务

MCP Server

一个用于在分布式环境中管理Django迁移的Model Context Protocol (MCP)服务,提供迁移状态检查、创建新迁移、应用迁移等功能,并支持CI/CD集成。

工具数

0

提示词数

0

GitHub Stars

6

资源数

0
Python开发工具命令行工具

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

mrrobotke

提供方

mrrobotke

最后核验

2026/5/17 20:32

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install -r requirements.txt

详细介绍

](https://mseep.ai/app/mrrobotke-django-migrations-mcp)

Django迁移MCP服务

用于管理分布式环境中Django迁移的模型上下文协议(MCP)服务。该服务封装了Django的迁移命令,并将其作为MCP端点公开,从而可以轻松管理跨多个服务的迁移并与CI/CD管道集成。

特性

  • 检查迁移状态(相当于 showmigrations)
  • 创建带有验证的新迁移(相当于 makemigrations)
  • 应用带有安全检查的迁移(相当于 migrate)
  • 附加验证和安全检查:

- 顺序迁移顺序验证 - 冲突检测 - 依赖性验证 - 迁移操作的安全性分析

安装

地方发展

  1. 克隆存储库:
git clone https://github.com/mrrobotke/django-migrations-mcp.git
cd django-migrations-mcp
  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操作工作流示例:

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许可证。有关详细信息,请参阅LICENSE文件。

贡献

  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"}}'

目录标签

目录标签

Python开发工具命令行工具Django迁移本地部署分布式管理CI/CD集成数据库迁移

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP