fix(codemod): rewrite the bare barrel subpaths sdk/client, sdk/server and sdk/validation - #2947
Open
n-satoshi061 wants to merge 1 commit into
Open
n-satoshi061 wants to merge 1 commit into
n-satoshi061 wants to merge 1 commit into
Conversation
… 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`.
🦋 Changeset detectedLatest commit: 1fd0bc5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
v1-to-v2codemod now rewrites the bare barrel subpaths@modelcontextprotocol/sdk/client,@modelcontextprotocol/sdk/serverand@modelcontextprotocol/sdk/validationthe same way as their/index.jsforms.Motivation and Context
v1-to-v2codemod does not rewrite imports from@modelcontextprotocol/sdk/client,@modelcontextprotocol/sdk/serveror@modelcontextprotocol/sdk/validation.@mcp-codemod-error Unknown SDK import path: ... Manual migration required.marker.@modelcontextprotocol/sdkfrompackage.json, so the leftover import no longer resolves./index.jsforms of the same paths (sdk/client/index.js,sdk/server/index.js) are rewritten correctly.export { ... } from) and forvi.mock/vi.doMockpaths.Why these paths matter:
./client,./serverand./validationas explicit entries in theexportsfield of itspackage.json, so they are supported import paths../clientand./serverwere added in fix: client import & server imports #851 for the Metro bundler.packages/codemod/src/utils/projectAnalyzer.tsdescribes'@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_MAPis keyed by the/index.jsform.lookupImportMappingonly ignored a trailing.js/.mjs/.cjs, sosdk/clientnever matchedsdk/client/index.js.The change:
lookupImportMappingnow also ignores a trailing/index, both when building the normalized map and when looking up a specifier.packages/codemod/src/migrations/v1-to-v2/mappings/importMap.ts, two test files, one changeset (@modelcontextprotocol/codemod, patch).How Has This Been Tested?
sdk/client,sdk/client/index,sdk/server,sdk/validation), one re-export case, onevi.doMockcase.pnpm test,pnpm typecheckandpnpm lintpass inpackages/codemod(651 tests).Input:
Before (
mcp-codemod v1-to-v2):After:
Breaking Changes
None. Only specifiers that were previously reported as unknown are affected.
Types of changes
Checklist
Additional context
Not included:
@modelcontextprotocol/sdk/experimental(without/tasks) is still reported as unknown. It would need its own map entry, and the feature it exports was removed in v2.@modelcontextprotocol/sdk/shared/metadataUtils.jsis also still unmapped. It was noted in the review of feat(codemod): close v1-to-v2 mechanical gaps — outputSchema wrap, importMap entries; drop dead expressMiddleware transform #2361 and left out there.