Skip to content

fix: don't fail install when running npm install in an example workspace (#687)#695

Open
d-turley wants to merge 2 commits into
modelcontextprotocol:mainfrom
d-turley:fix/687-workspace-child-install
Open

fix: don't fail install when running npm install in an example workspace (#687)#695
d-turley wants to merge 2 commits into
modelcontextprotocol:mainfrom
d-turley:fix/687-workspace-child-install

Conversation

@d-turley

@d-turley d-turley commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Fixes #687.

Following an example's README literally — e.g.:

cd examples/basic-host
npm install

fails with a cryptic error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-to-zod' imported from .../scripts/generate-schemas.ts
npm error command sh -c npm run build && husky

Root cause

examples/* are npm workspaces of the repository root. Running npm install
inside an example directory makes npm install only that workspace's dependencies
(it does not install the root package's devDependencies such as ts-to-zod,
bun, tsx, esbuild), yet npm still runs the root package's prepare script
(npm run build && husky). The build immediately runs
generate:schemastsx scripts/generate-schemas.ts, which imports the missing
ts-to-zod and crashes. This affects every example, not just basic-host.

Changes

  1. Guard the prepare build — move it into scripts/prepare.mjs, which skips
    the SDK build with a clear, actionable message when the build toolchain isn't
    installed (i.e. a workspace-child/partial install) instead of failing with an
    opaque ERR_MODULE_NOT_FOUND. A full install from the repo root still builds
    as before.

    • Registry consumers are unaffected: prepare doesn't run for published
      packages and dist/ ships in the tarball.
    • Git installs still build, because npm installs a git dependency's
      devDependencies before running its prepare.
  2. Docs — update the example READMEs' setup instructions to install from the
    repository root (which installs all workspaces and builds the SDK the examples
    import), then run the example from its directory.

Testing

In a clean checkout on Windows:

  • cd examples/basic-host && npm installbefore: exit 1, ERR_MODULE_NOT_FOUND: ts-to-zod; after: exit 0 with:
    [prepare] Skipping SDK build: missing build tooling (ts-to-zod, bun). ... run npm install from the repository root.
  • npm install from the repository root — still runs the full build
    (generate:schemas + sync:snippets + bundle), exits 0, and produces dist/.

🤖 Generated with Claude Code

d-turley and others added 2 commits July 2, 2026 14:20
npm runs the root `prepare` script on every `npm install`, including when
installing a single workspace example via `npm install` inside
`examples/<name>`. That flow does not install the root package's
devDependencies, so `prepare`'s `npm run build` crashed with a cryptic
`ERR_MODULE_NOT_FOUND: ts-to-zod`.

Move `prepare` into scripts/prepare.mjs, which skips the SDK build with a
helpful message when the build toolchain is missing instead of failing the
install. Registry consumers are unaffected (prepare does not run for published
packages and dist/ ships in the tarball); git installs still build because npm
installs a git dependency's devDependencies before running prepare.

Refs modelcontextprotocol#687

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The examples are npm workspaces of the repository root. Running `npm install`
inside an example directory triggers the root `prepare` build without the root
devDependencies installed, which fails (issue modelcontextprotocol#687). Update the example
READMEs to install from the repository root (which installs all workspaces and
builds the SDK), then run the example from its directory.

Refs modelcontextprotocol#687

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

fresh install of basic-host example fails

1 participant