Codemod MCP (Model Context Protocol) provides AI assistants with tools for code analysis, AST manipulation, and codemod creation. The MCP server enables AI tools like Claude, Cursor, and others to understand code structure, create codemods, and perform automated code transformations.

Prerequisites

Before setting up Codemod MCP, ensure you have:
  • Node.js 16.0.0 or higher installed
  • An AI client that supports MCP (Claude Desktop, Cursor, etc.)
  • Logging in to Codemod with CLI

Quick setup

1

Open IDE settings

For Cursor IDE:
  • Open Cursor Settings
  • Navigate to MCP & Integrations
  • Click New MCP Server under MCP Tools
2

Add MCP server configuration

Add the following configuration to your MCP settings:
{
  "mcpServers": {
    "codemod": {
      "command": "npx",
      "args": ["codemod@latest", "mcp"],
      "cwd": "<your-project-directory>"
    }
  }
}
Replace <your-project-directory> with the path to your project folder.
3

Restart your IDE

Save the configuration file and restart your IDE to activate the Codemod MCP server.

Available tools

The Codemod MCP server provides these tools for AI assistants:
  • dump_ast - Dump AST nodes in an AI-friendly format for given source code and language
  • get_node_types - Get compressed tree-sitter node types for specific programming languages
  • run_jssg_tests - Run tests for jssg (JavaScript AST-grep) codemods with test cases
  • get_jssg_instructions - Get jssg instructions for creating codemods
  • get_ast_grep_instructions - Get ast-grep instructions for creating ast-grep rules
  • get_codemod_cli_instructions - Get Codemod CLI instructions for creating codemods

Why use Codemod MCP?

Codemod MCP democratizes code transformation by integrating robust deterministic engines into AI-powered development workflows:
  • Individual Developers: Take care of repetitive refactors without manual effort
  • Accessibility: Makes tackling tech debt more approachable for developers of all skill levels
  • AI Integration: Seamlessly integrates deterministic code transformation engines into AI IDE workflows

Codemod MCP vs Codemod Studio

Codemod MCPCodemod Studio
InterfaceIntegrated into your IDEWeb-based interface
AI ModelYour choice of AI modelBuilt-in AI assistant
ControlGranular control over codemod creationQuick prototyping and sharing
IterationDirect, instant control in your IDEWeb-based iteration
SharingExport and version controlBuilt-in sharing with peers
Best ForPower users, framework maintainers, pro codemodsQuick codemod creation and collaboration

Best practices

When working with AI assistants through Codemod MCP, follow these guidelines for better results:
1

Be specific about output format

Tell the AI exactly what type of codemod you want:
  • jssg for JavaScript/TypeScript transformations
  • ast-grep YAML rule for general-purpose transformations
  • shell workflow for complex multi-step migrations
2

Provide clear requirements

Describe your transformation in plain language with concrete examples:
  • Show before/after code snippets
  • Specify edge cases to handle or avoid
  • Include any constraints or special conditions
3

Break down complex changes

Instead of one large transformation, create focused codemods for specific patterns:
  • One codemod per logical change
  • Simpler codemods are more maintainable
  • Easier to test and debug individual transformations

Troubleshooting