Repository navigation
docs: Say that an unknown block keeps its JSON value, not its bytes - #403
Merged
Merged
Conversation
The `.unknown` cases on the content blocks and `CreateElicitation.Parameters` said the block "is encoded as received", and the migration guide said the same. `UnknownBlock` decodes into `Value` and re-encodes it, so key order and number formatting can change (`1.0` is written `1`). Anyone who signs, hashes or byte-compares a block passed through needs to know that.
Review follow-up. "The same JSON value" was too strong: `Value.Preserved`
reads a number as an `Int`, then a `Double`, so an integer outside the
`Int` range or a decimal beyond `Double` precision is rounded on the way
back. The list of byte-level changes also left out whitespace and string
escapes (`\u00e9` comes back as `é`, and the client's `JSONEncoder` writes
`/` as `\/`).
The migration paragraph spoke for every unknown kind, but an unknown
`InputRequest` keeps only `method` and `params`, and a request without
`params` (or with `"params": null`) goes back out with `"params": {}`.
It now names blocks and elicitation `params`, and states that exception.
A test pins it, and the test that said "re-encoded as received" is renamed.
Written with AI assistance and reviewed by a human.
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.
Motivation and Context
The
.unknowncases onTool.Content,Prompt.Message.Content, the two sampling content blocks andCreateElicitation.Parameterspromised that the block "is encoded as received", and the migration guide's "Unknown kinds" section said the same.UnknownBlockdecodes the block intoValueand re-encodes it, so neither the bytes nor every number survive. Anyone who signs, hashes or byte-compares a block they pass through needs to know that.Intor aDouble, so one outside their range or precision is rounded (12345678901234567890comes back as1.2345678901234567e+19). The bytes can differ: key order, whitespace, string escapes and number formatting may change (1.0is written1,\u00e9comes back asé). The internalUnknownBlockcomment says the same.paramsonly, and names the exception: an unknownInputRequestis written back with only itsmethodandparams, and with"params": {}when it had none (or had"params": null).How Has This Been Tested?
Doc comments and docs, plus one test. The new test in
UnknownKindTestspins the documentedInputRequestbehavior: a request withoutparams, and one with"params": nulland an extra top-level key, both come back as{"method":…,"params":{}}.swift test --filter UnknownKindTests,swift scripts/weave.swift --checkandswift package generate-documentation --target MCP --warnings-as-errorspass.Breaking Changes
None. No behavior changes.
Types of changes
Written with AI assistance and reviewed by a human.