Skip to content

Commit 7a6ddf9

Browse files
committed
Fix Bug modelcontextprotocol#6: Remove blocking await logger calls from response handlers
- Removed await logger?.trace() from handleResponse() (lines 689-692) - Removed await logger?.trace() from handleMessage() (lines 716-719) - Removed await logger?.trace() from handleBatchResponse() (lines 762-763) These calls were causing 10-second actor boundary crossing delays when processing tool call responses, causing callTool() to appear to hang. Replaced with NSLog() for immediate, non-blocking logging. This fixes the final blocker preventing MCP tool execution from working.
1 parent 614c251 commit 7a6ddf9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Sources/MCP/Client/Client.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,11 @@ public actor Client {
686686
// MARK: -
687687

688688
private func handleResponse(_ response: Response<AnyMethod>) async {
689-
await logger?.trace(
690-
"Processing response",
691-
metadata: ["id": "\(response.id)"])
689+
// REMOVED: await logger?.trace() - causes actor boundary crossing delay
690+
// await logger?.trace(
691+
// "Processing response",
692+
// metadata: ["id": "\(response.id)"])
693+
NSLog("🔵 CLIENT.handleResponse() for id: \(response.id)")
692694

693695
// Attempt to remove the pending request using the response ID.
694696
// Resume with the response only if it hadn't yet been removed.
@@ -711,9 +713,11 @@ public actor Client {
711713
}
712714

713715
private func handleMessage(_ message: Message<AnyNotification>) async {
714-
await logger?.trace(
715-
"Processing notification",
716-
metadata: ["method": "\(message.method)"])
716+
// REMOVED: await logger?.trace() - causes actor boundary crossing delay
717+
// await logger?.trace(
718+
// "Processing notification",
719+
// metadata: ["method": "\(message.method)"])
720+
NSLog("🔵 CLIENT.handleMessage() method: \(message.method)")
717721

718722
// Find notification handlers for this method
719723
guard let handlers = notificationHandlers[message.method] else { return }
@@ -755,7 +759,9 @@ public actor Client {
755759

756760
// Add handler for batch responses
757761
private func handleBatchResponse(_ responses: [AnyResponse]) async {
758-
await logger?.trace("Processing batch response", metadata: ["count": "\(responses.count)"])
762+
// REMOVED: await logger?.trace() - causes actor boundary crossing delay
763+
// await logger?.trace("Processing batch response", metadata: ["count": "\(responses.count)"])
764+
NSLog("🔵 CLIENT.handleBatchResponse() count: \(responses.count)")
759765
for response in responses {
760766
// Attempt to remove the pending request.
761767
// If successful, pendingRequest contains the request.

0 commit comments

Comments
 (0)