Notion MCP 401 in n8n/Docker: {"code":"unauthorized","message":"API token is invalid."} with tools list working
Fixes the Notion MCP server listing tools fine but 401ing on every call in n8n or Docker. Use when tools/list works and only tool calls fail. Not for tokens that fail everywhere.
Notion MCP 401 in n8n/Docker: {"code":"unauthorized","message":"API token is invalid."} with tools list working
TL;DR: Your OPENAPIMCPHEADERS env value is misquoted, so the Authorization header never reaches the server even though tools list works. Escape the inner quotes: OPENAPIMCPHEADERS as a JSON string with backslash-escaped quotes. Restart the n8n container so the corrected env takes effect.
The error
{"status":401,"object":"error","code":"unauthorized","message":"API token is invalid."}Fix it
- Inspect the OPENAPIMCPHEADERS value in your docker-compose file or n8n env.
Expected: The quotes around the JSON are unescaped or the value is split.
- Set it as a single properly escaped string, e.g. OPENAPIMCPHEADERS with escaped inner quotes around Authorization and Notion-Version.
Expected: The value parses as valid JSON with both headers.
- Restart the container.
Expected: Tool calls authenticate and return data.
When this applies
Notion MCP tools/list succeeds but every tool call 401s with unauthorized/API token is invalid, in n8n or Docker Compose.
When this does NOT apply
If tools/list also fails, the token or URL is wrong. If the token fails in curl, regenerate it.
Tool compatibility
makenotion/notion-mcp-server via n8n or Docker Compose
Also seen as
- notion MCP n8n API token is invalid
- OPENAPIMCPHEADERS 401
- notion MCP docker unauthorized tool calls
Why it happens
tools/list does not need the Notion credential, but every tool call does. A misquoted OPENAPIMCPHEADERS means the server never forwards the Authorization header, so Notion 401s each call while listing tools works fine.
Edge cases
- YAML quoting rules differ between compose file styles; test with a JSON parse.
- n8n community packages need N8NCOMMUNITYPACKAGESALLOWTOOL_USAGE=true for tool use at all.
- Restarting the container matters; compose does not re-read env on its own.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.