Skip to content

fix(codemod): rewrite the bare barrel subpaths sdk/client, sdk/server and sdk/validation - #2947

Open
n-satoshi061 wants to merge 1 commit into
modelcontextprotocol:mainfrom
n-satoshi061:fix/codemod-bare-subpath-imports
Open

n-satoshi061 wants to merge 1 commit into
modelcontextprotocol:mainfrom
n-satoshi061:fix/codemod-bare-subpath-imports

Conversation

@n-satoshi061

@n-satoshi061 n-satoshi061 commented Oct 3, 2026 •

Copy link
Copy Markdown

The v1-to-v2 codemod now rewrites the bare barrel subpaths @modelcontextprotocol/sdk/client, @modelcontextprotocol/sdk/server and @modelcontextprotocol/sdk/validation the same way as their /index.js forms.

Motivation and Context

  • The v1-to-v2 codemod does not rewrite imports from @modelcontextprotocol/sdk/client, @modelcontextprotocol/sdk/server or @modelcontextprotocol/sdk/validation.
  • It leaves the import as is and adds an @mcp-codemod-error Unknown SDK import path: ... Manual migration required. marker.
  • In the same run it removes @modelcontextprotocol/sdk from package.json, so the leftover import no longer resolves.
  • The /index.js forms of the same paths (sdk/client/index.js, sdk/server/index.js) are rewritten correctly.
  • The same happens for re-exports (export { ... } from) and for vi.mock / vi.doMock paths.

Why these paths matter:

  • v1 lists ./client, ./server and ./validation as explicit entries in the exports field of its package.json, so they are supported import paths.
  • ./client and ./server were added in fix: client import & server imports #851 for the Metro bundler.
  • A comment in packages/codemod/src/utils/projectAnalyzer.ts describes '@modelcontextprotocol/sdk/client' as a form the codemod already supports, and the analyzer has a test for it. The import transform had no such test.

Cause:

  • IMPORT_MAP is keyed by the /index.js form.
  • lookupImportMapping only ignored a trailing .js / .mjs / .cjs, so sdk/client never matched sdk/client/index.js.

The change:

  • lookupImportMapping now also ignores a trailing /index, both when building the normalized map and when looking up a specifier.
  • No new map entries and no new options.
  • Files: packages/codemod/src/migrations/v1-to-v2/mappings/importMap.ts, two test files, one changeset (@modelcontextprotocol/codemod, patch).

How Has This Been Tested?

  • New tests: four import cases (sdk/client, sdk/client/index, sdk/server, sdk/validation), one re-export case, one vi.doMock case.
  • The five cases that use the bare form fail without the source change and pass with it.
  • pnpm test, pnpm typecheck and pnpm lint pass in packages/codemod (651 tests).
  • Ran the rebuilt CLI on a small sample project.

Input:

import { Client } from '@modelcontextprotocol/sdk/client';
import { Server } from '@modelcontextprotocol/sdk/server';
import type { jsonSchemaValidator } from '@modelcontextprotocol/sdk/validation';

Before (mcp-codemod v1-to-v2):

/* @mcp-codemod-error Unknown SDK import path: @modelcontextprotocol/sdk/client. Manual migration required. */
import { Client } from '@modelcontextprotocol/sdk/client';

After:

import { Server } from "@modelcontextprotocol/server";
import type { jsonSchemaValidator } from "@modelcontextprotocol/server";
import { Client } from "@modelcontextprotocol/client";

Breaking Changes

None. Only specifiers that were previously reported as unknown are affected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Not included:

… and sdk/validation

v1 exports `./client`, `./server` and `./validation` as explicit subpaths, but
the import map is keyed by the `/index.js` form and the lookup only ignored a
JS extension. Imports, re-exports and mocks of the bare form were left in place
with an "Unknown SDK import path" marker while `@modelcontextprotocol/sdk` was
removed from package.json.

The lookup now also ignores a trailing `/index`.
@n-satoshi061
n-satoshi061 requested a review from a team as a code owner October 3, 2026 12:55
@changeset-bot

changeset-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1fd0bc5

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 Oct 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 1fd0bc5

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Oct 4, 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