claude-code - 💡(How to fix) Fix MCP server with empty Bearer token silently fails to register tools at session start [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56223Fetched 2026-05-06 06:33:53
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

When an MCP server entry in settings.json has an empty Authorization: Bearer header, Claude Code silently skips registering that server's tools. No warning is shown to the user, and the server never appears in the available tool list.

Error Message

  • Warn the user when a Bearer token slot is empty

Root Cause

Users who configure MCP servers via scripts (e.g. session-start hooks that write settings.json) may leave a token placeholder empty. Currently there is no feedback that anything is wrong — the server is just missing. Auto-detection of a matching env var using the naming convention would recover the common case automatically.

Fix Action

Fix / Workaround

Workaround (until fixed)

Users must set up a SessionStart hook that reads token env vars and patches settings.json at session start. This is non-trivial, recurs every session, and requires knowing which env var maps to which server. No user should need to write this manually.

Code Example

{
     "mcpServers": {
       "my-server": {
         "type": "url",
         "url": "https://example.com/mcp",
         "headers": { "Authorization": "Bearer " }
       }
     }
   }
RAW_BUFFERClick to expand / collapse

Summary

When an MCP server entry in settings.json has an empty Authorization: Bearer header, Claude Code silently skips registering that server's tools. No warning is shown to the user, and the server never appears in the available tool list.

Steps to reproduce

  1. Add an MCP server to ~/.claude/settings.json with an empty Bearer token:
    {
      "mcpServers": {
        "my-server": {
          "type": "url",
          "url": "https://example.com/mcp",
          "headers": { "Authorization": "Bearer " }
        }
      }
    }
  2. Start a new Claude Code session.
  3. The server's tools are absent with no explanation.

Expected behaviour

Claude Code should validate MCP server auth configuration at startup and:

  • Warn the user when a Bearer token slot is empty
  • Attempt to resolve the token automatically by checking env vars using a naming convention: server-nameUPPER_SNAKE_CASE_TOKEN (e.g. n8n-toolsN8N_TOOLS_TOKEN, my-apiMY_API_TOKEN), then fall back to a generic MCP_TOKEN if present
  • Surface a clear diagnostic rather than silently dropping the server

Workaround (until fixed)

Users must set up a SessionStart hook that reads token env vars and patches settings.json at session start. This is non-trivial, recurs every session, and requires knowing which env var maps to which server. No user should need to write this manually.

Why this matters

Users who configure MCP servers via scripts (e.g. session-start hooks that write settings.json) may leave a token placeholder empty. Currently there is no feedback that anything is wrong — the server is just missing. Auto-detection of a matching env var using the naming convention would recover the common case automatically.

Environment

  • Claude Code version: 2.1.42
  • Platform: Linux 6.18.5
  • Entrypoint: remote_trigger (Claude Code on the web)

Labels

claude-code mcp bug

extent analysis

TL;DR

To fix the issue, validate the MCP server auth configuration at startup and attempt to resolve the token automatically by checking env vars using a naming convention.

Guidance

  • Check the settings.json file for empty Bearer tokens in the headers section of each MCP server entry.
  • Implement a validation mechanism at startup to warn the user when a Bearer token slot is empty.
  • Attempt to resolve the token automatically by checking env vars using the naming convention (e.g., server-nameUPPER_SNAKE_CASE_TOKEN).
  • If the specific env var is not found, fall back to a generic MCP_TOKEN env var.

Example

// Example settings.json with automatic token resolution
{
  "mcpServers": {
    "my-server": {
      "type": "url",
      "url": "https://example.com/mcp",
      "headers": { "Authorization": "Bearer ${MY_SERVER_TOKEN}" }
    }
  }
}

Note: The example assumes that the MY_SERVER_TOKEN env var is set with the actual token value.

Notes

This solution assumes that the env vars are set correctly and follow the specified naming convention. If the env vars are not set or do not follow the convention, the automatic token resolution will not work.

Recommendation

Apply a workaround by setting up a SessionStart hook that reads token env vars and patches settings.json at session start, until the issue is fixed in a future version of Claude Code. This will provide a temporary solution to the problem, but it requires manual configuration and may not be suitable for all users.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix MCP server with empty Bearer token silently fails to register tools at session start [1 participants]