|
1 | 1 | // v1 compat: `@modelcontextprotocol/sdk/server/auth/errors.js` |
2 | | -// v2 consolidated 17 OAuth error subclasses into OAuthError + OAuthErrorCode. |
3 | | -// These deprecated subclasses preserve `instanceof` and `throw new InvalidTokenError(msg)` patterns. |
4 | | - |
5 | | -import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server'; |
6 | | - |
7 | | -/** @deprecated Construct-signature type for the v1 OAuth error subclasses below. */ |
8 | | -export type OAuthErrorSubclass = new (message: string, errorUri?: string) => OAuthError; |
9 | | - |
10 | | -function sub(code: OAuthErrorCode): OAuthErrorSubclass { |
11 | | - return class extends OAuthError { |
12 | | - constructor(message: string, errorUri?: string) { |
13 | | - super(code, message, errorUri); |
14 | | - } |
15 | | - }; |
16 | | -} |
17 | | - |
18 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidRequest, ...)` */ |
19 | | -export const InvalidRequestError = sub(OAuthErrorCode.InvalidRequest); |
20 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidClient, ...)` */ |
21 | | -export const InvalidClientError = sub(OAuthErrorCode.InvalidClient); |
22 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidGrant, ...)` */ |
23 | | -export const InvalidGrantError = sub(OAuthErrorCode.InvalidGrant); |
24 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.UnauthorizedClient, ...)` */ |
25 | | -export const UnauthorizedClientError = sub(OAuthErrorCode.UnauthorizedClient); |
26 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.UnsupportedGrantType, ...)` */ |
27 | | -export const UnsupportedGrantTypeError = sub(OAuthErrorCode.UnsupportedGrantType); |
28 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidScope, ...)` */ |
29 | | -export const InvalidScopeError = sub(OAuthErrorCode.InvalidScope); |
30 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.AccessDenied, ...)` */ |
31 | | -export const AccessDeniedError = sub(OAuthErrorCode.AccessDenied); |
32 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.ServerError, ...)` */ |
33 | | -export const ServerError = sub(OAuthErrorCode.ServerError); |
34 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.TemporarilyUnavailable, ...)` */ |
35 | | -export const TemporarilyUnavailableError = sub(OAuthErrorCode.TemporarilyUnavailable); |
36 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.UnsupportedResponseType, ...)` */ |
37 | | -export const UnsupportedResponseTypeError = sub(OAuthErrorCode.UnsupportedResponseType); |
38 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.UnsupportedTokenType, ...)` */ |
39 | | -export const UnsupportedTokenTypeError = sub(OAuthErrorCode.UnsupportedTokenType); |
40 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidToken, ...)` */ |
41 | | -export const InvalidTokenError = sub(OAuthErrorCode.InvalidToken); |
42 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.MethodNotAllowed, ...)` */ |
43 | | -export const MethodNotAllowedError = sub(OAuthErrorCode.MethodNotAllowed); |
44 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.TooManyRequests, ...)` */ |
45 | | -export const TooManyRequestsError = sub(OAuthErrorCode.TooManyRequests); |
46 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InvalidClientMetadata, ...)` */ |
47 | | -export const InvalidClientMetadataError = sub(OAuthErrorCode.InvalidClientMetadata); |
48 | | -/** @deprecated Use `new OAuthError(OAuthErrorCode.InsufficientScope, ...)` */ |
49 | | -export const InsufficientScopeError = sub(OAuthErrorCode.InsufficientScope); |
50 | | - |
51 | | -/** @deprecated Construct {@link OAuthError} directly. */ |
52 | | -export class CustomOAuthError extends OAuthError {} |
53 | | - |
54 | | -export { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server'; |
| 2 | +// Re-exports the frozen v1 OAuth error classes from the legacy package so that |
| 3 | +// errors thrown from this subpath share the same `OAuthError` identity that |
| 4 | +// `mcpAuthRouter`/`requireBearerAuth` (re-exported by sibling subpaths) check |
| 5 | +// with `instanceof`. |
| 6 | +export * from '@modelcontextprotocol/server-auth-legacy'; |
0 commit comments