File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -362,6 +362,12 @@ public actor StdioTransport: Transport {
362362 messageContinuation. yield ( message)
363363 }
364364 }
365+ } catch let error as NWError {
366+ if !Task. isCancelled {
367+ logger. error ( " Network error occurred " , metadata: [ " error " : " \( error) " ] )
368+ messageContinuation. finish ( throwing: MCP . Error. transportError ( error) )
369+ }
370+ break
365371 } catch {
366372 if !Task. isCancelled {
367373 logger. error ( " Receive error: \( error) " )
@@ -375,7 +381,6 @@ public actor StdioTransport: Transport {
375381 }
376382
377383 private func receiveData( ) async throws -> Data {
378- // Use a local actor-isolated variable to track continuation state
379384 var receiveContinuationResumed = false
380385
381386 return try await withCheckedThrowingContinuation {
@@ -391,7 +396,13 @@ public actor StdioTransport: Transport {
391396 if !receiveContinuationResumed {
392397 receiveContinuationResumed = true
393398 if let error = error {
394- continuation. resume ( throwing: error)
399+ if let nwError = error as? NWError {
400+ continuation. resume ( throwing: MCP . Error. transportError ( nwError) )
401+ } else {
402+ continuation. resume (
403+ throwing: MCP . Error. internalError ( " Receive error: \( error) " )
404+ )
405+ }
395406 } else if let content = content {
396407 continuation. resume ( returning: content)
397408 } else {
You can’t perform that action at this time.
0 commit comments