Model Context Protocol (MCP)
Integrate Codegen with AI editors like Cursor using the Model Context Protocol
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 API 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
With Codegen’s MCP integration, your AI editor can:
- Generate codemods using the Codegen CLI
- Create and manage agent runs
- Access organization and user information
- 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: Set up your Codegen API credentials
-
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:
This starts the server with default settings (stdio transport). The server will display:
For additional options:
Note: HTTP transport is currently not fully implemented and will fall back to stdio transport.
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 → Model Context Protocol
- Press
-
Add New MCP Server
- Click “Add 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/globalStorage/mcp.json
- Windows:
%APPDATA%\Cursor\User\globalStorage\mcp.json
- Linux:
~/.config/Cursor/User/globalStorage/mcp.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_codemod
create_agent_run
get_organizations
get_users
Alternative Editors
Claude Desktop
For Claude Desktop, add this configuration to your claude_desktop_config.json
:
Configuration file locations:
- 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 your MCP settings:
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
Example usage in chat:
What it does: Provides instructions to use the Codegen CLI to create a codemod with the specified title and task description.
create_agent_run
Create a new agent run in your Codegen organization.
Parameters:
org_id
: Your organization IDprompt
: The task/prompt for the agent to executerepo_name
: Repository name (optional)branch_name
: Branch name (optional)
Example usage in chat:
get_agent_run
Get details of a specific agent run.
Parameters:
org_id
: Organization IDagent_run_id
: Agent run ID
Example usage in chat:
get_organizations
Get list of organizations you have access to.
Parameters:
page
: Page number (default: 1)limit
: Number of organizations per page (default: 10)
Example usage in chat:
get_users
Get list of users in an organization.
Parameters:
org_id
: Organization IDpage
: Page number (default: 1)limit
: Number of users per page (default: 10)
Example usage in chat:
get_user
Get details of a specific user in an organization.
Parameters:
org_id
: Organization IDuser_id
: User ID
Example usage in chat:
Authentication
The MCP server uses API key authentication. You can provide your API key in several ways:
Environment Variable (Recommended)
MCP Configuration
Include the API key in your MCP server configuration:
Getting Your API Key
- Visit the Codegen dashboard
- Navigate to your account settings
- Generate or copy your API key
- Set it as an environment variable or in your MCP configuration
Troubleshooting
Common Issues
MCP Server Not Starting
- Verify Codegen is properly installed:
codegen --version
- Check that the
codegen mcp
command works:codegen mcp --help
- Ensure your API key is set correctly
Tools Not Appearing in Editor
- Restart your AI editor after configuration changes
- Check the MCP server configuration syntax
- Verify the
codegen
command is in your system PATH - Look for error messages in the editor’s developer console
Authentication Errors
- Verify your API key is correct and not expired
- Check that the
CODEGEN_API_KEY
environment variable is set - Ensure you have the necessary permissions in your organization
Permission Errors
- Ensure the
codegen
command is executable - Check file permissions on configuration files
- Try running the editor with appropriate permissions
Path Resolution Issues
- Use absolute paths in configuration when possible
- Verify the
codegen
command 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:
Environment Variables You can set additional environment variables for the MCP server:
HTTP Transport (Future) For remote or multi-user setups, HTTP transport will be available:
Best Practices
-
Secure Your API Key: Never commit API keys to version control. Use environment variables or secure configuration management.
-
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
-
Monitor Agent Runs: Use the
get_agent_run
tool to monitor the progress and results of your agent runs
Examples
Example 1: Generate a React Hook Migration Codemod
In your AI editor chat:
Example 2: Create an Agent Run
Example 3: Monitor Agent Progress
Example 4: List Team Members
Resources
The MCP server also provides these resources for additional context:
system://agent_prompt
: Information about the Codegen SDK and platformsystem://setup_instructions
: Environment setup instructionssystem://manifest
: Server metadata and version information
Support
If you encounter issues with the MCP integration:
- Check the documentation: Review this guide and the official MCP documentation
- Test the CLI: Ensure
codegen mcp
works independently - Check logs: Look for error messages in your editor’s developer console
- 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
- Create and manage agent runs without leaving your IDE
- Access your organization’s resources and team information
- Streamline your code transformation workflows
- Integrate Codegen into your existing development process
Explore our API documentation to learn more about Codegen’s capabilities, or check out our examples repository for inspiration.