Skip to content

build: declare sideEffects in core, client and server - #3254

Open
ochafik wants to merge 1 commit into
mainfrom
claude/loving-johnson-onwvrg-side-effects
Open

ochafik wants to merge 1 commit into
mainfrom
claude/loving-johnson-onwvrg-side-effects

Conversation

@ochafik

@ochafik ochafik commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Declares sideEffects in the core, client and server manifests so bundlers can leave out modules an app does not use. First of a stack of three.

Motivation and Context

Browser code that only needs Protocol currently gets Client, the JSON Schema validator and @opentelemetry/api too. MCP Apps views and hosts (@modelcontextprotocol/ext-apps) are in that position.

Minified size of a bundle using App from ext-apps, zod included, against packed builds of main:

esbuild webpack rolldown rollup
before 347 kB 338 kB 264 kB 247 kB
after 256 kB 245 kB 246 kB 243 kB

shimsWorkerd calls preloadSchemas() at module scope, so client and server list it instead of using false.

How Has This Been Tested?

New treeShaking.test.ts bundles the built client with esbuild. It fails on main and passes here, and checks the Workers warm-up survives. The server warm-up was checked by hand only. The core, core-internal, client, server, integration and e2e suites were run on the full stack with no new failures, using unlocked dependencies; three tests fail there with and without this change.

Breaking Changes

None.

Types of changes

  • CI/build script update

Additional context

Notes for review:

  • esbuild becomes a devDependency of client (already in the lockfile). Fine, and wanted in server too?
  • server-legacy and the middleware packages are not audited or changed.

Generated by Claude Code

Lets bundlers leave out unused modules. The workerd shim is listed so its
schema warm-up survives.

Co-authored-by: ochafik <ochafik@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 23538c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/core Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core-internal Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3254

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3254

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3254

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3254

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3254

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3254

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3254

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3254

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3254

commit: 23538c4

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Dec 1, 2026
@ochafik
ochafik marked this pull request as ready for review December 1, 2026 14:59
@ochafik
ochafik requested a review from a team as a code owner December 1, 2026 14:59

@claude claude Bot 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment on lines +10 to +12
"sideEffects": [
"./dist/shimsWorkerd.*"
],

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.

🟡 (optional) Workers apps built with webpack or rspack that import only re-exported names such as Protocol lose the schema warm-up they get on the base branch. The list at packages/client/package.json:10-12 leaves dist/index.mjs side-effect free, and those bundlers skip such a re-exporting module, so its _shims import is never reached. Fix: keep the workerd shim reachable without evaluating the root entry, e.g. also list ./dist/index.*, which covers the 2 sites listed. Same pattern at 2 sites (packages/client/package.json:12, packages/server/package.json:12). I did not run webpack; esbuild keeps the shim.

Why this was flagged

Trigger: an app bundled by webpack or rspack with the workerd condition whose only imports from the package are re-exports of code that never imports _shims, e.g. import { Protocol } from '@ modelcontextprotocol/client'. With the manifest flag, webpack points the import straight at the core-internal chunk and drops dist/index.mjs with its imports, so preloadSchemas(); (packages/client/src/shimsWorkerd.ts:15) is never bundled. On base there is no sideEffects field, the root entry is evaluated and the call runs at isolate warm-up; after, schema construction lands in the first request of each fresh isolate. The glob does mark the shim as side-effectful, but nothing kept imports it. packages/client/test/client/treeShaking.test.ts:43-45 pins this case for esbuild only. Apps using Client or McpServer are unaffected. Based on reading; webpack was not run.

Verification: packages/client/package.json:10-12 lists only ./dist/shimsWorkerd.*, so dist/index.mjs and every shared chunk are declared side-effect free. The warm-up is the module-scope preloadSchemas(); at packages/client/src/shimsWorkerd.ts:15. It is reached only through the _shims import. packages/client/test/client/treeShaking.test.ts:43-45 checks the Protocol case with esbuild only.

Finding ID: f-872e844a

Comment on lines +10 to +12
"sideEffects": [
"./dist/shimsWorkerd.*"
],

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.

🟡 nit (optional): Workers users of the server package rely on a sideEffects list that no automated test bundles, so a lost schema warm-up would go unnoticed. packages/server/package.json:10-12 gets the same declaration as the client, but only the client has treeShaking.test.ts. The server's existing workerdSchemaPreload.test.ts reads dist files and never runs a bundler. Fix: add a server counterpart that bundles @ modelcontextprotocol/server with the workerd condition and asserts the top-level preloadSchemas(); call survives; packages/server/test/helpers/ensureBuilt.ts already exists for it.

Why this was flagged

The condition is a server dist whose entry or chunk layout reaches @ modelcontextprotocol/server/_shims differently from the client, now or after a later build change. packages/server/package.json:10-12 marks every dist file except ./dist/shimsWorkerd.* as side-effect free, so a bundler may drop the module whose top-level preloadSchemas() (packages/server/src/shimsWorkerd.ts:15) warms the schemas. Then a Workers app pays schema construction inside the first request of each fresh isolate, which the base branch never risks because it declares no sideEffects. packages/server/test/server/workerdSchemaPreload.test.ts:60-63 only checks that dist/shimsWorkerd.mjs contains the call; it does not bundle, so it stays green. The changeset at .changeset/side-effects-flag.md:7 states the warm-up is kept for all three packages, and for the server nothing in the repository checks that. I did not run a build or bundle to see the server output.

Verification: packages/server/package.json:10-12 adds "sideEffects": ["./dist/shimsWorkerd.*"], the same declaration as the client. packages/server/test/server/workerdSchemaPreload.test.ts:51-53 reads dist files with readFileSync and matches regexes on shimsWorkerd.mjs/.cjs (lines 60-63). Nothing here shows a present regression.

Finding ID: f-34033d40


const pkgDir = join(dirname(fileURLToPath(import.meta.url)), '../..');

/** Bundles an app that uses only `name` from the built package, the way a consumer's bundler would. */

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.

🟡 nit (optional): bundleUsing is a private test helper but carries a JSDoc block, which CLAUDE.md keeps for the public API. Fix: make it a one-line // comment, or drop it. [also at: packages/client/test/client/treeShaking.test.ts:12 - nit: CLAUDE.md principle 8 keeps JSDoc to the public API: bundleUsing in packages/client/test/client/treeShaking.test.ts is a file-local, unexported test helper, yet it carries a /** ... */ JSDoc block.]

Why this was flagged

There is no runtime trigger; this is a convention check on a new file. packages/client/test/client/treeShaking.test.ts:12 puts a /** ... */ block on bundleUsing, a non-exported function used only inside this test file. CLAUDE.md principle 8 limits JSDoc to the public API and asks for one-line inline comments elsewhere. Nothing a user or caller sees changes against the base branch. No safeguard applies: ESLint runs on src/ only (packages/client/package.json:145), so it does not flag test files.

Verification: nit — no runtime trigger; a comment-form rule from the root CLAUDE.md is broken by a line this diff adds. packages/client/test/client/treeShaking.test.ts:12 is a /** ... */ block on async function bundleUsing(...) at line 13. The function is not exported and is called only inside this file (lines 33, 40, 44), so it is not public API. Nothing a user, caller or build observes changes.

Finding ID: f-c9fe8190

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants