Skip to content

CoderHelm as an MCP server: OAuth sign-in, run and review tools - #530

Merged
nambok merged 1 commit into
mainfrom
feat/mcp-server
Nov 9, 2026
Merged

nambok merged 1 commit into
mainfrom
feat/mcp-server

Conversation

@nambok

@nambok nambok commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

CoderHelm is now an MCP server. People add https://api.coderhelm.com/mcp (or https://<install address>/mcp on a self-hosted install) to Claude, Cursor, VS Code or any MCP client, sign in with OAuth, and see runs, start and retry them, and read or ask for reviews, as themselves.

Each tool is a dashboard action and runs as one: a tool call becomes a request to the same /api route the dashboard calls, through the same router and auth middleware, as the person who connected the app. Their membership, current role (custom roles included), the team's two-factor rule, the route's capability and its own role check all apply, plus the connection's scopes. Every call is written to the team's log before it runs.

Changes

MCP server (mcp_server.rs)

  • POST /mcp, Streamable HTTP, stateless JSON answers; GET and DELETE answer 405. Protocol versions 2025-11-25, 2025-06-18 and 2025-03-26.
  • Tools with readOnlyHint / destructiveHint / idempotentHint / openWorldHint: list_runs (status, repo, since), get_run (steps, pull requests, holds and open questions, error, latest notes), start_run (GitHub issue URL or owner/name#N, a Jira key CoderHelm has seen, or a task in words with its repo), retry_run, list_reviews, get_review (by id or PR URL, with findings), request_review (PR URL).
  • Tool calls run through the API router with an McpCaller request extension, which only the gateway can set. middleware::auth::app_request checks it like a session: check_member_session against when the person connected the app (a removal, role change or two-factor reset ends the connection), check_session with the sign-in proof kept from consent, then mcp_server::decide: the route must be one the called tool uses, the connection must hold its scope, and permissions::resolve_access must allow it.
  • Every tools/call writes an mcp_call entry to the team's audit log first; if the log can't be written, the call doesn't run.
  • A write tool without runs:write answers 403 with WWW-Authenticate: Bearer error="insufficient_scope" (step-up).

OAuth 2.1 (mcp_oauth.rs, routes/mcp_oauth.rs)

  • /.well-known/oauth-protected-resource[/mcp] (RFC 9728) and /.well-known/oauth-authorization-server (RFC 8414). The 401 on /mcp names the resource metadata and asks for runs:read.
  • POST /oauth/register (RFC 7591): public clients only, redirect addresses must be https, http on loopback (any port, RFC 8252) or an app's own scheme. Rate-limited per address.
  • GET /oauth/authorize: checks client, redirect, PKCE S256 and resource, then sends the person to the dashboard consent page with the request signed into the link (10 minutes). A bad client or redirect is a page, never a redirect.
  • Consent from the person's own session (POST /api/mcp/authorize/describe, POST /api/mcp/authorize); never from a support view or an API key. Writing is a separate choice on the page. The connection is logged (mcp_connected).
  • POST /oauth/token: one-time codes (deleted on swap, 5 minutes, bound to client, redirect and PKCE verifier); access tokens are JWTs for audience coderhelm-mcp (1 hour), checked against their connection on every call; refresh tokens are opaque, stored as hashes, replaced on every use, 30 days from last use, and a replaced one used again ends the connection.
  • POST /oauth/revoke (RFC 7009) for refresh or access tokens.
  • GET /api/mcp/connections and DELETE /api/mcp/connections/:id: your own connections, or everyone's for people who manage API keys. Revoking is logged (mcp_revoked) and stops every token of the connection at once.
  • Storage is in the settings table (clients, codes, connections, all with TTLs). No new table.

Starting a run from a ticket (routes/run_start.rs)

  • POST /api/runs/start (capability runs, member and up): a GitHub issue is read with the team's app and queued as labeling it would queue it, with the person as requester; a known Jira key starts again from its latest run as Retry does. The token limit and the in-flight trigger gate apply.

Edges

  • CORS: /mcp, the metadata and the token endpoints answer any origin without credentials (bearer tokens only), with Authorization and the MCP headers allowed and WWW-Authenticate exposed.
  • Infra: HTTP API routes for /mcp, /.well-known/{proxy+} and /oauth/{proxy+}; the self-hosted CloudFront sends /mcp, /.well-known/oauth-* and /oauth/* to the API. Both go through the normal stack template. No new IAM: the gateway uses the settings and users tables it already reads and writes, and the deploy role already manages the API's routes and the distribution.

Verification

  • cargo fmt --check --all, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test --workspace: all pass (common 1569, gateway 793, worker 1410).
  • New tests (46 in gateway's mcp_, run_start and cors modules): PKCE (RFC 7636 vector, wrong verifier, malformed verifiers), authorization request checks (no PKCE, plain PKCE, wrong response type, foreign resource, unregistered redirect shown as a page), redirect address rules, registration, scopes, signed consent link expiry, code swap once only and by its own app, expired code, access token expiry, refresh rotation with reuse ending the connection, narrowing scopes on refresh and never widening, revocation from the dashboard and by the app, wrong team, person or app on a token, per-tool authorization for viewer, member, admin, owner and custom roles under each scope, a tool reaching only its own routes, routes no tool uses refused, the 401 and 403 challenges, /mcp over HTTP (no token, a session token, garbage, an expired token, GET and DELETE), CORS for browser MCP clients, ticket parsing.
  • infra: npm test (155 pass), including a new test that the MCP routes reach the gateway hosted and self-hosted, and that /authorize stays with the dashboard.
  • The dashboard (consent page, Connected AI apps) is in the coderhelm repository's companion pull request.

People add CoderHelm to Claude, Cursor, VS Code or any MCP client at /mcp
on the install's API address, sign in with OAuth 2.1 (dynamic client
registration, PKCE S256, short-lived access tokens checked against their
connection on every call, rotating refresh tokens, revocation), and use
list_runs, get_run, start_run, retry_run, list_reviews, get_review and
request_review as themselves.

Each tool call goes through the API router and auth middleware as the
person who connected the app, so it is authorized exactly like the same
dashboard action, limited to the routes of the tool being called and the
connection's scopes, and written to the team's log before it runs.
@nambok
nambok merged commit dd4db7c into main Nov 9, 2026
10 checks passed
@nambok
nambok deleted the feat/mcp-server branch November 9, 2026 03:11
coderhelm Bot pushed a commit that referenced this pull request Dec 3, 2026
Moves dashboardRef from 6593784 to 1002bc7, carrying CoderHelm/coderhelm #502, #514, #513, #527, #530, #531, #533, #529, #536, #535, #499 and #537.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant