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;