Add MCP-Protocol-Version header

This commit is contained in:
Justin Spahr-Summers 2025-02-11 17:58:58 +00:00
commit fceebdcf5a
No known key found for this signature in database

View file

@ -1,5 +1,6 @@
import pkceChallenge from "pkce-challenge";
import { z } from "zod";
import { LATEST_PROTOCOL_VERSION } from "../types.js";
export const OAuthMetadataSchema = z
.object({
@ -229,9 +230,15 @@ export async function auth(
*/
export async function discoverOAuthMetadata(
serverUrl: string | URL,
opts?: { protocolVersion?: string },
): Promise<OAuthMetadata | undefined> {
const url = new URL("/.well-known/oauth-authorization-server", serverUrl);
const response = await fetch(url);
const response = await fetch(url, {
headers: {
"MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION
}
});
if (response.status === 404) {
return undefined;
}