Skip to content

Commit 28c5c7a

Browse files
fix(compat): export OAuth subclass type aliases (value+type binding like v1); fix changeset count
1 parent 473d2d8 commit 28c5c7a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.changeset/error-compat-aliases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
'@modelcontextprotocol/server': patch
44
---
55

6-
Add v1-compat `@deprecated` error aliases: `McpError`/`ErrorCode` (alias `ProtocolError`/`ProtocolErrorCode`, with `ConnectionClosed`/`RequestTimeout` from `SdkErrorCode`), `OAuthError.errorCode` getter (alias `.code`), `JSONRPCError`/`isJSONRPCError`, the 17 v1 OAuth error subclasses (`InvalidTokenError`, `ServerError`, …) as thin wrappers around `OAuthError` + `OAuthErrorCode`, and `StreamableHTTPError` as an `SdkError` subclass that the StreamableHTTP client transport now throws (so `instanceof StreamableHTTPError` matches; `.status` carries the HTTP status code).
6+
Add v1-compat `@deprecated` error aliases: `McpError`/`ErrorCode` (alias `ProtocolError`/`ProtocolErrorCode`, with `ConnectionClosed`/`RequestTimeout` from `SdkErrorCode`), `OAuthError.errorCode` getter (alias `.code`), `JSONRPCError`/`isJSONRPCError`, 16 of the 17 v1 OAuth error subclasses (`InvalidTokenError`, `ServerError`, …`InvalidRequestError` is omitted from the public surface to avoid colliding with the JSON-RPC `InvalidRequest` type) as thin wrappers around `OAuthError` + `OAuthErrorCode`, and `StreamableHTTPError` as an `SdkError` subclass that the StreamableHTTP client transport now throws (so `instanceof StreamableHTTPError` matches; `.status` carries the HTTP status code).

packages/core/src/errors/oauthErrorsCompat.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,59 @@ function sub(code: OAuthErrorCode, name: string): OAuthErrorSubclass {
2727
return Sub;
2828
}
2929

30-
/* eslint-disable @typescript-eslint/naming-convention */
30+
/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-redeclare */
3131

3232
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidRequest`. */
3333
export const InvalidRequestError = sub(OAuthErrorCode.InvalidRequest, 'InvalidRequestError');
34+
export type InvalidRequestError = InstanceType<typeof InvalidRequestError>;
3435
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidClient`. */
3536
export const InvalidClientError = sub(OAuthErrorCode.InvalidClient, 'InvalidClientError');
37+
export type InvalidClientError = InstanceType<typeof InvalidClientError>;
3638
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidGrant`. */
3739
export const InvalidGrantError = sub(OAuthErrorCode.InvalidGrant, 'InvalidGrantError');
40+
export type InvalidGrantError = InstanceType<typeof InvalidGrantError>;
3841
/** @deprecated Use `OAuthError` with `OAuthErrorCode.UnauthorizedClient`. */
3942
export const UnauthorizedClientError = sub(OAuthErrorCode.UnauthorizedClient, 'UnauthorizedClientError');
43+
export type UnauthorizedClientError = InstanceType<typeof UnauthorizedClientError>;
4044
/** @deprecated Use `OAuthError` with `OAuthErrorCode.UnsupportedGrantType`. */
4145
export const UnsupportedGrantTypeError = sub(OAuthErrorCode.UnsupportedGrantType, 'UnsupportedGrantTypeError');
46+
export type UnsupportedGrantTypeError = InstanceType<typeof UnsupportedGrantTypeError>;
4247
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidScope`. */
4348
export const InvalidScopeError = sub(OAuthErrorCode.InvalidScope, 'InvalidScopeError');
49+
export type InvalidScopeError = InstanceType<typeof InvalidScopeError>;
4450
/** @deprecated Use `OAuthError` with `OAuthErrorCode.AccessDenied`. */
4551
export const AccessDeniedError = sub(OAuthErrorCode.AccessDenied, 'AccessDeniedError');
52+
export type AccessDeniedError = InstanceType<typeof AccessDeniedError>;
4653
/** @deprecated Use `OAuthError` with `OAuthErrorCode.ServerError`. */
4754
export const ServerError = sub(OAuthErrorCode.ServerError, 'ServerError');
55+
export type ServerError = InstanceType<typeof ServerError>;
4856
/** @deprecated Use `OAuthError` with `OAuthErrorCode.TemporarilyUnavailable`. */
4957
export const TemporarilyUnavailableError = sub(OAuthErrorCode.TemporarilyUnavailable, 'TemporarilyUnavailableError');
58+
export type TemporarilyUnavailableError = InstanceType<typeof TemporarilyUnavailableError>;
5059
/** @deprecated Use `OAuthError` with `OAuthErrorCode.UnsupportedResponseType`. */
5160
export const UnsupportedResponseTypeError = sub(OAuthErrorCode.UnsupportedResponseType, 'UnsupportedResponseTypeError');
61+
export type UnsupportedResponseTypeError = InstanceType<typeof UnsupportedResponseTypeError>;
5262
/** @deprecated Use `OAuthError` with `OAuthErrorCode.UnsupportedTokenType`. */
5363
export const UnsupportedTokenTypeError = sub(OAuthErrorCode.UnsupportedTokenType, 'UnsupportedTokenTypeError');
64+
export type UnsupportedTokenTypeError = InstanceType<typeof UnsupportedTokenTypeError>;
5465
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidToken`. */
5566
export const InvalidTokenError = sub(OAuthErrorCode.InvalidToken, 'InvalidTokenError');
67+
export type InvalidTokenError = InstanceType<typeof InvalidTokenError>;
5668
/** @deprecated Use `OAuthError` with `OAuthErrorCode.MethodNotAllowed`. */
5769
export const MethodNotAllowedError = sub(OAuthErrorCode.MethodNotAllowed, 'MethodNotAllowedError');
70+
export type MethodNotAllowedError = InstanceType<typeof MethodNotAllowedError>;
5871
/** @deprecated Use `OAuthError` with `OAuthErrorCode.TooManyRequests`. */
5972
export const TooManyRequestsError = sub(OAuthErrorCode.TooManyRequests, 'TooManyRequestsError');
73+
export type TooManyRequestsError = InstanceType<typeof TooManyRequestsError>;
6074
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidClientMetadata`. */
6175
export const InvalidClientMetadataError = sub(OAuthErrorCode.InvalidClientMetadata, 'InvalidClientMetadataError');
76+
export type InvalidClientMetadataError = InstanceType<typeof InvalidClientMetadataError>;
6277
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InsufficientScope`. */
6378
export const InsufficientScopeError = sub(OAuthErrorCode.InsufficientScope, 'InsufficientScopeError');
79+
export type InsufficientScopeError = InstanceType<typeof InsufficientScopeError>;
6480
/** @deprecated Use `OAuthError` with `OAuthErrorCode.InvalidTarget`. */
6581
export const InvalidTargetError = sub(OAuthErrorCode.InvalidTarget, 'InvalidTargetError');
82+
export type InvalidTargetError = InstanceType<typeof InvalidTargetError>;
6683

6784
/**
6885
* @deprecated Construct {@link OAuthError} directly with a custom code string.

packages/core/test/errors/compat.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ describe('v1-compat error aliases', () => {
5050
expect(e.constructor.name).toBe('InvalidTokenError');
5151
});
5252

53+
it('OAuth subclasses are usable in type position (value + type binding like v1 classes)', () => {
54+
const e: InvalidTokenError = new InvalidTokenError('expired');
55+
const handle = (err: ServerError): string => err.code;
56+
expect(handle(new ServerError('boom'))).toBe('server_error');
57+
expect(e.code).toBe('invalid_token');
58+
});
59+
5360
it('subclass static errorCode and toResponseObject() match v1 wire format', () => {
5461
expect(ServerError.errorCode).toBe('server_error');
5562
const e = new ServerError('boom');

0 commit comments

Comments
 (0)