🕰️ Git时间机器
一个基于Rust的MCP(模型上下文协议)服务器,为GitHub Copilot等AI助手提供git历史见解。此服务器公开了允许LLM推理代码库演变的工具和上下文提供程序。
特性
- 有责任意识的代码分析:暴露
git blame对于任何文件 - 提交时间线探索:查询提交了一个文件
- Diff上下文提供程序:暴露任何提交的上下文差异
- 交互式Git元数据:访问作者信息、时间戳、提交消息
- 由Rust+MCP提供技术支持:使用
axum,tokio,以及serde
API终点
| 端点 | 描述 |
|---|---|
POST /tools/get_git_blame | 逐行返回非责任元数据 |
POST /tools/get_commit_diff | 显示与元数据的完全差异 |
POST /tools/summarize_diff | 描述提交之间的更改 |
POST /tools/get_commits_affecting | 列出修改文件的提交 |
POST /tools/get_file_at_commit | 返回过去提交时的文件内容 |
GET /metadata | 返回MCP元数据 |
GET /.well-known/ai-plugin.json | 返回AI集成的插件清单 |
GET /openapi.json | 返回OpenAPI架构 |
安装
选项1:从Crates.io安装(推荐)
cargo install git-time-machine
git-time-machine选项2:从源代码安装
先决条件
- Rust(最新稳定版本)
- Git
设置
# Clone the repository
git clone https://github.com/hrirkslab/git-time-machine.git
cd git-time-machine
# Build the project
cargo build --release
# Run the server
cargo run --release选项3:使用Docker
# Build Docker image
docker build -t git-time-machine .
# Run container
docker run -p 3000:3000 -v $(pwd):/workspace git-time-machine服务器将于启动 http://localhost:3000.
用法
使用GitHub Copilot
Git Time Machine通过MCP协议与GitHub Copilot兼容。使用Copilot时,您可以:
- 询问有关代码历史的问题
- 深入了解何时引入了bug
- 了解代码随时间的演变
示例提示:
- “上次修改此功能的是谁?”
- “上周这个文件有什么变化?”
- “显示此文件的历史记录。”
API直接访问
您还可以直接访问API端点:
# Example: Get blame for a file
curl -X POST -H "Content-Type: application/json" \
-d '{"file": "src/main.rs"}' \
http://localhost:3000/tools/get_git_blameGitHub复制集成
Git Time Machine通过 .copilot 配置目录。这允许Copilot使用Git Time Machine作为工具提供者来回答有关代码历史的问题。
设置
- 确保Git Time Machine服务器正在运行:
cargo run --release- 这
.copilot/settings.jsonfile将服务器注册为GitHub Copilot的工具提供者:
{
"tool_providers": [
{
"name": "git-time-machine",
"url": "http://localhost:3000",
"enabled": true
}
]
}- 如果您使用的是GitHub Copilot CLI或Copilot Workspace,它将自动检测工具提供程序配置。
使用Copilot
配置后,您可以向Copilot询问有关代码历史的问题,例如:
- “上次修改身份验证功能的是谁?”
- “这个bug是什么时候引入的?”
- “这个文件在过去一个月里是如何演变的?”
- “提交abc123的主要变化是什么?”
- “显示重构前此文件的外观”
Copilot将使用Git Time Machine工具根据您的存储库历史提供有见地的答案。
发展
项目结构
src/
main.rs # Server setup and routing
handlers/ # HTTP endpoint handlers
mod.rs
blame.rs # Git blame handlers
commits.rs # Commit history handlers
diff.rs # Diff generation handlers
metadata.rs # MCP metadata handlers
models/ # Data models
mod.rs
tool_schema.rs # API request/response schemas
git.rs # Git-related models
utils/ # Utility functions
mod.rs
git_helpers.rs # Git interaction utilities贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 提交您的更改:
git commit -am 'Add some feature' - 推到分支:
git push origin feature-name - 提交拉取请求
许可证
麻省理工学院
