Skip to content

Commit 7b5acf0

Browse files
fix(merge): restore main-side drops — auth.test invalid_token case + JSONRPCResultResponse* migration rows
1 parent 7de6b6d commit 7b5acf0

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

docs/migration/upgrade-to-v2.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,14 +783,18 @@ include task vocabulary; the deprecated `Task*` types remain importable on their
783783
| `JSONRPCErrorSchema` | `JSONRPCErrorResponseSchema` |
784784
| `isJSONRPCError` | `isJSONRPCErrorResponse` |
785785
| `isJSONRPCResponse` (deprecated in v1) | `isJSONRPCResultResponse` ² |
786+
| `JSONRPCResponseSchema` (result-only in v1) | `JSONRPCResultResponseSchema` ² |
787+
| `JSONRPCResponse` (result-only in v1) | `JSONRPCResultResponse` ² |
786788
| `ResourceReference` / `ResourceReferenceSchema` | `ResourceTemplateReference` / `ResourceTemplateReferenceSchema` |
787789
| `IsomorphicHeaders` | Web Standard `Headers` |
788790
| `RequestHandlerExtra` | `ServerContext` / `ClientContext` / `BaseContext` |
789791
| `ResourceTemplate` (the spec wire **type** from `sdk/types.js`) | `ResourceTemplateType` ³ |
790792

791-
² v2 introduces a **new** `isJSONRPCResponse` with corrected semantics — it matches
792-
**both** result and error responses. v1's `isJSONRPCResponse` only matched results. To
793-
preserve v1 behavior, rename to `isJSONRPCResultResponse` (the codemod does this).
793+
² v2 introduces **new** `isJSONRPCResponse` / `JSONRPCResponse` / `JSONRPCResponseSchema`
794+
with corrected semantics — they match **both** result and error responses (the schema is
795+
`z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema])`). v1's symbols only
796+
matched results. To preserve v1 behavior, rename to `isJSONRPCResultResponse` /
797+
`JSONRPCResultResponse` / `JSONRPCResultResponseSchema` (the codemod does this).
794798

795799
³ The `ResourceTemplate` URI-template helper **class** (from `sdk/server/mcp.js`) is
796800
**unchanged** — keep `new ResourceTemplate(...)` as-is. Only the like-named spec wire

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ describe('OAuth Authorization', () => {
155155
expect(extractWWWAuthenticateParams(mockResponse)).toEqual({ error: 'insufficient_scope', scope: 'admin' });
156156
});
157157

158+
it('parses invalid_token challenges with protected resource metadata', async () => {
159+
const resourceUrl = 'https://resource.example.com/.well-known/oauth-protected-resource/mcp';
160+
const mockResponse = {
161+
headers: {
162+
get: vi.fn(name =>
163+
name === 'WWW-Authenticate'
164+
? `Bearer resource_metadata="${resourceUrl}", error="invalid_token", error_description="The access token expired"`
165+
: null
166+
)
167+
}
168+
} as unknown as Response;
169+
170+
expect(extractWWWAuthenticateParams(mockResponse)).toEqual({
171+
resourceMetadataUrl: new URL(resourceUrl),
172+
error: 'invalid_token',
173+
errorDescription: 'The access token expired'
174+
});
175+
});
176+
158177
it('returns error_description when present', async () => {
159178
const mockResponse = {
160179
headers: {

0 commit comments

Comments
 (0)