Repository navigation
fix(claude-code): send the saved Server credential to the plugin MCP server - #2669
Conversation
…server
Setup saves a URL-bound credential that the hooks read, but the plugin's
MCP server sent only `${POWERCONTEXT_CLAUDE_AUTHORIZATION:-}`. Without that
variable in the process that starts Claude Code, MCP failed to connect and
offered no tools while the hooks kept working.
The MCP server now runs a `headersHelper` that emits the credential saved
for the endpoint Claude Code connects to, and nothing for another endpoint.
The static environment header stays for when nothing is saved. Claude Code
removes credential-like variables before it runs a plugin's helper, so the
helper does not read the environment and the saved credential wins for MCP;
the docs say to rerun setup to rotate the token.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed a6000df. I did not establish a correctness defect introduced by this patch. Reusing the URL-bound credential reader is reasonable, and the documented MCP-versus-Hook precedence makes the token-rotation behavior explicit.
Merge readiness remains blocked:
- Merging current master e725225 conflicts in integrations/claude-code/plugins/powercontext/hooks/session_start.py. Please resolve and revalidate the combined behavior.
- All three native-service CI jobs fail the migration retry assertion expecting v1_5_0_004 while receiving v1_5_0_005. These failures are outside the changed plugin code; this review does not attribute them to the patch.
Validation limit: the related local suite finished with 156 passes and four failures (one oversized-response outcome mismatch and three Server startup failures), so it is not a clean acceptance run. The new helper tests and Python 3.9 checks passed, as did additional endpoint/permission/malformed-storage probes. I did not independently replay the author's real-Claude-host experiment.
No database tables or HTTP/MCP operations are added. There is a new host headersHelper contract and an exported mcp_authorization function, so this does not qualify for the requested no-new-interface automatic approval.
…cp-saved-credential # Conflicts: # integrations/claude-code/plugins/powercontext/hooks/session_start.py
|
Thanks for the review. I merged master (fd16583) into the branch as deef2b5. Conflict resolution
Validation on deef2b5
|
hidb4ai
left a comment
There was a problem hiding this comment.
Re-reviewed deef2b5. The SessionStart conflict resolution preserves master's lifecycle delegation, with the version bump correctly moved to CLAUDE_CODE.user_agent. The previous merge conflict and all three native-service CI failures are cleared. I found no new patch-specific correctness defect.
The remaining Linux Desktop check fails while downloading OpenAPI Generator from Maven Central (HTTP 429), before application validation. Please rerun that check once the rate limit clears; the green aggregate CI result does not make this individual check successful.
Independent validation is still limited: my local run reports one Python 3.9 trickle-body case failing at scope_resolve instead of context_prepare, plus four service-chain cases failing to start the Server. The new helper tests pass. These failures do not establish a regression in this patch, and I have not independently replayed the real-Claude-host experiment.
No database tables or HTTP/MCP operations are added. The new host headersHelper contract and exported mcp_authorization remain, so the requested no-new-interface automatic-approval condition is not met.
Which issue or RFC does this PR close?
No tracking issue. It follows #1530 and #1531 and was found while writing a real-host Claude Code E2E.
Rationale for this change
powercontext setup claude-codesaves a URL-bound credential under$CLAUDE_CONFIG_DIR/powercontext/credentials.json, and the hooks read it. The plugin's MCP server sent only${POWERCONTEXT_CLAUDE_AUTHORIZATION:-}. When that variable was missing from the process that starts Claude Code, for example a session that Desktop starts,claude -p2.1.277 recalled and captured normally. The MCP server, however, reportedfailed, Claude Code offered no PowerContext tools, and the turn still succeeded.#1531 replaced a
headersHelperwith the static header because the helper "ignored" the credential (#1530). That helper readPOWERCONTEXT_CLAUDE_AUTHORIZATIONfrom its environment. On Claude Code 2.1.277, the variable never reaches a plugin MCP server'sheadersHelperwhen its value looks like a credential. With a token containing digits and_ + / =, the helper saw no variable and emitted{}. A token made only of letters and hyphens did reach it. That stripping explains #1530. The helper in this PR reads the saved file instead of the environment.What changes are included in this PR?
scripts/mcp_headers.pyis the plugin MCP server'sheadersHelper.CLAUDE_CODE_MCP_SERVER_URL.claude_code_settings.mcp_authorization).{}..mcp.jsonkeeps the static${POWERCONTEXT_CLAUDE_AUTHORIZATION:-}header and addsheadersHelper: python3 "${CLAUDE_PLUGIN_ROOT}/scripts/mcp_headers.py".--server-url "$POWERCONTEXT_CLAUDE_SERVER_URL", a variable the section never sets.Are there any user-facing changes?
Yes.
POWERCONTEXT_CLAUDE_AUTHORIZATIONnow get the PowerContext MCP tools when setup saved a credential.Known limitation, not changed here: neither the hooks nor the helper use a saved credential for a non-loopback HTTP Server, even with insecure-HTTP consent, because the URL comparison rejects plain HTTP to a non-loopback host. The docs say to export the value in that case.
How was this change tested?
claude -p, stream-json) against an in-process bearer-auth Server and a Messages API fake. This used the E2E from the unpublished branchfeat/claude-code-host-e2e, run in a scratch checkout with this change applied and the plugin under a path containing a space. A realistic token (digits,_ + / =) was used.remember_memoryandsearch_memorycalls succeed.headersHelperremoved from.mcp.json: the tools case fails.POWERCONTEXT_CLAUDE_AUTHORIZATIONfor the realistic token, while it does for a token of letters and hyphens.headersHelpersupport, the static environment header still applies as before.uv run pytest tests/claude_code_plugin tests/e2e/test_claude_code_service_chain.py tests/test_docs_remote_access_contract.py --require-claude-code-python-floor(Python 3.9.6 floor); related CLI and wizard tests;make check.--server-urlvariable in the docs;AI usage statement
Claude Code (Claude Opus 5.5) wrote the change, the tests and this description, and ran the verification above.