Skip to content

MCP connect on Fly (device sign-in): sign-in drops redirect_to, user lands on dashboard instead of the consent screen #3936

Done

Description

@integry

Problem

Connecting an MCP client to a Fly-launched instance (device sign-in mode) never reaches the consent screen. Found in the 0.9.4 release-candidate test: a client (mcptest.io) started OAuth against https://<app>.fly.dev/api/mcp, the user completed the GitHub device sign-in, and landed on the dashboard instead of /mcp/consent (permissions and repositories). The client never gets a code, so MCP cannot be connected on any Fly instance unless the user was already signed in to the dashboard in that browser.

Cause

  1. /authorize redirects to /mcp/consent?request=<id>; unauthenticated, mountMcpBrowser (packages/api/mcp/browser.ts, loginUrl) sends the browser to /api/auth/github?redirect_to=<origin>/mcp/consent?request=<id>.
  2. createOAuthStartHandler (packages/api/auth.ts) validates redirect_to and then, in device mode, discards it: res.redirect(\${FRONTEND_URL}/login`)`.
  3. createDeviceFinishLogin also deletes authSession.redirectTo, and the login page sends the user to the dashboard after a device sign-in.

Fix

  • In device mode, carry the validated redirect_to through: store it in the session (or pass a validated same-origin path to /login), keep it until the device sign-in finishes, and return it in the finish response (e.g. { status: 'complete', redirectTo }) instead of deleting it.
  • The login page then does a full-page navigation to that URL (/mcp/consent is server-rendered, not a SPA route). Only same-origin paths validated by getValidatedRedirectTo are honoured.
  • Preserve the pending request's 10-minute TTL: if the device sign-in takes longer, the consent page should say "Request expired, return to your app and connect again" (already exists).
  • Same treatment for any other server-side redirect_to users (PR previews, /mcp/apps).

Tests: device mode /api/auth/github?redirect_to=/mcp/consent?request=x keeps the target; finish returns it; login page navigates to it; off-origin targets are dropped; web OAuth mode unchanged. Live check on Fly: mcptest.io (or claude mcp add + /mcp) signs in with a device code and lands on the consent screen, then completes.

Activity

  1. propr-dev commented on Nov 30, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using codex agent with gpt-6.2-sol model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: codex
    • Model: gpt-6.2-sol
    • Branch: 3936/gpt-6.2-sol-mcp-connect-on-fly-device-20261130-2317-8mc
    • Base Branch: 3758-epic-runtime-abstraction-sc0
    • Worktree: issue-3936-20261130-2317-gpt-6.2-sol-8mc

    🔍 Track Task Execution

  2. integry commented on Nov 30, 2026

    @integry
    OwnerAuthor

    Live check on propr-rc2: with the dashboard session already present, a repeat connect from mcptest.io went straight to the consent screen and completed. So only the device sign-in leg loses redirect_to.

  3. added a commit that references this issue on Nov 30, 2026
    d75af24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions