Skip to content

Context7 Platform -- Up-to-date docs for AI agents

CTX7-3290: Put scopes_supported back in the Admin MCP resource metadata (#3516)

Enes Gules739d164ae301
diff --git a/packages/admin-mcp/api/oauth-protected-resource.ts b/packages/admin-mcp/api/oauth-protected-resource.ts
index 8853353d..43edbb64 100644
--- a/packages/admin-mcp/api/oauth-protected-resource.ts
+++ b/packages/admin-mcp/api/oauth-protected-resource.ts
@@ -1,13 +1,23 @@
// RFC 9728 metadata: where an MCP client gets a token for this server (Vercel's mcp-handler).
-import { metadataCorsOptionsRequestHandler, protectedResourceHandler } from "mcp-handler";
-import { OAUTH_AUTH_SERVER_URL, RESOURCE_URL } from "../src/http.js";
+import { generateProtectedResourceMetadata, metadataCorsOptionsRequestHandler } from "mcp-handler";
+import { OAUTH_AUTH_SERVER_URL, RESOURCE_URL, withCors } from "../src/http.js";
-const metadata = protectedResourceHandler({
+/**
+ * `scopes_supported` is required in practice: a client without it asks for
+ * every scope Clerk lists, and Clerk refuses `openid` for MCP clients with
+ * `invalid_scope`, so the sign-in fails.
+ */
+export const metadata = generateProtectedResourceMetadata({
authServerUrls: [OAUTH_AUTH_SERVER_URL],
resourceUrl: RESOURCE_URL,
+ additionalMetadata: {
+ scopes_supported: ["profile", "email"],
+ bearer_methods_supported: ["header"],
+ },
});
const preflight = metadataCorsOptionsRequestHandler();
export default {
- fetch: (request: Request) => (request.method === "OPTIONS" ? preflight() : metadata(request)),
+ fetch: (request: Request) =>
+ request.method === "OPTIONS" ? preflight() : withCors(request, () => Response.json(metadata)),
};
diff --git a/packages/admin-mcp/test/admin-mcp.test.ts b/packages/admin-mcp/test/admin-mcp.test.ts
index caeb28f5..0cfad992 100644
--- a/packages/admin-mcp/test/admin-mcp.test.ts
+++ b/packages/admin-mcp/test/admin-mcp.test.ts
@@ -327,3 +327,17 @@ test("suggestions are read per library, and no tool starts an agent run", async
path: `/v2/teamspaces/${TS}/libraries/acme/docs/suggestions`,
});
});
+
+// Without scopes_supported, clients ask Clerk for every scope it lists, and
+// Clerk answers invalid_scope for `openid`: the sign-in fails.
+test("the protected resource metadata names the scopes clients may ask for", async () => {
+ const { default: route } = await import("../api/oauth-protected-resource.js");
+ const response = await route.fetch(
+ new Request("https://admin.mcp.context7.com/.well-known/oauth-protected-resource/mcp")
+ );
+ expect(await response.json()).toMatchObject({
+ resource: "https://admin.mcp.context7.com/mcp",
+ authorization_servers: ["https://clerk.context7.com"],
+ scopes_supported: ["profile", "email"],
+ });
+});