Skip to content

docs: Say that an unknown block keeps its JSON value, not its bytes - #403

Merged
jeanmatthieu merged 2 commits into
rel/1.0.0from
docs/unknown-encoding
Nov 29, 2026
Merged

jeanmatthieu merged 2 commits into
rel/1.0.0from
docs/unknown-encoding

Conversation

@jeanmatthieu

Copy link
Copy Markdown
Contributor

Motivation and Context

The .unknown cases on Tool.Content, Prompt.Message.Content, the two sampling content blocks and CreateElicitation.Parameters promised that the block "is encoded as received", and the migration guide's "Unknown kinds" section said the same. UnknownBlock decodes the block into Value and 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.

  • The doc comments now say the block encodes back to the same JSON value, except that a number is read as an Int or a Double, so one outside their range or precision is rounded (12345678901234567890 comes back as 1.2345678901234567e+19). The bytes can differ: key order, whitespace, string escapes and number formatting may change (1.0 is written 1, \u00e9 comes back as é). The internal UnknownBlock comment says the same.
  • The migration paragraph now speaks for unknown blocks and elicitation params only, and names the exception: an unknown InputRequest is written back with only its method and params, and with "params": {} when it had none (or had "params": null).
  • The test that said "re-encoded as received" is renamed.

How Has This Been Tested?

Doc comments and docs, plus one test. The new test in UnknownKindTests pins the documented InputRequest behavior: a request without params, and one with "params": null and an extra top-level key, both come back as {"method":…,"params":{}}. swift test --filter UnknownKindTests, swift scripts/weave.swift --check and swift package generate-documentation --target MCP --warnings-as-errors pass.

Breaking Changes

None. No behavior changes.

Types of changes

  • Documentation update

Written with AI assistance and reviewed by a human.

alexbull and others added 2 commits November 29, 2026 15:47
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.
@jeanmatthieu
jeanmatthieu requested a review from a team as a code owner November 29, 2026 15:48

@canarik canarik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jeanmatthieu

@jeanmatthieu
jeanmatthieu merged commit c14df3a into rel/1.0.0 Nov 29, 2026
14 checks passed
@jeanmatthieu
jeanmatthieu deleted the docs/unknown-encoding branch November 29, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants