Repository navigation
[P10] docs: go-sdk layout, feature guides, design notes and process docs - #362
Merged
Merged
Conversation
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.
This was referenced Nov 25, 2026
Merged
Merged
canarik
approved these changes
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: P8 (#363) · next: P9 (#361))conformance/p10-docsconformance/p8-oauth(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)d2efd2edocs: go-sdk layout, feature guides, design notes and process docsa25ba95docs: review fixes90a0bb7docs: second-pass review fixesd072eb5docs: custom transports receive request headers through send(_:additionalHeaders:)3f53229docs: third-pass review fixesSummary
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 indesign/, process documents at the root, and runnable examples. Every code block in the guides is copied from compiled, tested sources underExamples/Snippetsbyscripts/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 addsCLAUDE.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
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.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).Changes
Layout (
d2efd2e)conformance/baseline.yml,conformance/baseline.2025-11-25.yml,conformance/baseline.2026-07-28.yml(content unchanged).scripts/run-conformance.shreads them there.Sources/MCPConformance/{Server,Client}toconformance/everything-{server,client}. Target and product names (mcp-everything-server,mcp-everything-client) are unchanged.Package.swiftadds anexamplestarget list, none of them a product:QuickStartSnippets,ServerSnippets,ClientSnippets,ProtocolSnippets,GuidesSnippets(pathsExamples/Snippets/<Name>), theSnippetTeststest target (Examples/Tests), and the executablesHelloServer,HelloClient,HTTPServerExample.scripts/weave.swift(see Diagram).Documentation (
d2efd2e)docs/README.mddocs/quick_start.mddocs/protocol.mdinitialize,server/discover,_meta), transports, notification streams, authorization, security, utilitiesdocs/server.mddocs/client.mddocs/protocol_versions.mddocs/migration.mddocs/testing.md,docs/troubleshooting.mddocs/rough_edges.mddocs/src/*.src.md.mdfiles are generateddesign/design.mddesign/{stateless,request_headers,subscriptions,mrtr,auth}.mdROADMAP.mdVERSIONING.mdDEPENDENCY_POLICY.mdCONTRIBUTING.mdconformance/README.mdREADME.src.mdREADME.md(161 lines): eras, requirements, installation, a 30-line server, docs links, layoutSources/MCP/MCP.docc/MCP.mddocs/and groups the main symbolsFixes made lower in the stack (P0 (#371), P3 (#368) to P8 (#363)), as the guides and design notes describe them:
protocol_versions,client,protocol,troubleshooting,design/stateless.md):.automaticfalls back toinitializeon a JSON-RPC error, an HTTP 400/404/405 refusal or no answer withindiscoveryTimeout, and rethrows other transport errors;.stateless(v)never retries with another version;protocolVersions: Version.statelessrefusesinitializewith -32022 without a handler replacement; saved configurations decode with missing keys (themigration-configuration-decodingsnippet is gone).protocol,server,troubleshooting): schemas read once and kept untilToolListChangedNotification, fail-closed checks, 64 annotations and 32 levels ofpropertiesat most.protocol,client,design/subscriptions.md): one background stream for list changes and subscribed URIs, reopened with backoff; the subscription authorizer (newlisten-authorizersnippet),notify(_:to:),maxSubscriptionStreamsandmaxResourceSubscriptions; 406 without SSE,: keep-alivecomments, one-hour idle timeout for listen POSTs.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-timerequestState(RequestStateProtection.consume), principals from verified authentication.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,TokenStoragecalled from several tasks.HTTPClientTransportdelivers only the request's own JSON-RPC error from a non-2xx reply.testing): the harness tree locked inscripts/conformance-harness/package-lock.jsonand installed withnpm ci,CONFORMANCE_PKG, solo re-runs of stale entries,server-fixture.log.rough_edges: the.stateless(v)retry, the stateless-onlyinitializeand theCodableconfiguration 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 exampleServer/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,GuidesSnippetTestsrun the snippets in both eras.Examples/hello-server,Examples/hello-client: a stdio server with onegreettool, and a client that starts it as a subprocess, lists tools and callsgreet(exit status 0 on success).HelloClientdepends onSystemPackage.Examples/http-server:HTTPServerExample, one NIO endpoint at/mcpfor both eras. Requests whoseMCP-Protocol-Versionnames a stateless revision go to one sharedServeron aStatelessHTTPServerTransport;initializecreates aServerand aStatefulHTTPServerTransportper session, routed byMcp-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.defaultConfigurationand why it allows 64 connections per host. The client transport table statesLast-Event-IDuse per era.docs/src/migration.src.md: both behavior changes, and a summary row.docs/src/troubleshooting.src.md: the deadlock with a customURLSessionConfiguration, the resumption errors, the expired-session behavior.CLAUDE.md(d2efd2e)CI (
.github/workflows/ci.yml)"$BIN/HelloClient" "$BIN/HelloServer"afterswift test.continue-on-error: trueremoved, so it gates.swift scripts/weave.swift --checkafter the DocC build.Doc comments (no behavior change)
OAuthConfiguration: namesOAuthAuthorizer(configuration:)andHTTPClientTransport(endpoint:authorizer:)instead of the nonexistentHTTPClientTransport(oauth:); theapplicationTypeinference mentions the grant.BearerTokenValidatorexample passesresourceIdentifierand returns.valid(BearerTokenInfo(...)).InMemoryTransportexample usesserver.start(transport:);StatefulHTTPServerTransportnamesServer.currentHandlerContext?.httpContext;HTTPClientTransportmentions the SEP-2243 headers.Client.notifyRootsChanged()andClient.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)Mcp-Session-Idcreated aServerand aStatefulHTTPServerTransportwhatever its method. Now only a POSTinitializecreates a session; anything else gets 400 "Missing Mcp-Session-Id; send initialize first". At most 100 sessions (Router.maxSessions); the nextinitializegets 503.inFlight, decremented when the forwarded stream ends); the reaper reads the live entry and closes only sessions with nothing in flight.HTTPHandlerbuffered request bodies without limit. Bodies over 4 MiB (maxBodySize) are discarded while they arrive and answered with 413, then the connection is closed.OriginValidator.localhost(), which accepts any port. Their pipelines now start withOriginValidator.localhost(port:)for the listening port, followed by the default validators (AcceptHeaderValidator,ContentTypeValidator,ProtocolVersionValidator, andSessionValidatorfor 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, passOriginValidator(allowedHosts:allowedOrigins:)with the public host names and allowed browser origins. The text no longer offersOriginValidator.disabledas 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..disabledis 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"]weave.swiftreplaces each%include <path> <region>line with a dedented Swift code block and prepends a "Generated by scripts/weave.swift" comment. With--checkit writes nothing and fails when a generated file differs from its source, when a relative link indocs/names a missing file or heading, or when a##section ofprotocol.md,server.mdorclient.mdis not linked fromdocs/README.md.API changes
Added
None.
Changed
None. The package gains non-product targets only; the
MCPlibrary and the two fixture executables are unchanged. The review fix changes only theHTTPServerExampleexecutable, which is not a product.Removed
None.
Behavior changes
<method>asked for input 10 times" instead of "more than 10 times"; the limit itself is unchanged.conformance/. Scripts and CI that used the old paths need the new ones.HTTPServerExample: a request without a session that is not a POSTinitializegets 400; a 101st session gets 503; a body over 4 MiB gets 413 and the connection closes; aHostorOriginwith 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):
Tier score stays 100% for client and server at 2025-11-25 and 2026-07-28.
Tests
SnippetTeststarget: 98 tests over the five snippet targets (ClientSnippetTests26,GuidesSnippetTests36,ServerSnippetTests17,ProtocolSnippetTests16,QuickStartSnippetTests3). Tests that apply to both eras run with.handshakeand.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.statelessmode fails instead of retrying, a stateless-only server refusesinitialize, a handshake client without the elicitation capability gets -32021, the subscription authorizer narrows the filter.MCPTestsis unchanged.HTTPServerExampleis an executable without tests.weave --checkand the hello smoke run are new CI checks.Review notes
Examples/targets are in the mainPackage.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 onlyMCPandMCPTests, as before, so the examples and fixtures build only with the 6.1 manifest (Package.swift, tools version 6.1).Client.Configuration.protocolModeis.handshakeandVersion.supportedexcludes 2026-07-28.ROADMAP.md("Remaining release step") anddocs/rough_edges.md("Defaults that will change") say so; P9 ([P9] versions: make 2026-07-28 the client default #361) updates them.README.mdanddocs/*.mdare generated: editREADME.src.mdanddocs/src/*.src.md, then runswift scripts/weave.swift. Links in the root README are not checked; links fromdocs/to files outside it are checked for existence only, not for headings.docsdirectory ongithub.com/modelcontextprotocol/swift-sdkatmain.withBatchbypassingdispatch, strict-mode notification replies with a random id, oneinitializeperServerbehindStatelessHTTPServerTransport, unbounded replay store, CryptoKit-only PKCE andprivate_key_jwt, DCR for a plain.none(clientID:), SSRF gaps andToolwriting"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 answeringinitializeand no handler cancellation for a pending JSON reply (P3 ([P3] server: serve 2026-07-28 stateless requests #368)), and the sharedserver.log(P0 ([P0] conformance: pin harness 0.2.0-alpha.11 and run per-revision legs #371)).docs/rough_edges.md.Verification
State: the branch builds and passes
swift test(783 swift-testing tests plus the XCTest suites, all passed);swift scripts/weave.swift --checkpasses; 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.