@@ -23,7 +23,7 @@ public protocol Transport: Actor {
2323 func send( _ data: Data ) async throws
2424
2525 /// Receives data in an async sequence
26- func receive( ) -> AsyncThrowingStream < Data , Swift . Error >
26+ func receive( ) -> AsyncThrowingStream < Data , Error >
2727}
2828
2929/// Standard input/output transport implementation
@@ -74,11 +74,11 @@ public actor StdioTransport: Transport {
7474 private func setNonBlocking( fileDescriptor: FileDescriptor ) throws {
7575 let flags = fcntl ( fileDescriptor. rawValue, F_GETFL)
7676 guard flags >= 0 else {
77- throw Error . transportError ( Errno . badFileDescriptor)
77+ throw MCPError . transportError ( Errno . badFileDescriptor)
7878 }
7979 let result = fcntl ( fileDescriptor. rawValue, F_SETFL, flags | O_NONBLOCK)
8080 guard result >= 0 else {
81- throw Error . transportError ( Errno . badFileDescriptor)
81+ throw MCPError . transportError ( Errno . badFileDescriptor)
8282 }
8383 }
8484
@@ -110,7 +110,7 @@ public actor StdioTransport: Transport {
110110 messageContinuation. yield ( Data ( messageData) )
111111 }
112112 }
113- } catch let error where Error . isResourceTemporarilyUnavailable ( error) {
113+ } catch let error where MCPError . isResourceTemporarilyUnavailable ( error) {
114114 try ? await Task . sleep ( for: . milliseconds( 10 ) )
115115 continue
116116 } catch {
@@ -133,7 +133,7 @@ public actor StdioTransport: Transport {
133133
134134 public func send( _ message: Data ) async throws {
135135 guard isConnected else {
136- throw Error . transportError ( Errno . socketNotConnected)
136+ throw MCPError . transportError ( Errno . socketNotConnected)
137137 }
138138
139139 // Add newline as delimiter
@@ -149,16 +149,16 @@ public actor StdioTransport: Transport {
149149 if written > 0 {
150150 remaining = remaining. dropFirst ( written)
151151 }
152- } catch let error where Error . isResourceTemporarilyUnavailable ( error) {
152+ } catch let error where MCPError . isResourceTemporarilyUnavailable ( error) {
153153 try await Task . sleep ( for: . milliseconds( 10 ) )
154154 continue
155155 } catch {
156- throw Error . transportError ( error)
156+ throw MCPError . transportError ( error)
157157 }
158158 }
159159 }
160160
161- public func receive( ) -> AsyncThrowingStream < Data , Swift . Error > {
161+ public func receive( ) -> AsyncThrowingStream < Data , Error > {
162162 return AsyncThrowingStream { continuation in
163163 Task {
164164 for await message in messageStream {
@@ -179,8 +179,8 @@ public actor StdioTransport: Transport {
179179 public nonisolated let logger : Logger
180180
181181 private var isConnected = false
182- private let messageStream : AsyncThrowingStream < Data , Swift . Error >
183- private let messageContinuation : AsyncThrowingStream < Data , Swift . Error > . Continuation
182+ private let messageStream : AsyncThrowingStream < Data , Error >
183+ private let messageContinuation : AsyncThrowingStream < Data , Error > . Continuation
184184
185185 // Track connection state for continuations
186186 private var connectionContinuationResumed = false
@@ -195,7 +195,7 @@ public actor StdioTransport: Transport {
195195 )
196196
197197 // Create message stream
198- var continuation : AsyncThrowingStream < Data , Swift . Error > . Continuation !
198+ var continuation : AsyncThrowingStream < Data , Error > . Continuation !
199199 self . messageStream = AsyncThrowingStream { continuation = $0 }
200200 self . messageContinuation = continuation
201201 }
@@ -209,9 +209,9 @@ public actor StdioTransport: Transport {
209209
210210 // Wait for connection to be ready
211211 try await withCheckedThrowingContinuation {
212- [ weak self] ( continuation: CheckedContinuation < Void , Swift . Error > ) in
212+ [ weak self] ( continuation: CheckedContinuation < Void , Error > ) in
213213 guard let self = self else {
214- continuation. resume ( throwing: MCP . Error . internalError ( " Transport deallocated " ) )
214+ continuation. resume ( throwing: MCPError . internalError ( " Transport deallocated " ) )
215215 return
216216 }
217217
@@ -245,7 +245,7 @@ public actor StdioTransport: Transport {
245245 }
246246 }
247247
248- private func handleConnectionReady( continuation: CheckedContinuation < Void , Swift . Error > )
248+ private func handleConnectionReady( continuation: CheckedContinuation < Void , Error > )
249249 async
250250 {
251251 if !connectionContinuationResumed {
@@ -259,7 +259,7 @@ public actor StdioTransport: Transport {
259259 }
260260
261261 private func handleConnectionFailed(
262- error: Swift . Error , continuation: CheckedContinuation < Void , Swift . Error >
262+ error: Error , continuation: CheckedContinuation < Void , Error >
263263 ) async {
264264 if !connectionContinuationResumed {
265265 connectionContinuationResumed = true
@@ -268,13 +268,13 @@ public actor StdioTransport: Transport {
268268 }
269269 }
270270
271- private func handleConnectionCancelled( continuation: CheckedContinuation < Void , Swift . Error > )
271+ private func handleConnectionCancelled( continuation: CheckedContinuation < Void , Error > )
272272 async
273273 {
274274 if !connectionContinuationResumed {
275275 connectionContinuationResumed = true
276276 logger. warning ( " Connection cancelled " )
277- continuation. resume ( throwing: MCP . Error . internalError ( " Connection cancelled " ) )
277+ continuation. resume ( throwing: MCPError . internalError ( " Connection cancelled " ) )
278278 }
279279 }
280280
@@ -288,7 +288,7 @@ public actor StdioTransport: Transport {
288288
289289 public func send( _ message: Data ) async throws {
290290 guard isConnected else {
291- throw MCP . Error . internalError ( " Transport not connected " )
291+ throw MCPError . internalError ( " Transport not connected " )
292292 }
293293
294294 // Add newline as delimiter
@@ -299,9 +299,9 @@ public actor StdioTransport: Transport {
299299 var sendContinuationResumed = false
300300
301301 try await withCheckedThrowingContinuation {
302- [ weak self] ( continuation: CheckedContinuation < Void , Swift . Error > ) in
302+ [ weak self] ( continuation: CheckedContinuation < Void , Error > ) in
303303 guard let self = self else {
304- continuation. resume ( throwing: MCP . Error . internalError ( " Transport deallocated " ) )
304+ continuation. resume ( throwing: MCPError . internalError ( " Transport deallocated " ) )
305305 return
306306 }
307307
@@ -316,7 +316,7 @@ public actor StdioTransport: Transport {
316316 if let error = error {
317317 self . logger. error ( " Send error: \( error) " )
318318 continuation. resume (
319- throwing: MCP . Error . internalError ( " Send error: \( error) " ) )
319+ throwing: MCPError . internalError ( " Send error: \( error) " ) )
320320 } else {
321321 continuation. resume ( )
322322 }
@@ -326,7 +326,7 @@ public actor StdioTransport: Transport {
326326 }
327327 }
328328
329- public func receive( ) -> AsyncThrowingStream < Data , Swift . Error > {
329+ public func receive( ) -> AsyncThrowingStream < Data , Error > {
330330 return AsyncThrowingStream { continuation in
331331 Task {
332332 do {
@@ -363,7 +363,7 @@ public actor StdioTransport: Transport {
363363 } catch let error as NWError {
364364 if !Task. isCancelled {
365365 logger. error ( " Network error occurred " , metadata: [ " error " : " \( error) " ] )
366- messageContinuation. finish ( throwing: MCP . Error . transportError ( error) )
366+ messageContinuation. finish ( throwing: MCPError . transportError ( error) )
367367 }
368368 break
369369 } catch {
@@ -382,9 +382,9 @@ public actor StdioTransport: Transport {
382382 var receiveContinuationResumed = false
383383
384384 return try await withCheckedThrowingContinuation {
385- [ weak self] ( continuation: CheckedContinuation < Data , Swift . Error > ) in
385+ [ weak self] ( continuation: CheckedContinuation < Data , Error > ) in
386386 guard let self = self else {
387- continuation. resume ( throwing: MCP . Error . internalError ( " Transport deallocated " ) )
387+ continuation. resume ( throwing: MCPError . internalError ( " Transport deallocated " ) )
388388 return
389389 }
390390
@@ -394,12 +394,12 @@ public actor StdioTransport: Transport {
394394 if !receiveContinuationResumed {
395395 receiveContinuationResumed = true
396396 if let error = error {
397- continuation. resume ( throwing: MCP . Error . transportError ( error) )
397+ continuation. resume ( throwing: MCPError . transportError ( error) )
398398 } else if let content = content {
399399 continuation. resume ( returning: content)
400400 } else {
401401 continuation. resume (
402- throwing: MCP . Error . internalError ( " No data received " ) )
402+ throwing: MCPError . internalError ( " No data received " ) )
403403 }
404404 }
405405 }
0 commit comments