Skip to content

fix: add Accept-Encoding: identity to OAuth discovery fetch requests - #277

Closed
clouatre wants to merge 1 commit into
geelen:mainfrom
clouatre:fix/accept-encoding-discovery
Closed

fix: add Accept-Encoding: identity to OAuth discovery fetch requests#277
clouatre wants to merge 1 commit into
geelen:mainfrom
clouatre:fix/accept-encoding-discovery

Conversation

@clouatre

@clouatre clouatre commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Node's built-in fetch (undici) sends Accept-Encoding: gzip, deflate, br by default on every request. Servers that honor this header -- including mcp.atlassian.com -- return gzip-compressed response bodies. fetchAuthorizationServerMetadata and fetchProtectedResourceMetadata both call response.json() on the raw compressed bytes, causing a fatal crash before any OAuth flow begins:

Connection error: SyntaxError: Unexpected token '', "..."  is not valid JSON
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:4227:19)

The --header CLI arg does not help here because custom headers are only applied to MCP transport requests, not to the upstream OAuth discovery fetches.

Changes

  • src/lib/authorization-server-metadata.ts: add Accept-Encoding: identity to the discovery fetch
  • src/lib/protected-resource-metadata.ts: same fix for consistency

Test plan

  • mcp-remote https://mcp.atlassian.com/v1/mcp --resource https://<org>.atlassian.net/ proceeds past OAuth discovery on Node 18+
  • Existing tests pass

Fixes #276

Node built-in fetch (undici) sends Accept-Encoding: gzip, deflate, br
by default. Servers that honor this (e.g. mcp.atlassian.com) return
gzip-compressed bodies. Both fetchAuthorizationServerMetadata and
fetchProtectedResourceMetadata call response.json() on the raw bytes,
causing a fatal SyntaxError before any OAuth flow begins.

Add Accept-Encoding: identity to suppress compression on these two
discovery requests. The --header CLI arg does not help here because
custom headers are only applied to MCP transport requests, not to
the upstream OAuth discovery fetch.

Fixes geelen#276

Signed-off-by: Hugues Clouâtre <hugues@linux.com>
@pkg-pr-new

pkg-pr-new Bot commented Jun 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/mcp-remote@277

commit: 86f3b3c

@clouatre

clouatre commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing -- submitted prematurely without proper review.

@clouatre clouatre closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: fetchAuthorizationServerMetadata sends no Accept-Encoding header, causing gzip parse crash on Node 18+

1 participant