Back to MCP directory
publicPublicdnsLocal runtime

dev-kit-mcp-server

一个面向代理开发工具的MCP服务器,提供在根项目目录下的安全操作,包括执行Makefile命令、文件操作和Git操作等,适合与VS-Code copilot等AI辅助开发工具集成。

article

README

🚀 Dev-Kit MCP Server

Dev-Kit MCP Server 是一个面向代理开发工具的模型上下文协议(MCP)服务器,可在根项目目录中提供有作用域的授权操作。该软件包支持安全地执行各种操作,如运行 makefile 命令、移动和删除文件等,未来还计划加入更多代码编辑工具。它是 VS-Code Copilot 等 AI 辅助开发工具的理想 MCP 服务器。

PyPI - Python Version version License OS OS OS Tests Code Checks codecov Ruff Last Commit

🚀 快速开始

安装

pip install dev-kit-mcp-server

运行服务器

# 推荐方法(指定根目录)
dev-kit-mcp-server --root-dir=workdir

# 使用自定义 TOML 文件定义预定义命令
dev-kit-mcp-server --root-dir=workdir --commands-toml=custom_commands.toml

# 其他方法
uv run python -m dev_kit_mcp_server.mcp_server --root-dir=workdir
python -m dev_kit_mcp_server.mcp_server --root-dir=workdir

--root-dir 参数指定了文件操作的目录。出于安全考虑,该参数将文件操作限制在指定目录内。

--commands-toml 参数允许你指定一个自定义的 TOML 文件来定义预定义命令,而不是使用默认的 pyproject.toml 文件。当你需要为不同目的定义一组独立的命令时,这个参数非常有用。

可用工具

服务器提供以下工具:

文件操作

  • create_dir:在授权的根目录内创建目录
  • edit_file:通过用新文本替换指定起始行和结束行之间的内容来编辑文件
  • move_dir:在授权的根目录内移动文件和目录
  • remove_file:在授权的根目录内删除文件
  • rename_file:在授权的根目录内重命名文件和目录

Git 操作

  • git_status:获取 Git 仓库的状态(如更改的文件、未跟踪的文件等)
  • git_add:将文件添加到 Git 索引(暂存区)
  • git_commit:将更改提交到 Git 仓库
  • git_push:将更改推送到远程 Git 仓库
  • git_pull:从远程 Git 仓库拉取更改
  • git_checkout:在 Git 仓库中检出或创建分支
  • git_diff:显示提交之间、提交与工作树之间的差异等

Makefile 操作

  • exec_make_target:在项目内安全地运行 makefile 命令

预定义命令

  • predefined_commands:执行 TOML 文件中定义的预定义命令(默认:pyproject.toml 文件中 [tool.dkmcp.commands] 部分)

预定义命令的 TOML 文件格式如下:

[tool.dkmcp.commands]
test = "uv run pytest"
lint = "ruff check"
check = "uvx pre-commit run --all-files"
doctest = "make doctest"

每个命令都定义为一个键值对,其中键是命令名称,值是要执行的命令。例如,当你调用预定义命令 "test" 时,它将在根目录中执行 "uv run pytest"。

以下是在自定义 TOML 文件中定义命令的简单示例:

# custom_commands.toml
[tool.dkmcp.commands]
# 基本命令
hello = "echo Hello, World!"
date = "date"

# 开发命令
test = "pytest"
lint = "ruff check ."
build = "python setup.py build"

与 MCP 客户端的使用示例

from fastmcp import Client
async def example():
    async with Client() as client:
        # 列出可用工具
        tools = await client.list_tools()

        # 文件操作
        # 创建目录
        result = await client.call_tool("create_dir", {"path": "new_directory"})

        # 移动文件
        result = await client.call_tool("move_dir", {"path1": "source.txt", "path2": "destination.txt"})

        # 删除文件
        result = await client.call_tool("remove_file", {"path": "file_to_remove.txt"})

        # 重命名文件
        result = await client.call_tool("rename_file", {"path": "old_name.txt", "new_name": "new_name.txt"})

        # 编辑文件
        result = await client.call_tool("edit_file", {
            "path": "file_to_edit.txt",
            "start_line": 2,
            "end_line": 4,
            "text": "This text will replace lines 2-4"
        })

        # Git 操作
        # 获取仓库状态
        result = await client.call_tool("git_status")

        # 将文件添加到索引
        result = await client.call_tool("git_add", {"paths": ["file1.txt", "file2.txt"]})

        # 提交更改
        result = await client.call_tool("git_commit", {"message": "Add new files"})

        # 从远程拉取更改
        result = await client.call_tool("git_pull", {"remote": "origin", "branch": "main"})

        # 将更改推送到远程
        result = await client.call_tool("git_push")

        # 检出分支
        result = await client.call_tool("git_checkout", {"branch": "feature-branch", "create": True})

        # Makefile 操作
        # 运行 makefile 命令
        result = await client.call_tool("exec_make_target", {"commands": ["test"]})

        # 预定义命令
        # 执行预定义命令
        result = await client.call_tool("predefined_commands", {"command": "test"})

        # 执行带参数的预定义命令
        result = await client.call_tool("predefined_commands", {"command": "test", "param": "specific_test"})

✨ 主要特性

  • 🔒 安全操作:在有作用域的授权根目录内执行操作
  • 🛠️ Makefile 命令执行:在项目内安全地运行 makefile 命令
  • 📁 文件操作:在授权目录内移动、创建、重命名和删除文件
  • 🔄 Git 操作:执行如状态检查、添加、提交、推送、拉取和检出等 Git 操作
  • 🔌 MCP 集成:将任何代码库转换为符合 MCP 的系统
  • 🤖 AI 辅助开发:与 VS-Code Copilot 等 AI 工具完美集成
  • 🔄 可扩展框架:轻松添加新的代码编辑和其他操作工具
  • 🚀 高性能:基于 FastMCP 构建,性能卓越

📦 安装指南

pip install dev-kit-mcp-server

💻 使用示例

基础用法

from fastmcp import Client
async def example():
    async with Client() as client:
        # 列出可用工具
        tools = await client.list_tools()

        # 文件操作
        # 创建目录
        result = await client.call_tool("create_dir", {"path": "new_directory"})

        # 移动文件
        result = await client.call_tool("move_dir", {"path1": "source.txt", "path2": "destination.txt"})

        # 删除文件
        result = await client.call_tool("remove_file", {"path": "file_to_remove.txt"})

        # 重命名文件
        result = await client.call_tool("rename_file", {"path": "old_name.txt", "new_name": "new_name.txt"})

        # 编辑文件
        result = await client.call_tool("edit_file", {
            "path": "file_to_edit.txt",
            "start_line": 2,
            "end_line": 4,
            "text": "This text will replace lines 2-4"
        })

        # Git 操作
        # 获取仓库状态
        result = await client.call_tool("git_status")

        # 将文件添加到索引
        result = await client.call_tool("git_add", {"paths": ["file1.txt", "file2.txt"]})

        # 提交更改
        result = await client.call_tool("git_commit", {"message": "Add new files"})

        # 从远程拉取更改
        result = await client.call_tool("git_pull", {"remote": "origin", "branch": "main"})

        # 将更改推送到远程
        result = await client.call_tool("git_push")

        # 检出分支
        result = await client.call_tool("git_checkout", {"branch": "feature-branch", "create": True})

        # Makefile 操作
        # 运行 makefile 命令
        result = await client.call_tool("exec_make_target", {"commands": ["test"]})

        # 预定义命令
        # 执行预定义命令
        result = await client.call_tool("predefined_commands", {"command": "test"})

        # 执行带参数的预定义命令
        result = await client.call_tool("predefined_commands", {"command": "test", "param": "specific_test"})

🔧 技术细节

开发

环境搭建

# 克隆仓库
git clone https://github.com/DanielAvdar/dev-kit-mcp-server.git
cd dev-kit-mcp-server

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

贡献代码

欢迎贡献代码!请随时提交拉取请求。

📄 许可证

本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client