OAuth token exchange fails with URL-encoded responses - assumes JSON format only
Les mainteneurs répondent en général sous 1 jour
@tylergibbs1 y travaille déjà.
Depuis le 22/7/2026.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 74/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Calme
- Stack technique
- typescript
- Domaine
- api, authentication
Piste de recherche
Commencez dans client/auth.js, au niveau de exchangeAuthorization(), où l’issue identifie l’appel direct à response.json(). Reproduisez l’échange avec l’endpoint de tokens de GitHub si des identifiants sont disponibles, puis vérifiez la gestion des réponses JSON et des réponses encodées dans l’URL. Le travail est terminé lorsque OAuthTokensSchema.parse réussit pour l’un ou l’autre format sans perturber la gestion existante des erreurs HTTP.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
** Describe the bug **
The exchangeAuthorization() function in client/auth.js assumes OAuth token responses are always in JSON format and calls response.json() directly. However, many OAuth providers (including GitHub) return token responses in URL-encoded format (application/x-www-form-urlencoded), causing token exchange to fail with a JSON parsing error.
** Steps to reproduce the behavior: **
Set up OAuth authentication with GitHub's MCP server (https://api.githubcopilot.com/mcp)
Register a GitHub OAuth app and configure pre-registered credentials
Complete the authorization flow successfully (Step 1 works fine)
Attempt token exchange in Step 2 of the OAuth flow
Observe JSON parsing error when GitHub returns URL-encoded token response
** Expected behavior **
The SDK should handle both common OAuth token response formats:
JSON format: {"access_token": "...", "token_type": "bearer", "scope": "..."}
URL-encoded format: access_token=...&token_type=bearer&scope=...
The token exchange should succeed regardless of which format the OAuth provider uses.
Logs
🔍 Token URL: https://github.com/login/oauth/access_token
🔍 Response Text: access_token=gho_oB*****************************&scope=gist%2Cnotifications%2Cpublic_repo&token_type=bearer
❌ SyntaxError: Unexpected token 'a', "access_tok"... is not valid JSON
at JSON.parse (<anonymous>)
at exchangeAuthorization (file://client/auth.js:335:41)
** Additional context **
OAuth Standards: Both response formats are valid according to OAuth 2.0/2.1 specifications. Different providers use different formats.
GitHub Behavior: GitHub's OAuth token endpoint returns URL-encoded responses by default, but does provide valid JSON when the new Accept request header is added. Not all oAuth servers will respect the Accept header though.
Current SDK Code (line ~325 in client/auth.js):
const response = await fetch(tokenUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: params,
});
if (!response.ok) {
throw new Error(`Token exchange failed: HTTP ${response.status}`);
}
return OAuthTokensSchema.parse(await response.json()); // ❌ Assumes JSON
** Suggested Fix **
const response = await fetch(tokenUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json", // ✅ Request JSON response
},
body: params,
});
if (!response.ok) {
throw new Error(`Token exchange failed: HTTP ${response.status}`);
}
// ✅ Handle both JSON and URL-encoded responses
const responseText = await response.text();
let tokenData;
try {
tokenData = JSON.parse(responseText);
} catch (jsonError) {
// Fallback to URL-encoded parsing
const urlParams = new URLSearchParams(responseText);
tokenData = {
access_token: urlParams.get("access_token"),
token_type: urlParams.get("token_type"),
scope: urlParams.get("scope"),
refresh_token: urlParams.get("refresh_token"),
expires_in: urlParams.get("expires_in") ? parseInt(urlParams.get("expires_in")) : undefined,
};
}
return OAuthTokensSchema.parse(tokenData);
This issue can be reproduced using GitHub's MCP server at https://api.githubcopilot.com/mcp with proper GitHub OAuth app credentials. NOTE: There is a related issue with GitHubs oAuth where by it does not expose it's oAuth info on .well-known/oauth-authorization-server, but rather returns a resource_metadata="https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp" param in the www-authenticate field (see #758)
** Impact **
This affects compatibility with any OAuth provider that returns URL-encoded token responses, making the SDK incompatible with a significant portion of OAuth servers.
- Langage dominant
- TypeScript
- Étoiles
- 13.6k
- Forks
- 2.5k
- Merge moyen
- 1 j 2 h
- PR mergées (30 j)
- 53
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de modelcontextprotocol/typescript-sdk
-
[v2] e2e `protocol:timeout:max-total` is flaky over SSE: fake timers advance before the request reaches the serverPeut-être pris @Singmin l’a pris il y a 3 jours. Ouvertev1 v2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
modelcontextprotocol/typescript-sdk#3045 ·
Les mainteneurs répondent en général sous 1 jour
-
[v1.x] Backport #2654: `notifications/cancelled` with `requestId: 0` is ignored, so the first server→client request cannot be cancelled (still in 1.32.1)Peut-être pris @CloudCorpRecords l’a pris il y a 4 jours. Ouvertev1
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
modelcontextprotocol/typescript-sdk#3043 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Stateless 405 response omits the Allow headerPeut-être pris @Hugo-DDT l’a pris il y a 10 jours. Ouvertev2
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
modelcontextprotocol/typescript-sdk#2970 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
[v2] @modelcontextprotocol/server inlines fast-uri 3.1.0, which has 9 published advisoriesPeut-être pris @Andiii208 l’a pris il y a 12 jours. Ouvertev2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
modelcontextprotocol/typescript-sdk#2966 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
v1 v2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
modelcontextprotocol/typescript-sdk#2946 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de modelcontextprotocol/typescript-sdk
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 72/100
zts212653/clowder-ai#1678 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
Progressive-Victory/the-website#680 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100