~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

Sign-in asks for what HUD's views do, never transition:generic

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:oauth/scopes

HUD's sign-in stops asking for transition:generic. It now asks each account's server only for what the bundled views do: their collections, their services, a composer's images. A sign-in made before shows a bar to sign in again, and an MCP host is asked to sign in again the first time its PDS refuses a call.

Claude Opus 5.5 · high

What changes

The scope (hud_core::scope, built when the server starts):

  • repo: for each collection a bundled view writes (an Action's create, a Compose's writes), plus place.hud.theme.
  • blob: for the composer's image types.
  • rpc?lxm=*&aud=<service> for each service a view names: Bluesky's AppView and chat, knotless's and Grain's AppViews.
  • rpc:app.bsky.actor.getPreferences?aud=*. The PDS answers it itself, against whichever AppView it's configured with.
  • rpc:app.bsky.feed.sendInteractions?aud=*.
  • SPACE_SCOPE with HUD_SPACES=on, unchanged.

HUD_OAUTH_SCOPE is gone: the server refuses to start with it set. A view's scope field is gone too, with its gating: chat needs no setting now.

Outside the grant: a query to any other service goes as no one, signed in or not (xrpc::call_query). A write of any other collection is refused before the PDS is asked (create_record, apply_writes, delete_record). create_record's description lists the collections.

Sign in again:

  • Each session keeps the scope it asked for, beside what it was granted. Sessions stored before keep their granted scope as asked, so transition:generic ones count as behind.
  • When a PDS answers ScopeMissingError for a session that's behind, an MCP host gets the 401 challenge. The workspace's methods answer an error that says to sign in again, so the iOS app isn't signed out.
  • A sign-in that asked for everything but was granted less gets a tool error naming the permission.
  • getWorkspace gains signInAgain. The page and the iOS app show a bar with "Sign in again".
  • /workspace/signin?handle= fills in the handle.
  • A new web sign-in ends the browser's previous session.

Docs: sign-in.md gains "What HUD asks for" and "Signing in again". tools.md, running.md, internals.md, overview.md and workspace-api.md follow.

Why

transition:generic is the whole account, close to what an app password grants. HUD's reads and writes are known from its views, so the permissions follow from them: knotless builds its scope from its constants, and this builds HUD's from the views.

Two other ways were considered. repo:* with no per-service rpc would keep create_record open to any collection, which is the whole account again. Per-method rpc would cut the query tool down to the bundled views' methods. Each service a view names takes lxm=* instead, since the spec forbids only lxm=* with aud=*.

How it was checked

  • just check passes on the merge with main: fmt, clippy, tests, svelte-check, lint and lex.
  • New tests:
    • the scope builder;
    • no permission is any method of any service;
    • behind;
    • writes held to the scope against the fake PDS, which now refuses a write its grant lacks: a collection no view writes is refused before the PDS, a narrow grant gets its error, and a session that's behind gets SignIn;
    • query joins send an unlisted service's query as no one;
    • the sign-in page's ?handle=.
  • just e2e against the reference PDS signed in with the new scope. Two flows failed in the full run because a tile from an earlier spec was already on the canvas. Both passed run alone (11/11).
  • just look pictures of the bar (desktop light, phone dark) and of the page without it. An agent that didn't draw them critiqued them, and its padding and spacing fixes are in.
  • The iOS app builds. just ios-test wasn't run.

Shortcomings

  • For a few minutes after a deploy that adds a permission, a PDS holding the old client metadata refuses sign-ins with invalid_scope. HUD doesn't retry with less.
  • Signing in again on iOS doesn't revoke the old session. Revoking it fires the end callback, which signs the app out. The old session expires after 30 days.
  • The getPreferences audience was checked against the reference PDS's code alone.
  • Every existing session is behind once this deploys, so each person signs in again once.

Review

Start at crates/hud-core/src/scope.rs, then Hud::scope_refused in oauth/mod.rs and its callers.

signin-again-desktop-light.png

signin-again-phone-dark.png

Approved

This pull replaces transition:generic with a scope built from the bundled views. It asks for repo: for each collection a view writes plus themes, blob: for the composer's image types, rpc?lxm=*&aud=<service> for each service a view names, and the two aud=* methods. HUD now enforces that scope too. Writes of any other collection are refused before the PDS is asked, and queries to an unlisted service go as no one. Each session records what it asked for, so behind can send an MCP host the 401 challenge and show the page and iOS app a "Sign in again" bar.

I read every file in the diff. What I checked:

  • Every path that calls the PDS as the account is covered by a permission:
    • pds_call and pds_send callers: createRecord, applyWrites, deleteRecord, uploadBlob, getPreferences, getFeedGenerators and getFeedGenerator through APPVIEW, sendInteractions, space.rs, procedures and call_query.
    • Procedures name their service explicitly, so bundled_services picks them up.
  • No rpc permission pairs lxm=* with aud=*.
  • Sessions stored before this change fall back to their granted scope as asked, and there is a test for it.
  • ?handle= is validated as a handle or DID before it fills the form, and the test covers an injection attempt.
  • .notice:not(:empty) holds, because Svelte's comment anchors don't count against :empty.

At this review, lexicons, docs and check passed; web, test, e2e and e2e-spaces were still running.

One non-blocking note: on the workspace's methods, any Refusal::SignIn from a session that is behind now becomes the "sign in again" message, not a 401. That includes a refresh token that has really died. Right after deploy every session is behind, so expired sessions will show the bar instead of being signed out. Signing in from the bar recovers either way.

crates/hud-server/src/xrpc.rslines 764 to 766
Some(Err(Refusal::SignIn)) if hud.behind(&caller.account).await => {
Err(hud_core::oauth::SIGN_IN_AGAIN.to_string())
}
review.knotless.dev

Not blocking: pds_send also returns Refusal::SignIn when the refresh token is dead or revoked. Once this deploys, every session is behind, so a session that has really expired gets this message, not the 401 that signs the page out. The bar recovers it, but you could match only the ScopeMissingError case, for example with a dedicated refusal from scope_refused, so a dead session still gets the 401.

Merged as 9d88a44