Skip to content

Commit 3e1d3b2

Browse files
authored
Merge branch 'main' into fix/router-prm-baseurl
2 parents 5935e5f + 1f5950b commit 3e1d3b2

File tree

10 files changed

+1791
-59
lines changed

10 files changed

+1791
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ const upgradeAuthTool = server.tool(
898898
// If we've just upgraded to 'write' permissions, we can still call 'upgradeAuth'
899899
// but can only upgrade to 'admin'.
900900
upgradeAuthTool.update({
901-
paramSchema: { permission: z.enum(["admin"]) }, // change validation rules
901+
paramsSchema: { permission: z.enum(["admin"]) }, // change validation rules
902902
})
903903
} else {
904904
// If we're now an admin, we no longer have anywhere to upgrade to, so fully remove that tool

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.17.2",
3+
"version": "1.17.3",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",

src/client/auth.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ describe("OAuth Authorization", () => {
212212
expect(url.toString()).toBe("https://resource.example.com/.well-known/oauth-protected-resource/path?param=value");
213213
});
214214

215-
it("falls back to root discovery when path-aware discovery returns 404", async () => {
216-
// First call (path-aware) returns 404
215+
it.each([400, 401, 403, 404, 410, 422, 429])("falls back to root discovery when path-aware discovery returns %d", async (statusCode) => {
216+
// First call (path-aware) returns 4xx
217217
mockFetch.mockResolvedValueOnce({
218218
ok: false,
219-
status: 404,
219+
status: statusCode,
220220
});
221221

222222
// Second call (root fallback) succeeds
@@ -267,6 +267,20 @@ describe("OAuth Authorization", () => {
267267
expect(calls.length).toBe(2);
268268
});
269269

270+
it("throws error on 500 status and does not fallback", async () => {
271+
// First call (path-aware) returns 500
272+
mockFetch.mockResolvedValueOnce({
273+
ok: false,
274+
status: 500,
275+
});
276+
277+
await expect(discoverOAuthProtectedResourceMetadata("https://resource.example.com/path/name"))
278+
.rejects.toThrow();
279+
280+
const calls = mockFetch.mock.calls;
281+
expect(calls.length).toBe(1); // Should not attempt fallback
282+
});
283+
270284
it("does not fallback when the original URL is already at root path", async () => {
271285
// First call (path-aware for root) returns 404
272286
mockFetch.mockResolvedValueOnce({
@@ -907,7 +921,7 @@ describe("OAuth Authorization", () => {
907921
const metadata = await discoverAuthorizationServerMetadata("https://auth.example.com/tenant1");
908922

909923
expect(metadata).toBeUndefined();
910-
924+
911925
// Verify that all discovery URLs were attempted
912926
expect(mockFetch).toHaveBeenCalledTimes(8); // 4 URLs × 2 attempts each (with and without headers)
913927
});

src/client/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ async function authInternal(
359359
const fullInformation = await registerClient(authorizationServerUrl, {
360360
metadata,
361361
clientMetadata: provider.clientMetadata,
362+
fetchFn,
362363
});
363364

364365
await provider.saveClientInformation(fullInformation);
@@ -395,6 +396,7 @@ async function authInternal(
395396
refreshToken: tokens.refresh_token,
396397
resource,
397398
addClientAuthentication: provider.addClientAuthentication,
399+
fetchFn,
398400
});
399401

400402
await provider.saveTokens(newTokens);
@@ -569,7 +571,7 @@ async function tryMetadataDiscovery(
569571
* Determines if fallback to root discovery should be attempted
570572
*/
571573
function shouldAttemptFallback(response: Response | undefined, pathname: string): boolean {
572-
return !response || response.status === 404 && pathname !== '/';
574+
return !response || (response.status >= 400 && response.status < 500) && pathname !== '/';
573575
}
574576

575577
/**

0 commit comments

Comments
 (0)