From 1b8e94ca4091c2db442961c033ca512469aa9f6b Mon Sep 17 00:00:00 2001 From: Jerome Date: Sat, 22 Feb 2025 16:20:41 +0000 Subject: [PATCH] During metadata fetching, try with the MCP header, then without, then return undefined if both fail --- src/client/auth.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client/auth.ts b/src/client/auth.ts index c0bac9e8..5f5c860e 100644 --- a/src/client/auth.ts +++ b/src/client/auth.ts @@ -163,11 +163,20 @@ export async function discoverOAuthMetadata( opts?: { protocolVersion?: string }, ): Promise { const url = new URL("/.well-known/oauth-authorization-server", serverUrl); - const response = await fetch(url, { - headers: { - "MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION + let response: Response; + try { + response = await fetch(url, { + headers: { + "MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION + } + }); + } catch { + try { + response = await fetch(url); + } catch { + return undefined; } - }); + } if (response.status === 404) { return undefined;