Model Context Protocol (MCP)
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.What is MCP?
MCP acts as a bridge between AI assistants and external tools, allowing them to:- Access external data sources and APIs
- Execute tools and commands safely
- Provide rich context to improve AI responses
- Maintain security through standardized protocols
- Generate codemods using the Codegen SDK
- Access Codegen documentation and examples
- Get expert guidance on Codegen best practices
- Streamline your code transformation workflows
Prerequisites
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:
- Cursor (recommended)
- Claude Desktop
- Cline (VS Code extension)
Quick Start
1. Start the MCP Server
The easiest way to start the Codegen MCP server is using the built-in CLI command:2. Configure Your AI Editor
The configuration depends on your AI editor. See the sections below for specific setup instructions.Cursor Configuration
Cursor provides the most seamless MCP integration experience. Follow these steps:Method 1: Using Cursor Settings (Recommended)
-
Open Cursor Settings
- Press
Cmd/Ctrl + ,to open settings - Navigate to Features → MCP Servers
- Press
-
Add New MCP Server
- Click “Add New MCP Server”
- Fill in the following details:
-
Save and Restart
- Click “Save”
- Restart Cursor to activate the MCP server
Method 2: Manual Configuration File
If you prefer manual configuration, you can edit Cursor’s MCP configuration file directly:-
Locate the configuration file:
- macOS:
~/Library/Application Support/Cursor/User/mcp_servers.json - Windows:
%APPDATA%\Cursor\User\mcp_servers.json - Linux:
~/.config/Cursor/User/mcp_servers.json
- macOS:
-
Add the Codegen MCP server:
- Restart Cursor to load the new configuration.
Verification
To verify the MCP server is working in Cursor:- Open a new chat in Cursor
- Look for “Available Tools” in the chat interface
- You should see Codegen MCP tools listed, such as:
generate_codemodask_codegen_sdkimprove_codemod
Alternative Editors
Claude Desktop
For Claude Desktop, add this configuration to yourclaude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Cline (VS Code Extension)
For the Cline VS Code extension, add this to yourcline_mcp_settings.json:
Available Tools
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 directory
ask_codegen_sdk
Get expert guidance on any aspect of the Codegen SDK.
Parameters:
query: Your question about the Codegen SDK
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)
Authentication
The MCP server uses your existing Codegen authentication. Ensure you’re logged in:- Verify your login status:
codegen profile - Re-authenticate if needed:
codegen logout && codegen login - Check your API token: Ensure your token hasn’t expired
Troubleshooting
Common Issues
MCP Server Not Starting- Verify Codegen is properly installed:
codegen --version - Check authentication:
codegen profile - Try running with verbose logging:
codegen mcp --verbose
- Restart your AI editor after configuration changes
- Check the MCP server configuration syntax
- Verify the
codegencommand is in your system PATH
- Ensure the
codegencommand is executable - Check file permissions on configuration files
- Try running the editor with appropriate permissions
- Use absolute paths in configuration when possible
- Verify the
codegencommand location:which codegen - Consider using the full path to the codegen executable
Advanced Configuration
Custom Server Path If you need to specify a custom path to the Codegen installation:Best Practices
-
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
Examples
Example 1: Generate a React Hook Migration Codemod
In your AI editor chat:Example 2: Get SDK Help
Example 3: Improve an Existing Codemod
Support
If you encounter issues with the MCP integration:- Check the documentation: Review this guide and the official MCP documentation
- Enable verbose logging: Use
codegen mcp --verbosefor detailed error information - Community support: Join our Discord community for help
- Report bugs: Create an issue on our GitHub repository
What’s Next?
With Codegen MCP integration set up, you can:- Generate codemods directly from your AI editor
- Get instant help with Codegen SDK questions
- Streamline your code transformation workflows
- Iterate quickly on codemod improvements