Client auth(): concurrent 401s refresh with the same refresh token, and invalid_grant is rethrown instead of re-authorizing
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 50/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
- Área
- api, authentication
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 13.8k
- Forks
- 2.5k
- Merge medio
- 6 d 23 h
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/typescript-sdk
-
v2
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`Posiblemente ocupada @mgoldsborough la tomó hace 6 días. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/typescript-sdk#3249 ·
Los mantenedores suelen responder en 1 día
-
v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` replyPosiblemente ocupada @Tidehyc la tomó hace 7 días. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
UriTemplate.match() throws a TypeError on an empty expression it acceptsPosiblemente ocupada @yunusemrejs la tomó hace 12 días. Abiertov1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/typescript-sdk
Issues similares
-
clawsweeper:intake:bug clawsweeper:intake:needs-environment
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
openclaw/openclaw#212827 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
KT-2245 e2e specs that call the backend directly fall back to the developer's own Kronn on :3140Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Use one constant for the 10,000-character input limitPosiblemente ocupada @NginxL la tomó hoy. Abiertogood first issue refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
aniru-dh21/snap-validate#51 ·
Los mantenedores suelen responder en 1 día
-
dependencies effort: small good first issue priority: low
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
TMHSDigital/screencast-mcp#509 ·
Los mantenedores suelen responder en 1 día
-
from-review tech-debt testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
blamechris/chroxy#9520 ·
Los mantenedores suelen responder en 1 día