ngit-mcp
# ngit-mcp
**Let an AI assistant read and work with git repositories that live on Nostr. It is safe by default.**
[ngit](https://ngit.dev) is a way to host git repos on Nostr. There is no GitHub: pull requests,
issues and comments are signed events on relays. `ngit-mcp` connects that world to any MCP host
(Claude Desktop, Cursor, Grok Bot and others), so an assistant can:
- **Read**: a repo's maintainers and servers, the PR and issue lists, full threads with CI, the
actual code diff of a PR, and a live feed of "what happened sinceβ¦".
- **Act** (only when you switch it on): open or update a PR, comment, create an issue, label,
close or reopen, merge. Each action is shown to you as a plan first, and **your own signer app
signs it**. The server never holds a key.
## Why it's nice
| | |
|---|---|
| β‘ **Fast** | Repeat reads take about **0.2 ms** instead of about 560 ms, and stay fresh via a live relay subscription. With `--warm`, the first read is instant too. |
| π **Connect in the chat** | Ask for a write and you get one message: a QR for your signer app, or "just tell me your name". New to Nostr? Two questions (your name, an optional backup email) and you have an account, made on this machine, with the key never shown to the AI. There's no terminal and no config. See [ONBOARDING.md](ONBOARDING.md). |
| π **Can't post until you connect** | Signing tools stay off until you pair a signer in this session, which is a physical act on your own device. Reads need no setup and run in a private, keyless home that cannot reach a signer. |
| π§Ύ **Plan β approve β commit** | Every write is a plan with an exact preview and a token. The token is a hash of the exact command, so what you approved is exactly what runs. |
| π **Never posts twice** | Before any retry it checks the relays for the event. If the relays can't be reached, it refuses instead of guessing. |
| π‘οΈ **Prompt-injection fencing** | Anything other people wrote comes back inside `<untrusted author=β¦ role=β¦>`, so the assistant knows what is data and what is an instruction. |
| π€ **No secrets in output** | Keys and bunker secrets are redacted from every response, including errors. |
## Install
Requires Node β₯ 20 and [ngit](https://ngit.dev/install) on your `PATH`.
```bash
git clone <this repo> ngit-mcp && cd ngit-mcp
npm install && npm run build
```
### Add it to your MCP host
```json
{
"mcpServers": {
"ngit": {
"command": "node",
"args": ["/path/to/ngit-mcp/dist/index.js",
"--warm", "nostr://npub1β¦/relay.ngit.dev/my-repo"]
}
}
}
```
That's all the setup there is. Reading works at once. The first time you ask for a write, the
assistant calls `ngit_connect` and shows you this:
> Open your Nostr signer app and scan this.
> New to Nostr? Just tell me your name and I'll set you up here.
> βΉQRβΊ
Scan it and approve, and you get "β Connected as you". Or tell it your name: it asks one more
question ("Email for your backup? (optional)") and ends with "β You're on Nostr as Ada
(npubβ¦). Nothing is posted until you approve it." From then on every
write is shown to you as a plan first, and your signer app asks before signing. The full
script and every failure case are in [ONBOARDING.md](ONBOARDING.md).
Optional flags:
| Flag | Effect |
|---|---|
| `--allow-signing` | Enables `ngit_plan` and `ngit_commit` from the start for the ngit account that is already logged in, with no pairing needed. |
| `--read-only` | No writing at all: removes `ngit_connect` and the signing tools. Always wins. |
| `--secret-storage <auto\|file\|git-config>` | Passed to `ngit account login`. Without an OS keychain the assistant asks before falling back to `git-config`. |
| `--no-local-page` | For servers that don't run on your computer: no `127.0.0.1` pairing or backup page. The QR still works, and newcomers are told their key is kept on that machine. |
| `--signer-relay <url>` | Override the pairing relays. |
| `--warm <repo>` | Preloads a repo at startup, so the first call is instant. |
| `--lockdown` | Hides text from people who are not maintainers or in `--allow-npub`. |
| `--allow-npub <npub>` | Marks extra people as trusted. |
| `--repo-allowlist <repo,β¦>` | Refuses every other repo. Entries must use npub or naddr form. |
| `--allow-local-git` | Lets `ngit_pr_diff` fetch over plain http from 127.0.0.1 or localhost, for a local GRASP server. Off by default, because PR clone URLs are chosen by whoever opened the PR. |
| `--state-dir <dir>` | Where caches live (default `~/.local/state/ngit-mcp`). |
## Tools
| Tool | What it does |
|---|---|
| `ngit_repo` | Name, maintainers, git servers, health |
| `ngit_list` | `type: pr \| issue`, with optional status, label and author filters |
| `ngit_get` | One PR or issue with its comment thread (PRs include CI) |
| `ngit_pr_diff` | Diffstat and unified diff of a PR, fetched straight from its git servers |
| `ngit_activity` | New PRs, issues, comments, status changes and updates since a time (live) |
| `ngit_connect` | Connects your identity. It returns the QR (as an image and as text) and waits with `wait_s`, or takes a pasted `bunker://` link, or creates a new account from `name` (+ `email`) with `ngit account create`. `backup` points to the local backup page. Refuses anything that looks like a private key. |
| `ngit_plan` | *(signing)* Builds an exact plan and token for pr_open, pr_update, comment, issue_create, status, label or merge. Publishes nothing. |
| `ngit_commit` | *(signing)* Runs a plan by token. Your signer app asks you to approve. Call it again with the same token to check progress; it never publishes twice. |
Every read accepts `fresh: true` to force a network round trip. Repos can be written as `nostr://<npub>/<relay>/<id>`, `naddr1β¦`, or with a NIP-05 owner such as `nostr://dan@gitworkshop.dev/relay.ngit.dev/ngit`.
## Demo (real output, read-only, against a public repo)
```
> tools: ngit_repo, ngit_list, ngit_get, ngit_pr_diff, ngit_activity
> ngit_repo (610.7 ms, fetched)
name=<untrusted author="npub1m5tuβ¦" role="maintainer">routstrd-remote</untrusted> maintainers=1
> ngit_list type=pr (555.3 ms, fetched) count=2
[open] <untrusted author="npub1626pβ¦" role="other">feat(npubs): per-npub model allowlist and expiry</untrusted>
[applied] <untrusted author="npub1m5tuβ¦" role="maintainer">feat(admin): seed the container's own identity as the first admin</untrusted>
> ngit_list type=pr again (0.9 ms, memory)
> ngit_get type=pr (549.0 ms) comments=0
> ngit_pr_diff (1455 ms cold / 1.4 ms warm) 6 files changed, 667 insertions(+), 30 deletions(-)
> ngit_activity since=0 (2.5 ms) events=5
```
To reproduce it, run `npx tsx scripts/demo.ts [repo]`. A signing session looks like this:
```
assistant β ngit_plan {action:"comment", on:"pr", id:"nevent1β¦", body:"LGTM"}
server β {token:"ngp_3fβ¦", signer:"npub1youβ¦", preview:{what:"Comment on pr", body:"LGTM"},
commands:[["ngit","--repo","nostr://β¦","pr","comment","nevent1β¦","--body=LGTM","--json"]]}
assistant: "I'll post 'LGTM' on PR #β¦ as npub1youβ¦ β OK?" you: "yes"
assistant β ngit_commit {token:"ngp_3fβ¦"} (your phone asks you to approve; you tap Approve)
server β {state:"done", attempt:1, result:{β¦}}
```
## Speed (real MCP round trips, routstrd-pro on relay.ngit.dev)
| Tool | Raw `ngit` CLI | ngit-mcp cold | ngit-mcp warm p50 | with `--warm`, first call |
|---|---|---|---|---|
| repo | 545β1361 ms | 1215 ms | 0.22 ms | 7 ms |
| pr list | β570 ms | 540 ms | 0.35 ms | 1 ms |
| pr view | β560 ms | 553 ms | 0.44 ms | β |
| issue list | β560 ms | 539 ms | 0.12 ms | 1 ms |
| pr diff | (no equivalent) | 1484 ms | 1.5β1.9 ms | β |
| activity | (no equivalent) | 2 ms | 0.6 ms | β |
A cold read is ngit itself, because ngit stays the source of truth. Every later read is served from
memory and refreshed in the background. A live relay subscription marks it stale as soon as anything
changes. Raw numbers are in `bench/` (`npm run bench`).
## Tests
```bash
npm test # 60 tests (25 property suites, a 5,040-run model check of the
# signing protocol, the real server process); fakes, no network (β55 s)
./test/e2e/run.sh # 28 tests: real ngit + git-remote-nostr + real signatures with a
# throwaway key, against a local relay AND a local GRASP server
# (relay + git smart-HTTP enforcing GRASP push rules), inside a
# network namespace with NO internet (needs unshare)
```
The onboarding e2e pairs real ngit with a scripted NIP-46 signer (throwaway keys) in these
modes: ok, asleep, never answers, rejects, no keychain, already logged in, and a
pasted promenade-style bunker followed by a signed issue through it. It also runs the
newcomer wizard (with and without email, and hosted) using real `ngit account create` against
a local relay. That covers the backup page (its ncryptsec decrypts to the exact key ngit
stores) and a signed issue with the new key, and it checks every byte of tool output for the
key.
The e2e covers the whole PR lifecycle: open β diff β update (revision) β stale-plan refusal β
comment β draft/ready β merge and publish. It also checks that a rogue push is rejected by the
GRASP rules.
`INVARIANTS.md` lists the 19 invariants, how each is proved or checked, and the 15 bugs that
the tests found. `LOOPS.md` is the build diary.
## Limitations
- A cold read costs one ngit call (about 0.55β1.2 s). Use `--warm` for the repos you care about.
- A key created in the chat signs without asking on a device; the approval is the plan step
in the chat. Move it to your phone (backup page) for a second factor. On a hosted agent the
key lives on the host. See ONBOARDING.md, limits.
- The signer is whichever ngit account is active in your environment. The connector never
holds keys, and it has only been tested with throwaway keys. It has not been tested with a
real phone signer.
- Plans live in memory. After a restart, make a new plan. The new plan warns
(`possible_duplicate`) if you published a matching event in the last 10 minutes.
- The GRASP server used in the e2e is a minimal test implementation written for this project,
not ngit-grasp itself. ngit 3.2.0 and git-remote-nostr are the real thing.
- `ngit_pr_diff` fetches from https clone URLs named in the PR. That means it can reach any
https host the PR author chose, but only to read git objects.
- Short lowercase words (β€20 letters, such as status values) are left unfenced by design.
TDQS
Scored across 6 tools
The tools mostly target distinct resources and actions: repo metadata, listing, single-item retrieval, PR diff, activity feed, and identity connection. The boundary between ngit_list (current open/draft PRs and issues) and ngit_activity (changes since a timestamp) could be confused, but descriptions help clarify.
All names share the same ngit_ prefix and snake_case style, making them readable and predictable. However, the suffix pattern mixes verbs (list, get, connect) and nouns (repo, activity, pr_diff), so it is not a strict verb_noun convention throughout.
Six tools is well-scoped for a PR/issue browsing and monitoring server, with each tool covering a distinct capability. There is no obvious redundancy or bloated surface.
The surface covers repo metadata, listing/fetching PRs and issues, PR diffs, activity monitoring, and identity connection. But it appears read-only: there are no tools to create issues/PRs, comment, update status, or merge, which are notable gaps for a collaboration workflow.