Commit 74f2fb7
fix(mcp): fall back to live Clerk lookup when cached org_plan is stale
The MCP path was reading org_plan from a Setting populated only by the
subscription.created/updated/active webhook. When that webhook never
fires (org upgraded before the handler shipped, delivery failed, or the
Clerk plan slug doesn't match the literal "pro" key in RATE_LIMITS),
paid orgs get blocked with "MCP requires a Pro or Business plan" even
though their JWT-based dashboard correctly shows them as Pro.
Fix: add resolve_org_plan() in app/core/plans.py that:
- Returns the cached Setting immediately when it's a known paid plan
(fast path, zero API calls)
- Falls back to clerk.organizations.get_billing_subscription() to read
the live subscription state, then writes the corrected slug back to
the Setting so future calls hit the fast path
- Throttles live re-checks to once per 60s per org so a non-paid
caller hammering MCP can't drive Clerk API spend
- Survives Clerk API failures by returning the cached value (or
free_org)
Use the resolver in two places:
- mcp/server.py _resolve_org() — the auth gate that was rejecting
legitimate Pro orgs
- get_plan_limits_for_org() in plans.py — same drift can affect node
registration and any other API-key-authed endpoint reading plan
limits
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 69b8d3b commit 74f2fb7
2 files changed
Lines changed: 87 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
29 | 43 | | |
30 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
31 | 108 | | |
32 | 109 | | |
33 | 110 | | |
34 | 111 | | |
35 | | - | |
36 | | - | |
| 112 | + | |
| 113 | + | |
37 | 114 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 115 | + | |
41 | 116 | | |
42 | 117 | | |
43 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
649 | 652 | | |
650 | 653 | | |
651 | 654 | | |
652 | | - | |
| 655 | + | |
| 656 | + | |
653 | 657 | | |
654 | 658 | | |
655 | 659 | | |
| |||
0 commit comments