github-repo-mcp 讓 AI 無需手動複製即可探索任何 GitHub 儲存庫
github-repo-mcp: letting an AI explore any GitHub repo without cloning it by hand
github-repo-mcp 是一個本機 MCP 伺服器,讓 AI 助手透過 owner/repo 探索 GitHub 儲存庫,無須手動複製。伺服器提供五種工具,可載入儲存庫、查看檔案與匯出符號、搜尋及讀取檔案,並在本機快取複製的儲存庫;私有儲存庫才需要 GitHub token。
When an assistant needs to understand a codebase it does not have locally, the usual options are pasting files or cloning by hand. I wanted something better: point the assistant at owner/repo and let it explore, the way a developer would. So I wrote github-repo-mcp, a local Model Context Protocol server.
Architecture
The server runs over stdio. Repos are cloned once and reused from a local cache.
REQUEST PATH
Claude (MCP client)
──▶ github-repo-mcp (stdio server, written in TypeScript on Bun)
──▶ Local clone cache (~/.cache/github-repo-mcp/owner/repo)
──▶ GitHub (Cloned once, pulled on refresh)
FIVE TOOLS
load_repo (Clone or reuse, return a summary)
──▶ get_repo_map (Files and exported symbols)
──▶ grep (Regex search with context)
──▶ read_file (A file or a line range)
──▶ refresh_repo (Pull latest, invalidate the map)
How it works
- load_repo clones a repo (or reuses the cached copy) and returns languages, file count, a top-level tree and a README excerpt, enough to decide where to look next.
- get_repo_map builds a structural map of paths and exported symbols. TypeScript gets a fast extraction path, and other languages such as Python are parsed with tree-sitter.
- grep uses ripgrep for speed and falls back to a pure-JS search when ripgrep is not installed.
- A GitHub token is optional and only needed for private repos. Path guards keep reads inside the cloned repo.
The workflow it enables
Load the repo, read the map to find the right module, grep for the call sites, then read only the lines that matter. The assistant spends its context on understanding the code and not on scrolling through it.
It is a small server with a deliberately small surface: five tools, one cache directory, and tests around the guards and the parser.
Originally published on my portfolio.
來源:DEV Community · dev.to