Repository navigation
[P19] api: an extensibility promise for every public enum - #352
Merged
Merged
Conversation
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.
This was referenced Nov 25, 2026
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.
rel/1.0.0in order (previous: P18 (#353) · next: P20 (#351))conformance/p19-enumsconformance/p18-linux(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)a8c6b2bapi: an extensibility promise for every public enum81cf167api: review fixes2ea587dapi: second-pass review fixesf5361deapi: third-pass review fixesSummary
The package is built without library evolution, so adding a case to a public enum breaks every
exhaustive
switchin client code. Before 1.0, each public enum gets one of three promises,written on the type and in
VERSIONING.md:unknowncaseunknownInputRequest,InputResponse,CreateElicitation.Parameters;MCPErrorthroughserverErrorswitchneedsdefaultOAuthAuthorizationError,GrantType,TokenEndpointAuthentication,PrivateKeyJWTSigningAlgorithm,BearerTokenValidationResult,Elicitation.Mode,ToolChoice.ModeMotivation
The sets grew in every revision: tool content gained
audioandresource_link, samplingcontent
tool_useandtool_result, elicitation theurlmode,MCPErrorfive codes,OAuthAuthorizationErroreight cases in this stack. An unknown contenttypefailed decodingof the whole result, so a 1.0 client would have failed
tools/callagainst a server on a laterrevision.
Changes
Open structs
OAuthAuthorizationErroris a struct modeled onURLError:code(an openCode) andstatusCode,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, socatch OAuthAuthorizationError.tokenRequestFailedcompiles unchanged.
GrantTypeandPrivateKeyJWTSigningAlgorithmare structs with a publicrawValue;TokenEndpointAuthenticationexposesclientIDandmethodName;BearerTokenValidationResultkeeps its static constructors. Their initializers are internal:the SDK must implement a new grant, method or algorithm before it is usable.
Elicitation.ModeandToolChoice.Modeare openRawRepresentablestructs, so an unknownmode decodes.
Unknown kinds
.unknown(type:_:)onTool.Content,Prompt.Message.Content,Sampling.Message.Content.ContentBlockandSampling.ToolResultContent.ContentBlock: theblock as received, encoded back unchanged (
UnknownBlock.swift).InputRequest.unknown(method:params:), fulfilled by the client handler registered for themethod and forwarded by the server's bridge;
InputResponse.unknown(_:);CreateElicitation.Parameters.unknown(mode:_:).MCPError.Code, an openIntstruct of the known codes, andMCPError.errorCode.Documentation
VERSIONING.mdgains "Enums and open types": the three kinds, the classification rules andthe type lists. Each frozen and catch-all enum says which it is. Migration guide and
design/design.mdrows.API changes
Breaking, in the migration guide: the seven types above are structs (exhaustive
switchstatements need
default; patterns that bind associated values do not compile); the sevenenums have a new
unknowncase;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 unknownvalue),
UnknownKindTests(every catch-all decodes and re-encodes an unknown kind byte forbyte;
tools/callwith an unknown block succeeds). 893 swift-testing tests plus 101 XCTestat
a8c6b2b.Verification
The branch builds and passes
swift testandweave --check. Ata8c6b2b, onmacOS: every conformance leg, tier 100% at both revisions,
interop --check. Baselines andinterop/RESULTS.mdunchanged.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.