Integrate Codegen with AI editors like Cursor using the Model Context Protocol
The Model Context Protocol (MCP) is an open standard that enables AI applications to securely connect to external data sources and tools. Codegen provides an MCP server that allows AI editors like Cursor to access Codegen’s powerful codemod generation and SDK capabilities directly within your development workflow.
MCP acts as a bridge between AI assistants and external tools, allowing them to:
With Codegen’s MCP integration, your AI editor can:
Before setting up the MCP server, ensure you have:
Codegen CLI installed: Install via pip or your preferred package manager
Authentication: Log in to your Codegen account
AI Editor with MCP support: Currently supported editors include:
The easiest way to start the Codegen MCP server is using the built-in CLI command:
This starts the server with default settings (stdio transport). For additional options:
The configuration depends on your AI editor. See the sections below for specific setup instructions.
Cursor provides the most seamless MCP integration experience. Follow these steps:
Open Cursor Settings
Cmd/Ctrl + ,
to open settingsAdd New MCP Server
Save and Restart
If you prefer manual configuration, you can edit Cursor’s MCP configuration file directly:
Locate the configuration file:
~/Library/Application Support/Cursor/User/mcp_servers.json
%APPDATA%\Cursor\User\mcp_servers.json
~/.config/Cursor/User/mcp_servers.json
Add the Codegen MCP server:
Restart Cursor to load the new configuration.
To verify the MCP server is working in Cursor:
generate_codemod
ask_codegen_sdk
improve_codemod
For Claude Desktop, add this configuration to your claude_desktop_config.json
:
Configuration file locations:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
For the Cline VS Code extension, add this to your cline_mcp_settings.json
:
Once configured, the Codegen MCP server provides these tools to your AI editor:
generate_codemod
Generate a new codemod for a specific task and codebase.
Parameters:
title
: The title of the codemod (hyphenated format)task
: Description of what the codemod should accomplishcodebase_path
: Absolute path to your codebase directoryExample usage in chat:
ask_codegen_sdk
Get expert guidance on any aspect of the Codegen SDK.
Parameters:
query
: Your question about the Codegen SDKExample usage in chat:
improve_codemod
Improve an existing codemod based on feedback and concerns.
Parameters:
codemod_source
: The source code of the codemod to improvetask
: The original task descriptionconcerns
: List of issues discovered with the current codemodcontext
: Additional context and related fileslanguage
: Programming language (e.g., PYTHON, TYPESCRIPT)The MCP server uses your existing Codegen authentication. Ensure you’re logged in:
If you encounter authentication issues:
codegen profile
codegen logout && codegen login
MCP Server Not Starting
codegen --version
codegen profile
codegen mcp --verbose
Tools Not Appearing in Editor
codegen
command is in your system PATHPermission Errors
codegen
command is executablePath Resolution Issues
codegen
command location: which codegen
Custom Server Path If you need to specify a custom path to the Codegen installation:
Environment Variables You can set environment variables for the MCP server:
HTTP Transport For remote or multi-user setups, you can use HTTP transport:
Then configure your editor to connect to the HTTP endpoint instead of using the command interface.
Keep Codegen Updated: Regularly update to get the latest MCP features
Use Descriptive Codemod Names: Use clear, hyphenated names for generated codemods
Provide Clear Task Descriptions: Be specific about what you want the codemod to accomplish
Test Generated Codemods: Always review and test generated codemods before applying them to production code
Use Version Control: Commit your code before running codemods to easily revert if needed
In your AI editor chat:
If you encounter issues with the MCP integration:
codegen mcp --verbose
for detailed error informationWith Codegen MCP integration set up, you can:
Explore our SDK documentation to learn more about Codegen’s capabilities, or check out our examples repository for inspiration.