Skip to content

Commit 3936ea8

Browse files
dcherreraclaude
andcommitted
Add extensive debugging to callTool and send methods
Added NSLog tracing throughout callTool() and send() to identify exact hang point in tool execution flow. Debugging points: - callTool() entry/exit - send() entry and continuation flow - Task creation inside continuation - addPendingRequest() call - connection.send() call and result 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a2291cc commit 3936ea8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Sources/MCP/Client/Client.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,27 +319,34 @@ public actor Client {
319319

320320
/// Send a request and receive its response
321321
public func send<M: Method>(_ request: Request<M>) async throws -> M.Result {
322+
NSLog("🔵 CLIENT.send() ENTRY - method: \(M.method), id: \(request.id)")
322323
guard let connection = connection else {
323324
throw MCPError.internalError("Client connection not initialized")
324325
}
325326

326327
let requestData = try encoder.encode(request)
328+
NSLog("🔵 CLIENT.send() - Encoded request, entering continuation")
327329

328330
// Store the pending request first
329331
return try await withCheckedThrowingContinuation { continuation in
332+
NSLog("🔵 CLIENT.send() - Inside continuation, creating Task")
330333
Task {
334+
NSLog("🔵 CLIENT.send() - Task started, adding pending request")
331335
// Add the pending request before attempting to send
332336
self.addPendingRequest(
333337
id: request.id,
334338
continuation: continuation,
335339
type: M.Result.self
336340
)
341+
NSLog("🔵 CLIENT.send() - Pending request added, calling connection.send()")
337342

338343
// Send the request data
339344
do {
340345
// Use the existing connection send
341346
try await connection.send(requestData)
347+
NSLog("🔵 CLIENT.send() - connection.send() succeeded")
342348
} catch {
349+
NSLog("🔵 CLIENT.send() - connection.send() failed: \(error)")
343350
// If send fails, try to remove the pending request.
344351
// Resume with the send error only if we successfully removed the request,
345352
// indicating the response handler hasn't processed it yet.
@@ -642,9 +649,13 @@ public actor Client {
642649
public func callTool(name: String, arguments: [String: Value]? = nil) async throws -> (
643650
content: [Tool.Content], isError: Bool?
644651
) {
652+
NSLog("🔵 CLIENT.callTool() ENTRY - tool: \(name)")
645653
try validateServerCapability(\.tools, "Tools")
654+
NSLog("🔵 CLIENT.callTool() - Creating request")
646655
let request = CallTool.request(.init(name: name, arguments: arguments))
656+
NSLog("🔵 CLIENT.callTool() - Calling send()")
647657
let result = try await send(request)
658+
NSLog("🔵 CLIENT.callTool() - send() RETURNED!")
648659
return (content: result.content, isError: result.isError)
649660
}
650661

0 commit comments

Comments
 (0)