Dev-Kit MCP Server 是一个面向代理开发工具的模型上下文协议(MCP)服务器,可在根项目目录中提供有作用域的授权操作。该软件包支持安全地执行各种操作,如运行 makefile 命令、移动和删除文件等,未来还计划加入更多代码编辑工具。它是 VS-Code Copilot 等 AI 辅助开发工具的理想 MCP 服务器。
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 文件。当你需要为不同目的定义一组独立的命令时,这个参数非常有用。
服务器提供以下工具:
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"
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"})
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 文件。