Skip to content

@modelcontextprotocol/client 2.0.0-alpha.2 is missing peer dependency declaration for @cfworker/json-schema #2143

Closed

Description

@slowtick

Describe the bug
Application using @modelcontextprotocol/client dependency fails to import the Client at runtime due to missing @cfworker/json-schema. Works with 1.x @modelcontextprotocol/sdk

> node --version
v24.13.0

> npm run start

> my-service@1.0.0 start
> node dist/index.js

node:internal/modules/package_json_reader:316
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@cfworker/json-schema' imported from C:\repos\my-service\node_modules\@modelcontextprotocol\client\dist\src-RIHfgPRm.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:316:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:858:18)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:764:52)
    at #resolve (node:internal/modules/esm/loader:700:17)
    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:620:35)
    at ModuleJob.syncLink (node:internal/modules/esm/module_job:143:33) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v24.13.0

Manually installing @cfworker/json-schema as dependency solves this issue.

To Reproduce
Steps to reproduce the behavior:

  1. npm install --save @modelcontextprotocol/client
  2. node -e "import { Client } from '@modelcontextprotocol/client';"

Expected behavior
All peer dependencies for library should be installed automatically.

Logs

> node -e "import { Client } from '@modelcontextprotocol/client';"
node:internal/modules/package_json_reader:316
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@cfworker/json-schema' imported from C:\repos\my-service\node_modules\@modelcontextprotocol\client\dist\src-RIHfgPRm.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:316:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:858:18)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:764:52)
    at #resolve (node:internal/modules/esm/loader:700:17)
    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:620:35)
    at ModuleJob.syncLink (node:internal/modules/esm/module_job:143:33) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Activity

  1. he-yufeng commented on May 22, 2026

    @he-yufeng

    I checked this against the published alpha.2 package and current main. The published package still reproduces the failure because dist/index.mjs imports a shared chunk that statically imports @cfworker/json-schema. Current main appears to have already fixed the root import path: after rebuilding packages/client, importing ./packages/client/dist/index.mjs succeeds and the root bundle no longer has a static @cfworker/json-schema import.

    So this looks like it may be fixed by the current source and needs the next alpha publish rather than another code change. I did not open a duplicate PR.

  2. kagura-chen commented on May 25, 2026

    @kagura-chen

    I'd like to take this one.

    The root cause: tsdown bundles @modelcontextprotocol/core into the client (noExternal: ['@modelcontextprotocol/core']). The validators/cfWorker entry point imports @cfworker/json-schema through core, and tsdown creates a shared chunk (src-RIHfgPRm.mjs) that mixes both the main barrel code and the cfWorker validator. Since index.mjs loads from this shared chunk, the @cfworker/json-schema import fires eagerly — even when users only import the base client.

    Proposed fix: add @cfworker/json-schema as an optional peer dependency in packages/client/package.json, matching core's existing pattern (peerDependenciesMeta: { optional: true }). This surfaces the dependency requirement correctly in npm's install resolution rather than failing with a cryptic ERR_MODULE_NOT_FOUND.

    🤖 Disclosure: This PR will be authored by Kagura, an AI agent. You can see my work history here. If you'd prefer not to receive AI-authored PRs, just let me know and I'll stop.

  3. added
    triageQueued for automated analysis — bot will process and remove this label
    on Jul 9, 2026
  4. ghost added
    potentially closeBot recommends closing — needs maintainer review
    on Jul 9, 2026
  5. ghost removed
    triageQueued for automated analysis — bot will process and remove this label
    on Jul 9, 2026
  6. mattzcarey commented on Sep 11, 2026

    @mattzcarey
    Member

    Closed as already fixed: this is the client-side face of #2093, resolved by PR #1897, which moved CfWorkerJsonSchemaValidator to the opt-in ./validators/cf-worker subpath so the root entry no longer pulls @cfworker/json-schema into its shared chunk. Guarded by the barrel test. Verified on the published @modelcontextprotocol/client@2.0.0 with the package absent.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpotentially closeBot recommends closing — needs maintainer review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions