fix: preserve data-URL-looking JSON strings - #278
Open
bitbemol wants to merge 2 commits into
Open
Conversation
ianegordon
added a commit
to ianegordon/swift-sdk
that referenced
this pull request
Sep 11, 2026
The change is correct — Value.init(_:) only ever encodes its argument, so the Codable constraint is over-tight — but it fixes no bug, and unlike every other entry in the manifest its absence upstream is a compile error rather than a runtime fault. Fork code passing an Encodable-only type would not build against upstream unless modelcontextprotocol#227 lands there, turning the return this fork exists to make easy into a build break. No downstream needs the looser constraint today. Moved from the candidate table to 'Not included, and why'. Remaining candidates renumbered 7-10 to 6-9 so the intended order still continues the manifest sequence. modelcontextprotocol#278's note no longer calls itself the second Value.swift edit in the batch, since modelcontextprotocol#227 was the first. Tracking: fork issue #13, relabelled decline. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eb9yGSXH1TVkg5Afsu9phk
ianegordon
added a commit
to ianegordon/swift-sdk
that referenced
this pull request
Sep 11, 2026
… as entry 7a
Client.Capabilities.experimental was [String: String] where the 2025-11-25
schema defines a map of arbitrary objects, so a ChatGPT-shaped initialize
carrying {"openai/visibility": {"enabled": true}} failed to decode and the
server answered -32603 to a valid request. Reproduced on the wire before the
merge and confirmed fixed after.
The entry records what the PR description understates: the type change is
source-breaking for a typed [String: String] variable and for reading a value
back as String, and the extensions field it adds is a draft-schema capability
absent from 2025-11-25 — an unmodeled key already decoded fine, so that half
is a feature rather than a fix.
7a restores the typed-variable call site behind a deprecation warning. The
read direction cannot be shimmed by an initializer and still needs updating
downstream.
Remaining candidate modelcontextprotocol#278 renumbered 7 to 6.
Tracking: fork issue #11.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Eb9yGSXH1TVkg5Afsu9phk
ianegordon
added a commit
to ianegordon/swift-sdk
that referenced
this pull request
Sep 11, 2026
…ontextprotocol#278, bitbemol) Manifest entry 8. Upstream refs/pull/278/head at af48e3f, unmodified. Value.init(from:) treated any parseable data-URL-looking JSON string as Value.data, silently changing both the case and the string's spelling. Content explicitly tagged as MCP text was corrupted on round trip: data:text/plain,Hello%20World came back as data:text/plain;base64,SGVsbG8gV29ybGQ=. Generic JSON carries no discriminator, and the spec tags content explicitly (TextContent.type is const "text"), so the decoder had no business guessing. The string branch now always produces .string. Data.isDataURL(string:) and Data.parseDataURL(_:) remain public for callers that want to opt in, and explicit Value.data encoding is unchanged. Verified by running the PR's own tests against the unpatched tree first: six of eight fail there, including typed text content corruption, and all eight pass after the merge. Behavior change, not a source break: no API signature moves, so fork code calling parseDataURL explicitly still compiles and behaves identically against upstream. Note Value.data is now round-trip-asymmetric — it encodes as a data URL but decodes back as .string, which the PR pins with a test. The unrelated NetworkTransport capture-list hunk (Task { @mainactor [self] in) is behaviorally inert and emits no warning on this toolchain; left as authored, review feedback for upstream. Fixes modelcontextprotocol#277. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eb9yGSXH1TVkg5Afsu9phk
ianegordon
added a commit
to ianegordon/swift-sdk
that referenced
this pull request
Sep 11, 2026
…mple to 0.12.2-ianegordon.8 Value.init(from:) treated any parseable data-URL-looking JSON string as Value.data, silently changing both the case and the string's spelling. Content explicitly tagged as MCP text was corrupted on round trip. The entry records the measured before/after (the PR's own tests fail six of eight against the unpatched tree, all eight pass after), that this is a behavior change rather than a source break with no return trap, and two caveats: Value.data is now round-trip-asymmetric, and the unrelated NetworkTransport capture-list hunk is inert and left as authored. The candidate table is now empty. Its section and header are kept, with a note that the next candidates come from the twelve upstream PRs triaged Investigate under the investigate label. Tracking: fork issue #12. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eb9yGSXH1TVkg5Afsu9phk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #277.
Preserves JSON strings decoded through
Valueas.string, including strings that match data-URL syntax. ExplicitValue.dataencoding and the data-URL helper APIs remain available, and the public API documentation now clarifies that parsing is opt-in.Motivation and Context
Value.init(from:)currently interprets any parseable data-URL-looking JSON string as.data. Because generic JSON contains no discriminator between an ordinary string and an encodedValue.data, this can silently change both theValuecase and the string's spelling.For example:
This can also affect content explicitly tagged as MCP text when it passes through generic
Valueconversion.The change makes the string branch of
Value.init(from:)always produce.string. Applications that intentionally accept data URLs can continue to opt in throughData.parseDataURL(_:), while explicitly constructedValue.datavalues retain their existing encoding.How Has This Been Tested?
Added regression coverage for:
application/octet-streamdata-URL-looking stringsValue.dataencoding.datadiscriminator on the generic JSON wireValueerasureVerification performed:
swift test --filter ValueTests: 8/8 tests passedgit diff --check: cleanThe regression tests were also run against the previous decoder implementation to confirm that they reproduce the reported behavior.
Breaking Changes
This intentionally changes observable behavior for callers that relied on generic
Valuedecoding to automatically convert data-URL-looking JSON strings into.data.Those callers will need to explicitly call
Data.parseDataURL(_:)in fields where data URLs are expected. Encoding an explicitly constructedValue.dataremains unchanged, as does typed image and audio content serialization.Types of changes
Checklist
Additional context
This behavior was encountered in bitbemol/second-brain-mcp, which currently vendors the patched SDK pending an upstream resolution.
This is my first contribution to
swift-sdk. I may be missing context behind the original implicit decoding behavior and am happy to adjust the approach based on maintainer feedback.AI assistance disclosure: This bug was initially identified with LLM assistance, and Codex assisted with implementation analysis and regression-test development. I personally reviewed the relevant SDK behavior, reproduced the failure in Xcode with the previous decoder, and verified the fix with the complete test suite.