Skip to content

Commit c5451f2

Browse files
dcherreraclaude
andcommitted
Fix Sendable constraint error - add tryRemovePendingRequest helper
The removePendingRequest() method returns AnyPendingRequest? which is not Sendable. This caused errors when calling from Task context in the timeout wrapper. Solution: Added tryRemovePendingRequest() that returns Bool instead, which is Sendable and allows us to check if removal succeeded across actor boundaries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1909f22 commit c5451f2

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/MCP/Client/Client.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public actor Client {
353353
// If send fails, try to remove the pending request.
354354
// Resume with the send error only if we successfully removed the request,
355355
// indicating the response handler hasn't processed it yet.
356-
if await self.removePendingRequest(id: request.id) != nil {
356+
if await self.tryRemovePendingRequest(id: request.id) {
357357
continuation.resume(throwing: error)
358358
}
359359
// Otherwise, the request was already removed by the response handler
@@ -378,7 +378,7 @@ public actor Client {
378378
return result
379379
} catch {
380380
// Clean up pending request on timeout
381-
_ = await self.removePendingRequest(id: request.id)
381+
await self.tryRemovePendingRequest(id: request.id)
382382
throw error
383383
}
384384
}
@@ -396,6 +396,17 @@ public actor Client {
396396
return pendingRequests.removeValue(forKey: id)
397397
}
398398

399+
private func hasPendingRequest(id: ID) -> Bool {
400+
return pendingRequests[id] != nil
401+
}
402+
403+
@discardableResult
404+
private func tryRemovePendingRequest(id: ID) -> Bool {
405+
let existed = pendingRequests[id] != nil
406+
pendingRequests.removeValue(forKey: id)
407+
return existed
408+
}
409+
399410
// MARK: - Batching
400411

401412
/// A batch of requests.

0 commit comments

Comments
 (0)