Re-add MCP bridge so Hermes can delegate to the real Claude Code CLI

Recreates the PR #17 change (closed without merging, then asked for back
after confirming a real ANTHROPIC_API_KEY would mean separate/duplicate
billing rather than actually using the Pro/Max subscription).

New POST /mcp endpoint (Streamable HTTP transport, stateless — fresh
McpServer+transport per request) exposing one tool, ask_claude_code: runs
the real `claude` binary against a prompt, billed against the subscription
rather than API credits. Works specifically because it's the actual CLI
making the request server-side. Read-only — no Edit/Write/git-push/
git-commit tools.

Also removes litellm-config.yaml's "anthropic-claude" model entry: it only
ever worked when the real claude CLI itself was the caller (proven earlier),
so having it listed as a selectable model was actively misleading — Hermes
picking it directly is exactly what produced the '401: Missing Anthropic
API Key' confusion that led back to this bridge. The MCP tool is the actual
working path now; general_settings.forward_client_headers_to_llm_api is
also removed since nothing uses it anymore.

Tested end-to-end locally again before pushing (built the image, ran it,
full MCP handshake via curl) — real 'pong' from the real claude CLI.
This commit is contained in:
2026-08-23 17:41:49 +00:00
parent ec37245b37
commit 46192837e6
6 changed files with 125 additions and 17 deletions
+9 -13
View File
@@ -11,18 +11,15 @@ model_list:
model: openrouter/openai/gpt-4o-mini
api_key: os.environ/OPENROUTER_API_KEY
# Routes to Anthropic using the CALLER's forwarded Authorization header (the Claude
# Pro/Max subscription OAuth token) instead of a LiteLLM-held API key — billed against
# the subscription, not per-token. CONFIRMED WORKING, but only for the real `claude`
# CLI binary as caller (tested: `claude -p` with ANTHROPIC_BASE_URL pointed here
# returned a real completion). An earlier test with plain curl replicating the same
# request shape failed — Anthropic apparently requires header/fingerprint details only
# the real CLI sends, which LiteLLM faithfully relays but a hand-built request won't
# have. Do NOT expect this to work for other callers (Hermes, generic HTTP clients) —
# they aren't the real CLI and can't reproduce that fingerprint.
- model_name: anthropic-claude
litellm_params:
model: anthropic/claude-sonnet-5
# NOT included: an "anthropic-claude" model routing to Anthropic via the caller's
# forwarded OAuth header (general_settings.forward_client_headers_to_llm_api). It
# genuinely works — but ONLY when the real `claude` CLI binary is the caller (its
# request carries a header/fingerprint only that binary sends; a hand-built request,
# including Hermes selecting this model directly, gets a hard auth error from
# Anthropic). Having it selectable here caused exactly that confusion once already.
# The actual working path for "Hermes uses the Claude subscription" is the MCP bridge
# at claude-agent's /mcp (agent/src/mcpBridge.js) — it shells out to the real `claude`
# binary server-side instead of trying to make an arbitrary caller impersonate it.
litellm_settings:
# Callers (Hermes included) send provider-specific params like reasoning_effort that
@@ -30,5 +27,4 @@ litellm_settings:
drop_params: true
general_settings:
forward_client_headers_to_llm_api: true
master_key: os.environ/LITELLM_MASTER_KEY