使用说明
GitHub资源管理器MCP服务器
该项目是一个使用MCP(模型上下文协议)标准列出GitHub用户存储库的服务器。它可以在不同的通信协议(stdio、Streamable HTTP和SSE)上运行。
特性
- GitHub用户存储库列表
- 上下文:进度报告和结构化日志记录
- 采样:LLM驱动的存储库分析(需要Anthropic API密钥)
- 支持stdio、流式HTTP和SSE(服务器发送事件)协议
- 定制FastMCP配置
- 基本文件记录系统
需求
- python:3.12或更高
- 包管理器: 紫外线
- Node.js:18+(仅MCP检查员需要)
依赖项
核心依赖关系:
fastmcp:用于构建MCP服务器的FastMCP框架requests:用于发出请求的HTTP客户端uvicorn:ASGI服务器python-dotenv:环境变量管理
安装
使用uv安装依赖项:
uv sync
启用采样(可选)
要使用 analyze_user_repos 工具(LLM-powered分析),安装Anthropic SDK并配置您的API密钥:
uv add anthropic
然后将您的API密钥添加到 .env:
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-haiku-4-5-20251001 # optional, this is the default
服务器使用情况
您可以通过两种不同的模式启动服务器:
标准模式
uv run server
流式Http模式
uv run server_shttp
SSE(服务器发送事件)模式
uv run server_sse
查询示例
您可以使用MCP检查器查询服务器:
Can you give me the list of repos of user halilsafakkilic on GitHub?
检查器使用
配置设置
在使用检查器或客户端示例之前,您需要创建一个正确的配置文件:
-
复制配置模板文件:
cp mcp_configs.json.dist mcp_configs.json -
编辑
mcp_configs.json文件并更新中的路径server_stdio章节:"server_stdio": { "command": "uv", "args": [ "--directory", "/YOUR/ABSOLUTE/PROJECT/PATH", # Replace with your actual project path "run", "server" ] }
替换 /YOUR/ABSOLUTE/PROJECT/PATH 带有项目目录的绝对路径。
要使用MCP Inspector测试服务器,请执行以下操作:
# Using stdio
npx -y @modelcontextprotocol/inspector uv run server
# Using stdio with config file
npx -y @modelcontextprotocol/inspector --config mcp_configs.json --server server_stdio
# Using Streamable HTTP
npx -y @modelcontextprotocol/inspector --config mcp_configs.json --server server_shttp
# Using SSE
npx -y @modelcontextprotocol/inspector --config mcp_configs.json --server server_sse
SSE+流式HTTP健康检查
要检查SSE或Streamable HTTP服务器的运行状况,可以使用以下命令:
curl -X GET http://localhost:8080/health
客户端使用情况
该项目包括stdio和SSE协议的示例客户端。
Stdio客户端
这 client_stdio.py 演示如何使用 标准 协议:
uv run client_stdio.py
流式HTTP客户端
这 client_shttp.py 演示如何使用以下命令连接到服务器 可流式传输的HTTP 协议:
# Run the Streamable HTTP client (make sure server_shttp.py is running)
uv run client_shttp.py
SSE客户端
这 client_sse.py 演示如何使用以下命令连接到服务器 上海证券交易所 协议:
# Run the SSE client (make sure server_sse.py is running)
uv run client_sse.py
项目结构
server.py:stdio协议的主服务器server_shttp.py:流式HTTP协议的主服务器server_sse.py:SSE协议的主服务器client_stdio.py:使用stdio协议的示例客户端client_shttp.py:使用Streamable HTTP协议的示例客户端client_sse.py:使用SSE协议的客户端示例app/:应用程序逻辑和服务server.py:MCP服务器初始化routes.py:资源和提示定义services.py:业务逻辑和工具实现(上下文+采样)
lib/:自定义库文件custom_fastmcp.py:支持异步HTTP的扩展FastMCPresponse.py:响应格式化实用程序utils.py:实用功能sampling.py:采样处理程序构建器(Anthropic集成)
tests/:测试套件logs/:日志目录mcp_configs.json:检查器的MCP配置设置和示例用法
API工具
get_user_repos
列出GitHub用户的公共存储库。用途 上下文 向MCP客户端报告进度并记录消息。
参数:
username:GitHub用户名
示例用法:
Action: get_user_repos
Parameter (username): halilsafakkilic
analyze_user_repos
获取用户的GitHub存储库,并使用以下命令生成基于LLM的摘要 采样 (ctx.sample()).需要配置Anthropic API密钥。
参数:
username:GitHub用户名
示例用法:
Action: analyze_user_repos
Parameter (username): halilsafakkilic
测试
使用pytest运行测试套件:
uv run pytest tests/ -v
许可证
该项目根据MIT许可证获得许可。
