repopeek-mcp
by kitepon
README.md
# repopeek-mcp
A read-only [MCP](https://modelcontextprotocol.io) server that lets an AI client browse and search GitHub
repositories through `git`. Every tool result, errors included, is plain `type: "text"` content, so it works with
clients such as Gemini's custom MCP connector, which drop file bodies sent as MCP `resource` blocks.
- **Five tools, no writes**: `list_repos`, `list_files`, `read_file`, `read_files`, `grep`.
- **Read-only through git**: every read is `git ls-tree` / `cat-file` / `grep` against a bare clone or an existing
repository, never a working tree, always with argument arrays (no shell).
- **Deny by default**: an empty `ALLOWED_REPOS` refuses every repository; secret-looking files are hidden.
- **Remote MCP**: Streamable HTTP at `/mcp` (stateless), `GET /health`, Bearer auth plus OAuth 2.1 for web
connectors.
Docs: [tool contract](docs/tools.md), [architecture and data flow](docs/architecture.md),
[deploy example](deploy/README.md).
## Quick start (Docker Compose)
```sh
git clone https://github.com/kitepon/repopeek-mcp.git && cd repopeek-mcp
TOKEN=$(openssl rand -base64 32) # the Bearer token; keep it in your password manager
cat > docker-compose.override.yml <<EOF
services:
repopeek-mcp:
environment:
- ALLOWED_REPOS=octocat/Hello-World
- REPOPEEK_TOKEN_SHA256=$(printf %s "$TOKEN" | sha256sum | cut -d' ' -f1)
- REPOPEEK_STORE_KEY=$(openssl rand -base64 32)
EOF
docker compose up -d --build
curl -s http://127.0.0.1:39230/health # {"status":"ok","service":"repopeek-mcp"}
```
The server listens on `127.0.0.1:39230` and refuses to start without `REPOPEEK_TOKEN_SHA256`. Only the token's
SHA-256 goes into the config; clients send `Authorization: Bearer $TOKEN`. `docker-compose.override.yml` is
gitignored; [docker-compose.override.yml.example](docker-compose.override.yml.example) lists every option.
Without Docker (Node.js 20+ and `git` on PATH):
```sh
npm ci && npm run build
export REPOPEEK_TOKEN_SHA256=$(printf %s "$TOKEN" | sha256sum | cut -d' ' -f1)
export REPOPEEK_STORE_KEY=$(openssl rand -base64 32) ALLOWED_REPOS=octocat/Hello-World
npm start # http://0.0.0.0:39230/mcp
```
To reach it from a hosted client (Gemini and other web connectors), put it behind HTTPS on a public host name and
set `REPOPEEK_PUBLIC_URL`; [deploy/](deploy/README.md) has a Compose + Caddy example and an ssh deploy script.
## Configuration
Environment variables (all read at start):
| Variable | Default | Meaning |
|---|---|---|
| `REPOPEEK_TOKEN_SHA256` | required | SHA-256 hex of the shared Bearer token. The server exits without it |
| `ALLOWED_REPOS` | empty (refuse all) | comma-separated `owner/name` or `owner/*` (case-insensitive) |
| `REPOPEEK_PUBLIC_URL` | `http://localhost:<PORT>` | public origin advertised in OAuth metadata |
| `PORT` | `39230` | HTTP port |
| `REPOPEEK_DATA_DIR` | `./data` (`/data` in Docker) | OAuth store, wrapped store key, clones and mirrors |
| `REPOPEEK_STORE_KEY` | unset | base64 of 32 bytes; encrypts the OAuth store when no auth module is used |
| `GITHUB_TOKEN` | unset | github mode credential for private repositories; unset = public only |
| `REPOPEEK_LOCAL_REPOS` | empty | comma-separated `owner/name=/path`: serve an existing bare repo or checkout (never fetched) |
| `REPOPEEK_FETCH_INTERVAL_SEC` | `300` | github fetch and module re-sync period; `0` disables it |
| `REPOPEEK_SECRET_PATTERNS` | empty | extra comma-separated secret-file patterns (`*`, `?` wildcards) |
| `REPOPEEK_ACCESS_TEAM_DOMAIN` | unset | Cloudflare Access team domain (`https://<team>.cloudflareaccess.com`); set with `REPOPEEK_ACCESS_AUD` |
| `REPOPEEK_ACCESS_AUD` | unset | Access application AUD tag |
| `REPOPEEK_ACCESS_EMAILS` | empty | optional comma-separated e-mail allow-list on top of the Access policy |
| `REPOPEEK_AUTH_SOCKET` | unset | auth-module caller socket (module mode and module-wrapped store key) |
| `REPOPEEK_WRAP_KEY_NAME` | unset | auth-module wrap key name, needed for the first wrap |
| `REPOPEEK_MODULE_ITEMS` | empty | comma-separated `owner=item`: that owner's repositories are read through the module item `http <item>` |
| `REPOPEEK_LIST_MAX_ENTRIES` | `500` | `list_files` entry cap |
| `REPOPEEK_READ_MAX_CHARS` | `40000` | `read_file` output cap |
| `REPOPEEK_READ_FILES_MAX_CHARS` | `80000` | `read_files` default total cap |
| `REPOPEEK_READ_FILES_MAX_CHARS_LIMIT` | `400000` | hard max for `max_total_chars` |
| `REPOPEEK_GREP_MAX_RESULTS` | `50` | `grep` default hit cap |
| `REPOPEEK_GREP_MAX_RESULTS_LIMIT` | `500` | hard max for `max_results` |
| `REPOPEEK_GREP_LINE_MAX_CHARS` | `300` | `grep` line trim |
## Source modes
Each allowed repository is served from one source:
- **Public clone (github mode, default)**: `git clone --bare` over HTTPS into `REPOPEEK_DATA_DIR/repos` on first
use, refreshed by `git fetch` every `REPOPEEK_FETCH_INTERVAL_SEC`. No credentials needed.
- **Private repositories, standalone**: set `GITHUB_TOKEN` to a read-only token (a fine-grained PAT with
*Contents: read* on the repositories you allow). It is passed to `git` through environment config for clone and
fetch only, never in argv, the stored remote URL or tool output.
- **Local repositories**: `REPOPEEK_LOCAL_REPOS=owner/name=/path` serves a bare repository or checkout you mount or
keep on disk. It is never fetched; history, branches and tags are whatever that repository has.
- **Auth module (optional)**: for setups where no credential may enter RepoPeek at all. A separate process holds the
GitHub token and exposes a unix socket (`REPOPEEK_AUTH_SOCKET`) that takes one JSON request per connection: `wrap`
/ `unwrap` (used to protect the OAuth store key) and `http` (a GET to `https://api.github.com/repos/<owner>/...`,
to which the module adds the credential). For owners listed in `REPOPEEK_MODULE_ITEMS`, RepoPeek rebuilds a local
bare mirror from the GitHub git-data API and verifies every object id. The protocol is the one of the
[BellTeam](https://github.com/kitepon/BellTeam) auth-mediation module; see
[docs/architecture.md](docs/architecture.md#module-sync-module-mode) for the exact requests. Limits: only the latest
commit of each ref is mirrored (no history, so `HEAD~1` is not found), and a file larger than the module's answer
limit cannot be mirrored (the sync fails with the reason).
## Security model
- **Read-only**: there are no write tools. The only disk writes are clones/fetches and module mirrors inside
`REPOPEEK_DATA_DIR/repos`, and the encrypted OAuth store.
- **Allowlist**: `ALLOWED_REPOS` empty or unset refuses everything.
- **Secret-file hiding**: any path segment matching `.env`, `.env.*`, `*.pem`, `*.key`, `*secret*`, `id_rsa*`,
`id_ed25519*`, `*.p12`, `*.pfx`, `credentials.json` or a `REPOPEEK_SECRET_PATTERNS` entry is absent from
`list_files` and `grep`, and refused by `read_file` / `read_files`. This is a safety net, not a substitute for
keeping secrets out of the repositories you allow.
- **Input checks**: refs starting with `-` or containing `:` are refused (a `ref:path` tree-ish could otherwise
bypass the secret filter); `..` segments, absolute paths and pathspec magic in globs are refused.
- **Authentication**: `/mcp` needs `Authorization: Bearer`; the server stores only the token's SHA-256. Web
connectors use OAuth 2.1 with dynamic client registration (DCR) and PKCE S256; issued tokens live in an AES-256-GCM
encrypted store. The `/authorize` login page asks for the Bearer token, or, when `REPOPEEK_ACCESS_TEAM_DOMAIN` and
`REPOPEEK_ACCESS_AUD` are set, requires a valid Cloudflare Access JWT instead (fail closed). Put only `/authorize`
behind Access; `/mcp`, `/token`, `/register` and `/.well-known` must stay reachable for the client.
## Use with Gemini
1. Deploy RepoPeek on an HTTPS host and set `REPOPEEK_PUBLIC_URL=https://<your-host>`.
2. In Gemini, add a custom MCP connector with the URL `https://<your-host>/mcp`.
3. Gemini registers itself (DCR) and opens the authorize page. Log in: with Cloudflare Access in front of
`/authorize`, pass the Access login (e.g. one-time PIN to your e-mail); otherwise enter the Bearer token.
4. Try it: "call list_repos", then `list_files`, `read_file` and `grep` on one of the listed repositories.
Other MCP clients that send a static header can skip OAuth and use `Authorization: Bearer <token>` directly.
## Development
```sh
npm ci
npm run typecheck
npm test
```
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues