GitHub Fetcher MCP(注:MCP在此处可能代表某个特定项目、模块或配置的名称,但根据上下文无法确定具体含义,因此直接保留原样)
](https://www.npmjs.com/package/github-fetcher-mcp)  ](https://nodejs.org/)  
用于获取GitHub仓库文件和目录树的MCP(模型上下文协议)服务器。
特点/功能
- 获取文件从GitHub仓库获取原始文件内容
- 获取子目录树以Unix树形格式获取目录树结构
- 获取子树(或拉取子树) ⭐ 新增:增强的目录树功能,支持显示文件大小、深度限制、统计信息和过滤功能
- 通过CLI参数或每个请求的参数进行灵活配置
- 使用TypeScript构建以确保类型安全
- 全面的测试覆盖率(79项测试)
安装
NPM(Node Package Manager,节点包管理器)
npm install -g github-fetcher-mcpSmithery(这个单词在英语中并不常见,可能是Smith的某种变体或特定语境下的用词,但直接翻译并无对应中文词汇,若理解为与“Smith”相关或类似的概念,可大致译为“史密斯工坊”或“史密斯制造”,具体需根据上下文确定)
通过(某种方式)为任何客户端自动安装GitHub Fetcher MCP服务器 Smithery(此处根据常见用法,可译为“铁匠铺”或泛指“锻造工坊”,具体翻译需结合上下文):
npx -y @smithery/cli@latest install github-fetcher-mcp --client 可用客户端: cursor, claude, vscode, windsurf, cline, zed等。
光标示例:
npx -y @smithery/cli@latest install github-fetcher-mcp --client cursor这将自动在您选择的客户端中配置MCP服务器。
MCP客户端集成
GitHub Fetcher MCP 可以与各种支持模型上下文协议(MCP)的AI编码助手和集成开发环境(IDE)进行集成。
要求
- Node.js 版本 >= 18.0.0
- 一个与MCP兼容的客户端(Cursor、Claude Code、VS Code、Windsurf等)
Install in Cursor
首选 Settings -> Cursor Settings -> MCP -> Add new global MCP server
在您的(配置/设置中)添加以下配置 ~/.cursor/mcp.json 文件:
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}没有repoIdentifier (根据请求指定仓库):
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp"]
}
}
}Install in Claude Code
运行此命令:
claude mcp add github-fetcher -- npx -y github-fetcher-mcp --repoIdentifier facebook/react/main或者没有repoIdentifier:
claude mcp add github-fetcher -- npx -y github-fetcher-mcpInstall in VS Code
将此添加到您的 VS Code MCP 配置文件中。参见 VS Code MCP 文档 如需更多信息。
"mcp": {
"servers": {
"github-fetcher": {
"type": "stdio",
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Install in Windsurf
将此添加到您的帆板MCP配置文件中:
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Install in Cline
- 开放 克莱恩(Cline)
- 点击汉堡菜单图标(☰)以进入 MCP服务器 部分;章节
- 选择 远程服务器 制表符(Tab)
- 点击 编辑配置 按钮
- 将 github-fetcher 添加到
mcpServers:
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Install in Claude Desktop
打开Claude桌面版开发者设置并编辑您的 claude_desktop_config.json 文件:
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Install in Zed
将这个添加到你的Zed中 settings.json:
{
"context_servers": {
"github-fetcher": {
"source": "custom",
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Install in Roo Code
将此添加到您的Roo Code MCP配置文件中:
{
"mcpServers": {
"github-fetcher": {
"command": "npx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Using with Bun
{
"mcpServers": {
"github-fetcher": {
"command": "bunx",
"args": ["-y", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}Using with Docker
构建Docker镜像:
创建一个 Dockerfile:
FROM node:18-alpine
WORKDIR /app
# Install the package globally
RUN npm install -g github-fetcher-mcp
# Expose the server port
EXPOSE 3000
# Default command to run the server
CMD ["github-fetcher-mcp"]构建镜像:
docker build -t github-fetcher-mcp .配置您的MCP客户端:
{
"mcpServers": {
"github-fetcher": {
"command": "docker",
"args": ["run", "-i", "--rm", "-p", "3000:3000", "github-fetcher-mcp", "--repoIdentifier", "facebook/react/main"]
}
}
}使用方法
带有存储库标识符(CLI 参数)
当你提供一个 --repoIdentifier 参数,所有工具将默认使用该存储库:
github-fetcher-mcp --repoIdentifier facebook/react/main可用工具:
fetch-file仅需filePathfetch-subdir-tree只需dirPathfetch-sub-tree仅需dirPath(+ 可选:showSize,maxDepth,showStats,fileExtFilter)
没有仓库标识符
当未提供存储库标识符时,您可以为每个请求指定存储库:
github-fetcher-mcp可用工具:
fetch-file需要ownerName,repoName,branchName(可选,默认值:'main'),以及filePathfetch-subdir-tree需要ownerName,repoName,branchName(可选,默认值:'main'),以及dirPathfetch-sub-tree需要ownerName,repoName,branchName(可选,默认:'main'),dirPath(+ 可选:showSize,maxDepth,showStats,fileExtFilter)
可用工具
GitHub Fetcher MCP 提供了以下可由大型语言模型(LLMs)使用的工具:
- 获取文件从GitHub仓库中获取文件的原始内容
- 所需参数会根据是否(满足某种条件/存在某种情况)而有所不同 --repoIdentifier 被提供 - 返回完整的文件内容作为文本
- 获取子目录树以Unix树状格式获取目录树结构
- 所需的参数根据是否(满足某种条件或采用某种方式)而有所不同 --repoIdentifier 被提供 - 返回格式化的目录树,显示文件和子目录
- 获取子树 ⭐ 新增:增强版,包含高级选项
- 所需参数根据(情况)是否……而有所不同 --repoIdentifier 被提供 - 可选参数: - showSize (布尔值):显示文件和目录的大小 - maxDepth (数字):限制树的深度(例如,1 表示仅限直接子节点) - showStats (布尔值): 显示统计摘要(默认值:true) - fileExtFilter (string\[\]): 通过扩展名过滤文件(例如,\[“.ts”, “.js”\]) - 返回增强的目录树,可选显示文件大小和统计信息
使用示例
示例1:获取特定文件
在 Cursor/Claude 代码中:
Fetch the package.json file from the facebook/react repository on the main branch在任何配置了repoIdentifier的MCP客户端中:
Show me the contents of src/index.ts示例2:浏览目录结构
在 Cursor/Claude 代码中:
Show me the directory structure of the src folder in microsoft/vscode on the main branch在任何配置了repoIdentifier的MCP客户端中:
What files are in the components directory?示例3:分析代码结构
在 Cursor/Claude 代码中:
I want to understand the structure of the Next.js repository.
Show me the directory tree of the packages folder from vercel/next.js on the canary branch.
Then fetch the package.json file to see the dependencies.工具参考
获取文件
从GitHub仓库中获取文件的原始内容。
使用repoIdentifier:
{
"filePath": "src/index.ts"
}没有repoIdentifier:
{
"ownerName": "facebook",
"repoName": "react",
"branchName": "main",
"filePath": "src/index.ts"
}获取子目录树
以Unix树状格式获取目录树结构。
使用repoIdentifier:
{
"dirPath": "src"
}未提供repoIdentifier:
{
"ownerName": "microsoft",
"repoName": "vscode",
"branchName": "main",
"dirPath": "src"
}获取子树 ⭐ 新功能
增强的目录树,包含文件大小、深度限制和过滤选项。
使用repoIdentifier - 基本用法:
{
"dirPath": "src"
}使用 repoIdentifier - 显示文件大小:
{
"dirPath": "src",
"showSize": true
}使用repoIdentifier - 限制深度:
{
"dirPath": "src",
"maxDepth": 2
}使用repoIdentifier - 按文件扩展名过滤:
{
"dirPath": "src",
"fileExtFilter": [".ts", ".tsx"]
}使用repoIdentifier - 所有选项:
{
"dirPath": "src",
"showSize": true,
"maxDepth": 3,
"showStats": true,
"fileExtFilter": [".ts", ".js"]
}示例输出(包含 showSize 和 showStats):
src/
├── components/ (2 files, 15.3KB)
│ ├── Button.tsx (8.2KB)
│ └── Input.tsx (7.1KB)
└── utils/ (3 files, 5.8KB)
├── helpers.ts (2.1KB)
├── format.ts (1.9KB)
└── validate.ts (1.8KB)
📊 Summary: 2 directories, 5 files, 21.1KB total没有repoIdentifier:
{
"ownerName": "microsoft",
"repoName": "vscode",
"branchName": "main",
"dirPath": "src",
"showSize": true,
"maxDepth": 2
}Docker 使用方法
构建Docker镜像
docker build -t github-fetcher-mcp .使用 Docker 运行
带有repoIdentifier:
docker run -d -p 3000:3000 \
--name github-fetcher \
github-fetcher-mcp \
node dist/server.js --repoIdentifier facebook/react/main没有repoIdentifier:
docker run -d -p 3000:3000 \
--name github-fetcher \
github-fetcher-mcpDocker Compose 示例
创建一个 docker-compose.yml:
version: '3.8'
services:
github-fetcher-mcp:
build: .
ports:
- "3000:3000"
environment:
- PORT=3000
- NODE_ENV=production
command: ["node", "dist/server.js", "--repoIdentifier", "facebook/react/main"]
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/mcp', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5s使用 Docker Compose 运行:
docker-compose up -d在MCP客户端中使用Docker镜像
配置您的MCP客户端以使用Docker容器:
{
"mcpServers": {
"github-fetcher": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"github-fetcher-mcp",
"node",
"dist/server.js",
"--repoIdentifier",
"facebook/react/main"
]
}
}
}发展
# Install dependencies
npm install
# Run in development mode
npm run dev
# Run tests
npm test
# Build
npm run build
# Type check
npm run typecheck
# Lint
npm run lint建筑学
该项目采用模块化架构:
- 配置/CLI 参数解析
- 服务/GitHub API 集成和树形格式化
- 工具/MCP工具的实现
- 类型/TypeScript 类型定义
- 实用工具/实用函数
测试
该项目具有全面的测试覆盖率:
- 对所有服务、工具和实用程序进行单元测试
- 工具创建的集成测试
- 总共79项测试,全部通过
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage许可证
麻省理工学院(MIT)
贡献
欢迎贡献!请随时提交拉取请求。
作者
“choesumin”可以翻译为“乔素敏”(根据音译,实际翻译可能因人名具体发音和语境而有所调整)。不过,需要注意的是,如果“choesumin”是某个特定领域或文化背景下的专有名词或特定术语,其翻译可能需要根据具体情况进行调整。在没有更多上下文的情况下,上述翻译是基于音译的通用做法
