Add sync-snippets script for type-checked examples#1487
Open
jonathanhefner wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Add sync-snippets script for type-checked examples#1487jonathanhefner wants to merge 2 commits intomodelcontextprotocol:mainfrom
sync-snippets script for type-checked examples#1487jonathanhefner wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Add triple-backtick code fences to 5 JSDoc comments that had code examples without proper markdown fencing: - `createPrivateKeyJwtAuth()` in `authExtensions.ts` - `ClientCredentialsProvider` in `authExtensions.ts` - `PrivateKeyJwtProvider` in `authExtensions.ts` - `fetchToken()` in `auth.ts` - `hostHeaderValidationResponse()` in `hostHeaderValidation.ts` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
JSDoc `@example` code blocks were previously inlined and not type-checked, meaning they could silently drift from the actual API. This adds a `scripts/sync-snippets.ts` script (`pnpm sync:snippets`) that extracts code from co-located `.examples.ts` files — using `//#region` markers — and syncs them into JSDoc `@example` fences and markdown files. The script supports a `--check` mode (wired into `lint:all`) to catch drift in CI. Code fences use a `source="./file.examples.ts#regionName"` attribute to reference their source of truth. Includes `.examples.ts` companion files for: - `packages/core`: `SdkError`, validation providers (`AjvJsonSchemaValidator`, `CfWorkerJsonSchemaValidator`, `jsonSchemaValidator`), and module-level validator examples - `packages/client`: `Client` options, `fetchToken`, auth extensions (`createPrivateKeyJwtAuth`, `ClientCredentialsProvider`, `PrivateKeyJwtProvider`), client middleware (`applyMiddlewares`, `createMiddleware`), and experimental task streaming - `packages/server`: `hostHeaderValidation` response helper - `packages/middleware/express`: `createMcpExpressApp` and host header validation middleware Also removes the duplicate `@example` from `Protocol.requestStream()` (now covered by `ExperimentalClientTasks.requestStream()`), adds ESLint overrides for `.examples.ts` files (`no-unused-vars`, `no-console`), and updates `CLAUDE.md` with snippet conventions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
JSDoc
@examplecode blocks were previously inlined and not type-checked, meaning they could silently drift from the actual API. This adds ascripts/sync-snippets.tsscript (pnpm sync:snippets) that extracts code from co-located.examples.tsfiles — using//#regionmarkers — and syncs them into JSDoc@examplefences and markdown files.The script supports a
--checkmode (wired intolint:all) to catch drift in CI. Code fences use asource="./file.examples.ts#regionName"attribute to reference their source of truth.This is stacked on top of #1485. Feel free to merge either first.
The
sync-snippets.tsscript is mostly copied from https://github.com/modelcontextprotocol/ext-apps/blob/main/scripts/sync-snippets.ts, which has been working well for us.Note that the script is configured to run as part of
pnpm run lint:allandpnpm run lint:fix:all. The idea being that syncing code snippets is akin to applying linter / formatting rules. Is that acceptable?