Skip to content

Commit 7734124

Browse files
pcarletonclaude
andcommitted
refactor: restore original fallback behavior in discovery
Moves fallback logic back to individual functions instead of generating "fake" metadata during discovery. Discovery now returns undefined on 404 like the original code, maintaining the existing architectural pattern where functions handle their own URL fallbacks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ecb76f1 commit 7734124

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

src/client/auth.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ describe("OAuth Authorization", () => {
908908
expect(url.toString()).toBe("https://mcp.example.com/.well-known/oauth-authorization-server");
909909
});
910910

911-
it("returns fallback metadata when legacy MCP server returns 404", async () => {
911+
it("returns undefined when legacy MCP server returns 404", async () => {
912912
mockFetch.mockResolvedValueOnce({
913913
ok: false,
914914
status: 404,
@@ -919,14 +919,7 @@ describe("OAuth Authorization", () => {
919919
undefined
920920
);
921921

922-
expect(metadata).toEqual({
923-
issuer: "https://mcp.example.com",
924-
authorization_endpoint: "https://mcp.example.com/authorize",
925-
token_endpoint: "https://mcp.example.com/token",
926-
registration_endpoint: "https://mcp.example.com/register",
927-
response_types_supported: ["code"],
928-
code_challenge_methods_supported: ["S256"],
929-
});
922+
expect(metadata).toBeUndefined();
930923
});
931924

932925
it("throws on non-404 errors in legacy mode", async () => {

src/client/auth.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ export async function discoverAuthorizationServerMetadata(
721721
* @param options - Configuration options
722722
* @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch
723723
* @param options.protocolVersion - MCP protocol version to use (required)
724-
* @returns Promise resolving to OAuth metadata
724+
* @returns Promise resolving to OAuth metadata, or undefined if discovery fails
725725
*/
726726
async function retrieveOAuthMetadataFromMcpServer(
727727
serverUrl: string | URL,
@@ -732,7 +732,7 @@ async function retrieveOAuthMetadataFromMcpServer(
732732
fetchFn?: FetchLike;
733733
protocolVersion: string;
734734
}
735-
): Promise<OAuthMetadata> {
735+
): Promise<OAuthMetadata | undefined> {
736736
const serverOrigin = typeof serverUrl === 'string' ? new URL(serverUrl).origin : serverUrl.origin;
737737

738738
const metadataEndpoint = new URL(buildWellKnownPath('oauth-authorization-server'), serverOrigin);
@@ -745,19 +745,7 @@ async function retrieveOAuthMetadataFromMcpServer(
745745

746746
if (!response.ok) {
747747
if (response.status === 404) {
748-
/**
749-
* The MCP server does not implement OAuth 2.0 Authorization Server Metadata
750-
*
751-
* Return fallback OAuth 2.0 Authorization Server Metadata
752-
*/
753-
return {
754-
issuer: serverOrigin,
755-
authorization_endpoint: new URL('/authorize', serverOrigin).href,
756-
token_endpoint: new URL('/token', serverOrigin).href,
757-
registration_endpoint: new URL('/register', serverOrigin).href,
758-
response_types_supported: ['code'],
759-
code_challenge_methods_supported: ['S256'],
760-
};
748+
return undefined;
761749
}
762750

763751
throw new Error(`HTTP ${response.status} trying to load OAuth metadata from ${metadataEndpoint}`);

0 commit comments

Comments
 (0)