File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Sources/MCP/Base/Transports Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments