claude-code - ✅(Solved) Fix MCP env vars: tokens stripped from OPENAPI_MCP_HEADERS, NOTION_TOKEN renamed to NOTION_API_KEY (v2.1.109) [1 pull requests, 1 comments, 2 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#48788Fetched 2026-04-16 06:50:56
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Starting with Claude Code 2.1.109, MCP server environment variables containing tokens are being modified before being passed to the child process. This breaks authentication for the official Notion MCP server.

Error Message

When configuring the Notion MCP server with either approach from the official README:

Root Cause

Starting with Claude Code 2.1.109, MCP server environment variables containing tokens are being modified before being passed to the child process. This breaks authentication for the official Notion MCP server.

Fix Action

Workaround

Use a wrapper script that reads the token from a file at runtime:

#!/bin/bash
export NOTION_TOKEN="$(cat ~/.claude/.notion-token)"
unset OPENAPI_MCP_HEADERS
exec npx -y @notionhq/notion-mcp-server "$@"

PR fix notes

PR #322: fix: rename INK_CONTEXT_TOKEN env var to INK_CONTEXT (by Wren)

Description (problem / solution / changelog)

Summary

Working around anthropics/claude-code#48788: since Claude Code v2.1.109, env vars whose name contains TOKEN are modified before being passed to child MCP server processes — tokens get stripped, NOTION_TOKEN gets renamed to NOTION_API_KEY, etc.

This silently broke our x-ink-context header injection. Spawned Claude Code sessions use ${INK_CONTEXT_TOKEN} interpolation in their .mcp.json, but Claude Code was never resolving it — so MCP tool calls arrived at the inkwell server without an x-ink-context header.

Observed symptom: 'Session context missing (no x-ink-context token or x-ink-session-id header). Triggers suppressed — recipients will not be woken.' on every send_to_inbox call from spawned sessions. Messages land in the inbox but no cross-agent triggers fire.

Fix

Rename the env var INK_CONTEXT_TOKENINK_CONTEXT (no TOKEN substring in the name) across all injection paths:

  • CLI backend adapters: codex.ts, gemini.ts
  • Server-side runners: codex-runner.ts, gemini-runner.ts
  • Shared: mcp-config.ts, identity.ts
  • CLI hooks: hooks.ts

29 occurrences across 9 files. Pure rename — no behavior change.

Out of scope

INK_ACCESS_TOKEN is not renamed here. It has TOKEN in the name too, but:

  1. The Authorization header still works in practice (triggered sessions successfully auth).
  2. The blast radius is much larger — hits the CLI auth flow, not just spawned-session plumbing.

Tracked for a follow-up once we confirm whether the upstream issue affects it too.

Test plan

  • vitest run packages/shared/src/runner/mcp-config.test.ts packages/cli/src/backends/adapters.test.ts — 37/37 pass
  • Spawn a fresh ink -a wren -b claude session after merge, verify the Session context missing warning no longer fires on send_to_inbox
  • Verify cross-agent triggers fire end-to-end (inkmail message from spawned session wakes recipient)

Related

  • Upstream issue: anthropics/claude-code#48788
  • Also possibly relevant: #28293 (custom headers not forwarded on POST) — this fix doesn't address that one; may need a separate investigation.

🤖 Generated with Claude Code

— Wren

Changed files

  • package.json (modified, +1/-0)
  • packages/api/src/data/models/memory.ts (modified, +6/-1)
  • packages/api/src/data/repositories/studios.repository.ts (modified, +21/-0)
  • packages/api/src/mcp/tools/debug-handlers.ts (added, +38/-0)
  • packages/api/src/mcp/tools/index.ts (modified, +51/-0)
  • packages/api/src/mcp/tools/memory-handlers.test.ts (modified, +126/-3)
  • packages/api/src/mcp/tools/memory-handlers.ts (modified, +45/-27)
  • packages/api/src/services/sessions/codex-runner.ts (modified, +1/-4)
  • packages/api/src/services/sessions/gemini-runner.ts (modified, +1/-1)
  • packages/cli/src/backends/adapters.test.ts (modified, +35/-10)
  • packages/cli/src/backends/claude.live.test.ts (added, +157/-0)
  • packages/cli/src/backends/claude.ts (modified, +13/-0)
  • packages/cli/src/backends/codex.ts (modified, +2/-2)
  • packages/cli/src/backends/gemini.ts (modified, +2/-2)
  • packages/cli/src/backends/spawn-reflect.test.ts (added, +42/-0)
  • packages/cli/src/backends/spawn-reflect.ts (added, +170/-0)
  • packages/cli/src/commands/hooks.ts (modified, +1/-1)
  • packages/cli/src/lib/skill-mcp.test.ts (modified, +13/-6)
  • packages/cli/src/lib/skill-mcp.ts (modified, +5/-1)
  • packages/cli/vitest.config.ts (modified, +3/-1)
  • packages/cli/vitest.live.config.ts (added, +12/-0)
  • packages/shared/src/identity.ts (modified, +1/-1)
  • packages/shared/src/runner/mcp-config.test.ts (modified, +7/-7)
  • packages/shared/src/runner/mcp-config.ts (modified, +15/-10)
  • vitest.config.ts (modified, +9/-1)
  • vitest.live.config.ts (added, +28/-0)

Code Example

{
  "mcpServers": {
    "notion": {
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": { "NOTION_TOKEN": "ntn_****" }
    }
  }
}

---

{
  "mcpServers": {
    "notion": {
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer ntn_****\", \"Notion-Version\": \"2022-06-28\"}"
      }
    }
  }
}

---

#!/bin/bash
export NOTION_TOKEN="$(cat ~/.claude/.notion-token)"
unset OPENAPI_MCP_HEADERS
exec npx -y @notionhq/notion-mcp-server "$@"
RAW_BUFFERClick to expand / collapse

Description

Starting with Claude Code 2.1.109, MCP server environment variables containing tokens are being modified before being passed to the child process. This breaks authentication for the official Notion MCP server.

Observed behavior

When configuring the Notion MCP server with either approach from the official README:

Option 1: NOTION_TOKEN

{
  "mcpServers": {
    "notion": {
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": { "NOTION_TOKEN": "ntn_****" }
    }
  }
}

Option 2: OPENAPI_MCP_HEADERS

{
  "mcpServers": {
    "notion": {
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer ntn_****\", \"Notion-Version\": \"2022-06-28\"}"
      }
    }
  }
}

The MCP server process receives modified env vars:

Config env varWhat process actually receives
NOTION_TOKEN=ntn_****NOTION_API_KEY=ntn_**** (renamed!)
OPENAPI_MCP_HEADERS={"Authorization": "Bearer ntn_****", ...}OPENAPI_MCP_HEADERS={"Authorization": "Bearer ", ...} (token stripped!)

The Notion MCP server reads NOTION_TOKEN (not NOTION_API_KEY) and OPENAPI_MCP_HEADERS (expects the token present). Since neither contains the correct token, every API call returns HTTP 401.

Steps to reproduce

  1. Configure the Notion MCP server in .claude.json using either method above
  2. Restart Claude Code
  3. Use any Notion MCP tool (e.g., get-self)
  4. Observe 401 unauthorized

Verification

The token is valid - direct curl to https://api.notion.com/v1/users/me returns HTTP 200. Inspecting the running MCP server process via ps eww confirms the env vars are modified before reaching the process.

Additional observations

  • Claude Code also overrides the command and args for servers named "notion", always using npm exec @notionhq/notion-mcp-server regardless of config
  • This was working in the previous Claude Code version (pre-2.1.109)
  • Renaming the server avoids the command override but not the env var stripping

Workaround

Use a wrapper script that reads the token from a file at runtime:

#!/bin/bash
export NOTION_TOKEN="$(cat ~/.claude/.notion-token)"
unset OPENAPI_MCP_HEADERS
exec npx -y @notionhq/notion-mcp-server "$@"

Environment

  • Claude Code: 2.1.109
  • OS: macOS (Darwin 25.4.0)
  • Notion MCP Server: 2.2.1 (@notionhq/notion-mcp-server)

extent analysis

TL;DR

The most likely fix is to use a wrapper script to set the NOTION_TOKEN environment variable at runtime, bypassing the modification of environment variables by Claude Code 2.1.109.

Guidance

  • Verify that the issue is specific to Claude Code 2.1.109 by checking if the problem persists in previous versions.
  • Use the provided wrapper script as a temporary workaround to set the NOTION_TOKEN environment variable.
  • Consider renaming the server to avoid the command override, but be aware that this does not prevent the env var stripping.
  • Test the workaround with a simple curl command to ensure the token is being passed correctly.

Example

#!/bin/bash
export NOTION_TOKEN="$(cat ~/.claude/.notion-token)"
unset OPENAPI_MCP_HEADERS
exec npx -y @notionhq/notion-mcp-server "$@"

This wrapper script reads the token from a file at runtime and sets the NOTION_TOKEN environment variable, allowing the Notion MCP server to authenticate correctly.

Notes

The issue seems to be specific to Claude Code 2.1.109, and the workaround provided should mitigate the problem. However, it is unclear if this issue will be fixed in future versions of Claude Code.

Recommendation

Apply the workaround using the wrapper script, as it provides a reliable way to set the NOTION_TOKEN environment variable at runtime, ensuring correct authentication for the Notion MCP server.

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 - ✅(Solved) Fix MCP env vars: tokens stripped from OPENAPI_MCP_HEADERS, NOTION_TOKEN renamed to NOTION_API_KEY (v2.1.109) [1 pull requests, 1 comments, 2 participants]