一个面向代理开发工具的模型上下文协议(MCP)服务器,提供在项目根目录中授权操作的功能。此包允许安全执行诸如运行Makefile命令、移动和删除文件等操作,并计划在未来增加更多用于代码编辑的工具。它作为VS-Code Copilot和其他AI辅助开发工具的优秀MCP服务器。
<a href="https://glama.ai/mcp/servers/@DanielAvdar/dev-kit-mcp-server"> <img width="380" height="200" src="https://gips3.baidu.com/it/u=199770698,16453632&fm=3081&app=3081&f=PNG?w=760&h=400" alt="dev-kit-mcp-server MCP 服务器" /> </a>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"]})
# 探索操作
# 搜索Python文件
result = await client.call_tool("search_files", {"pattern": ".*\\.py$"})
# 在特定目录中搜索文件并限制输出长度
result = await client.call_tool("search_files", {
"pattern": "test.*",
"root": "tests",
"max_chars": 1000
})
# 搜索文件中的文本模式
result = await client.call_tool("search_text", {"pattern": "def.*test"})
# 在特定文件中搜索带有上下文的文本
result = await client.call_tool("search_text", {
"pattern": "import",
"files": ["main.py", "utils.py"],
"context": 2
})
# 从文件中读取特定行
result = await client.call_tool("read_lines", {"file_path": "README.md", "start": 1, "end": 10})
# 以字符限制读取整个文件
result = await client.call_tool("read_lines", {
"file_path": "config.json",
"max_chars": 500
})
# 预定义命令
# 执行预定义命令
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
欢迎贡献!请随时提交Pull Request。
该项目采用MIT许可证——详情见LICENSE文件。