Skip to content

[P21] ci: stability tooling for 1.x - #350

Merged
jeanmatthieu merged 6 commits into
rel/1.0.0from
conformance/p21-stability
Nov 25, 2026
Merged

jeanmatthieu merged 6 commits into
rel/1.0.0from
conformance/p21-stability

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P21 of P0–P35, merged into rel/1.0.0 in order (previous: P20 (#351) · next: P22 (#349))
Branch conformance/p21-stability
Base conformance/p20-api (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits 9b0329e ci: stability tooling for 1.x
78582fc ci: review fixes
19bb5e5 ci: second-pass review fixes
5b61b01 server: reset the handshake state when the server stops
2bb29bb server: answer nothing for a stopped connection
3875c20 ci: third-pass review fixes
Size 75 files, +1512 / -126

Summary

What keeps 1.x stable: one manifest at Swift 6.1, a CI job that fails on a breaking API change
within the major, a doc comment on every public declaration, libFuzzer on the parsers and the
HTTP server transports, and a threat model. Fuzzing found a leak: every started Server was
kept alive; fixed here.

Changes

Swift 6.1

[email protected] is removed. main builds with Swift 6.0, but the stack no longer
does (a non-Sendable closure in Client.swift), and no CI job used 6.0. README, quick start,
DEPENDENCY_POLICY.md, CONTRIBUTING.md, CLAUDE.md, the design notes and the migration
guide say 6.1.

API breakage

scripts/ci/api-breakage.sh runs swift package diagnose-api-breaking-changes --products MCP
against the newest X.Y.Z tag with X >= 1 that is an ancestor of HEAD, and passes when
there is none (today). A jobs entry that gates and a GitHub job (macOS, full
history for the tags).

A stopped server is released

The default handlers and the cancellation handler are stored on the server and captured it
strongly, so a started server was never freed: an application with a server per session
leaked one per session. They capture it weakly. A test checks that a stopped server and client
are released; without the fix it fails. The bug is in main; the migration guide lists it
under the behavior changes.

Doc comments

scripts/doc-coverage.swift lists the public declarations in Sources/MCP without a ///
comment (skipping attributes, including multi-line ones; exempting Method plumbing). It found
275; each now has one, describing what the code does. The docs job runs it.

Fuzzing

Path What
fuzz/Package.swift A separate package of libFuzzer targets. Tools version 5.4: from 5.5 SwiftPM renames the entry point of executables, and libFuzzer brings its own main
fuzz/Sources/FuzzDecode Every wire type decodes the input and encodes back without crashing
fuzz/Sources/FuzzSSE ServerSentEventParser: a body below the line limit never fails, and a parser resumed from a copy after every byte gives the same events
fuzz/Sources/FuzzStatelessHTTP, FuzzStatefulHTTP The input as the body of a POST, after initialize for the stateful one; every answer has a valid status, and the previous input's server and transport must have been released
fuzz/corpus/ Seeds
scripts/ci/fuzz.sh Builds with -sanitize=fuzzer,address, runs each target (60 s by default); a crash input lands in .build/fuzz/artifacts/. Linux only; elsewhere it passes and says so
scripts/ci/jobs, ci.yml, scripts/ci-linux.sh A fuzz job that gates; GitHub keeps crash inputs; ci-linux.sh copies them out

LeakSanitizer is off: Swift stores pointers inside enum payloads (Data, for one) with spare
bits set, so it reports reachable globals (187 bytes, constant). The release check in the HTTP
targets replaces it; before the server fix LeakSanitizer reported 459 MB over 146 000 inputs,
and the release check fails at once.

Threat model

design/threat_model.md: trust boundaries, adversaries, each defense with its default bound
(validation pipeline, era confusion, cross-client isolation, requestState, Mcp-Param-*,
client-side bounds, OAuth URL and redirect rules), what the SDK leaves to the HTTP framework,
and how it is tested. design/design.md indexes it and linux.md.

API changes

None beyond the Swift 6.1 floor (breaking: in the migration guide).

Behavior changes

A stopped server is released (migration guide, "Server default handlers").

Tests

897 swift-testing tests plus 101 XCTest; 982 on Linux. Fuzzing on ubi9: about 210 000 inputs
for FuzzDecode, 140 000 for FuzzSSE, 130 000 for FuzzStatelessHTTP and 10 000 for
FuzzStatefulHTTP in 30 s each, no failure.

Verification


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.

What keeps 1.x stable: one manifest at Swift 6.1, a CI job that fails on
a breaking API change within the major, a doc comment on every public
declaration, libFuzzer on the parsers and the HTTP server transports,
and a threat model. Fuzzing found a leak: every started `Server` was
kept alive; fixed here.
- FuzzStatelessHTTP: the tools/call header set carries Mcp-Param-Region,
  so the tools-call seed reaches its handler instead of being refused
  with -32020; a new tools/list header set does the same for the
  tools-list seed, which lacked MCP-Protocol-Version.
- FuzzSSE copies the parser only at up to 8 offsets named by the input's
  first bytes, not at every byte, which made long lines quadratic; the
  header comment now says what the target does.
- fuzz.sh runs every target when one fails and fails at the end, naming
  the failed targets.
- api-breakage.sh unshallows a shallow clone before choosing the
  baseline and fails with a clear message when it cannot fetch the
  history and tags; outside a git checkout it says it skipped.
- Server registers its notifications/cancelled handler once, not on
  every start, so restarting a server no longer stacks handlers.
- Server.stop() cancels the request handlers still running, and those
  about to start, and the shared tools/list schema pass: their
  responses can no longer be sent.
- CONTRIBUTING.md and CLAUDE.md: `scripts/ci-linux.sh fuzz 300` ran the
  `fuzz` job with its default 60 s, because `fuzz` is a job id and `300`
  became a second id pattern. They run the job as is, or
  `scripts/ci-linux.sh -- scripts/ci/fuzz.sh <seconds>` for longer runs.
- api-breakage.sh: the default baseline is the newest release whatever
  major version HEAD develops, so a pull request that starts the next major
  version sets the job line to `api-breakage none` (or a ref) until X.0.0 is
  tagged. The message without a tag no longer says "1.x".
Server.stop() reset the per-connection request state but kept the
handshake: isInitialized, the client info and capabilities, the
negotiated protocol version and whether the connection served a
stateless request. A stopped and restarted server answered the next
handshake client's `initialize` with -32600 "Server is already
initialized", and would otherwise have reported the previous client's
info and capabilities. A handshake is per connection (2025-11-25
lifecycle, "Initialization"), so stop() now clears that state and the
next connection starts from a fresh `initialize`.

The stop() doc comment now says so. The new ServerLifecycleTests test
restarts a server between two handshake clients with different info and
capabilities; it fails without the fix.
Server.stop() set isInitialized to false and marked the requests not yet
registered as cancelled before it awaited the transport's disconnect(),
and cleared `connection` only afterwards. A request task spawned just
before stop() ran its pre-dispatch checks first: with
Configuration.strict it was refused with -32600 "Server is not
initialized", and the error went out on the transport that was
disconnecting, or on the next connection once start(transport:) had
attached one. A request still waiting for its HTTP context lost its
cancelled mark when the next connection reused its id, and then ran and
answered on that connection. A request to the client sent just before
stop() kept its id in unsentRequests, so its registration task, running
during the disconnect or after a restart, registered a continuation that
stop() had already drained and sent the request on the old transport:
requestSampling, requestElicitation and listRoots never returned.

stop() now increments a connection generation where it cancels the
handlers. The receive loop passes the generation of its connection to
handleRequest and handleBatch, and send(_:) records it for a request to
the client. handleRequest returns without answering when the generation
changed: at entry, in reject before any refusal is sent, after the await
for the HTTP context, and after the handler. handleBatch sends nothing
for a stopped connection. The registration task of a request to the
client fails it with -32603 "Server disconnected", the error stop()
gives the requests it drains. stop() clears startingRequests and
unsentRequests, and a stale request no longer removes entries of
startingRequests or pendingRequestTasks that may belong to the next
connection. stop() clears `connection` before it awaits disconnect(), so
nothing is sent on a transport that is disconnecting.

Three ServerLifecycleTests tests fail without the fix: a request held at
its HTTP context while the server restarts and the next connection
reuses its id; a strict batch whose second call is handled while stop()
disconnects; and requestSampling called while stop() disconnects.
- doc-coverage.swift: the `case` alternative of the declaration pattern
  could never match, because an enum case takes no access modifier, so
  enum cases were never checked. The script now finds the bodies of
  public enums by counting braces outside string literals and comments,
  and checks their `case` lines; the cases of private, internal and
  package enums (`CodingKeys`) and of `switch` statements are not
  checked. The 25 undocumented public cases (MCPError, Value,
  ProgressToken, InputResponse, Elicitation.RequestSchema.SchemaType,
  CreateElicitation.Result.Action, PrivateKeyJWTAssertionError) now
  have doc comments. CONTRIBUTING.md says cases are checked.
- doc-coverage.swift: the walk over attributes took any line ending in
  `)` or `,` within 8 lines below an `@` line for the end of a
  multi-line attribute, so a declaration after one with an attribute,
  such as `public static let b = Foo(rawValue: "b")` after an
  `@available` constant, borrowed that constant's doc comment. A line
  now ends an attribute only when its parentheses balance on the `@`
  line above it.
- fuzz: FuzzStatefulHTTP's only `tools/call` seed was a batch, which
  StatefulHTTPServerTransport refuses with 400 before the server reads
  it. The new seed tools-call.json is a single request; batch.json
  stays for the refusal path. FuzzDecode reuses one decoder and one
  encoder instead of creating them for each of its probes.
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/p20-api to rel/1.0.0 November 25, 2026 12:45
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:45

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 3b36b8c into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p21-stability branch November 25, 2026 12:45
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