gitquery-mcp
Provides read-only Git history and repository inspection tools backed by GitHub APIs, enabling queries for commit refs, blame, path history, merge bases, ancestry, associated pull requests, changed files, diffs, and file contents at specific refs without cloning the repository.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@gitquery-mcp who last edited src/router.ts in expressjs/express, and in which PR?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
gitquery-mcp
"Ask your repo questions through an API, no clone required."
A fast, lightweight Model Context Protocol (MCP) server that provides read-only repository history tools backed directly by GitHub APIs (GraphQL + REST), featuring aggressive caching of immutable data.
Why gitquery-mcp?
AI coding agents frequently need answers about a repository's history:
Who last touched this function and why?
Which pull request introduced this breaking change?
What is the merge base between feature and main?
What changed inside this specific directory between two release tags?
Today, agents solve this by running git clone or shelling out to local git. This approach is heavy on disk, drains network bandwidth, and fails entirely in container sandboxes where local repositories do not exist.
The architectural inspiration comes from Anthropic's engineering post, "Redesigning source control at Anthropic":
Source control queries should be fast, server-side API lookups. Clients and AI agents should never need a full local copy of a repository just to inspect history.
gitquery-mcp exposes read-only git history tools over standard MCP stdio transport, caches immutable commit-addressed results aggressively, and works with public or private repositories without cloning a single byte.
Related MCP server: Git MCP Server
Features
🚀 Zero-Clone Operations: Answers blame, diff, log, and merge-base questions over the GitHub API.
⚡ Aggressive Caching: Data addressed by a 40-character commit SHA is mathematically immutable and cached permanently. Symbolic branch/tag resolutions use a short, configurable TTL.
💾 Two-Tier Cache: High-speed in-memory LRU cache plus an optional persistent disk cache (
GITQUERY_CACHE_DIR) that survives server restarts.🛡️ Strictly Read-Only & Secure: Zero write operations exist. Auth tokens are read only from
GITHUB_TOKEN, redacted from logs and errors, and never returned to the LLM.🔒 Repository Allowlisting: Restrict the server to specific repositories or organizations via
ALLOWED_REPOS.📏 Output Discipline: Diff and history outputs are strictly bounded with explicit truncation markers and instructions for LLMs to narrow their queries.
🔌 Provider Abstraction: All GitHub operations sit behind a clean
GitProviderinterface, designed for future GitLab / Bitbucket backends.
Quick Start (npx)
Run gitquery-mcp instantly without local installation:
npx -y gitquery-mcpWith GitHub authentication:
GITHUB_TOKEN=ghp_yourTokenHere npx -y gitquery-mcpClient Configuration
1. Claude Desktop
Add to your claude_desktop_config.json:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"gitquery": {
"command": "npx",
"args": ["-y", "gitquery-mcp"],
"env": {
"GITHUB_TOKEN": "ghp_yourPersonalAccessTokenHere",
"ALLOWED_REPOS": ""
}
}
}
}2. Claude Code CLI
Add using the Claude Code MCP command:
claude mcp add gitquery -- npx -y gitquery-mcp(Note: Ensure GITHUB_TOKEN is exported in your active shell or passed in your environment).
3. Gemini CLI / Generic MCP Client
For MCP-compliant clients configuring servers via JSON:
{
"name": "gitquery",
"command": "npx",
"args": ["-y", "gitquery-mcp"],
"env": {
"GITHUB_TOKEN": "ghp_yourTokenHere",
"GITQUERY_CACHE_DIR": ".gitquery-cache"
}
}Client syntax for Claude Desktop and Claude Code was verified against official MCP specifications. If your client uses a custom schema or runner, adjust thecommand, args, and env properties accordingly.
Available Tools
All 10 tools validate input via Zod, enforce ALLOWED_REPOS, and return a one-line summary followed by compact structured JSON:
Tool | Description | Example Prompt |
| Resolves a branch, tag, or partial SHA to a full 40-character commit SHA. | "What is the exact commit SHA of branch 'release-2.4' in vercel/next.js?" |
| Line-by-line blame ranges with author, date, and associated merged PR. | "Who last edited lines 40 to 80 of src/router.ts in expressjs/express and in what PR?" |
| Lists commits that modified a file or folder (capped at 100). | "Show me the last 5 commits that touched the docs/ folder in facebook/react." |
| Finds the common ancestor commit and ahead/behind counts between two refs. | "Find the merge base between 'main' and 'feature/login' in myorg/webapp." |
| Evaluates whether commit A is an ancestor of commit B with full explanation. | "Is commit a419aa7 an ancestor of master in expressjs/express?" |
| Finds merged pull requests associated with a commit SHA. | "Find the pull request that merged commit 7e562c6 in expressjs/express." |
| Lists modified, added, or deleted files between two refs (capped at 500). | "What files changed between v4.21.0 and v4.21.1 in expressjs/express?" |
| Returns unified git diff between refs, truncated at | "Show me the diff of package.json between tag 4.21.0 and 4.21.1 in expressjs/express." |
| Retrieves text content of a file at a ref, with optional line range slicing. | "Show lines 1 to 50 of README.md at commit f1573b8 in expressjs/express." |
| Returns cache hits, misses, entry count, and hit rate percentage. | "Check the gitquery cache hit rate." |
How Caching Works
Caching is the core architectural value of gitquery-mcp:
Immutable by Commit SHA: Anything addressed by a 40-character commit SHA (
get_blame,compare,get_diff,get_file_at_ref,get_path_history) is mathematically immutable. Results are cached forever in memory.Short TTL for Mutable Refs: Resolving branches or tags (
main,HEAD,v1.0) to a SHA is cached for a short TTL (default: 30 seconds, configurable viaCACHE_TTL_MUTABLE_SECONDS).Optional Persistent Disk Cache: Set
GITQUERY_CACHE_DIR=.gitquery-cache. All immutable SHA-addressed queries are written atomically to disk and survive server restarts. Mutable ref resolutions are never written to disk. Total disk size is capped (default: 200 MB), automatically evicting the oldest entries first.Resilience: Unreadable or corrupted cache files are deleted safely without interrupting requests or crashing the server.
Security & Best Practices
Read-Only:
gitquery-mcpdoes not contain a single write or mutating API endpoint.Token Safety: The GitHub token is loaded only from the
GITHUB_TOKENenvironment variable. It is never logged (auto-redacted bysrc/util/logger.ts) and never exposed in MCP tool responses.Minimal Scope: A GitHub Fine-Grained Personal Access Token with read-only permissions is recommended:
Repository Permissions:
Contents: Read-only (for file content, blame, commits, diffs)Pull requests: Read-only (for PR association)
Repository Allowlist (
ALLOWED_REPOS): Restrict access to approved repositories:ALLOWED_REPOS=facebook/react,vercel/*,my-org/private-repoAny attempt to query unlisted repositories is rejected with an immediate error before dispatching API requests.
Limits & Truncation Behavior
To protect LLM context windows and token budgets, responses are strictly bounded:
Diffs: Default max size is 60,000 UTF-8 bytes (customizable via
max_bytes). If a diff exceeds the limit, it is cleanly truncated with a notice:[truncated: 12450 more bytes, narrow with paths]File Content: Files over 1 MB (1,048,576 bytes) and binary files (detected by null bytes) are refused with a clear error advising line slicing or cloning.
Changed Files: Capped at 500 files with advice to filter with
path_prefix.Path History: Capped at 100 commits (default: 20) with advice to narrow with
sinceoruntil.
Environment Variables
Variable | Default | Description |
| (optional) | GitHub Personal Access Token (classic or fine-grained). |
|
| Comma-separated list of allowed repos ( |
| (disabled) | Directory path for optional persistent on-disk cache. |
|
| Disk cache capacity ceiling in bytes (default: 200 MB). |
|
| In-memory LRU cache maximum entry count. |
|
| In-memory TTL for mutable branch/tag ref resolutions. |
|
| Stderr logging verbosity ( |
Roadmap
GitLab & Bitbucket Providers: Implement
GitProviderfor GitLab (REST + GraphQL) and self-hosted instances.AGENTS.md Repo-Rules Guard: A tool checking candidate diffs against guidelines specified in an
AGENTS.mdfile in the repository.Intelligent Change Classifier: Classify diff hunks into comment-only, documentation, test-only, logic, or security-sensitive changes.
Post-Merge Auto-Bisect & Revert: Automated commit bisecting over the GitHub API to pinpoint regressions without local cloning.
Contributing
Pull requests and issues are welcome!
git clone https://github.com/attaelahi/gitquery-mcp.git
cd gitquery-mcp
npm install
npm run build
npm testLicense
MIT © 2026 Atta Elahi
Available Tools
10 toolscache_statsA
Returns in-memory cache metrics including total cache hits, misses, current entry count, and hit rate percentage. Use to inspect caching performance and verify cache hits.
Inputs: no named parameters.
find_merge_baseA
Finds the common ancestor commit (merge base) between two git refs and reports ahead/behind commit counts. Use to check branch divergence before merging or comparing histories. Returns mergeBaseSha, aheadBy, behindBy, and status.
Inputs: base (required), head (required), repo (required), owner (required).
find_pr_for_commitA
Finds merged pull requests associated with a commit SHA. Use to discover original PR discussions, reviews, and context for an existing commit. Returns PR number, title, URL, merged date, and author.
Inputs: sha (required), repo (required), owner (required).
get_blameA
Returns line-by-line git blame annotations for a file at a commit or ref. Use to identify who changed specific lines, when, in which commit, and via which PR. Returns ranges of lines with commit, author, and PR metadata. Use start_line and end_line to slice.
Inputs: path (required), repo (required), owner (required), ref, +2 more.
get_diffA
Returns the unified git diff between two refs, optionally restricted to specific file paths. Use to inspect code changes without cloning. Output is truncated at max_bytes (default 60KB; narrow with paths).
Inputs: base (required), head (required), repo (required), owner (required), +2 more.
get_file_at_refA
Retrieves file content at a specific ref or commit, with optional line slicing. Use to inspect historical code without cloning. Rejects binary files and files exceeding 1 MB. Narrow with start_line and end_line.
Inputs: path (required), repo (required), owner (required), ref, +2 more.
get_path_historyA
Lists commits modifying a specific file or directory up to a ref. Use to trace when a path was touched or refactored. Returns commit SHA, author, date, and headline. Capped at 100 commits (default 20). Narrow with since, until, or limit.
Inputs: path (required), repo (required), owner (required), ref, +3 more.
is_ancestorA
Determines whether commit 'ancestor' is an ancestor of commit 'descendant'. Use to verify whether a fix or feature branch is already contained within another branch without cloning. Returns a boolean and explanation.
Inputs: repo (required), owner (required), ancestor (required), descendant (required).
list_changed_filesA
Lists all files modified, added, or deleted between two git refs with change statistics. Use to survey changes across commits or branches. Capped at 500 files; narrow with path_prefix.
Inputs: base (required), head (required), repo (required), owner (required), +1 more.
resolve_refA
Resolves a git reference (branch name, tag, or partial SHA) to a full 40-character commit SHA. Use before queries when you need the canonical immutable commit identifier. Returns {sha, refType}. Fast and cached.
Inputs: ref (required), repo (required), owner (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool targets a distinct Git query operation: ref resolution, ancestry, blame, path history, PR lookup, changed files, diff, file content, merge base, and cache stats. Overlaps are only superficial (e.g., ancestry vs merge base, diff vs changed files), and descriptions make boundaries clear.
Most names follow a predictable verb_noun pattern (find_merge_base, resolve_ref, get_blame, get_path_history, list_changed_files, get_diff, get_file_at_ref). Minor deviations are predicate/noun forms like is_ancestor and cache_stats, but the set remains readable and coherent.
Ten tools is well-scoped for a read-only Git query server. Each tool earns its place by covering a distinct query need, with no obvious redundancy or bloat.
The surface covers core query operations: ref resolution, history, blame, diffs, changed files, file content, PR association, ancestry, and merge bases. Minor gaps include listing available branches/tags/remotes or richer commit metadata, but agents can often work around these with resolve_ref and path history.
Maintenance
Related MCP Connectors
Operate GitHub from your AI assistant: repos, PRs, issues, Actions. Previews and read-only mode.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Ask any GitHub repository a question. Get source-backed answers.
Access the GitHub API, enabling file operations, repository management, search functionality, and…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to access live GitHub repository data without cloning, supporting repo summarization, file explanation, recent changes, and dependency analysis.MIT
- AlicenseBqualityDmaintenanceEnables AI assistants to inspect local Git repositories and interact with the GitHub API for reading commits, diffs, files, issues, comments, pull requests, and project boards.10145 npmISC
- AlicenseAqualityCmaintenanceEnables asking natural-language questions about any GitHub repository and receiving answers grounded in the actual code, with read-only enforcement and automatic repository fetching.15 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to analyze local Git repositories with commit logs, diffs, blame, statistics, and branch analysis using native git commands without requiring a GitHub API.66 npmMIT