Resume with EOF instead of throwing error when no data is received (#94)

This commit is contained in:
Mattt 2025-05-02 14:24:37 -07:00 • committed by GitHub
commit 2b67a1233f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,6 +168,11 @@ import struct Foundation.Data
while isConnected && !Task.isCancelled { while isConnected && !Task.isCancelled {
do { do {
let newData = try await receiveData() let newData = try await receiveData()
// Check for EOF (empty data)
if newData.isEmpty {
logger.info("Connection closed by peer (EOF).")
break // Exit loop gracefully
}
buffer.append(newData) buffer.append(newData)
// Process complete messages // Process complete messages
@ -219,8 +224,8 @@ import struct Foundation.Data
} else if let content = content { } else if let content = content {
continuation.resume(returning: content) continuation.resume(returning: content)
} else { } else {
continuation.resume( // EOF: Resume with empty data instead of throwing an error
throwing: MCPError.internalError("No data received")) continuation.resume(returning: Data())
} }
} }
} }