Skip to content

Commit 1213c01

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 1213c01

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Regression test for https://github.com/modelcontextprotocol/typescript-sdk/issues/1342
3+
*
4+
* Some OAuth servers (e.g., GitHub) return error responses with HTTP 200 status
5+
* instead of 4xx. Previously, the SDK would try to parse these as tokens and fail
6+
* with a confusing Zod validation error. This test verifies that the SDK properly
7+
* detects the error field and surfaces the actual OAuth error message.
8+
*/
9+
10+
import { exchangeAuthorization } from '@modelcontextprotocol/client';
11+
import { describe, expect, it, vi } from 'vitest';
12+
13+
const mockFetch = vi.fn();
14+
vi.stubGlobal('fetch', mockFetch);
15+
16+
describe('Issue #1342: OAuth error response with HTTP 200 status', () => {
17+
const validClientInfo = {
18+
client_id: 'test-client',
19+
client_secret: 'test-secret',
20+
redirect_uris: ['http://localhost:3000/callback'],
21+
token_endpoint_auth_method: 'client_secret_post' as const
22+
};
23+
24+
it('should throw OAuth error when server returns error with HTTP 200', async () => {
25+
// GitHub returns errors with HTTP 200 instead of 4xx
26+
mockFetch.mockResolvedValueOnce({
27+
ok: true,
28+
status: 200,
29+
json: async () => ({
30+
error: 'invalid_client',
31+
error_description: 'The client_id and/or client_secret passed are incorrect.'
32+
})
33+
});
34+
35+
await expect(
36+
exchangeAuthorization('https://auth.example.com', {
37+
clientInformation: validClientInfo,
38+
authorizationCode: 'code123',
39+
codeVerifier: 'verifier123',
40+
redirectUri: 'http://localhost:3000/callback'
41+
})
42+
).rejects.toThrow('The client_id and/or client_secret passed are incorrect.');
43+
});
44+
});

0 commit comments

Comments
 (0)