Skip to content

[P10] docs: go-sdk layout, feature guides, design notes and process docs - #362

Merged
jeanmatthieu merged 5 commits into
rel/1.0.0from
conformance/p10-docs
Nov 25, 2026
Merged

jeanmatthieu merged 5 commits into
rel/1.0.0from
conformance/p10-docs

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P10 of P0–P35, merged into rel/1.0.0 in order (previous: P8 (#363) · next: P9 (#361))
Branch conformance/p10-docs
Base conformance/p8-oauth (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits d2efd2e docs: go-sdk layout, feature guides, design notes and process docs
a25ba95 docs: review fixes
90a0bb7 docs: second-pass review fixes
d072eb5 docs: custom transports receive request headers through send(_:additionalHeaders:)
3f53229 docs: third-pass review fixes
Size 89 files, +15125 / -2193

Summary

Reorganizes the repository after go-sdk and writes the documentation to the same depth: a feature-by-feature guide set in docs/ that follows the specification, design notes in design/, process documents at the root, and runnable examples. Every code block in the guides is copied from compiled, tested sources under Examples/Snippets by scripts/weave.swift, and CI fails when the generated docs drift. The root README shrinks from 1,950 to 161 lines and is generated the same way. The guides and design notes describe the SDK as of P8 (#363), including the review fixes of P3 (#368) to P8 (#363) (automatic fallback, header parameter checks, listen streams, MRTR bounds, OAuth concurrency) and the conformance runner changes of P0 (#371). No public API changes. It also documents the client transport changes of P1 (#370) and P4 (#367), and adds CLAUDE.md, guidance for coding agents. A review fix bounds sessions and request bodies in the HTTP example, binds its Host and Origin checks to its port, and replaces the advice to disable the Origin check behind a proxy.

Motivation

  • Requested scope: copy go-sdk's structure and write documentation of the same depth (go-sdk has about 4,400 lines: an index mirroring the spec, protocol.md, server.md, client.md, quick start, troubleshooting, rough edges, design notes, examples, generated from sources with compiled snippets). Python's docs add migration, protocol versions, testing, header parameters, subscriptions and multi round-trip topics.
  • The single 1,950-line README described the 2025-11-25 SDK and could not cover both protocol eras, the stateless transport, SEP-2243 headers, subscriptions/listen, MRTR and the OAuth changes of P3 ([P3] server: serve 2026-07-28 stateless requests #368) to P8 ([P8] oauth: issuer checks, application_type, AS migration (SEP-2468/837/2352) #363).
  • Order change: this PR runs before the default flip (P9 ([P9] versions: make 2026-07-28 the client default #361)). The process docs (ROADMAP, VERSIONING, DEPENDENCY_POLICY, CONTRIBUTING triage, migration guide) moved here from the flip, so the flip only changes the defaults and the few doc lines that state them.
  • The HTTP example is the template the guides point to for routing both eras on one endpoint, so it has to carry the limits a deployed router needs.

Changes

Layout (d2efd2e)

  • Baselines move to conformance/baseline.yml, conformance/baseline.2025-11-25.yml, conformance/baseline.2026-07-28.yml (content unchanged). scripts/run-conformance.sh reads them there.
  • Fixture sources move from Sources/MCPConformance/{Server,Client} to conformance/everything-{server,client}. Target and product names (mcp-everything-server, mcp-everything-client) are unchanged.
  • Package.swift adds an examples target list, none of them a product: QuickStartSnippets, ServerSnippets, ClientSnippets, ProtocolSnippets, GuidesSnippets (paths Examples/Snippets/<Name>), the SnippetTests test target (Examples/Tests), and the executables HelloServer, HelloClient, HTTPServerExample.
  • New scripts/weave.swift (see Diagram).

Documentation (d2efd2e)

Path Contents
docs/README.md Index in spec order: base protocol, server features, client features, testing and troubleshooting, backwards compatibility, links to examples, design and process docs
docs/quick_start.md stdio server and client, then HTTP
docs/protocol.md Lifecycle (initialize, server/discover, _meta), transports, notification streams, authorization, security, utilities
docs/server.md Tools, prompts, resources, list-changed notifications, MRTR, requests to the client, cacheable results, completion, logging, handler context, capabilities, pagination, lifecycle
docs/client.md Connecting, tools, prompts/resources/completions, roots, sampling, elicitation, MRTR, notifications and subscriptions, logging, cancellation and progress, batching, capabilities, errors
docs/protocol_versions.md The two eras, version lists, protocol modes, per-version feature table
docs/migration.md Breaking changes, behavior changes and new opt-in features of this major version
docs/testing.md, docs/troubleshooting.md In-memory pairs, HTTP without sockets, the conformance runner; common errors and their causes
docs/rough_edges.md API decisions kept for compatibility, the defaults that P9 (#361) changes, what is not implemented
docs/src/*.src.md Sources of all of the above; the .md files are generated
design/design.md Package structure, concurrency model, transports, JSON-RPC types, dual-era model, error model, handler registration, breaking changes, alternatives
design/{stateless,request_headers,subscriptions,mrtr,auth}.md One note per feature: context, goals, design, alternatives, open questions
ROADMAP.md Revisions supported, what is implemented, deferred items, the remaining release step, conformance status
VERSIONING.md Semver rules, public API definition, how spec revisions map to releases, support window, deprecation
DEPENDENCY_POLICY.md Current dependencies and where they are used, criteria for new ones, version ranges, platform floors
CONTRIBUTING.md Setup, build and test, conformance and docs workflows, triage labels, priorities and response times
conformance/README.md Legs and baselines, running one scenario
README.src.md Source of the root README.md (161 lines): eras, requirements, installation, a 30-line server, docs links, layout
Sources/MCP/MCP.docc/MCP.md DocC landing article that links to docs/ and groups the main symbols

Fixes made lower in the stack (P0 (#371), P3 (#368) to P8 (#363)), as the guides and design notes describe them:

  • Protocol modes (protocol_versions, client, protocol, troubleshooting, design/stateless.md): .automatic falls back to initialize on a JSON-RPC error, an HTTP 400/404/405 refusal or no answer within discoveryTimeout, and rethrows other transport errors; .stateless(v) never retries with another version; protocolVersions: Version.stateless refuses initialize with -32022 without a handler replacement; saved configurations decode with missing keys (the migration-configuration-decoding snippet is gone).
  • Header parameters (protocol, server, troubleshooting): schemas read once and kept until ToolListChangedNotification, fail-closed checks, 64 annotations and 32 levels of properties at most.
  • Listen streams (protocol, client, design/subscriptions.md): one background stream for list changes and subscribed URIs, reopened with backoff; the subscription authorizer (new listen-authorizer snippet), notify(_:to:), maxSubscriptionStreams and maxResourceSubscriptions; 406 without SSE, : keep-alive comments, one-hour idle timeout for listen POSTs.
  • MRTR (server, client, design/mrtr.md): maxInputRequests, cancellation of a running exchange, bridge capability checks (-32021) and -32603 naming the method, backoff on state-only results, opt-in one-time requestState (RequestStateProtection.consume), principals from verified authentication.
  • OAuth (protocol, migration, troubleshooting, design/auth.md, design/design.md): concurrent challenges handled one at a time, refresh at the issuing server before re-reading resource metadata, refresh tokens sent only to their issuer, the 2025-03-26 fallback only when every metadata URL answers 404 or 410, trusted issuer overrides, TokenStorage called from several tasks.
  • HTTPClientTransport delivers only the request's own JSON-RPC error from a non-2xx reply.
  • Conformance runner (testing): the harness tree locked in scripts/conformance-harness/package-lock.json and installed with npm ci, CONFORMANCE_PKG, solo re-runs of stale entries, server-fixture.log.
  • rough_edges: the .stateless(v) retry, the stateless-only initialize and the Codable configuration items are removed.
  • protocol: a rejected token's metadata reread falls back to the copy read before; with none, the request fails and the token is kept.

Examples (d2efd2e)

  • Examples/Snippets/: 27 source files in five targets (for example Server/Tools.swift, Client/MultiRoundTrip.swift, Protocol/Authorization.swift, Guides/Migration.swift). Each region is delimited by // snippet: <region> and // endsnippet.
  • Examples/Tests/: QuickStartSnippetTests, ServerSnippetTests, ClientSnippetTests, ProtocolSnippetTests, GuidesSnippetTests run the snippets in both eras.
  • Examples/hello-server, Examples/hello-client: a stdio server with one greet tool, and a client that starts it as a subprocess, lists tools and calls greet (exit status 0 on success). HelloClient depends on SystemPackage.
  • Examples/http-server: HTTPServerExample, one NIO endpoint at /mcp for both eras. Requests whose MCP-Protocol-Version names a stateless revision go to one shared Server on a StatelessHTTPServerTransport; initialize creates a Server and a StatefulHTTPServerTransport per session, routed by Mcp-Session-Id; idle sessions close after 10 minutes.

Transport documentation (d2efd2e)

  • docs/src/protocol.src.md: per-stream resumption of POST response streams at 2025-11-25 and the -32603 errors when a stream cannot be resumed; no resumption at 2026-07-28; HTTPClientTransport.defaultConfiguration and why it allows 64 connections per host. The client transport table states Last-Event-ID use per era.
  • docs/src/migration.src.md: both behavior changes, and a summary row.
  • docs/src/troubleshooting.src.md: the deadlock with a custom URLSessionConfiguration, the resumption errors, the expired-session behavior.

CLAUDE.md (d2efd2e)

CI (.github/workflows/ci.yml)

  • Test job: runs "$BIN/HelloClient" "$BIN/HelloServer" after swift test.
  • Tier-score job: continue-on-error: true removed, so it gates.
  • Documentation job: swift scripts/weave.swift --check after the DocC build.

Doc comments (no behavior change)

  • OAuthConfiguration: names OAuthAuthorizer(configuration:) and HTTPClientTransport(endpoint:authorizer:) instead of the nonexistent HTTPClientTransport(oauth:); the applicationType inference mentions the grant.
  • BearerTokenValidator example passes resourceIdentifier and returns .valid(BearerTokenInfo(...)).
  • InMemoryTransport example uses server.start(transport:); StatefulHTTPServerTransport names Server.currentHandlerContext?.httpContext; HTTPClientTransport mentions the SEP-2243 headers.
  • Client.notifyRootsChanged() and Client.setLoggingLevel(_:) each had two merged doc comments; now one each.
  • MRTR.maxRounds, Server.withMethodHandler, Server.log(...) state the actual round limit and log-level behavior.

Review fixes

HTTP example (d2efd2e, Examples/http-server/main.swift)

  • Sessions: a request without Mcp-Session-Id created a Server and a StatefulHTTPServerTransport whatever its method. Now only a POST initialize creates a session; anything else gets 400 "Missing Mcp-Session-Id; send initialize first". At most 100 sessions (Router.maxSessions); the next initialize gets 503.
  • Idle reaper: closed a session after 10 minutes without a new request even while a response or SSE stream was open, and iterated a copy of the session table taken before its awaits. Each session now counts requests whose response or SSE stream has not ended (inFlight, decremented when the forwarded stream ends); the reaper reads the live entry and closes only sessions with nothing in flight.
  • Bodies: HTTPHandler buffered request bodies without limit. Bodies over 4 MiB (maxBodySize) are discarded while they arrive and answered with 413, then the connection is closed.
  • Host and Origin: both transports used OriginValidator.localhost(), which accepts any port. Their pipelines now start with OriginValidator.localhost(port:) for the listening port, followed by the default validators (AcceptHeaderValidator, ContentTypeValidator, ProtocolVersionValidator, and SessionValidator for sessions). The header comment states the limits and that the example has no authentication and listens on 127.0.0.1 only.

Docs

  • docs/src/protocol.src.md: the paragraph on the example lists these limits.
  • docs/src/troubleshooting.src.md: behind a proxy or on a public host, pass OriginValidator(allowedHosts:allowedOrigins:) with the public host names and allowed browser origins. The text no longer offers OriginValidator.disabled as the alternative: an internal service behind a proxy is reachable by DNS rebinding from a page an employee visits, and the specification requires the Origin check. .disabled is for servers that authenticate every request and that no browser can reach.

Diagram

flowchart LR
    S["Examples/Snippets"] -->|"swift build, SnippetTests"| T["compiled and tested"]
    S -->|"snippet regions"| W["scripts/weave.swift"]
    D["docs/src/*.src.md"] -->|"%include path region"| W
    R["README.src.md"] --> W
    W -->|write| O["docs/*.md and README.md"]
    W -->|"--check"| K["fail on stale output, broken links, unindexed sections"]
Loading

weave.swift replaces each %include <path> <region> line with a dedented Swift code block and prepends a "Generated by scripts/weave.swift" comment. With --check it writes nothing and fails when a generated file differs from its source, when a relative link in docs/ names a missing file or heading, or when a ## section of protocol.md, server.md or client.md is not linked from docs/README.md.

API changes

Added

None.

Changed

None. The package gains non-product targets only; the MCP library and the two fixture executables are unchanged. The review fix changes only the HTTPServerExample executable, which is not a product.

Removed

None.

Behavior changes

  • The server bridge's round-limit error reads "<method> asked for input 10 times" instead of "more than 10 times"; the limit itself is unchanged.
  • Conformance baselines and fixture sources live under conformance/. Scripts and CI that used the old paths need the new ones.
  • The tier-score CI job fails the workflow on a scored failure.
  • HTTPServerExample: a request without a session that is not a POST initialize gets 400; a 101st session gets 503; a body over 4 MiB gets 413 and the connection closes; a Host or Origin with another port is refused (421, 403); a session with an open response or SSE stream is not closed by the idle reaper.

Conformance

No change. The baselines move without content changes (renames at 100% similarity):

Leg Before (P8) After (P10)
2025-11-25 0 / 0 0 / 0
2026-07-28 0 / 0 0 / 0
default 25 / 11 25 / 11

Tier score stays 100% for client and server at 2025-11-25 and 2026-07-28.

Tests

  • New SnippetTests target: 98 tests over the five snippet targets (ClientSnippetTests 26, GuidesSnippetTests 36, ServerSnippetTests 17, ProtocolSnippetTests 16, QuickStartSnippetTests 3). Tests that apply to both eras run with .handshake and .automatic. They include the behavior of the fixes of P3 ([P3] server: serve 2026-07-28 stateless requests #368) to P8 ([P8] oauth: issuer checks, application_type, AS migration (SEP-2468/837/2352) #363) that the guides show: a pinned .stateless mode fails instead of retrying, a stateless-only server refuses initialize, a handshake client without the elicitation capability gets -32021, the subscription authorizer narrows the filter.
  • MCPTests is unchanged.
  • No test covers the review fix: HTTPServerExample is an executable without tests.
  • weave --check and the hello smoke run are new CI checks.

Review notes

  • Examples/ targets are in the main Package.swift, not a separate package: a path dependency's identity is its directory name, which differs per checkout (worktrees). None is a product, so dependents do not build them. [email protected] declares only MCP and MCPTests, as before, so the examples and fixtures build only with the 6.1 manifest (Package.swift, tools version 6.1).
  • The docs describe the defaults at this commit: Client.Configuration.protocolMode is .handshake and Version.supported excludes 2026-07-28. ROADMAP.md ("Remaining release step") and docs/rough_edges.md ("Defaults that will change") say so; P9 ([P9] versions: make 2026-07-28 the client default #361) updates them.
  • README.md and docs/*.md are generated: edit README.src.md and docs/src/*.src.md, then run swift scripts/weave.swift. Links in the root README are not checked; links from docs/ to files outside it are checked for existence only, not for headings.
  • The DocC landing article links to the docs directory on github.com/modelcontextprotocol/swift-sdk at main.
  • Issues found while writing the docs are not fixed here, to keep this PR free of library behavior changes: client cancellation race, client handlers on the receive loop, withBatch bypassing dispatch, strict-mode notification replies with a random id, one initialize per Server behind StatelessHTTPServerTransport, unbounded replay store, CryptoKit-only PKCE and private_key_jwt, DCR for a plain .none(clientID:), SSRF gaps and Tool writing "description": null. P11 ([P11] fix: request lifecycle, server replies, OAuth hardening #360) fixes them. Three more were fixed lower in the stack, and the guides here describe the fixed behavior: stateless-only servers answering initialize and no handler cancellation for a pending JSON reply (P3 ([P3] server: serve 2026-07-28 stateless requests #368)), and the shared server.log (P0 ([P0] conformance: pin harness 0.2.0-alpha.11 and run per-revision legs #371)).
  • API warts that stay are documented in docs/rough_edges.md.

Verification

swift build
swift test
swift test --filter SnippetTests
swift scripts/weave.swift --check
swift package generate-documentation --target MCP --warnings-as-errors
BIN=$(swift build --show-bin-path)
"$BIN/HelloClient" "$BIN/HelloServer"
swift run HTTPServerExample --port 3000
export npm_config_registry=https://registry.npmjs.org
scripts/run-conformance.sh --bin-path "$BIN"
scripts/run-conformance.sh --spec-version 2025-11-25 --bin-path "$BIN"
scripts/run-conformance.sh --spec-version 2026-07-28 --bin-path "$BIN"
scripts/run-conformance.sh --requirements 2025-11-25 --bin-path "$BIN"
scripts/run-conformance.sh --requirements 2026-07-28 --bin-path "$BIN"

State: the branch builds and passes swift test (783 swift-testing tests plus the XCTest suites, all passed); swift scripts/weave.swift --check passes; DocC builds with --warnings-as-errors; the three conformance legs pass at their baselines, and the tier score is 100% at both revisions.


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.

Reorganizes the repository after go-sdk and writes the documentation to
the same depth: a feature-by-feature guide set in `docs/` that follows
the specification, design notes in `design/`, process documents at the
root, and runnable examples. Every code block in the guides is copied
from compiled, tested sources under `Examples/Snippets` by
`scripts/weave.swift`, and CI fails when the generated docs drift. The
root README shrinks from 1,950 to 161 lines and is generated the same
way. The guides and design notes describe the SDK at this point,
including the automatic fallback, header parameter checks, listen
streams, multi round-trip bounds, OAuth concurrency and the conformance
runner. No public API changes. They also cover the client transport's
stream resumption and stateless mode, and `CLAUDE.md` adds guidance for
coding agents. The HTTP example bounds sessions and request bodies and
binds its Host and Origin checks to its port, and the advice to disable
the Origin check behind a proxy is replaced.
- Count initialize requests still being handled toward the example
  router's 100-session limit; the check ran before the awaits that
  create the session, so concurrent initializes all passed it.
- Start the shared stateless server in the routing snippet with one
  task that every stateless request awaits; a start failure answers 500
  and the next request tries again, instead of being swallowed with the
  server marked started.
- Document that a refused initialize is stored by the session router and
  the example, and how its slot is freed.
- Write each SSE chunk in the example NIO adapter only after the
  previous write completed, so a slow client applies backpressure
  instead of growing NIO's outbound buffer.
- weave.swift reports a snippet region without // endsnippet instead of
  copying to the end of the file, and a generated docs/*.md file whose
  source no longer exists.
- Describe behavior changed by earlier fixes: data: strings kept on the
  SDK's own Value hops, the parameter header check without a tools/list
  handler and the single parse of a stateless POST, delivery from a
  replaced listen stream, kept subscriptions and growing backoff, the
  end of a cancelled stateless request's HTTP response, and the OAuth
  challenge flow (repeated refresh, unavailable metadata, waiters of a
  failed challenge, 403 waiters, the sent token, registration retry,
  callbacks that must not use the transport they authorize).
- server.md: the Server.init table names description, websiteUrl and icons
  (main's #258), which every stateless result repeats in serverInfo; the
  Value accessors include numberValue (main's #226).
- The SessionRouter snippet and the protocol guide say that the snippet
  is a sketch without a session limit, an initialize-only check or an
  idle reaper, and point to Examples/http-server/main.swift, which has
  all three. The snippet's comment no longer promises that the router
  closes idle sessions.
- The server guide says that a RequestStateProtection.consume hook that
  throws fails the round with -32603 (the hook becomes async throws in
  conformance/p7-mrtr; the guide starts here).
…onalHeaders:)

The guides said the client sends the SEP-2243 Mcp-Param-* headers only
through HTTPClientTransport. With the Transport requirement
send(_:additionalHeaders:) (and its default, which ignores the headers),
any transport receives them; a Streamable HTTP transport sends them on
the request's POST and a wrapping transport forwards them.

- protocol: the request headers section names send(_:additionalHeaders:),
  and the custom transports section describes the requirement and its
  default next to send(_:relatedRequestID:).
- client, troubleshooting: a custom or wrapping transport gets the
  headers through send(_:additionalHeaders:); keeping the default drops
  them (-32020 from a conforming server).
- migration: the new-API table lists Transport.send(_:additionalHeaders:).
- The WireLog snippet forwards the headers, so wrapping a transport for
  logging no longer breaks annotated tool calls.
- design/request_headers.md: the Sending row names the requirement.
- The protocol and protocol-versions guides and the design note list
  the stateless checks in the order StatelessRequests.classify runs
  them: the version is served (-32022) before clientCapabilities and
  clientInfo are checked (-32602), and an unserved handshake revision
  also gets -32022.
- The server guide says how the statelessRequestHook refuses a request:
  it runs before each stateless request with
  Server.currentHandlerContext set and nil client info when the request
  carries none, and an MCPError it throws goes back as is, any other
  error as -32600. The guides and design note name start by its full
  signature, start(transport:initializeHook:statelessRequestHook:).

The -32022 refusal of stateless requests on a server with only an
initialize hook is documented in conformance/p11-fixes, the .stateless(v)
row there too, and the reopening of streams the server ends with its
result in conformance/p18-linux.
canarik
canarik previously approved these changes Nov 25, 2026

@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

Base automatically changed from conformance/p8-oauth to rel/1.0.0 November 25, 2026 12:38
@jeanmatthieu
jeanmatthieu dismissed canarik’s stale review November 25, 2026 12:38

The base branch was changed.

@jeanmatthieu
jeanmatthieu merged commit 9b7d4ec into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p10-docs branch November 25, 2026 12:39
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.

2 participants