Skip to content

Fix Windows build: gate EventSource/FoundationNetworking on canImport in HTTPClientTransport - #271

Open
lionheart-jhanke wants to merge 1 commit into
modelcontextprotocol:mainfrom
LionheartTechnology:windows-canimport-eventsource
Open

Fix Windows build: gate EventSource/FoundationNetworking on canImport in HTTPClientTransport#271
lionheart-jhanke wants to merge 1 commit into
modelcontextprotocol:mainfrom
LionheartTechnology:windows-canimport-eventsource

Conversation

@lionheart-jhanke

Copy link
Copy Markdown

Fixes #261.

Package.swift provides the EventSource product on Apple platforms only, but HTTPClientTransport.swift gates the import and the SSE code paths on #if !os(Linux). On Windows the import is compiled without the module being available, so any target depending on MCP fails with no such module 'EventSource'. (#261 has the full analysis; the guards drifted when #143 moved the platform logic into a .when(platforms:) condition.)

This keys the guards off availability instead of naming platforms, along the two axes that actually differ:

  • #if canImport(EventSource) for the import, the SSE listen loop, and connectToEventStream — on Apple and Linux this selects exactly the code selected today, because the manifest grants EventSource to all Apple platforms and denies it to Linux.
  • #if canImport(FoundationNetworking) for the session.data(for:) vs session.bytes(for:) split and the paired processResponse overloads — URLSession.AsyncBytes is a Darwin-Foundation capability, independent of EventSource, so this names the real dependency rather than folding it into the SSE guard. Selection today is likewise identical on Apple and Linux.
  • The two log messages that said "on Linux" now say "on this platform".

Windows takes the same graceful-degradation path Linux already takes: JSON request/response works, SSE streaming logs a warning and is skipped.

Verified: swift build --target MCP succeeds for x86_64-unknown-windows-msvc with Swift 6.3.3 (all 113 sources); before the patch it fails at HTTPClientTransport.swift:5. No selection change on Apple or Linux by construction, since each new condition is equivalent to the old one on those platforms.

🤖 Generated with Claude Code

…ntTransport

The package manifest already limits the EventSource dependency to Apple
platforms, but HTTPClientTransport.swift gates its import and the SSE
code paths on `#if !os(Linux)`. On any other non-Apple platform (e.g.
x86_64-windows-msvc) the module is absent yet the import is still
compiled, so the whole MCP target fails with:

    HTTPClientTransport.swift:5:12: error: no such module 'EventSource'

Gate on capabilities instead of naming Linux:

- `#if canImport(EventSource)` for the import, the SSE listen loop, and
  connectToEventStream -- selects exactly the same code on Apple and
  Linux as before
- `#if canImport(FoundationNetworking)` for the data(for:) vs bytes(for:)
  split and the matching processResponse overloads, since
  URLSession.AsyncBytes only exists in Darwin Foundation
- reword the two log messages that named Linux

No behavior change on Apple or Linux; the MCP target now compiles for
x86_64-unknown-windows-msvc (verified with Swift 6.3.3).
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.

HTTPClientTransport fails to build on Windows: #if !os(Linux) guards no longer match the EventSource platform condition

1 participant