Context7 Platform -- Up-to-date docs for AI agents
fix(mcp): allow empty Claude plugin API key (#3168)
Fahreddin Özcan0087bab2dcef
diff --git a/.changeset/tidy-dogs-connect.md b/.changeset/tidy-dogs-connect.mdnew file mode 100644index 00000000..985f0ef9--- /dev/null+++ b/.changeset/tidy-dogs-connect.md@@ -0,0 +1,5 @@+---+"@upstash/context7-mcp": patch+---++Allow the Claude Code plugin to use anonymous access when its API key header is empty.diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.tsindex cbd2ad7d..d118149c 100644--- a/packages/mcp/src/index.ts+++ b/packages/mcp/src/index.ts@@ -37,7 +37,12 @@ function getPluginFromRequest(req: express.Request): typeof CLAUDE_CODE_PLUGIN |function requiresAuthentication(req: express.Request, plugin?: typeof CLAUDE_CODE_PLUGIN): boolean {// The MCP routes live on a router mounted at /mcp, so req.path is relative to it.- return `${req.baseUrl}${req.path}` === "/mcp/oauth" || Boolean(plugin);+ const isOAuthEndpoint = `${req.baseUrl}${req.path}` === "/mcp/oauth";+ // The current official Claude plugin expands an unset API key to an empty header.+ const hasEmptyPluginAuthorization =+ plugin === CLAUDE_CODE_PLUGIN && req.headers.authorization === "";++ return isOAuthEndpoint || (Boolean(plugin) && !hasEmptyPluginAuthorization);}// Parse CLI arguments using commanderdiff --git a/packages/mcp/test/integration.test.ts b/packages/mcp/test/integration.test.tsindex f591edc2..9daa9f23 100644--- a/packages/mcp/test/integration.test.ts+++ b/packages/mcp/test/integration.test.ts@@ -455,10 +455,22 @@ describe("plugin authentication", () => {expect(res.wwwAuthenticate).toContain("/.well-known/oauth-protected-resource");});+ test("allows the Claude Code plugin's empty API key fallback", async () => {+ const res = await postMcp(`${httpUrl}?client=claude-code-plugin`, {+ Authorization: "",+ });++ expect(res.status).toBe(200);+ });+test("keeps the OAuth endpoint protected", async () => {- const res = await postMcp(httpUrl.replace(/\/mcp$/, "/mcp/oauth"));+ const oauthUrl = httpUrl.replace(/\/mcp$/, "/mcp/oauth");+ const emptyHeaderRes = await postMcp(`${oauthUrl}?client=claude-code-plugin`, {+ Authorization: "",+ });- expect(res.status).toBe(401);+ expect((await postMcp(oauthUrl)).status).toBe(401);+ expect(emptyHeaderRes.status).toBe(401);});test("tracks authenticated plugin requests separately", async () => {