关于 Dev-Kit MCP Server
Dev-Kit MCP Server 面向 Agent 开发,为 AI 编码工具提供受项目目录限制的操作。它将文件、Git、搜索和命令执行集中为 MCP 工具。
主要功能
- 01限制在根目录内操作
- 02创建、编辑、移动和删除文件
- 03查看 Git 状态、暂存和提交
- 04运行 Makefile 与预定义命令
- 05搜索文件并读取指定行
适用场景
- 01通过预定义命令运行项目检查
- 02使用 Git 工具查看并暂存代码更改
- 03搜索代码库并检查指定文件行
MCP 相关
它向 MCP 客户端提供文件、Git、搜索和命令操作工具。操作范围限制在配置的根目录内。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Dev-Kit MCP 服务
一个面向 Agent 开发工具的 Model Context Protocol(MCP)服务,可在项目根目录中执行受限且经授权的操作。此软件包支持安全地执行各种操作,例如运行 makefile 命令、移动和删除文件,未来还计划加入更多代码编辑工具。它是 VS-Code copilot 和其他 AI 辅助开发工具的理想 MCP 服务。
功能
- 🔒 安全操作:在受限且经授权的根目录中执行操作
- 🛠️ Makefile 命令执行:在项目中安全地运行 makefile 命令
- 📁 文件操作:在授权目录中移动、创建、重命名和删除文件
- 🔄 Git 操作:执行 status、add、commit、push、pull 和 checkout 等 Git 操作
- 🔌 MCP 集成:将任意代码库转变为符合 MCP 标准的系统
- 🤖 AI 辅助开发:与 VS-Code copilot 和其他 AI 工具完美集成
- 🔄 可扩展框架:轻松添加用于代码编辑和其他操作的新工具
- 🚀 高性能:基于 FastMCP 构建,性能出色
安装
pip install dev-kit-mcp-server
用法
运行服务
# Recommended method (with root directory specified)
dev-kit-mcp-server --root-dir=workdir
# With custom TOML file for predefined commands
dev-kit-mcp-server --root-dir=workdir --commands-toml=custom_commands.toml
# Alternative methods
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 命令
探索操作
- search_files:按正则表达式模式搜索项目目录中的文件。支持可选的根目录和输出长度限制。
- search_text:搜索文件中匹配给定模式的行。支持文件筛选、上下文行和输出长度限制。
- read_lines:读取文件中的指定行或行范围。支持选择行范围和输出长度限制。
预定义命令
- 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]
# Basic commands
hello = "echo Hello, World!"
date = "date"
# Development commands
test = "pytest"
lint = "ruff check ."
build = "python setup.py build"
使用 MCP 客户端的示例
from fastmcp import Client
async def example():
async with Client() as client:
# List available tools
tools = await client.list_tools()
# File Operations
# Create a directory
result = await client.call_tool("create_dir", {"path": "new_directory"})
# Move a file
result = await client.call_tool("move_dir", {"path1": "source.txt", "path2": "destination.txt"})
# Remove a file
result = await client.call_tool("remove_file", {"path": "file_to_remove.txt"})
# Rename a file
result = await client.call_tool("rename_file", {"path": "old_name.txt", "new_name": "new_name.txt"})
# Edit a file
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 Operations
# Get repository status
result = await client.call_tool("git_status")
# Add files to the index
result = await client.call_tool("git_add", {"paths": ["file1.txt", "file2.txt"]})
# Commit changes
result = await client.call_tool("git_commit", {"message": "Add new files"})
# Pull changes from remote
result = await client.call_tool("git_pull", {"remote": "origin", "branch": "main"})
# Push changes to remote
result = await client.call_tool("git_push")
# Checkout a branch
result = await client.call_tool("git_checkout", {"branch": "feature-branch", "create": True})
# Makefile Operations
# Run a makefile command
result = await client.call_tool("exec_make_target", {"commands": ["test"]})
# Exploration Operations
# Search for Python files
result = await client.call_tool("search_files", {"pattern": ".*\\.py$"})
# Search for files in a specific directory with output limit
result = await client.call_tool("search_files", {
"pattern": "test.*",
"root": "tests",
"max_chars": 1000
})
# Search for text patterns in files
result = await client.call_tool("search_text", {"pattern": "def.*test"})
# Search in specific files with context
result = await client.call_tool("search_text", {
"pattern": "import",
"files": ["main.py", "utils.py"],
"context": 2
})
# Read specific lines from a file
result = await client.call_tool("read_lines", {"file_path": "README.md", "start": 1, "end": 10})
# Read entire file with character limit
result = await client.call_tool("read_lines", {
"file_path": "config.json",
"max_chars": 500
})
# Predefined Commands
# Execute a predefined command
result = await client.call_tool("predefined_commands", {"command": "test"})
# Execute a predefined command with a parameter
result = await client.call_tool("predefined_commands", {"command": "test", "param": "specific_test"})
开发
设置
# Clone the repository
git clone https://github.com/DanielAvdar/dev-kit-mcp-server.git
cd dev-kit-mcp-server
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
贡献
欢迎贡献!欢迎提交 Pull Request。
许可证
本项目采用 MIT License 许可,详情请参阅 LICENSE 文件。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。
