Skip to content

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

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

fix: add Accept-Encoding: identity to OAuth discovery fetch requests#279
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

On Node 26, fetch (undici) sends Accept-Encoding: gzip, deflate, br by default. fetchAuthorizationServerMetadata and fetchProtectedResourceMetadata set Accept: application/json but not Accept-Encoding, so Cloudflare-fronted servers (e.g. mcp.atlassian.com) return gzip-compressed bodies that response.json() cannot parse. This crashes mcp-remote at OAuth discovery before the transport is initialized.

Related Issues

Changes

  • Added 'Accept-Encoding': 'identity' to fetch() headers in fetchAuthorizationServerMetadata (src/lib/authorization-server-metadata.ts)
  • Added 'Accept-Encoding': 'identity' to fetch() headers in fetchProtectedResourceMetadata (src/lib/protected-resource-metadata.ts)
  • Updated header assertions in both test files to match

Test Plan

  • Unit tests: pnpm test:unit (103 tests, all pass)
  • Type check + formatting: pnpm check (clean)
  • Build: pnpm build (clean)
  • Backward compatible: servers that do not compress are unaffected; verified with curl against mcp.atlassian.com for all three cases (no Accept-Encoding, gzip, identity)

Verification Checklist

  • Tests pass: pnpm test:unit
  • Type check clean: pnpm check
  • Build clean: pnpm build
  • No scope creep (two fetch call sites + matching test assertions only)
  • No secrets or credentials in diff
  • I have reviewed every line in this PR and can explain it

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@279

commit: bdd4d3e

@clouatre

clouatre commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

The e2e failure is a pre-existing flakiness unrelated to this change: the test asserts model_search exists in the Hugging Face MCP server's tool list, but that tool has been removed from their live server since the last successful main run (2026-02-05). All unit tests and the Cloudflare docs e2e pass.

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.

[BUG] OAuth discovery crashes on Node 26 with gzip-compressed response

1 participant