Description
I will prephrase my question by saying I am not sure at all that any of my findings are accurate.
I think I am seeing consistent failure of the client to handle responses due to 2 issues:
First of all it appears that we are passing response twice under
https://github.com/loopwork-ai/mcp-swift-sdk/blob/main/Sources/MCP/Client/Client.swift#L132-L133
Where instead we should be getting appropriate request from pandingRequests like so
if let response = try? decoder.decode(AnyResponse.self, from: data), let request = pendingRequests[response.id] {
await handleResponse(response, for: request)
} ...
Even fixing that locally downcast here https://github.com/loopwork-ai/mcp-swift-sdk/blob/main/Sources/MCP/Client/Client.swift#L329 fails
guard let typedRequest = request as? PendingRequest<Any> else { return }
Not sure if there is a way to tell Swift "don't worry about generic the original value was created with", it seem to consistently fail. Specifically I am debugging initialize sequence and so when I fix passing pending request, $ po request
prints MCP.Client.PendingRequest<MCP.Initialize.Result>)
, tho guard let typedRequest = request as? PendingRequest<Any> else { return }
fails
Any ideas if I am holding it wrong? or we might need to store type-erased pending requests instead of Any?