Skip to content

Fix Windows builds: guard EventSource usage in HTTPClientTransport - #279

Open
onetamer wants to merge 4 commits into
modelcontextprotocol:mainfrom
onetamer:windows-eventsource-guard
Open

onetamer wants to merge 4 commits into
modelcontextprotocol:mainfrom
onetamer:windows-eventsource-guard

Conversation

@onetamer

Copy link
Copy Markdown

Problem

Package.swift provides the EventSource product to the MCP target only on Apple platforms:

.product(
    name: "EventSource", package: "eventsource",
    condition: .when(platforms: [.macOS, .iOS, .tvOS, .visionOS, .watchOS, .macCatalyst])),

but HTTPClientTransport.swift imports and uses it behind #if !os(Linux). Any Windows build of the SDK therefore fails with:

error: no such module 'EventSource'

Fix

Widen every EventSource-related guard in HTTPClientTransport.swift from os(Linux) to os(Linux) || os(Windows). Windows takes the same buffered (non-streaming) HTTP response path Linux already takes, and an SSE streaming request logs the same "not fully supported" warning instead of attempting an EventSource connection.

No behavior change on any platform that built before.

Verification

  • swift build on macOS: unchanged, green.
  • swift build on Windows 11 ARM64 (Swift 6.3.3): the MCP target builds with this patch applied; without it, the build fails as above. We (CopyBucket) have been shipping a production Windows MCP server against 0.12.1 with exactly this diff applied as a vendored patch since 2026-08.

Package.swift provides the EventSource product only on Apple platforms
(condition: .when(platforms: [.macOS, .iOS, ...])), but
HTTPClientTransport.swift imports and uses it behind #if !os(Linux),
so any Windows build of the MCP target fails with
"no such module 'EventSource'".

Widen every EventSource-related guard from os(Linux) to
os(Linux) || os(Windows): Windows takes the same buffered
(non-streaming) HTTP path Linux already takes, and SSE streaming is
reported unsupported the same way.
ianegordon added a commit to ianegordon/swift-sdk that referenced this pull request Sep 11, 2026
The Windows build failure is real — Package.swift provides EventSource
only on Apple platforms while HTTPClientTransport.swift imports it behind
#if !os(Linux) — and widening the five guards to os(Linux) || os(Windows)
is the obvious fix. It is inert on macOS and Linux by inspection.

But that it actually fixes Windows cannot be verified here: no Windows
machine, and ci.yml runs macos-latest and ubuntu-latest only. Windows is
low priority for this fork's downstreams, so an unverifiable patch is not
worth the divergence.

Cheap to reverse if that changes: unlike modelcontextprotocol#227, this cannot make fork code
fail to build against upstream.

Moved from the candidate table to 'Not included, and why'. Remaining
candidates renumbered 7-9 to 6-8 so the intended order still continues
the manifest sequence.

Tracking: fork issue #9, relabelled decline.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Eb9yGSXH1TVkg5Afsu9phk
@varun06

varun06 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Hi @onetamer, thanks for this PR! I've reviewed it and it looks good to merge.

Could you please rebase it onto the latest main? CI was broken on macOS runners for every PR (a toolchain/SDK mismatch, fixed in #306), so rebasing will pick up the fix and give us a green run. I'll review and merge once it's updated.

Optional nit while you're in there: #if canImport(EventSource) would track the Package.swift platform condition automatically instead of listing OSes.

If you're no longer able to work on this, no problem: just let us know. If we don't hear back in about two weeks, we may carry the change forward in a new PR, with credit to you.

@varun06
varun06 requested a review from a team as a code owner October 24, 2026 13:49
Replace the per-OS conditions with #if canImport(EventSource) so the
guards track the EventSource platform condition in Package.swift
automatically (review suggestion). The warning no longer names Linux:
it fires on any platform without EventSource.

Verified: swift build on macOS 26.5.2 / Xcode 26.5 / Swift 6.3.2 (the
EventSource path), swift build --target MCP on Windows 11 ARM64 /
Swift 6.3.3 (the buffered path).
@onetamer
onetamer force-pushed the windows-eventsource-guard branch from c284efc to 8cd82e9 Compare October 27, 2026 04:23
@onetamer

Copy link
Copy Markdown
Author

Thanks for the review and for merging main in, @varun06. I've taken the nit: the guards are now #if canImport(EventSource) / #if !canImport(EventSource) (8cd82e9), so they follow the Package.swift platform condition instead of naming OSes, and the warning no longer says "on Linux" since it fires on any platform without EventSource. I also merged the current main (869052e) since it had moved again.

Verified with swift build on macOS 26.5.2 (Xcode 26.5, Swift 6.3.2 — the EventSource path) and swift build --target MCP on Windows 11 ARM64 with Swift 6.3.3 (the buffered path). Ready for another look whenever you are. #280 (the Windows StdioTransport) builds on this one; I'll rebase it once this lands.

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.

2 participants