codemod v1-to-v2: run at a monorepo root, it rewrites workspace members' source files but not their package.json

Offen
#3,230 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@adlanehzx arbeitet bereits daran.

Seit 24.11.2026.

  • #3231 von @adlanehzx — ohne Merge geschlossen
  • #3232 von @adlanehzx — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
node.js, typescript
Bereich
tooling

Rechercherichtung

Start from the codemod runner source that ships as dist/runner-*.mjs: read discoverManifests(), updatePackageJson() and ownerManifest(), plus the doc comment pointing at #2393. Reproduce with a pnpm monorepo fixture where a workspace member depends on the SDK, run the codemod at the root, and confirm the member's source is rewritten while its package.json is not. Done means member manifests get the dependency swap (or the run exits non-zero) with a test covering the monorepo case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

v2
Issue

Running npx @modelcontextprotocol/[email protected] v1-to-v2 . at the root of a pnpm monorepo, where the SDK is a
dependency of a workspace member (packages/<name>), not of the root:

  • the member's source files are rewritten to import @modelcontextprotocol/client, @modelcontextprotocol/server
    and @modelcontextprotocol/node;
  • the member's package.json is left as it was: it still depends on @modelcontextprotocol/sdk and doesn't declare
    the new packages. The run ends with:
Manifests that declare @modelcontextprotocol/sdk but are not modified by the codemod — apply the listed changes yourself:
  packages/<name>/package.json
    Removed: @modelcontextprotocol/sdk
    Added:   @modelcontextprotocol/client, @modelcontextprotocol/server, ...

We saw this on every monorepo we ran it on.

Where

As published in @modelcontextprotocol/[email protected] (dist/runner-*.mjs):

  • discoverManifests() finds the nearest package.json walking up from the target, plus every workspace member's manifest.
  • updatePackageJson() only writes the first of those, the nearest one (here the root, which doesn't declare the SDK).
    Its doc comment says the others are only reported, "so workspace members never receive writes the user did not
    point the codemod at."
  • The source transforms have no such limit: they rewrite every file under the target, members included.

So the codemod does write to the workspace members, but only to their source files and never to their manifests.
Writing only the nearest manifest was a deliberate choice in #2393. This issue is about the mismatch with the source
transforms, which do write inside the members.

Consequences
  • Each migrated member ends up half-migrated: its code imports v2 packages that its package.json doesn't declare,
    and it still declares the v1 SDK.
  • The user has to copy the reported "Removed/Added" lists into each member's package.json by hand and reinstall
    before anything builds against v2.
  • The run still exits 0 and reports its changes (e.g. Changes: 15 across 8 file(s)). The manual step is one block
    among the warnings, so it's easy to miss, and anything that only checks the exit code treats the migration as done.
Suggested fix

Apply the dependency swap to every manifest whose files the run rewrote. ownerManifest() already maps each file to its
manifest, so the rule "a manifest is written when its source is" follows the same scope the user pointed the codemod at.
If writing member manifests is deliberately out of scope, then exit non-zero when a rewritten member's manifest was
left unmodified, instead of only reporting it.


Found with modeval, which runs codemods against real repositories
that depend on a package and checks the results.

Vorherrschende Sprache
TypeScript
Sterne
13.8k
Forks
2.5k
Ø Merge
6 T. 23 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/typescript-sdk

Alle Issues in modelcontextprotocol/typescript-sdk

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.