Client auth(): concurrent 401s refresh with the same refresh token, and invalid_grant is rethrown instead of re-authorizing
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 50/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- node.js, typescript
- Bereich
- api, authentication
Rechercherichtung
Start by tracing auth() and OAuthClientProvider token handling in @modelcontextprotocol/client, then reproduce the race with concurrent callTool requests or parallel refresh_token grants. Done means concurrent refreshes share one result, while invalid_grant re-reads provider.tokens(), retries changed tokens, or starts fresh authorization when they have not changed.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
When an access token expires while several requests are in flight, each request gets a 401 and calls auth() on its own. Each call reads the same stored refresh token and sends its own refresh_token grant. Nothing makes the refresh single-flight.
An authorization server that rotates refresh tokens (OAuth 2.1, RFC 9700 section 4.14.2) accepts the first of these requests. It treats the second as reuse of a consumed token, rejects it with invalid_grant, and usually revokes the whole grant, including the tokens the first request just received. The client then rethrows OAuthError: invalid_grant to the caller instead of falling back to a full authorization, so the session is left unusable until the user reconnects.
To reproduce
- Connect a client with an
OAuthClientProviderto a server whose authorization server rotates refresh tokens. - Let the access token expire.
- Issue two or more requests at once (for example
Promise.allofcallTool). - One refresh succeeds and the other gets
invalid_grant. Because of reuse detection, later requests also fail withinvalid_grant.
In our tests this happened in about 2 of 12 runs with real request concurrency. With two refresh_token grants fired directly at once it happened 10 of 10 times.
Expected behavior
- Concurrent refreshes for the same provider share one in-flight refresh, and every caller reuses its result.
- If a refresh still fails with
invalid_grant, the client re-readsprovider.tokens(). If the tokens changed, it retries with them. Otherwise it invalidates the stored tokens and starts a fresh authorization rather than throwing.
Environment
@modelcontextprotocol/client 2.2.0, Node 22, Streamable HTTP transport.
Workaround
Wrap the provider so that refresh is single-flight, or refresh once before fanning out parallel requests.
AI disclosure: I used an AI coding assistant to draft this; I have reviewed it and can answer for it.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 13.8k
- Forks
- 2.5k
- Ø Merge
- 6 T. 23 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/typescript-sdk
-
v2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`Evtl. vergeben @mgoldsborough hat das vor 6 Tagen übernommen. Offenv2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/typescript-sdk#3249 ·
Maintainer antworten meist innerhalb von 1 Tag
-
v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` replyEvtl. vergeben @Tidehyc hat das vor 7 Tagen übernommen. Offenv2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
UriTemplate.match() throws a TypeError on an empty expression it acceptsEvtl. vergeben @yunusemrejs hat das vor 12 Tagen übernommen. Offenv1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/typescript-sdk
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Vessel9817/onion-site-template#512 ·
Maintainer antworten meist innerhalb von 1 Tag
-
nightly-tests
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
Maintainer antworten meist innerhalb von 1 Tag
-
approved
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
fritzprix/libr-agent#3266 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
better-auth/better-auth#13101 · 1 Kommentar · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag