Skip to content

[P19] api: an extensibility promise for every public enum - #352

Merged
jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p19-enums
Nov 25, 2026
Merged

jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p19-enums

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P19 of P0–P35, merged into rel/1.0.0 in order (previous: P18 (#353) · next: P20 (#351))
Branch conformance/p19-enums
Base conformance/p18-linux (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits a8c6b2b api: an extensibility promise for every public enum
81cf167 api: review fixes
2ea587d api: second-pass review fixes
f5361de api: third-pass review fixes
Size 44 files, +1770 / -433

Summary

The package is built without library evolution, so adding a case to a public enum breaks every
exhaustive switch in client code. Before 1.0, each public enum gets one of three promises,
written on the type and in VERSIONING.md:

Kind Promise Types
Frozen enum no case is added in 1.x 19, each closed by an external definition (JSON-RPC, JSON, RFC 5424, OIDC, CSS) or by the SDK's structure
Enum with an unknown case no case is added in 1.x; a new kind arrives through unknown the four content-block enums, InputRequest, InputResponse, CreateElicitation.Parameters; MCPError through serverError
Open struct new static members in minors; a switch needs default OAuthAuthorizationError, GrantType, TokenEndpointAuthentication, PrivateKeyJWTSigningAlgorithm, BearerTokenValidationResult, Elicitation.Mode, ToolChoice.Mode

Motivation

The sets grew in every revision: tool content gained audio and resource_link, sampling
content tool_use and tool_result, elicitation the url mode, MCPError five codes,
OAuthAuthorizationError eight cases in this stack. An unknown content type failed decoding
of the whole result, so a 1.0 client would have failed tools/call against a server on a later
revision.

Changes

Open structs

  • OAuthAuthorizationError is a struct modeled on URLError: code (an open Code) and
    statusCode, oauthError, context, url, clientID, detail, expected, actual.
    Each former case is a static member, and the cases with values are static functions with the
    same labels. ~= matches by code, so catch OAuthAuthorizationError.tokenRequestFailed
    compiles unchanged.
  • GrantType and PrivateKeyJWTSigningAlgorithm are structs with a public rawValue;
    TokenEndpointAuthentication exposes clientID and methodName;
    BearerTokenValidationResult keeps its static constructors. Their initializers are internal:
    the SDK must implement a new grant, method or algorithm before it is usable.
  • Elicitation.Mode and ToolChoice.Mode are open RawRepresentable structs, so an unknown
    mode decodes.

Unknown kinds

  • .unknown(type:_:) on Tool.Content, Prompt.Message.Content,
    Sampling.Message.Content.ContentBlock and Sampling.ToolResultContent.ContentBlock: the
    block as received, encoded back unchanged (UnknownBlock.swift).
  • InputRequest.unknown(method:params:), fulfilled by the client handler registered for the
    method and forwarded by the server's bridge; InputResponse.unknown(_:);
    CreateElicitation.Parameters.unknown(mode:_:).
  • MCPError.Code, an open Int struct of the known codes, and MCPError.errorCode.

Documentation

VERSIONING.md gains "Enums and open types": the three kinds, the classification rules and
the type lists. Each frozen and catch-all enum says which it is. Migration guide and
design/design.md rows.

API changes

Breaking, in the migration guide: the seven types above are structs (exhaustive switch
statements need default; patterns that bind associated values do not compile); the seven
enums have a new unknown case; Mode(rawValue:) is not optional;
PrivateKeyJWTSigningAlgorithm(rawValue:) is not public.

Behavior changes

A result, request or elicitation of a kind the SDK does not know decodes instead of failing.

Tests

OAuthAuthorizationErrorTests, OpenTypeTests (every open struct round-trips an unknown
value), UnknownKindTests (every catch-all decodes and re-encodes an unknown kind byte for
byte; tools/call with an unknown block succeeds). 893 swift-testing tests plus 101 XCTest
at a8c6b2b.

Verification

The branch builds and passes swift test and weave --check. At a8c6b2b, on
macOS: every conformance leg, tier 100% at both revisions, interop --check. Baselines and
interop/RESULTS.md unchanged.


AI usage disclosure: the changes, the tests, the commit messages and this description were written with Claude Opus 5.5 and reviewed by the authors.

The package is built without library evolution, so adding a case to a
public enum breaks every exhaustive `switch` in client code. Before 1.0,
each public enum gets one of three promises, written on the type and in
`VERSIONING.md`:
- Require form elicitation for a form elicitation input request: a
  client that declared only URL elicitation now gets -32021 naming
  elicitation.form, at 2026-07-28 and in the handshake bridge. A
  declaration with neither sub-capability still counts as form, as the
  capability decoder reads it.
- Accept an elicitation of a mode the SDK does not know for any client
  that declares elicitation, instead of always refusing it, and name
  only elicitation, without form, in -32021 for a client without it.
- Decode an input response that has a roots, action, content or model
  key but does not decode as that kind as unknown, so a result of a
  later kind that reuses one of these keys no longer fails the
  parameters that carry it.
- Add BearerTokenValidationResult.tokenInfo, the BearerTokenInfo of a
  valid result and nil otherwise, so a result can be read back without
  making its outcome public.
- Decode unknown content blocks and unknown elicitation modes with
  strings as written (Value.Preserved), so a data: URL string inside
  one is forwarded byte for byte instead of as a base64 data: URL.
- Document on OAuthAuthorizationError's pattern operators and in the
  migration guide that a pattern built with values compiles and
  matches by code only; compare statusCode or oauthError in a where
  clause. Update the MRTR design note for both behavior changes.
- A 408 or 429 from the token endpoint during a refresh fails the request
  and keeps the stored tokens, as a 5xx or a network error does. Before,
  every 4xx counted as a refusal, so a timed-out or rate-limited refresh
  cleared a valid refresh token and started a new grant (a browser
  prompt for authorization_code). Other 4xx still count as a refusal:
  servers often answer an invalid client with 401 and no error member.
- Keep data: URL strings as written in input requests and responses.
  A plain Value decode turns such a string into .data, which encodes as
  a base64 data: URL, and several conversions went through one:
  InputRequest.params() used Value(_:), so a sampling prompt or an
  elicitation message "data:,hello" reached the client's handler
  rewritten; InputResponse.init(from:) decoded [String: Value] and
  re-encoded it, so a sampling text or a roots name was rewritten before
  the typed result was decoded; the params of an unknown input request,
  an unknown input response and the result of a bridged unknown request
  were kept as .data, not as received. params() now uses
  Value.preservingStrings, a known response decodes from the decoder
  itself (a Value field reads a data: URL once, as for any other type),
  unknown params and responses decode as Value.Preserved, and the
  handshake bridge reads an unknown request's result as Value.Preserved.
  A response built from a client handler's result keeps its strings too,
  so it is sent as the handler returned it.
- Correct UnknownBlock.decode's comment: an unknown block encodes back
  to the same JSON value, not byte for byte (key order and number
  formatting can change).
- Run the end-to-end half of the unknown elicitation mode test at both
  2026-07-28 and through the handshake bridge, and test an input request
  of an unknown method end to end, at both, through the client's handler
  for it.
varun06
varun06 previously approved these changes Nov 25, 2026

@varun06 varun06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looking good!!

Base automatically changed from conformance/p18-linux to rel/1.0.0 November 25, 2026 12:44
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:44

The base branch was changed.

@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 8916d32 into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p19-enums branch November 25, 2026 12:44
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