Skip to content

fix(packaging): expose Ajv from CJS validator subpaths#2431

Open
morluto wants to merge 1 commit into
modelcontextprotocol:mainfrom
morluto:codex/fix-cjs-ajv-validator-subpaths
Open

fix(packaging): expose Ajv from CJS validator subpaths#2431
morluto wants to merge 1 commit into
modelcontextprotocol:mainfrom
morluto:codex/fix-cjs-ajv-validator-subpaths

Conversation

@morluto

@morluto morluto commented Jul 3, 2026

Copy link
Copy Markdown

Summary

Fixes the CommonJS validators/ajv subpath export for both @modelcontextprotocol/server and @modelcontextprotocol/client. In CommonJS consumers, reading Ajv from either AJV validator subpath currently throws ReferenceError: import_ajv is not defined.

The CJS build was preserving Ajv as a live getter but leaving it pointed at an ESM-only local alias (import_ajv). Exporting Ajv as a concrete local value from the provider makes the generated CJS subpath re-export require_ajvProvider.Ajv, matching the actual CJS provider module.

Adds regression coverage through the existing dist/barrel tests by requiring the built CJS validator subpath and constructing Ajv, addFormats, and AjvJsonSchemaValidator.

Fixes #2430.

Verification

  • pnpm --filter @modelcontextprotocol/server --filter @modelcontextprotocol/client build
  • node -e "const m = require('./packages/server/dist/validators/ajv.cjs'); new m.Ajv({ strict: false })"
  • node -e "const m = require('./packages/client/dist/validators/ajv.cjs'); new m.Ajv({ strict: false })"
  • pnpm --filter @modelcontextprotocol/server test -- test/server/barrelClean.test.ts
  • pnpm --filter @modelcontextprotocol/client test -- test/client/barrelClean.test.ts
  • pnpm --filter @modelcontextprotocol/core-internal test -- test/validators/validators.test.ts
  • node scripts/smoke-dist-types.mjs
  • git diff --check

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c269c39

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

This PR includes changesets to release 2 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/client 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

@morluto morluto marked this pull request as ready for review July 3, 2026 16:43
@morluto morluto requested a review from a team as a code owner July 3, 2026 16:43
@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: c269c39

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.

[v2] CJS AJV validator subpath crashes when reading exported Ajv

1 participant