StdioTransport traps ("Negative value is not representable") when stdio is a socket, e.g. spawned by Node clients
Maintainers usually reply within 1 day
@branben is already working on this.
Since Nov 17, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 73/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- swift
- Domain
- backend-api-design
Research direction
Read Sources/MCP/Base/Transports/StdioTransport.swift around the reported lines in setNonBlocking(fileDescriptor:) and restoreFlags. The issue provides the proposed conversion and a reproducing Node socketpair scenario; add a socketpair regression test to verify the transport connects without trapping and run the relevant Swift tests. Done when socket-backed stdin/stdout no longer cause the negative-value trap.
Written by the indexing model from the issue text.
Description
Summary
Since #297 (merged 2026-10-31, on main, not in 0.12.1), StdioTransport.connect() traps when stdin/stdout is a socket:
Fatal error: Negative value is not representable
Node's child_process.spawn with stdio: 'pipe' uses socketpairs on macOS, and fstat on a socket reports st_dev == -1. dev_t is signed (Int32 on Darwin), so UInt64(status.st_dev) traps. Every Node-based MCP client hits this: Claude Desktop and Claude Code both report "Connection closed" right after initialize.
Affected lines: StdioTransport.swift L147, L159–160. Symbolicated crash: StdioTransport.setNonBlocking(fileDescriptor:) (StdioTransport.swift:147) ← StdioTransport.connect() ← Server.start(transport:).
Repro (macOS)
Build any server using StdioTransport(), then:
// node repro.js /path/to/server
const p = require("child_process").spawn(process.argv[2], [], { stdio: ["pipe", "pipe", "inherit"] });
p.on("exit", (c, s) => console.log("exit", c, s)); // → exit null SIGTRAP
p.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 0, method: "initialize",
params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "n", version: "1" } } }) + "\n");
Shell pipes don't reproduce it (st_dev == 0), which is why terminal testing passes:
$ python3 -c "import os,socket; a,_=socket.socketpair(); r,_=os.pipe(); print(os.fstat(a.fileno()).st_dev, os.fstat(r).st_dev)"
-1 0
Fix
Convert by bit pattern instead of value (the values are only compared for identity):
-flags: flags, device: UInt64(status.st_dev), inode: UInt64(status.st_ino))
+flags: flags, device: UInt64(truncatingIfNeeded: status.st_dev), inode: UInt64(truncatingIfNeeded: status.st_ino))
(and the same in restoreFlags). Patch with this change: https://github.com/noisyneighborstudio/swift-sdk/commit/b7a26b8d887fda9389a81f0c5feaa34e3d7e8ff7. Happy to open a PR with it plus a socketpair regression test.
- Dominant language
- Swift
- Stars
- 1.6k
- Forks
- 278
- Avg merge
- 11h 15m
- Merged PRs (30d)
- 46
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/swift-sdk
-
-32042 without elicitations drops JSON-RPC error dataPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
modelcontextprotocol/swift-sdk#381 ·
Maintainers usually reply within 1 day
-
Value decoding changes data-URL-looking JSON strings into Value.dataPossibly taken @bitbemol claimed this 89 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/swift-sdk#277 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 78/100
modelcontextprotocol/swift-sdk#274 ·
Maintainers usually reply within 1 day
-
`HTTPClientTransport` fails to build on Windows: `#if !os(Linux)` guards no longer match the `EventSource` platform conditionMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelcontextprotocol/swift-sdk#261 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
modelcontextprotocol/swift-sdk#376 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/swift-sdk
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
manaflow-ai/cmux#59692 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
App 仍在下载和解析用不上的会话列表Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
vibe-cafe/vibe-usage-app#125 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
touyou/CheckItOut#39 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
touyou/IntentTodo#232 ·
Maintainers usually reply within 1 day