Skip to content

app/: /mcp/admin and the staff-only admin OAuth scope, ported from the Loco server (sc-8900) - #145

Merged
ndbroadbent merged 2 commits into
mainfrom
app-staff-admin-mcp
Dec 3, 2026
Merged

ndbroadbent merged 2 commits into
mainfrom
app-staff-admin-mcp

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Ports the Loco server's staff admin MCP endpoint and the staff-only admin OAuth scope into app/ (sc-8900, before sign-ups open). It's the first of three PRs. The staff commands and the credit override come in separate PRs.

/mcp/admin (app/src/mcp/admin.rs)

The tools have the same names, arguments and answers as the old server/src/mcp/admin.rs (git show 0788198^:server/src/mcp/admin.rs):

  • Reads: list_feedback, get_feedback, find_user, find_org, get_org (with billing and usage), recent_failures, list_emails.
  • Writes, each needing a reason: set_plan, mark_feedback_handled, rerun_build (only a build stuck processing), resolve_email (retry or dismiss), set_open_source_withdrawn.
  • Shared tools for any organization: get_project, list_builds, get_build, get_snapshot, snapshot_history. Staff act as an admin there (Via::Admin), and the answer starts with the untrusted-customer-data note.
  • Every call writes an admin_audit row (user, OAuth client, agent, tool, arguments, reason, ok). Customer-written text comes back under untrusted_customer_data.
  • The feedback and failed-email queries are now shared with the staff pages (auth::staff::feedback_page, resolve_failed).

The admin scope (app/src/auth/oauth.rs)

  • The OAuth server now has two resources: <mcp url>/mcp (scope mcp) and <mcp url>/mcp/admin (scope admin). Each one's metadata advertises only its own scope. The admin resource is added automatically next to every /mcp resource, so OAUTH_RESOURCES needs no change.
  • The package's consent step grants whatever the posted form asks for. consent_scopes (web group, after the session) decides first, as the old granted_scopes did:
    • The consent page shows what will be granted: admin alone on the admin resource and only for staff, mcp alone on /mcp.
    • A non-staff person asking for the admin resource gets a 403 page ("only for VisualCI staff").
    • A non-staff person asking for mcp admin on /mcp gets mcp only.
    • An approval POST asking for more than that is refused, so a tampered form can't get the admin scope.
  • The endpoint takes only an OAuth token for its own resource with admin, for someone who is still staff (403 once they aren't).
  • Personal (vcu_) and project (vci_) tokens get a 401 saying they don't work there, even a staff member's. That matches the old server, which never let personal tokens use /mcp/admin.

Fix: OAuth tokens on /mcp

/mcp had no check for OAuth access tokens: the Principal extractor only knows sessions and vcu_/vci_ tokens, and no test called /mcp with a vca_ token. So I believe MCP clients connected over OAuth were refused with 401. mcp::handle now verifies vca_ tokens for <mcp url>/mcp with the mcp scope. A revoked token gets the invalid_token challenge. Test: an_oauth_token_reaches_mcp_as_its_person.

Tests

app/tests/mcp_admin.rs, through the real flow (registration, consent page, approval, token exchange):

  • Non-staff can't get the admin scope or reach /mcp/admin, and a tampered approval is refused.
  • Staff can.
  • Each endpoint's challenge and metadata names its own scope, and a personal token is refused.
  • Every tool refuses unknown arguments.
  • Every ported tool is checked against goldens in app/tests/golden/mcp_admin/, in the public MCP's golden style.
  • Writes without a reason are refused and audited as failed. Demoting staff locks the same token out.

Gates on the build box: cargo fmt --all --check, cargo clippy --locked --workspace --all-targets -- -D warnings and cargo test --locked --workspace all pass.

VisualCI build

The new golden files are JSON snapshots, so the build should show new mcp_admin/... JSON snapshots and no other changes.

Docs: design.md's "Admin tools" section now describes what exists (the "app/ doesn't serve it yet" note is gone).


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review fixes (second commit)

  • The audit is atomic. Each call runs in one db::transaction together with its admin_audit insert. Every query joins it, including job dispatches on the database queue. If the audit row can't be written, the call's change is rolled back and the agent gets "this call failed, or couldn't be recorded in the audit log, so nothing was changed". Test: with a CHECK constraint that rejects mark_feedback_handled audit rows, the call returns that error, the feedback stays unhandled and the audit table gains no rows.
  • Admin consent warning. The consent page on the admin resource shows a warning under its heading, in the page's own warning style: "Admin access. This app could read every organization's data, change plans, re-run builds and resolve customers' emails and feedback, as you." It also shows the redirect host prominently ("After you allow it, you're sent to 127.0.0.1:9999"). The /mcp consent page is unchanged. Test: the_admin_consent_page_warns_and_names_the_redirect_host.
  • Smaller fixes:
    • The consent check refuses an approval POST that the OAuth server can't read, instead of passing it through to the package.
    • resolve_email uses the same reason check as the other writes.
    • find_user and find_org escape %, _ and backslashes, and refuse an empty query.
    • get_feedback uses checked_add.
    • rerun_build only takes builds still processing 30 minutes after they were finalized, as recent_failures counts them.
    • set_plan refuses an organization with a Stripe subscription: "... pays for its plan through Stripe (subscription ...); setting it here would leave Stripe billing them. Change or cancel the subscription in Stripe instead". I chose a refusal over changing the plan and leaving Stripe billing them.
  • Each of these has a test or golden: find_user-2/-3, set_plan-4, rerun_build-3. The existing goldens are unchanged.
  • Gates on the build box: fmt, clippy -D warnings and cargo test --locked --workspace all pass.

…uth scope, ported from the Loco server (sc-8900)

- /mcp/admin with the old server's 12 tools (list_feedback, get_feedback, find_user, find_org, get_org,
  recent_failures, list_emails, resolve_email, set_open_source_withdrawn, set_plan, mark_feedback_handled,
  rerun_build) and the 5 shared read tools for any organization; writes need a reason; every call goes to
  admin_audit; customer text under untrusted_customer_data.
- OAuth: two resources (/mcp with mcp, /mcp/admin with admin), each advertising its own scope. The consent step
  grants admin only to staff and only on the admin resource; mcp alone on /mcp.
- /mcp now accepts MCP clients' OAuth access tokens (vca_), which it refused before.

Co-authored-by: Claude <noreply@anthropic.com>
…nsaction, an admin consent warning with the redirect host, and tighter tools (sc-8900)

- A call and its admin_audit row run in one transaction: a row that can't be written undoes the call.
- The admin consent page warns what admin access can do and shows the host the person is sent back to.
- An approval the OAuth server can't read is refused by the consent check too.
- resolve_email needs a real reason; find_user and find_org take % and _ literally and refuse an empty query;
  get_feedback can't overflow; rerun_build takes only builds stuck over 30 minutes; set_plan refuses an
  organization with a Stripe subscription.

Co-authored-by: Claude <noreply@anthropic.com>
@ndbroadbent
ndbroadbent merged commit 6dae041 into main Dec 3, 2026
14 checks passed
@ndbroadbent
ndbroadbent deleted the app-staff-admin-mcp branch December 3, 2026 18:52
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