Skip to content

Add sync-snippets script for type-checked examples#1487

Open
jonathanhefner wants to merge 2 commits intomodelcontextprotocol:mainfrom
jonathanhefner:add-sync-snippets-script
Open

Add sync-snippets script for type-checked examples#1487
jonathanhefner wants to merge 2 commits intomodelcontextprotocol:mainfrom
jonathanhefner:add-sync-snippets-script

Conversation

@jonathanhefner
Copy link
Member

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.


This is stacked on top of #1485. Feel free to merge either first.

The sync-snippets.ts script 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:all and pnpm run lint:fix:all. The idea being that syncing code snippets is akin to applying linter / formatting rules. Is that acceptable?

jonathanhefner and others added 2 commits February 5, 2026 10:37
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>
@jonathanhefner jonathanhefner requested a review from a team as a code owner February 5, 2026 21:37
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

⚠️ No Changeset found

Latest commit: 37e0a1b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 5, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1487

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1487

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1487

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1487

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1487

commit: 37e0a1b

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.

1 participant