ghcontext:使用实时GitHub Context为LLMs充电
*“但我的GitHub仓库昨天发生了变化……”-再也不用担心人工智能助手中的过时信息了。*
ghcontext(GitHub Context Provider)弥合了GitHub和大型语言模型之间的差距,通过标准化的模型上下文协议(MCP)让AI助手实时访问存储库信息。
🔥 为什么是ghcontext?
- 准确、实时的信息: LLM通常对存储库有过时的知识。ghcontext提供了最新的API文档、README内容和代码库结构-也用于 私人回购
- 更深入的理解: 帮助LLM掌握项目的体系结构、设计原则和API使用模式。
- 无缝集成: 与任何启用MCP的型号兼容,包括Claude、GPT等。
- 高效: 智能缓存减少了API调用,同时保持信息新鲜。
✨ 主要特点
- API文件提取: 从自述文件和专用文档文件中自动识别并提取API文档
- 存储库结构分析: 提供代码库组织的地图
- README内容检索: 直接从GitHub获取最新文档
- 文件内容搜索: 查找并提取特定文件或代码片段
- 存储库搜索: 发现符合特定条件的存储库
🚀 快速开始
关于代币的说明
ghcontext需要GitHub令牌进行身份验证。你有责任安全地管理你的令牌,你应该只给它你的用例真正需要的范围。 例如,如果您只需要读取公共存储库,则可以使用 public_repo 范围。ghcontext不需要对存储库进行写访问。
安装
方法1:使用npx无需安装即可运行
# Run directly without installation (GitHub token is REQUIRED)
npx ghcontext --GITHUB_TOKEN your_github_token
# OR using pnpm
pnpm dlx ghcontext --GITHUB_TOKEN your_github_token这是将其提供给claude代理的首选方式,因为它不需要任何安装,您可以直接从命令行运行它。
方法2:从npm进行全局安装
# Install globally using npm
npm install -g ghcontext
# OR using pnpm
pnpm add -g ghcontext
# Run ghcontext with your GitHub token (REQUIRED)
ghcontext --GITHUB_TOKEN your_github_token方法3:手动安装(开发)
# Clone the repository
git clone https://github.com/yourusername/ghcontext.git
cd ghcontext
# Install dependencies
pnpm install
# Start the server with GitHub token (REQUIRED)
pnpm start --GITHUB_TOKEN your_github_token与LLM一起使用
将兼容MCP的LLM连接到ghcontext服务器端点:
http://localhost:3000/api/mcp您的法学硕士现在可以使用以下工具:
get-repository-info:获取有关存储库的详细信息get-repository-readme:检索当前README内容get-repository-api-docs:摘录API文档search-repository-files:在存储库中查找文件get-file-content:检索特定文件内容
🔍 示例场景
询问启用MCP的AI助手:
“axios库中处理请求拦截器的可用方法是什么?”
您的助手可以:
- 使用
get-repository-api-docs获取最新的axios API文档 - 分析拦截器方法的当前文档
- 为您提供准确、最新的信息
🧰 建筑
ghcontext遵循模块化设计:
┌─────────────────┐ ┌──────────────┐ ┌────────────────┐
│ MCP Server │◄─────►│ GitHub API │◄─────►│ GitHub.com │
│ (TypeScript) │ │ Client │ │ │
└────────┬────────┘ └──────────────┘ └────────────────┘
│
│
┌────────▼────────┐ ┌──────────────┐
│ Context │ │ Caching │
│ Processors │◄─────►│ System │
└─────────────────┘ └──────────────┘- MCP服务器: 处理模型上下文协议通信
- GitHub API客户端: 管理GitHub REST和GraphQL API交互
- 上下文处理器: 提取并整理相关信息
- 缓存系统: 提高性能并减少API负载
🧠 为什么重要
传统的人工智能助手面临以下挑战:
- 存储库知识过时
- 对项目结构的理解不完整
- 无法查看最近的更改和更新
ghcontext通过让LLM直接访问GitHub的最新信息来解决这些问题,使您的AI助手更准确、更有帮助,并且与您不断发展的代码库更加同步。
🛠️ 发展
# Build the project
pnpm run build
# Run tests
pnpm test
# Lint your code
pnpm run lint
# Format your code
pnpm run format📦 发布到npm
如果您是此软件包的维护者,需要发布新版本:
- 更新package.json中的版本:
# For patch releases (bug fixes)
npm version patch
# For minor releases (new features, no breaking changes)
npm version minor
# For major releases (breaking changes)
npm version major- 发布到npm:
# The prepublishOnly script will run linting, tests, and build automatically
npm publish- 将标签推送到GitHub:
git push --follow-tags📝 许可证
该项目已获得麻省理工学院的许可-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
ghcontext: Because your AI assistant should understand your code as well as you do.

