During metadata fetching, try with the MCP header, then without, then return undefined if both fail

This commit is contained in:
Jerome 2025-02-22 16:20:41 +00:00
commit 1b8e94ca40
No known key found for this signature in database

View file

@ -163,11 +163,20 @@ export async function discoverOAuthMetadata(
opts?: { protocolVersion?: string },
): Promise<OAuthMetadata | undefined> {
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;