modelcontextprotocol / modelcontextprotocol/typescript-sdk
codemod v1-to-v2 hoists rewritten imports above the file's license header
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 13.4k
- Fork
- 2.2k
- Merge medio
- 3g 15h
- PR unite (30g)
- 4
Descrizione
v1-to-v2 moves a rewritten import above the file's leading comment block. On a file whose leading comment is a license or copyright header, the header stops being the first thing in the file, and any lint rule that enforces header position (eslint-plugin-header, eslint-plugin-notice, SPDX scanners) starts failing on a file it previously passed.
The guide's remedy for layout damage is "run your formatter". Prettier does not move the import back, so this survives the documented cleanup step.
Repro
mkdir -p repro/src && cd repro
cat > package.json <<'EOF'
{ "name": "repro", "version": "1.0.0", "type": "module",
"dependencies": { "@modelcontextprotocol/sdk": "^1.29.0" } }
EOF
cat > src/a.ts <<'EOF'
// Copyright (c) 2026 Example Corp.
// SPDX-License-Identifier: Apache-2.0
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
export const ok = (): CallToolResult => ({ content: [] });
EOF
npx @modelcontextprotocol/codemod@2.0.0 v1-to-v2 .
cat src/a.ts
Actual:
import type { CallToolResult } from "@modelcontextprotocol/server";
// Copyright (c) 2026 Example Corp.
// SPDX-License-Identifier: Apache-2.0
export const ok = (): CallToolResult => ({ content: [] });
Expected: the import stays where it was, below the header.
// Copyright (c) 2026 Example Corp.
// SPDX-License-Identifier: Apache-2.0
import type { CallToolResult } from "@modelcontextprotocol/server";
export const ok = (): CallToolResult => ({ content: [] });
Two things go wrong in those six lines. The import is hoisted above the header, and the blank line that separated the header from export const ok is consumed, so the header now reads as that declaration's doc comment.
Running npx prettier@latest --write src/a.ts afterwards produces byte-identical output, so step 5 of the TL;DR does not cover this.
Second shape, same cause
When the leading comment is a multi-line // run and the rewritten import is not the first import in the file, the import is inserted inside the comment run rather than above it. From a real migration:
// page_to_markdown tool: fetches a URL and returns clean Markdown for LLM context.
import type { CallToolResult } from "@modelcontextprotocol/server";
// Uses @page2ai/core under the hood — inherits SSRF protection, 10MB size cap,
// 15s AbortController timeout, `.md`-first attempt (Mintlify convention), and
// static tab discovery (emits `### Tab: {label}` sections for docs sites).
import { fetchAndConvert } from '@page2ai/core';
Line 1 of a four-line file comment now sits alone above an unrelated import. Prettier leaves this one alone too.
Both look like the same root cause: the new import node is attached at a position derived from the old node without carrying the leading comments with it.
Environment
@modelcontextprotocol/codemod2.0.0- Node 24.14.1, npm 11.13.0, Windows 11
- Migrating a published stdio server (
@modelcontextprotocol/sdk@^1.29.0to@modelcontextprotocol/server@^2.0.0)
Everything else in the run was correct, including the zod >= 4.2.0 floor warning, which was accurate and saved a debugging session: the ZodError.errors to .issues rename only surfaces at type-check.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo la riproduzione fornita con l’entry point v1-to-v2 e ispeziona il percorso di riscrittura degli imports del codemod. Aggiungi una copertura di regressione per entrambe le forme di intestazione iniziale descritte nell’issue. Il lavoro è completato quando gli imports riscritti rimangono sotto il blocco completo dei commenti iniziali, la riga vuota separatrice viene preservata e il passaggio di formattazione documentato non lascia più l’intestazione nella posizione errata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- node.js, typescript
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 67/100