Skip to content

Commit d793545

Browse files
committed
fix(mcp): shrink OAuth-start step budgets to fit the 30s client deadline with 4 DB steps
Bounding setOauthRowUser added a fourth possible DB step, so 4x5+12=32s exceeded the client's 30s /oauth/start abort. Lower DB steps to 4s and auth to 10s: 4x4+10=26s worst case, leaving margin for middleware/network. Comment corrected.
1 parent 43dcd07 commit d793545

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • apps/sim/app/api/mcp/oauth/start

apps/sim/app/api/mcp/oauth/start/route.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ const timedStep = makeTimedStep(logger)
2929
const OAUTH_START_TTL_MS = 10 * 60 * 1000
3030
/**
3131
* Per-step budgets, kept small so the whole request stays under the client's 30s `/oauth/start`
32-
* deadline even in the worst case (5+5+5 DB + 12 auth = 27s). OAuth discovery + DCR occasionally
33-
* hits the transient headers-then-stalled-body class documented for CDN-fronted MCP hosts; the
34-
* bound turns that into a fast, labeled failure so the popup closes with a clear error and the
35-
* user can retry (a fresh click = a fresh connection that dodges the per-connection stall) rather
36-
* than the popup hanging blank. We deliberately do NOT auto-retry here: `timedStep` can't cancel
37-
* a wedged attempt, and a lingering first attempt sharing this server's OAuth row could overwrite
38-
* the retry's PKCE verifier / state and break the callback.
32+
* deadline even in the worst case: up to four bounded DB steps (loadServer, getOrCreateOauthRow,
33+
* setOauthRowUser, loadPreregisteredClient) + the auth step = 4×4 + 10 = 26s, leaving margin for
34+
* middleware and network. OAuth discovery + DCR occasionally hits the transient
35+
* headers-then-stalled-body class documented for CDN-fronted MCP hosts; the bound turns that into
36+
* a fast, labeled failure so the popup closes with a clear error and the user can retry (a fresh
37+
* click = a fresh connection that dodges the per-connection stall) rather than the popup hanging
38+
* blank. We deliberately do NOT auto-retry here: `timedStep` can't cancel a wedged attempt, and a
39+
* lingering first attempt sharing this server's OAuth row could overwrite the retry's PKCE
40+
* verifier / state and break the callback.
3941
*/
40-
const DB_STEP_MS = 5_000
41-
const MCP_AUTH_STEP_MS = 12_000
42+
const DB_STEP_MS = 4_000
43+
const MCP_AUTH_STEP_MS = 10_000
4244
const MAX_SURFACED_ERROR_LENGTH = 250
4345
const DCR_UNSUPPORTED_MESSAGE =
4446
"This server doesn't support automatic OAuth client registration. Add a pre-registered OAuth client ID and secret, or configure a token instead."

0 commit comments

Comments
 (0)