@@ -298,31 +298,20 @@ public actor StdioTransport: Transport {
298298 throw MCP . Error. internalError ( " Failed to encode message " )
299299 }
300300
301- // Use a local actor-isolated variable to track continuation state
302- var sendContinuationResumed = false
303-
304301 try await withCheckedThrowingContinuation {
305- [ weak self] ( continuation: CheckedContinuation < Void , Swift . Error > ) in
306- guard let self = self else {
307- continuation. resume ( throwing: MCP . Error. internalError ( " Transport deallocated " ) )
308- return
309- }
310-
302+ @Sendable ( continuation: CheckedContinuation < Void , Swift . Error > ) in
311303 connection. send (
312304 content: data,
313- completion: . contentProcessed { [ weak self] error in
305+ completion: . contentProcessed { @ Sendable [ weak self] error in
314306 guard let self = self else { return }
315307
316- Task { @MainActor in
317- if !sendContinuationResumed {
318- sendContinuationResumed = true
319- if let error = error {
320- self . logger. error ( " Send error: \( error) " )
321- continuation. resume (
322- throwing: MCP . Error. internalError ( " Send error: \( error) " ) )
323- } else {
324- continuation. resume ( )
325- }
308+ Task {
309+ if let error = error {
310+ self . logger. error ( " Send error: \( error) " )
311+ continuation. resume (
312+ throwing: MCP . Error. internalError ( " Send error: \( error) " ) )
313+ } else {
314+ continuation. resume ( )
326315 }
327316 }
328317 } )
@@ -383,28 +372,19 @@ public actor StdioTransport: Transport {
383372 }
384373
385374 private func receiveData( ) async throws -> Data {
386- var receiveContinuationResumed = false
387-
388- return try await withCheckedThrowingContinuation {
389- [ weak self] ( continuation: CheckedContinuation < Data , Swift . Error > ) in
390- guard let self = self else {
391- continuation. resume ( throwing: MCP . Error. internalError ( " Transport deallocated " ) )
392- return
393- }
394-
375+ try await withCheckedThrowingContinuation {
376+ @Sendable ( continuation: CheckedContinuation < Data , Swift . Error > ) in
395377 connection. receive ( minimumIncompleteLength: 1 , maximumLength: 65536 ) {
378+ @Sendable
396379 content, _, _, error in
397- Task { @MainActor in
398- if !receiveContinuationResumed {
399- receiveContinuationResumed = true
400- if let error = error {
401- continuation. resume ( throwing: MCP . Error. transportError ( error) )
402- } else if let content = content {
403- continuation. resume ( returning: content)
404- } else {
405- continuation. resume (
406- throwing: MCP . Error. internalError ( " No data received " ) )
407- }
380+ Task {
381+ if let error = error {
382+ continuation. resume ( throwing: MCP . Error. transportError ( error) )
383+ } else if let content = content {
384+ continuation. resume ( returning: content)
385+ } else {
386+ continuation. resume (
387+ throwing: MCP . Error. internalError ( " No data received " ) )
408388 }
409389 }
410390 }
0 commit comments