Skip to content
Source
Sign inSign up
pingdotgg/t3code

Keep MCP credentials alive across provider turns #4659

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/4659/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Refresh MCP credential liveness whenever a provider turn starts.
  • Replace fixed credential expiration with a session liveness window and thread-scoped touch updates.
  • Log rejected MCP requests with missing or invalid credentials.
  • Decouple preview host assignments from MCP credential expiration.
  • Adjust branch toolbar layout sizing behavior.

Testing

  • Added focused MCP session registry coverage for long-lived sessions and unrelated thread activity.
  • Not run.

Note

Medium Risk Changes MCP bearer validity and pruning on /mcp, which sits outside the main environment auth stack; behavior is safer for long sessions but alters when abandoned tokens expire (24h liveness window).

Overview Fixes agents silently losing the preview MCP toolkit when a session runs for a long time without calling browser tools, because the one-shot token minted at session start could no longer be renewed in-process.

MCP credential lifetime drops fixed expiresAt, idle timeout, and max lifetime in favor of a liveness window (default 24h after the last sign of life). Liveness refreshes on MCP requests (resolve) and on touch per thread, which ProviderService.sendTurn invokes so ordinary turns keep the same bearer token valid without re-issuing.

Observability: rejected /mcp calls with missing or bad tokens emit a warning (missing_bearer_token vs unknown_or_expired_token) instead of failing quietly on the client.

Preview automation: host assignment leases no longer inherit MCP credential expiry—stickiness follows live connection identity only, avoiding mid-flow host migration when auth deadlines passed.

Tests cover long sessions refreshed only via touch, unrelated threads not extending each other’s credentials, and expiry when liveness stops.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 754299aa63a799e31598ddf37aac1a623f679269. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Keep MCP credentials alive across provider turns using a liveness window

  • Replaces the idleTimeoutMs/maximumLifetimeMs model in McpSessionRegistry with a single livenessWindowMs (default 24 hours): credentials are pruned only when lastAliveAt is older than the window.
  • Adds a touch(threadId) method to McpSessionRegistry and a touchActiveMcpThread helper so credentials can be refreshed without MCP traffic.
  • ProviderService calls touchActiveMcpThread before each provider turn, preventing credential pruning during long sessions.
  • Removes expiresAt from McpInvocationScope, McpIssuedCredential, and HostAssignment; host assignments now stay valid for the lifetime of the connection instead of expiring on a clock.
  • Behavioral Change: credentials no longer have a maximum lifetime — they live as long as there is activity within the liveness window.
Macroscope summarized 754299a.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 66249481-b751-41ab-956c-2bb709d2bdee

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/fix-mcp-auth-expiration`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Approvability

      Verdict: Needs human review

      Changes MCP credential lifetime model from 8-hour max to 24-hour liveness window, with the code itself noting this token is 'the only thing guarding the preview toolkit on a remote-reachable server.' Security-sensitive auth changes warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged this0e19c10

    5. juliusmarminge closed this

Sign in to join this conversation.