MCP Git Commit Generator 借助 Model Context Protocol (MCP),依据你暂存的 Git 更改自动生成符合规范的提交信息,助力高效的版本管理。
你可以通过多种方式安装和使用 MCP Git Commit Generator:
使用 uvx 是使用该包的最简单方式,它会自动管理虚拟环境:
uvx mcp-git-commit-generator
pip install mcp-git-commit-generator
或者使用 uv:
uv pip install mcp-git-commit-generator
使用来自 GitHub Container Registry 的预构建 Docker 镜像(无需安装):
docker run -i --rm --mount type=bind,src=${HOME},dst=${HOME} ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest
根据你的客户端,选择合适的配置方式:
在 VS Code 的 mcp.json 文件(通常位于工作区的 .vscode/mcp.json)中添加以下配置之一:
{
"servers": {
"mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
{
"servers": {
"mcp-git-commit-generator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=${userHome},dst=${userHome}",
"ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest"
]
}
}
}
如果你想将配置添加到用户的 settings.json 文件中,可以这样做:
{
"mcp": {
"servers": {
"mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
}
在 Cursor 的 MCP 配置文件(通常位于 ~/.cursor/mcp.json)中添加以下配置之一:
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=${userHome},dst=${userHome}",
"ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest"
]
}
}
}
在 Windsurf 的 MCP 服务器设置文件(通常位于 ~/.codeium/windsurf/mcp_config.json)中添加以下配置之一:
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=${userHome},dst=${userHome}",
"ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest"
]
}
}
}
在 Claude Desktop 的配置文件(在 macOS 上通常位于 ~/Library/Application Support/Claude/claude_desktop_config.json)中添加以下配置之一:
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
{
"mcpServers": {
"mcp-git-commit-generator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=${userHome},dst=${userHome}",
"ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest"
]
}
}
}
⚠️ 重要提示
Docker 配置中的
--mount选项允许 Docker 容器访问你的主目录,使其能够处理文件系统中任何位置的 Git 仓库。使用 uvx 或 pip 安装时,不需要此挂载,因为工具直接在你的系统上运行。如果使用 Docker 时仓库位于其他位置,请调整挂载路径。
git add
check_git_status 查看当前仓库状态。generate_commit_message 创建符合规范的提交信息。generate_commit_message根据你暂存的 Git 更改生成符合规范的提交信息。 参数:
repo_path(字符串,可选):Git 仓库的路径。如果省略,使用当前目录。commit_type(字符串,可选):符合规范的提交类型(例如,feat、fix、docs、style、refactor、perf、build、ci、test、chore、revert)。如果省略,类型将自动检测。scope(字符串,可选):更改的范围(例如,文件或模块名称)。如果省略,范围将根据更改的文件自动检测。
用法:git add check_git_status检查当前 Git 仓库的状态,包括已暂存、未暂存和未跟踪的文件。 参数:
repo_path(字符串,可选):Git 仓库的路径。如果省略,使用当前目录。
用法:
在生成提交信息之前,使用此工具查看当前 Git 仓库的状态。如果你不想在开发中使用 Docker,可以在本地运行服务器: 要求:
克隆仓库:
git clone https://github.com/theoklitosBam7/mcp-git-commit-generator.git
cd mcp-git-commit-generator
准备环境: 有两种方法可以为这个项目设置环境。你可以根据自己的喜好选择其中一种。
注意:创建虚拟环境后,重新加载 VSCode 或终端以确保使用虚拟环境中的 Python。
| 方法 | 步骤 |
|---|---|
使用 uv |
1. 创建虚拟环境:uv venv 2. 运行 VSCode 命令 "Python: Select Interpreter" 并选择创建的虚拟环境中的 Python 3. 安装依赖(包括开发依赖): uv pip install -r pyproject.toml --group dev 4. 使用以下命令安装 mcp-git-commit-generator:uv pip install -e .。 |
使用 pip |
1. 创建虚拟环境:python -m venv .venv 2. 运行 VSCode 命令 "Python: Select Interpreter" 并选择创建的虚拟环境中的 Python 3. 安装依赖: pip install -e .。 4. 安装 pip 开发依赖: pip install -r requirements-dev.txt。 |
(可选)安装 Inspector 依赖:
cd inspector
npm install
项目包含一个自动化的 PyPI 发布工作流(.github/workflows/pypi-publish.yml),它:
v*.*.* 模式的标签、手动触发工作流或向主分支提交拉取请求时触发。build 包构建 Python 包分发。pyproject.toml 中更新版本。git tag vX.Y.Z && git push origin vX.Y.Z你可以使用 Docker 构建和运行 MCP Git Commit Generator。提供的 Dockerfile 使用多阶段构建,使用 uv 进行依赖管理,并以非根用户身份运行服务器以提高安全性。
docker build -t mcp-git-commit-generator .
你可以直接从 GitHub Container Registry 运行已发布的镜像。
docker run -d \
--name mcp-git-commit-generator \
ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest
默认情况下,容器运行:
mcp-git-commit-generator --transport stdio
如果你想使用 SSE 传输(用于 Inspector UI 或远程访问),可以覆盖入口点或手动运行:
docker run -d \
--name mcp-git-commit-generator \
-p 3001:3001 \
--entrypoint mcp-git-commit-generator \
ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest --transport sse --host 0.0.0.0 --port 3001
使用 SSE 时,服务器将在 http://localhost:3001 可用。
本地运行(不使用 Docker):
从 inspector 目录运行:
npm run dev:inspector
Inspector UI 将在
http://localhost:5173可用。
.
├── .github/ # GitHub 工作流和问题模板
├── .gitignore
├── .markdownlint.jsonc
├── .python-version
├── .vscode/ # VSCode 配置
├── LICENSE
├── README.md
├── pyproject.toml # Python 项目配置
├── requirements-dev.txt # 开发依赖
├── uv.lock # Python 依赖锁定文件
├── Dockerfile # Docker 构建文件
├── build/ # 构建工件
├── src/ # Python 源代码
│ └── mcp_git_commit_generator/
│ ├── __init__.py # 主入口点
│ ├── __main__.py # CLI 入口点
│ └── server.py # 主服务器实现
└── inspector/ # Inspector 相关文件
├── package.json # Node.js 依赖
└── package-lock.json
.vscode/mcp.json 文件配置了 VS Code 和相关工具如何连接到 MCP Git Commit Generator 服务器。该文件定义了可用的服务器传输方式及其连接详细信息,使你可以轻松在不同模式(默认是 stdio,可选 SSE)之间切换进行开发和调试。
mcp.json{
"servers": {
"mcp-git-commit-generator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=${userHome},dst=${userHome}",
"ghcr.io/theoklitosbam7/mcp-git-commit-generator:latest"
]
},
"sse-mcp-git-commit-generator": {
"type": "sse",
"url": "http://localhost:3001/sse"
},
"stdio-mcp-git-commit-generator": {
"type": "stdio",
"command": "${command:python.interpreterPath}",
"args": ["-m", "mcp_git_commit_generator", "--transport", "stdio"]
},
"uvx-mcp-git-commit-generator": {
"command": "uvx",
"args": ["mcp-git-commit-generator"]
}
}
}
http://localhost:3001/sse 连接到 MCP 服务器。仅在使用 --transport sse 运行服务器时有用。注意:
- MCP Inspector 是一个用于测试和调试 MCP 服务器的可视化开发工具。
- 所有调试模式都支持断点,因此你可以在工具实现代码中添加断点。
- 你可以在 Inspector UI 中直接测试工具参数:使用 Inspector 时,选择一个工具并在输入字段中提供参数,以模拟实际使用并调试参数处理。
| 调试模式 | 描述 | 调试步骤 |
|---|---|---|
| MCP Inspector | 使用 MCP Inspector 调试 MCP 服务器。 | 1. 安装 Node.js 2. 设置 Inspector: cd inspector 并执行 npm install 3. 打开 VS Code 调试面板。选择 Debug in Inspector (Edge) 或 Debug in Inspector (Chrome)。按 F5 开始调试。4. 当 MCP Inspector 在浏览器中启动时,点击 Connect 按钮连接此 MCP 服务器。5. 然后你可以 List Tools,选择一个工具,输入参数(见上述参数),并 Run Tool 来调试服务器代码。 |
| 调试模式 | 端口 | 定义 | 自定义 | 注意 |
|---|---|---|---|---|
| MCP Inspector | 3001(服务器,仅 SSE);5173 和 3000(Inspector) | tasks.json | 编辑 launch.json、tasks.json、__init__.py、mcp.json 以更改上述端口。 | 无 |
如果你有任何反馈或建议,请在 MCP Git Commit Generator GitHub 仓库 上创建一个问题。
MIT 许可证 © 2025 Theoklitos Bampouris