Skip to content

fix(codemod): add test-only v2 packages to devDependencies - #3208

Open
costajohnt wants to merge 1 commit into
modelcontextprotocol:mainfrom
costajohnt:fix/codemod-test-only-deps
Open

costajohnt wants to merge 1 commit into
modelcontextprotocol:mainfrom
costajohnt:fix/codemod-test-only-deps

Conversation

@costajohnt

Copy link
Copy Markdown

Motivation and Context

When @modelcontextprotocol/sdk is in dependencies, the v1-to-v2 codemod adds every v2 package the code imports to dependencies, including packages that only test files import. I hit this migrating a real MCP server: src/server.ts imports @modelcontextprotocol/sdk/server/mcp.js and the tests import @modelcontextprotocol/sdk/client/index.js, and both @modelcontextprotocol/server and @modelcontextprotocol/client ended up in dependencies. The upgrade guide puts test-only packages in devDependencies, and the codemod already does that for the zod it injects.

What changed

  • packages/codemod/src/runner.ts: record which files import each specifier, next to usedByManifest, and pass it to updatePackageJson.
  • packages/codemod/src/utils/packageJsonUpdater.ts: roll that file map up through the existing workspace hoisting. A package goes to devDependencies only when every file that imports it is a test file, checked relative to the manifest that receives it with the same TEST_PATH_RE as the zod demotion (now a shared isTestFile helper). Anything a non-test file imports lands where it did before, and existing entries are never moved.
  • Changeset (patch: codemod).

How Has This Been Tested?

Four new runner-level cases in test/v1-to-v2/packageJsonUpdater.test.ts: a test-only package, a package used by both test and source files, a hoisted workspace member, and a tests/ segment in an ancestor directory. The test-only and hoisted cases fail on main (dependencies gets both client and server) and pass with this change; the other two pass on both and guard against demoting too much. In packages/codemod: typecheck, lint and the full suite (649 tests) pass.

Breaking Changes

None.

When the v1 SDK sat in dependencies, the v1-to-v2 codemod added every v2
package the code imports to dependencies, including packages only test
files import. Track which files use each specifier through the hoisting
roll-up and put packages only test files import in devDependencies,
classified relative to the receiving manifest like the injected zod
dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@costajohnt
costajohnt requested a review from a team as a code owner November 18, 2026 23:49
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 930b419

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core-internal 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 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 930b419

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Nov 19, 2026

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.

1 participant