Skip to content

NOTION_TOKEN env var not read when spawned by Claude Code on Windows (stdio + HTTP) #291

@AngieOdin

Description

@AngieOdin

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Node.js: v24.14.1
  • Claude Code: v2.1.133
  • Package version: @notionhq/notion-mcp-server v2.2.1
  • Notion API token: Valid integration token (verified via direct curl to api.notion.com)

Summary

When the MCP server is spawned by Claude Code on Windows, NOTION_TOKEN (and OPENAPI_MCP_HEADERS) environment variables are not being read correctly, resulting in all Notion API calls returning 401 Unauthorized.

The same configuration and token work perfectly when the server is started from bash/command line, both via stdio and HTTP transport.

Steps to Reproduce

Working: Manual bash test

echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"API-get-self"}}' | NOTION_TOKEN="ntn_****" npx -y @notionhq/notion-mcp-server
# Result: ✅ Returns user info correctly

Working: HTTP transport manual test

NOTION_TOKEN="ntn_****" npx -y @notionhq/notion-mcp-server --transport http --port 3339 --auth-token "test"
# Then curl to /mcp endpoint → ✅ Works

Broken: Claude Code spawn (stdio)

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

Result: API-get-self401 Unauthorized: API token is invalid

Broken: Claude Code spawn (HTTP transport)

{
  "mcpServers": {
    "notion": {
      "type": "http",
      "url": "http://localhost:3339/mcp",
      "headers": {
        "Authorization": "Bearer test"
      }
    }
  }
}

Result: API-get-self401 Unauthorized: API token is invalid

(HTTP server started with NOTION_TOKEN set correctly)

Testing Done

Configurations tried (ALL fail through Claude Code, ALL work manually):

  1. npx.cmd + NOTION_TOKEN env var
  2. node.exe + --require setup script (sets process.env.NOTION_TOKEN)
  3. node.exe + npx-cli.js directly (bypasses .cmd batch file)
  4. HTTP transport (server runs independently with env var)
  5. Both NOTION_TOKEN and OPENAPI_MCP_HEADERS env vars
  6. Package versions v2.2.1 and v1.4.0

Ruled out:

  • Token validity (direct curl to api.notion.com works)
  • Env var name (all documented names tested)
  • npx.cmd batch file interference (bypassed with node.exe directly)
  • Transport type (both stdio and HTTP fail)
  • Global env var passing (other MCP servers work with env vars via Claude Code on the same machine)
  • Empty env ({}) causing process issues

Expected Behavior

NOTION_TOKEN env var should be read correctly when the MCP server is spawned by Claude Code on Windows, same as when spawned from bash.

Actual Behavior

All Notion API calls return 401 Unauthorized: API token is invalid regardless of transport type or configuration approach.

Additional Context

Other MCP servers (nocodb-cloud, postgres-local, n8n-local) configured in the same Claude Code instance with env vars work correctly, proving Claude Code's env var passing mechanism is functional.

Possible Clue

The process.env.NOTION_TOKEN may be accessible during module initialization (tools/list works) but becomes unavailable or empty when the OpenAPI MCP wrapper makes HTTP requests to the Notion API. This could be related to how the OpenAPI MCP framework resolves security schemes in a child process context on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions