New apps/rithub-mcp-oauth: a thin OAuth 2.1 authorization server (to the
MCP client) that is itself an OAuth client of the engine's real OAuth2
server (to Gitea) -- the same "front-door service wraps the engine's real
OAuth2 flow" shape already used by rithub-device-auth/approvals/export,
facing a different kind of caller. Lets any MCP-Authorization-spec-
compliant client (Claude Code, Cursor, VS Code, Codex, Gemini CLI...)
connect to rithub.dev/mcp with just the URL and a browser sign-in -- no
pasted token.
- RFC 9728 Protected Resource Metadata + RFC 8414 Authorization Server
Metadata, both served at their required well-known paths.
- RFC 7591 Dynamic Client Registration (POST /mcp-oauth/register), public
clients only (PKCE, no secret), persisted to a small JSON store.
- /mcp-oauth/authorize validates the MCP client's own PKCE challenge and
redirect_uri, then starts a SEPARATE engine-facing OAuth2 leg with this
service's own fresh PKCE pair against a dedicated real OAuth2 app
("Rithub for Agents", client_id 6717d838-...) -- deliberately its own
app, not the shared "Rit CLI" one device-auth/approvals/export use: a
real user who already has a `rit login` grant against "Rit CLI" hits
the engine's hard "a grant exists with different scope" error the
moment a second service tries to authorize the SAME client_id with a
different scope string -- live-reproduced against the owner's own
account 2026-12-01. A dedicated app means this service's grants can
never collide with `rit login`'s, for any user, ever.
- /mcp-oauth/authorize/callback exchanges the engine's code (this
service's own PKCE verifier), mints a short-lived one-time code bound
to the MCP client's original code_challenge, and hands it off with a
styled "Connected" page (meta-refresh + JS redirect, not an invisible
302) instead of the owner's reported unstyled blank success state.
error_description (not the bare error code) is translated into plain
words for the exact scope-collision class above, and any other engine
error still shows escaped, never swallowed.
- /mcp-oauth/token verifies the MCP client's PKCE verifier against the
stored challenge before handing back the real engine access_token
(never a second, parallel token format) + refresh_token; refresh_token
grants relay straight to the engine.
- apps/rithub-mcp/src/http.mjs: a 401 on /mcp now carries
`WWW-Authenticate: Bearer resource_metadata="..."` per the MCP
Authorization spec, so a compliant client auto-discovers this flow
instead of needing a token out of band. Uses RITHUB_PUBLIC_BASE_URL
(same convention as this app's own agentSignup.mjs), not the internal
loopback RITHUB_BASE_URL this service calls the real API on.
Live-verified end to end, real `claude mcp login` (Claude Code 2.1.322,
unmodified): DCR, browser consent, token exchange, `tools/list` returning
the real tool catalog, "Status: Connected" in `claude mcp get`. Separately
confirmed via curl with a clean cookie jar: a user who already had a
`rit login` grant against "Rit CLI" completes this flow with zero
collision now that it's a separate app, and a brand-new user completes it
too. Consent/success/error pages screenshotted at 1440 and 390, read
directly -- no layout issues, no stock-engine chrome. All QA accounts,
DCR test-client registrations, and agent-session marks purged after.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rithub-mcp
Streamable-HTTP MCP server for Rithub: one endpoint (https://rithub.dev/mcp)
any MCP-capable agent (Claude Code, Cursor, Codex) can point at to work on
Rithub repos -- no per-tool glue code.
Auth is a caller-supplied Rithub access token, sent as
Authorization: Bearer <token> on every request. This service holds no
credential of its own by default; it forwards the token to the Rithub API
as-is -- except for agent-scoped tokens (below), which it does hold the
backing credential for, encrypted at rest, purely so it can enforce a
narrower fence than the real token would allow on its own.
Run locally
npm install
RITHUB_BASE_URL=https://rithub.dev PORT=3399 node bin/start.mjs
GET /healthz returns {"ok":true}. The MCP endpoint is POST/GET/DELETE /mcp.
Agent-scoped tokens + the agent PR loop (wedge #2)
Any repo owner can mint a token limited to one repo and a chosen
scope (read / pr / full) instead of handing an agent their full
account token -- via one MCP tool call (mint_agent_token) or the plain
settings page at /agent-tokens (paste your real token, pick a repo +
scope, get a rtat_... token back once). That token can then itself be
used as the Authorization: Bearer on /mcp -- src/scopeGuard.mjs
checks every request against the bound repo + scope before it reaches the
real Rithub API, so a pr-scope token can open branches/PRs/issues/
comments but can never merge, touch another repo, or mint itself a
broader token (ownerOnly tools are refused outright for an agent-scoped
session -- see src/server.mjs).
enable_agent_on_repo turns the second half on: labelling any open issue
"agent" (the label is auto-created) makes bin/agent-worker.mjs -- a
separate pm2 process polling every AGENT_POLL_INTERVAL_MS (default
20s) -- read the issue + repo, call the Anthropic Messages API
(CLAUDE_API_KEY/ANTHROPIC_API_KEY, model RITHUB_AGENT_MODEL default
claude-sonnet-4-6) for a structured fix, commit it on a new branch, and
open a pull request that Closes #N, commenting on the issue when it
starts and when it opens the PR. The worker uses the exact same
scope-guarded client a human-held pr-scope token would be restricted
by -- it cannot merge or exceed that fence either. disable_agent_on_repo
revokes it. See src/agentTokens.mjs (storage + encryption),
src/agentTokenActions.mjs (shared mint/list/revoke/enable/disable
logic behind both the MCP tools and the REST settings routes),
src/claudeFix.mjs (the model call), src/agentWorker.mjs (the poll
loop).
Token records live in data/agent-tokens.json (gitignored, 0600,
AES-256-GCM-encrypted backing tokens; the encryption key is
RITHUB_MCP_TOKEN_KEY or an auto-generated data/token-key.hex).
Processed-issue state lives in data/agent-processed.json so an issue is
never re-processed once it has a PR.
Verified end to end against production, 2026-11-18: a throwaway
mail.tm-registered user, a real repo with a real one-line bug, an
mint_agent_token/list_agent_tokens/revoke_agent_token round trip (and
a confirmed-blocked self-escalation attempt), enable_agent_on_repo, an
agent-labelled issue, one real pollOnce() run that called the live
Anthropic API and produced a correct one-line fix, a PR that closed the
issue on merge, and the REST /agent-tokens mint/list routes -- all
cleaned up after (repo deleted, user purged, token deleted, mail.tm inbox
deleted). Full trail: plans/rithub-beat-github-2026-11-18.md.
Production
Runs under pm2 (ecosystem.config.cjs): rithub-mcp (the HTTP server,
bound to 127.0.0.1:3351 only) and rithub-agent-worker (the poller,
no HTTP surface). Both use RITHUB_BASE_URL=http://127.0.0.1:3350 (the
engine's own port) instead of the public rithub.dev domain, because
Cloudflare's edge proxy in front of rithub.dev hard-times-out slow
requests around ~100s -- import_from_github on even a small repo can
exceed that. Caddy (/etc/caddy/sites-enabled/rithub-dev.caddy) proxies
/mcp* and /agent-tokens* on the public domain to the rithub-mcp
service.
Tools
See src/tools.mjs. Docs with one-line client config:
https://rithub.dev/mcp-docs.
Tests
npm test