Skip to content

Commit 1b8e94c

Browse files
During metadata fetching, try with the MCP header, then without, then return undefined if both fail
1 parent 80e1484 commit 1b8e94c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/client/auth.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,20 @@ export async function discoverOAuthMetadata(
163163
opts?: { protocolVersion?: string },
164164
): Promise<OAuthMetadata | undefined> {
165165
const url = new URL("/.well-known/oauth-authorization-server", serverUrl);
166-
const response = await fetch(url, {
167-
headers: {
168-
"MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION
166+
let response: Response;
167+
try {
168+
response = await fetch(url, {
169+
headers: {
170+
"MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION
171+
}
172+
});
173+
} catch {
174+
try {
175+
response = await fetch(url);
176+
} catch {
177+
return undefined;
169178
}
170-
});
179+
}
171180

172181
if (response.status === 404) {
173182
return undefined;

0 commit comments

Comments
 (0)