Skip to content

codemod improvements#2156

Open
KKonstantinov wants to merge 5 commits into
mainfrom
feature/v2-codemode-iterations
Open

codemod improvements#2156
KKonstantinov wants to merge 5 commits into
mainfrom
feature/v2-codemode-iterations

Conversation

@KKonstantinov
Copy link
Copy Markdown
Contributor

Motivation and Context

How Has This Been Tested?

Breaking Changes

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

@KKonstantinov KKonstantinov requested a review from a team as a code owner May 25, 2026 12:29
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

⚠️ No Changeset found

Latest commit: a0a1dd0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2156

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2156

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2156

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2156

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2156

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2156

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2156

commit: a0a1dd0

@KKonstantinov
Copy link
Copy Markdown
Contributor Author

@claude review

Comment thread packages/codemod/src/runner.ts Outdated
Comment thread packages/codemod/src/cli.ts
Comment thread packages/codemod/test/commentInsertion.test.ts Outdated
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the previous round — the CRLF offset handling, the hasMcpImports gate in handlerRegistration, the grep quoting, and the same-line merge test all look fixed in the latest commit, and I found no new bugs in this revision. Since the PR adds a new user-file-mutating behavior (writing @mcp-codemod-error comments into source) plus import-map changes, a human maintainer should still take a pass; one small residual from my earlier comment is that comment insertion still has no guard against landing inside a multi-line template literal, and the changeset bot is flagging a missing changeset.

Extended reasoning...

Overview

This PR ("codemod improvements") touches 17 files in packages/codemod. The main feature is a new actionRequired diagnostic kind that causes the runner to physically insert /* @mcp-codemod-error ... */ comments into user source files at the diagnostic location, plus a CLI hint pointing users at a grep command. Supporting changes include a shared isKeyPositionIdentifier helper extracted into astUtils, an import-map simplification for client/stdio.js, expanded mock-method coverage (unmock, requireActual, etc.), removal of the incorrect registerResource schema-wrap path, namespace-import guards in symbolRenames, shorthand-property expansion in contextTypes, and a new commentInsertion.test.ts suite.

Status relative to prior review

My previous review (2026-05-27 05:57 UTC) raised four issues. The latest commit (3e50511, pushed after that review) addresses them: the runner now computes offsets from the un-normalized text and preserves the file's line ending (with a CRLF test added), handlerRegistrationTransform now gates on hasMcpImports (with a test), the grep hint quotes the path, and the same-line merge test now drives run() end-to-end and asserts the merged comment. The only residual from that round is the lack of a safe-boundary check when the insertion line falls inside a multi-line template literal or JSX text — a narrow edge case, noted but not blocking on its own.

Security risks

None of significance. The codemod is a developer-run CLI tool operating on the user's own source tree; it does not touch the SDK runtime, transports, or auth. The grep hint is printed, not executed, and is now quoted. The main risk class is unwanted mutation of user files, which the new hasMcpImports gate and dry-run behavior mitigate.

Level of scrutiny

Moderate. This is tooling code rather than protocol/transport code, so the blast radius is limited to the migration experience, but the comment-insertion feature is a deliberate design choice (writing annotations into user code) that a maintainer should consciously sign off on, and the PR bundles several semi-independent transform fixes. The PR description is empty and there is no changeset, which a maintainer may want filled in before merge.

Other factors

Test coverage is reasonable: the new comment-insertion suite covers insertion, dry-run, idempotency, indentation, line-shift placement, same-line merging, and CRLF, and the transform test updates match the behavior changes. The bug hunting system found no bugs in this revision. Given the feature scope and the missing changeset/description, I am deferring rather than shadow-approving.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — the remaining open issue from my last pass (no safe-boundary check before splicing the comment into multi-line template literals) is now addressed by the isInsideLiteral guard and the new template-literal/CRLF tests, and I found no new issues in this revision. Given the breadth of behavior changes here (warning→actionRequired escalation that physically writes comments into user files, the importMap stdio simplification, removal of registerResource uriSchema wrapping, expanded mock methods), this still warrants a human maintainer pass before merge — also note the missing changeset.

Extended reasoning...

Overview

This PR spans 17 files in packages/codemod: it introduces an actionRequired diagnostic kind that physically inserts /* @mcp-codemod-error */ comments into users' source files via a new insertDiagnosticComments() step in runner.ts, escalates many existing warnings to that level across the v1→v2 transforms, simplifies the client/stdio.js import mapping to target @modelcontextprotocol/client/stdio directly, removes the registerResource/uriSchema wrapping path in mcpServerApi, expands the recognized vi/jest mock methods, hardens import-merge logic against namespace imports, and adds a substantial commentInsertion.test.ts suite.

Status of prior feedback

All issues raised in my earlier reviews have been addressed in the current revision: the CRLF offset computation and the template-literal boundary guard (isInsideLiteral before sf.insertText), the missing hasMcpImports() gate in handlerRegistrationTransform, the unquoted path in the grep hint, and the same-line merge test now genuinely exercises the merge path through run(). I verified the stdio import-map simplification against packages/client/src/stdio.ts, whose subpath export covers exactly the four symbols previously listed in symbolTargetOverrides, so the simplification is behavior-preserving. The bug-hunting system found no new issues in this revision.

Security risks

None of significance — this is a developer-side migration tool, not runtime SDK/transport/auth code. The main risk class is unwanted mutation of user source files by the comment-insertion feature, which the new boundary/idempotency/CRLF tests now cover.

Level of scrutiny

Moderate. The codemod package is not protocol- or security-critical, but the new behavior of writing annotations into users' files and several intentional behavior changes (e.g. dropping the registerResource uriSchema wrapping, the diagnostic-level escalations) are design-level decisions a maintainer should sign off on rather than something to shadow-approve. The PR description is empty and there is no changeset despite the package being published, which a maintainer should also weigh.

Other factors

Test coverage for the new functionality is good (comment insertion, dry-run, idempotency, indentation, line-shift, template-literal skip, CRLF), and the transform-level test updates match the behavior changes. The remaining open questions are intent-level (scope of the escalation, the registerResource removal) rather than correctness bugs, hence deferring rather than approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant