TypeMismatchError unrecoverable when server response doesn't round-trip through CallTool.Result codable
I maintainer di solito rispondono entro 7 giorni
@EhsanAzish80 ci sta già lavorando.
Dal 24/9/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- swift
- Ambito
- api, backend-api-design
Direzione di ricerca
Start in Sources/MCP/Base/PendingRequest.swift at PendingRequest.AnyPendingRequest._resume and trace how the decoded Value is discarded when decoding CallTool.Result fails. Reproduce against @adeze/raindrop-mcp and inspect TypeMismatchError handling. Done should provide clients with enough underlying decoding or raw-response information to diagnose and recover from incompatible tools/call responses.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
PendingRequest.AnyPendingRequest._resume (in Sources/MCP/Base/PendingRequest.swift) throws TypeMismatchError() whenever the Value returned by the server can be encoded as JSON but the subsequent JSONDecoder().decode(T.self, from: ...) fails. When this happens with CallTool.Result, there is no way for client code to recover the raw response — the decoded Value is discarded before it reaches the client, and TypeMismatchError() carries no diagnostics (not even the underlying DecodingError, not even which key/path was missing).
This breaks interoperability with real MCP servers in the wild whose tools/call responses are "codable-close but not strictly compliant" with the Swift CallTool.Result shape (extra fields, slightly different casing, optional wrapping, etc.).
Reproduction
Client: swift-sdk 0.12.0 on macOS 26.
Server: @adeze/raindrop-mcp (stdio transport, npx -y @adeze/raindrop-mcp).
Request:
{ "method": "tools/call",
"params": { "name": "list_raindrops",
"arguments": {"collectionId": 0, "perPage": 3} } }
Every response decodes to TypeMismatchError(). Because the SDK doesn't surface the underlying DecodingError, downstream consumers cannot tell whether the issue is a missing content key, an unexpected extra field, a union-type mismatch inside Tool.Content, or something else entirely. We see only the opaque error string TypeMismatchError().
We tried several tools on the same server (list_raindrops, bookmark_search, collection_list) and all fail identically — the server is simply using a response shape the SDK rejects.
Why this matters
MCP is meant to be a cross-language/cross-vendor protocol. A Python server and a Swift client should be able to talk even when the server's Zod schema and the client's Codable model don't line up perfectly — at minimum the client should have enough information to recover, log, or surface the raw payload.
Today the Swift SDK is materially harder to use than the TypeScript or Python SDKs in these cases.
Proposed fix (any of)
-
Leak the
DecodingError: changeTypeMismatchErrorfrom a marker to an error that wrapsDecodingErrorand the rawValue. This alone would unblock debugging.struct TypeMismatchError: Error { let expected: Any.Type let underlying: Error let rawValue: Value } -
Expose a raw-response escape hatch on
Client:func callToolRaw(...) async throws -> Valuethat returns the protocol-levelValuewithout attempting to decode intoCallTool.Result. Downstream clients can implement lenient parsing themselves. -
Use
decodeIfPresent-style lenient decoding forCallTool.Resultso extra fields are ignored and optional fields can be missing. This is the TypeScript SDK behavior.
Option 1 is the cheapest and unblocks the most users — it's a couple of lines in PendingRequest.swift. Option 2 is the most flexible. Option 3 is the most user-friendly.
Workaround we're using
We catch the error by type name (errorType.contains(\"TypeMismatchError\")) and surface a generic "tool call decode failed" string to the end user. This is obviously fragile and hides the real bug.
Environment
- swift-sdk: 0.12.0
- Swift: 6.0, strict concurrency
- macOS: Tahoe 26.4
- Xcode: 26.4.1
- Project: trapias/EasyChat, see
Data/Services/MCP/MCPManager.swift
- Lingua principale
- Swift
- Stelle
- 1.5k
- Fork
- 249
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di modelcontextprotocol/swift-sdk
-
NetworkTransport leaks the underlying socket (CLOSE_WAIT) when reconnection is disabled and the receive loop terminatesForse già presa @skirrellyjones l’ha presa 31 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
modelcontextprotocol/swift-sdk#282 ·
I maintainer di solito rispondono entro 7 giorni
-
Value decoding changes data-URL-looking JSON strings into Value.dataForse già presa @bitbemol l’ha presa 41 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/swift-sdk#277 ·
I maintainer di solito rispondono entro 7 giorni
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
modelcontextprotocol/swift-sdk#274 ·
I maintainer di solito rispondono entro 7 giorni
-
`HTTPClientTransport` fails to build on Windows: `#if !os(Linux)` guards no longer match the `EventSource` platform conditionForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
modelcontextprotocol/swift-sdk#261 ·
I maintainer di solito rispondono entro 7 giorni
-
Value: add numberValue (Double?) that coerces .int and .doubleForse già presa @gsdali l’ha presa 153 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/swift-sdk#225 ·
I maintainer di solito rispondono entro 7 giorni
Tutte le issue di modelcontextprotocol/swift-sdk
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
DataDog/dd-sdk-ios#3293 ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug]: container logs -f exits immediately with no output when the container's log file is emptyAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
mozilla-mobile/firefox-ios#35996 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
wultra/ssl-pinning-ios#60 ·
-
fix: pre-push hook이 worktree에서 GIT_DIR을 상속해 SwiftPM 패키지 해석에 실패Forse già presa @zaehorang l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100