Skip to content

Commit 59df40b

Browse files
test: add regression test for OAuth error with HTTP 200 status
Adds test case for issue modelcontextprotocol#1342 where OAuth servers like GitHub return error responses with HTTP 200 instead of 4xx. Ensures the fix properly surfaces the OAuth error message instead of a confusing Zod validation error.
1 parent af56916 commit 59df40b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/client/test/client/auth.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,28 @@ describe('OAuth Authorization', () => {
12771277
).rejects.toThrow('Token exchange failed');
12781278
});
12791279

1280+
it('handles OAuth error response with HTTP 200 status (GitHub-style)', async () => {
1281+
// Some OAuth servers (e.g., GitHub) return errors with HTTP 200
1282+
// See: https://github.com/modelcontextprotocol/typescript-sdk/issues/1342
1283+
mockFetch.mockResolvedValueOnce({
1284+
ok: true,
1285+
status: 200,
1286+
json: async () => ({
1287+
error: 'invalid_client',
1288+
error_description: 'The client_id and/or client_secret passed are incorrect.'
1289+
})
1290+
});
1291+
1292+
await expect(
1293+
exchangeAuthorization('https://auth.example.com', {
1294+
clientInformation: validClientInfo,
1295+
authorizationCode: 'code123',
1296+
codeVerifier: 'verifier123',
1297+
redirectUri: 'http://localhost:3000/callback'
1298+
})
1299+
).rejects.toThrow('The client_id and/or client_secret passed are incorrect.');
1300+
});
1301+
12801302
it('supports overriding the fetch function used for requests', async () => {
12811303
const customFetch = vi.fn().mockResolvedValue({
12821304
ok: true,

0 commit comments

Comments
 (0)