使用说明
GitHub MCP服务
用于带有集成身份验证的GitHub操作的MCP服务器(模型上下文协议)。
描述
这个MCP服务器提供了一个完整的接口,可以通过标准化的方法与GitHub进行交互。它允许管理GitHub的存储库、文件、问题、拉动请求和工作流,以及其他实用方法。
特点
- ✅ 仓库管理:列出经过身份验证的用户的存储库
- ✅ 档案管理:获取、创建和更新存储库中的文件
- ✅ 问题:创建和列出存储库问题
- ✅ 拉取请求:创建、列表和合并拉动请求
- ✅ 工作流:GitHub操作的不同工作流程
- ✅ 工具:base64编码、时间戳和服务器信息
- ✅ 安全认证:基于GitHub令牌和环境变量
安装
-
克隆或下载项目:
git clone <repository-url> cd github-mcp -
安装依赖项:
npm install -
配置环境变量:
cp .env.example .env编辑文件
.env用你真正的证书。
配置
所需环境变量
创建新文件 .env 在项目的根源上:
# Autenticación MCP (requerido)
AUTH_ID=tu_auth_id_aqui
AUTH_TOKEN=tu_auth_token_aqui
# Token de GitHub (requerido)
GITHUB_TOKEN=ghp_tu_token_de_github_aqui
获取GitHub令牌
- Ve a GitHub→ 设置→ 开发人员设置→ 个人访问令牌
- 点击“生成新令牌(经典)”
- 选择所需的权限:
repo(完全访问存储库)workflow(用于启动工作流)admin:org(可选,适用于组织)
使用
启动服务器
node server.js
服务器将可用并准备接收MCP请求。
可用方法
仓库管理
Listar存储库
server.method("github.listRepos", {
visibility: "all" // "all", "public", "private"
})
档案管理
获取文件
server.method("github.getFile", {
owner: "usuario",
repo: "repositorio",
path: "ruta/al/archivo.js",
ref: "main" // opcional
})
创建于
server.method("github.createFile", {
owner: "usuario",
repo: "repositorio",
path: "nuevo/archivo.js",
content: "console.log('Hola mundo');",
message: "Agregar nuevo archivo",
branch: "main" // opcional
})
更新文件
server.method("github.updateFile", {
owner: "usuario",
repo: "repositorio",
path: "archivo/existente.js",
content: "contenido actualizado",
message: "Actualizar archivo",
branch: "main" // opcional
})
问题管理
Crear问题
server.method("github.createIssue", {
owner: "usuario",
repo: "repositorio",
title: "Bug en la aplicación",
body: "Descripción detallada del problema",
labels: ["bug", "priority-high"] // opcional
})
列表问题
server.method("github.listIssues", {
owner: "usuario",
repo: "repositorio",
state: "open" // "open", "closed", "all"
})
拉取请求
Crear Pull请求
server.method("github.createPullRequest", {
owner: "usuario",
repo: "repositorio",
title: "Nueva funcionalidad",
head: "rama-feature",
base: "main",
body: "Descripción de los cambios",
draft: false // opcional
})
合并拉取请求
server.method("github.mergePullRequest", {
owner: "usuario",
repo: "repositorio",
pull_number: 123,
merge_method: "squash" // "merge", "squash", "rebase"
})
GitHub操作
Disparar工作流
server.method("github.dispatchWorkflow", {
owner: "usuario",
repo: "repositorio",
workflow_id: "ci.yml", // archivo del workflow
ref: "main",
inputs: {
environment: "production"
}
})
工具
Base64 编码
server.method("utils.base64Encode", {
text: "Hola mundo"
})
装饰底座64
server.method("utils.base64Decode", {
encoded: "SGFsYSBtdW5kbw=="
})
实际时间戳
server.method("utils.timestamp", {})
服务器信息
server.method("utils.serverInfo", {})
答案举例
Listar存储库
[
{
"name": "mi-repo",
"full_name": "usuario/mi-repo",
"private": false,
"default_branch": "main",
"html_url": "https://github.com/usuario/mi-repo",
"description": "Mi repositorio",
"language": "JavaScript",
"stargazers_count": 5
}
]
创建于
{
"commitSha": "abc123...",
"contentSha": "def456...",
"html_url": "https://github.com/usuario/repo/blob/main/archivo.js"
}
常见错误
缺少环境变量
Error: Faltan credenciales de MCP - AUTH_ID y AUTH_TOKEN son requeridos en .env
解决方案:验证文件 .env 包含所有必要的变量。
无效的GitHub令牌
Error: Error listando repositorios: Bad credentials
解决方案:验证 GITHUB_TOKEN 有效并拥有必要的许可证。
找不到文件
Error: Error obteniendo archivo: Not Found
解决方案:验证文件路径是否正确,以及您是否可以访问存储库。
依赖性
mcp:框架MCP(模型上下文协议)dotenv:环境变量管理@octokit/rest:github for node.js的官方客户端
争议
欢迎捐款。请:
- 叉项目
- 为您的功能创建分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推拉拉马(
git push origin feature/AmazingFeature) - 打开拉动请求
许可证
这个项目是在麻省理工学院的许可下进行的。查看文件 LICENSE 更多细节。
支撑
如果您有问题或问题:
- Revisa la API文档
- 寻找现有问题
- 创建带有问题细节的新问题
版本: 1.0.0
作者:MCP服务器生成器
许可证:MIT
