modelscope·@cyanheads/git-mcp-server
一种模型上下文协议服务器,使大型语言模型能够通过强大的API与Git仓库进行交互,支持仓库初始化、克隆、文件暂存、提交和分支管理等操作。
一个模型上下文协议 (MCP) 服务器,提供了与 Git 仓库交互的工具。该服务器允许 AI 助手和 LLM 代理通过标准化接口管理仓库、分支、提交和文件,而无需直接访问文件系统或命令行。它将 Git 操作暴露为 MCP 资源和工具,利用 simple-git 库实现核心功能,同时保持适当的安全边界。
主要功能:
核心系统架构:
<details> <summary>点击展开 Mermaid 图表</summary>flowchart TB
subgraph API["API Layer"]
direction LR
MCP["MCP Protocol"]
Val["Validation (Zod)"]
MCP --> Val
end
subgraph Core["Core Services"]
direction LR
GitService["Git Service (simple-git)"]
ErrorService["Error Service"]
GitService <--> ErrorService
end
subgraph Resources["Resource Layer"]
direction LR
Repo["Repository Resources"]
Diff["Diff Resources"]
File["File Resources"]
History["History Resources"]
Repo <--> Diff
Repo <--> File
Repo <--> History
end
subgraph Tools["Tool Layer"]
direction LR
RepoTools["Repository Tools"]
BranchTools["Branch Tools"]
WorkdirTools["Working Directory Tools"]
RemoteTools["Remote Tools"]
AdvancedTools["Advanced Tools"]
RepoTools <--> BranchTools
BranchTools <--> WorkdirTools
WorkdirTools <--> RemoteTools
RemoteTools <--> AdvancedTools
end
Val --> GitService
GitService --> Resources
GitService --> Tools
classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
classDef component fill:#1a202c,stroke:#a0aec0,stroke-width:2px,rx:3,color:#fff
classDef api fill:#3182ce,stroke:#90cdf4,stroke-width:2px,rx:3,color:#fff
classDef core fill:#319795,stroke:#81e6d9,stroke-width:2px,rx:3,color:#fff
classDef resource fill:#2f855a,stroke:#9ae6b4,stroke-width:2px,rx:3,color:#fff
classDef tool fill:#805ad5,stroke:#d6bcfa,stroke-width:2px,rx:3,color:#fff
class API,Core,Resources,Tools layer
class MCP,Val api
class GitService,ErrorService core
class Repo,Diff,File,History resource
class RepoTools,BranchTools,WorkdirTools,RemoteTools,AdvancedTools tool
</details>
核心组件:
server.ts): 使用 @modelcontextprotocol/sdk 创建一个暴露资源和工具的服务器。services/git-service.ts): 在 simple-git 库之上提供了一个抽象层,为 Git 操作提供了清晰的接口。resources/): 通过 MCP 资源以一致的 URI 模板形式暴露 Git 数据(如状态、日志、文件内容)。tools/): 通过定义良好的输入模式(使用 Zod 进行验证)的 MCP 工具暴露 Git 操作(如提交、推送、拉取)。services/error-service.ts): 为 Git 和 MCP 操作提供标准化的错误处理和报告。index.ts): 初始化并启动服务器,将其连接到标准 I/O 传输。通过 MCP 资源暴露 Git 仓库信息:
通过 MCP 工具执行 Git 命令:
npm install -g @cyanheads/git-mcp-server
git clone https://github.com/cyanheads/git-mcp-server.git
cd git-mcp-server
npm install
npm run build
如果通过 NPM 全局安装:
git-mcp-server
如果从源代码运行:
node build/index.js
该服务器通过标准输入/输出使用模型上下文协议进行通信,使其与任何 MCP 客户端兼容。
将以下内容添加到您的 Claude 配置文件中(例如,cline_mcp_settings.json 或 claude_desktop_config.json):
{
"mcpServers": {
"git": {
"command": "git-mcp-server", // Or the full path to build/index.js if not installed globally
"args": [],
"env": {},
"disabled": false,
"autoApprove": [] // Configure auto-approval rules if desired
}
}
}
使用 MCP 检查器测试服务器:
# If installed globally
npx @modelcontextprotocol/inspector git-mcp-server
# If running from source
npx @modelcontextprotocol/inspector build/index.js
代码库遵循模块化结构:
git-mcp-server/
├── src/
│ ├── index.ts # Entry point: Initializes and starts the server
│ ├── server.ts # Core MCP server implementation and setup
│ ├── resources/ # MCP Resource implementations
│ │ ├── descriptors.ts # Resource URI templates and descriptions
│ │ ├── diff.ts # Diff-related resources (staged, unstaged, commit)
│ │ ├── file.ts # File content and directory listing resources
│ │ ├── history.ts # Commit history and blame resources
│ │ ├── index.ts # Aggregates and registers all resources
│ │ └── repository.ts # Repository info, branches, remotes, tags resources
│ ├── services/ # Core l…
一个MCP服务器,它在本地git仓库上提供语义搜索功能,使用户能够克隆仓库、处理分支并通过矢量化代码块搜索代码。
一种模型上下文协议(MCP)服务器,可以帮助大型语言模型以最少的设置来索引、搜索和分析代码库。
一个功能齐全的编码代理,它使用符号操作(由语言服务器启用),即使在大型代码库中也能很好地工作。本质上是 Cursor 和 Windsurf Agents、Cline、Roo Code 等的免费替代品。
为虚幻引擎代码库提供深度源代码分析,使人工智能助手能够理解C++类结构、搜索代码和分析子系统。
一个通过分析你的编程项目、自动提取技能并生成专业描述来更新你的JSON简历,从而增强AI助手功能的服务器。
提供了深入的Git文件级法医工具,用于分析Git仓库中详细的文件历史、变更和模式,重点是个别文件分析而非整个仓库的操作。