Skip to content

fix(typescript): pass SSE headers through requestInit - #674

Open
ZIFeIYUuuuuuu wants to merge 1 commit into
2FastLabs:mainfrom
ZIFeIYUuuuuuu:fix/typescript-sse-headers
Open

fix(typescript): pass SSE headers through requestInit#674
ZIFeIYUuuuuuu wants to merge 1 commit into
2FastLabs:mainfrom
ZIFeIYUuuuuuu:fix/typescript-sse-headers

Conversation

@ZIFeIYUuuuuuu

Copy link
Copy Markdown

Summary

Fixes the remaining TypeScript sse compatibility path for #640.

MCPToolProvider now passes configured SSE headers through requestInit, which is the option shape consumed by the MCP SDK for both the SSE GET stream and the POST request. This keeps the legacy TypeScript path consistent with the already-correct v2 path and prevents authentication headers from being silently ignored.

Problem

For a TypeScript server configuration such as:

{
  type: "sse",
  url: "https://example.test/mcp",
  headers: { "x-api-key": "abc" },
}

the v1 compatibility branch constructed SSEClientTransport with { headers: ... } at the top level. SSEClientTransportOptions does not read that property; custom headers were therefore absent from the actual SSE requests and authenticated servers could not connect. The same configuration with no headers also passed an unnecessary { headers: {} } object.

Changes

  • Use requestInit: { headers } for configured SSE headers in the shared TypeScript path.
  • Pass undefined when no headers are configured, preserving the SDK defaults.
  • Add regression coverage for both configured and absent headers, including the URL and exact transport options.

Validation

  • npm test -- --runInBand tests/mcpToolProvider.test.ts: 35 passed.
  • The related MCP v2 and v2-partial suites were also run: 45/45 passed across the three focused suites.
  • npx eslint src/tools/mcpToolProvider.ts tests/mcpToolProvider.test.ts: passed.
  • npx tsc --noEmit: passed.
  • git diff --check: passed.
  • Full test run: 188 passed, 1 pre-existing failure in tests/storage/ChatStorage.test.ts (an order assertion unrelated to MCP transport options).

No API shape outside the TypeScript SSE transport construction is changed. The existing streamable-http and stdio paths remain unchanged.

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.

1 participant