Skip to content

Commit dd14862

Browse files
fix: use InvalidTokenError instead of generic Error in MockTokenVerifier (#138)
The SDK's `requireBearerAuth` middleware only converts `InvalidTokenError` instances to HTTP 401 responses. Generic `Error` instances fall through as HTTP 500, which prevents clients from detecting authentication failures and initiating the OAuth refresh/re-auth flow. This was discovered while building token refresh conformance scenarios — the mock server was returning 500 for expired/invalid tokens instead of the expected 401. Co-authored-by: JD Maturen <70791+jdmaturen@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 83c446d commit dd14862

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/scenarios/client/auth/helpers/mockTokenVerifier.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { OAuthTokenVerifier } from '@modelcontextprotocol/sdk/server/auth/provider.js';
22
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
3+
import { InvalidTokenError } from '@modelcontextprotocol/sdk/server/auth/errors.js';
34
import type { ConformanceCheck } from '../../../../types';
45
import { SpecReferences } from '../spec-references';
56

@@ -53,6 +54,6 @@ export class MockTokenVerifier implements OAuthTokenVerifier {
5354
token: token ? token.substring(0, 10) + '...' : 'missing'
5455
}
5556
});
56-
throw new Error('Invalid token');
57+
throw new InvalidTokenError('Invalid token');
5758
}
5859
}

0 commit comments

Comments
 (0)