Skip to content

fix(client): preserve Request semantics in createProxyFetch#1208

Open
shaun0927 wants to merge 2 commits intomodelcontextprotocol:mainfrom
shaun0927:fix/proxyfetch-request-semantics
Open

fix(client): preserve Request semantics in createProxyFetch#1208
shaun0927 wants to merge 2 commits intomodelcontextprotocol:mainfrom
shaun0927:fix/proxyfetch-request-semantics

Conversation

@shaun0927
Copy link
Copy Markdown

@shaun0927 shaun0927 commented Apr 16, 2026

Summary

createProxyFetch() currently preserves request semantics when it is called as (url, init), but not when the caller passes a real Request object. In the Request case, the proxy payload keeps request.url but drops the original method, headers, and body.

This patch preserves those fields for Request inputs, still lets an explicit init override them, and adds focused regression coverage for both the passthrough and override cases.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Refactoring (no functional changes)
  • Test updates
  • Build/CI improvements

Changes Made

  • read method, headers, and body from Request inputs inside client/src/lib/proxyFetch.ts
  • preserve the existing (url, init) behavior
  • let an explicit init continue to override the values derived from the Request
  • add regression tests in client/src/lib/__tests__/proxyFetch.test.ts that cover:
    • the basic Request passthrough case
    • the init-overrides-Request precedence case

Related Issues

Fixes #1207

Testing

  • Tested in UI mode
  • Tested in CLI mode
  • Tested with STDIO transport
  • Tested with SSE transport
  • Tested with Streamable HTTP transport
  • Added/updated automated tests
  • Manual testing performed

Test Results and/or Instructions

Added focused regression tests for the Request input path in client/src/lib/__tests__/proxyFetch.test.ts.

Local verification in this environment used targeted Node 22 harnesses against the checked-out source to confirm:

  1. (url, init) still forwards method, headers, and body
  2. new Request(...) now forwards the same fields instead of sending an empty init
  3. when both a Request and an explicit init are provided, the explicit init values win

Reviewers can test the change by running the client unit tests, or by comparing the serialized POST /fetch payload before and after this patch when createProxyFetch() is called with a Request.

Checklist

  • Code follows the style guidelines (ran npm run prettier-fix)
  • Self-review completed
  • Code is commented where necessary
  • Documentation updated (README, comments, etc.)

Breaking Changes

None.

Additional Context

This keeps createProxyFetch() closer to normal fetch-wrapper expectations: callers should not get different proxy behavior solely because they constructed a Request object instead of passing (url, init) separately.

The proxy auth wrapper handled (url, init) correctly but dropped method, headers, and body when callers supplied a real Request object. That made wrapper behavior depend on call shape and could break Request-based OAuth or proxy flows.

This change reads method, headers, and body from Request inputs, lets an explicit init override them, and adds a focused regression test covering the Request path while preserving the existing URL+init behavior.

Constraint: Keep the fix narrow and V1-compatible with no transport/proxy refactor
Rejected: Broader fetch wrapper redesign | out of scope for a correctness bug fix
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Preserve parity between Request input and (url, init) input in future proxyFetch changes
Tested: Targeted Node 22 source-backed reproduction before and after fix; added regression test in client/src/lib/__tests__/proxyFetch.test.ts
Not-tested: Full workspace Jest/CI run in this local environment
The original fix branch already repaired Request preservation in createProxyFetch, but the test suite only locked the basic Request passthrough case. This follow-up adds coverage for the override rule the implementation promises: explicit init values should still win over the Request's method, headers, and body.

It also keeps the small formatting adjustment in proxyFetch.ts consistent with the surrounding style.

Constraint: Keep follow-up scope limited to merge-readiness hardening for PR modelcontextprotocol#1208
Rejected: Broader semantic changes around bodyUsed handling | no reviewer request and would expand scope beyond the validated bug
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Preserve both Request passthrough and explicit init override semantics in future proxyFetch edits
Tested: Targeted Node 22 harness validating override semantics against current source
Not-tested: Full workspace Jest/CI run in this local environment
@cliffhall cliffhall added the v1 label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createProxyFetch drops Request method, headers, and body

2 participants