Skip to content

Commit 2b67a12

Browse files
authored
Resume with EOF instead of throwing error when no data is received (#94)
1 parent 48c19c2 commit 2b67a12

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sources/MCP/Base/Transports/NetworkTransport.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ import struct Foundation.Data
168168
while isConnected && !Task.isCancelled {
169169
do {
170170
let newData = try await receiveData()
171+
// Check for EOF (empty data)
172+
if newData.isEmpty {
173+
logger.info("Connection closed by peer (EOF).")
174+
break // Exit loop gracefully
175+
}
171176
buffer.append(newData)
172177

173178
// Process complete messages
@@ -219,8 +224,8 @@ import struct Foundation.Data
219224
} else if let content = content {
220225
continuation.resume(returning: content)
221226
} else {
222-
continuation.resume(
223-
throwing: MCPError.internalError("No data received"))
227+
// EOF: Resume with empty data instead of throwing an error
228+
continuation.resume(returning: Data())
224229
}
225230
}
226231
}

0 commit comments

Comments
 (0)