Sponsored by Deepsite.site

GitHub SSH MCP Server - 智能访问检测版

Created By
pyz116 months ago
增强版GitHub MCP Server,支持智能SSH访问检测和自动访问方式切换
Content

GitHub SSH MCP Server - 智能访问检测版

🚀 项目简介

这是一个增强版的GitHub MCP (Model Context Protocol) Server,专门为Cursor IDE和其他支持MCP的工具设计。本项目在原有GitHub MCP Server基础上,添加了智能SSH访问检测功能,能够自动检测并选择最佳的GitHub访问方式。

✨ 核心功能特性

🔐 智能SSH访问检测

  • 自动SSH密钥检测: 扫描常见SSH密钥文件(id_rsa, id_ed25519, id_ecdsa, id_dsa)
  • SSH配置验证: 检查SSH客户端和Git配置
  • 实时连接测试: 测试GitHub SSH连接(端口22)的可用性
  • 智能访问切换: 优先使用SSH,不可用时自动切换到HTTPS
  • 结果缓存机制: 5分钟缓存避免频繁检测,提高性能

🛠️ 新增MCP工具

  1. get_github_access_info: 获取当前GitHub访问方式信息
  2. test_github_access: 测试GitHub访问方式并强制刷新缓存
  3. convert_github_url: 在SSH和HTTPS URL格式之间转换

🔧 完整的GitHub操作支持

  • 仓库管理(创建、搜索、分支操作)
  • Issue和Pull Request管理
  • 代码扫描和安全警报
  • 通知管理
  • 用户和组织信息获取
  • 文件操作(读取、创建、更新、删除)

🏗️ 技术架构

访问检测流程

SSH密钥检测 → SSH配置验证 → 连接测试 → 结果缓存 → 智能选择访问方式

核心组件

  • GitHubAccessDetector: 核心检测器,负责SSH可用性检测
  • SSHClient: SSH客户端,处理Git SSH操作
  • AccessTools: MCP工具集,提供访问检测相关功能

📦 安装和配置

前置要求

  • Go 1.21+
  • Git客户端
  • GitHub Personal Access Token
  • SSH密钥(可选,用于SSH访问)

编译安装

# 克隆项目
git clone https://github.com/pyz11/githubSSH-mcp-server.git
cd githubSSH-mcp-server

# 编译
go build -o github-mcp-server.exe ./cmd/github-mcp-server

# 复制到系统路径(可选)
copy github-mcp-server.exe C:\Users\%USERNAME%\go\bin\

Cursor配置

在Cursor的设置中添加MCP服务器配置:

{
  "mcpServers": {
    "github": {
      "command": "C:\\Users\\%USERNAME%\\go\\bin\\github-mcp-server.exe",
      "args": ["stdio"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your_github_token_here"
      }
    }
  }
}

🔍 使用示例

检查GitHub访问方式

{
  "tool": "get_github_access_info",
  "arguments": {}
}

测试SSH连接

{
  "tool": "test_github_access",
  "arguments": {
    "force_refresh": true
  }
}

URL格式转换

{
  "tool": "convert_github_url",
  "arguments": {
    "url": "https://github.com/user/repo.git",
    "target_format": "ssh"
  }
}

🛡️ 安全特性

  • 无私钥读取: 只检测密钥文件存在性,不读取私钥内容
  • 安全连接测试: 仅进行连接测试,不传输敏感数据
  • Token保护: GitHub Token通过环境变量安全传递
  • 权限最小化: 只请求必要的GitHub API权限

🔧 配置选项

环境变量

  • GITHUB_PERSONAL_ACCESS_TOKEN: GitHub个人访问令牌(必需)
  • SSH_AUTH_SOCK: SSH Agent套接字路径(可选)
  • HOME / USERPROFILE: 用户主目录,用于查找SSH密钥

SSH密钥支持

  • RSA密钥: ~/.ssh/id_rsa
  • Ed25519密钥: ~/.ssh/id_ed25519
  • ECDSA密钥: ~/.ssh/id_ecdsa
  • DSA密钥: ~/.ssh/id_dsa

📊 性能优化

  • 智能缓存: SSH检测结果缓存5分钟
  • 并发安全: 使用互斥锁保护并发访问
  • 连接复用: 复用HTTP客户端连接
  • 超时控制: 合理的连接超时设置

🐛 故障排除

常见问题

  1. SSH检测失败: 检查SSH密钥是否存在且权限正确
  2. 连接超时: 检查网络连接和防火墙设置
  3. Token无效: 验证GitHub Token权限和有效性

诊断工具

项目包含诊断脚本:

.\diagnose_mcp.ps1

🤝 贡献指南

欢迎提交Issue和Pull Request!

开发环境设置

# 安装依赖
go mod download

# 运行测试
go test ./...

# 构建
go build ./cmd/github-mcp-server

📄 许可证

本项目基于原GitHub MCP Server项目,遵循相同的开源许可证。

🙏 致谢

  • 感谢GitHub MCP Server原项目团队
  • 感谢MCP协议开发团队
  • 感谢所有贡献者

📞 联系方式


让GitHub访问更智能,让开发更高效! 🚀

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Serper MCP ServerA Serper MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
CursorThe AI Code Editor
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
WindsurfThe new purpose-built IDE to harness magic
ChatWiseThe second fastest AI chatbot™
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
DeepChatYour AI Partner on Desktop
Amap Maps高德地图官方 MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Playwright McpPlaywright MCP server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors