Fix MCP authentication headers not forwarded for all tool calls #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Auth headers (
x-adcp-auth) were inconsistently forwarded to MCP servers:get_products- Headers forwarded correctlysync_creatives- Headers NOT forwardedRoot Cause
Known bug in MCP TypeScript SDK where
requestInit.headersare not properly merged for all HTTP requests:_normalizeHeaders(), real-world testing showed headers were still inconsistently applied between tool callsSolution
Implemented custom
fetchfunction that intercepts ALL HTTP requests and ensures auth headers are included:Testing
Unit Tests ✅
node --test test/unit/mcp-custom-fetch.test.jsReal Server Integration ✅
Tested against Wonderstruck MCP server:
get_products- Auth headers present, no errorssync_creatives- Auth headers present, NO auth errors (fix verified!)Build & Regression ✅
Changes
src/lib/protocols/mcp.ts- Custom fetch function with header mergingpackage-lock.json- Updated@modelcontextprotocol/sdk1.18.1 → 1.18.2test/unit/mcp-custom-fetch.test.js- Unit tests for the fixFIX-AUTH-HEADERS.md- Comprehensive documentationTEST-RESULTS.md- Real server test resultsDocumentation
See
FIX-AUTH-HEADERS.mdfor:🤖 Generated with Claude Code