From a1c545d21a4429c1c841cfe1ba5e44509b4354e5 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 21 Jul 2026 23:43:56 +0100 Subject: [PATCH] fix(mcpd): anthropic adapter supports OAuth (sk-ant-oat) keys via Bearer Claude subscription / Claude Code keys are OAuth tokens and authenticate with Authorization: Bearer, not x-api-key. mcpd's server adapter only sent x-api-key, so registering an OAuth key as a fallback Llm 401'd ("invalid x-api-key"). Mirror the mcplocal client adapter's isOAuth switch so an OAuth key works as a server-side anthropic fallback. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/mcpd/src/services/llm/adapters/anthropic.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mcpd/src/services/llm/adapters/anthropic.ts b/src/mcpd/src/services/llm/adapters/anthropic.ts index 4f2f185..a8ddd5f 100644 --- a/src/mcpd/src/services/llm/adapters/anthropic.ts +++ b/src/mcpd/src/services/llm/adapters/anthropic.ts @@ -182,9 +182,15 @@ export class AnthropicAdapter implements LlmAdapter { } private headers(ctx: InferContext): Record { + // Claude subscription / Claude Code keys are OAuth tokens (`sk-ant-oat…`) + // and authenticate via Bearer, not x-api-key — mirror the mcplocal client + // adapter so an OAuth key works as a server-side fallback Llm. + const isOAuth = ctx.apiKey.startsWith('sk-ant-oat'); return { 'Content-Type': 'application/json', - 'x-api-key': ctx.apiKey, + ...(isOAuth + ? { Authorization: `Bearer ${ctx.apiKey}` } + : { 'x-api-key': ctx.apiKey }), 'anthropic-version': ANTHROPIC_VERSION, }; }