Skip to content

Commit 1effdb9

Browse files
Upgrade codegen MCP server
- Remove all codemod-related functionality and legacy imports - Remove ask_codegen_sdk, generate_codemod, and improve_codemod tools - Delete system_prompt.py and system_setup_instructions.py resources - Update server description to focus on API integration - Add port information display when server starts - Add comprehensive MCP documentation in docs/integrations/mcp.mdx - Update docs.json to include MCP in integrations section - Clean up ruff.toml configuration The MCP server now focuses on Codegen platform API integration rather than codemod generation, providing a cleaner interface for AI agents to interact with Codegen services.
1 parent 53af51f commit 1effdb9

8 files changed

Lines changed: 188 additions & 10002 deletions

File tree

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"integrations/figma",
4040
"integrations/circleci",
4141
"integrations/web-search",
42-
"integrations/postgres"
42+
"integrations/postgres",
43+
"integrations/mcp"
4344
]
4445
},
4546
{

docs/integrations/mcp.mdx

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
---
2+
title: "MCP Server"
3+
description: "Connect AI agents to Codegen using the Model Context Protocol (MCP) server"
4+
---
5+
6+
The Codegen MCP server enables AI agents to interact with the Codegen platform through the Model Context Protocol (MCP). This integration allows AI agents to access Codegen APIs, manage agent runs, and interact with your development workflow.
7+
8+
## Overview
9+
10+
The MCP server provides:
11+
- **API Integration**: Direct access to Codegen platform APIs
12+
- **Agent Management**: Create and monitor agent runs
13+
- **Organization Management**: Access organization and user information
14+
- **Workflow Integration**: Seamless integration with AI development tools
15+
16+
## Installation
17+
18+
The MCP server is included with the Codegen CLI. Install it using:
19+
20+
```bash
21+
uv tool install codegen
22+
```
23+
24+
## Configuration
25+
26+
### For Cline (VS Code Extension)
27+
28+
Add this to your `cline_mcp_settings.json` file:
29+
30+
```json
31+
{
32+
"mcpServers": {
33+
"codegen": {
34+
"command": "codegen",
35+
"args": ["mcp"],
36+
"cwd": "<path to your project>"
37+
}
38+
}
39+
}
40+
```
41+
42+
### For Claude Desktop
43+
44+
Under the `Settings` > `Feature` > `MCP Servers` section, click "Add New MCP Server" and add the following:
45+
46+
- **Server Name**: codegen-mcp
47+
- **Command**: `codegen`
48+
- **Arguments**: `["mcp"]`
49+
50+
## Usage
51+
52+
### Starting the Server
53+
54+
Start the MCP server using the Codegen CLI:
55+
56+
```bash
57+
# Start with stdio transport (default)
58+
codegen mcp
59+
60+
# Start with HTTP transport on a specific port
61+
codegen mcp --transport http --port 8080
62+
63+
# Start with custom host and port
64+
codegen mcp --transport http --host 0.0.0.0 --port 3000
65+
```
66+
67+
The server will display the transport method and port information when it starts:
68+
69+
```
70+
🚀 Starting Codegen MCP server...
71+
📡 Using stdio transport
72+
🚀 MCP server running on stdio transport
73+
```
74+
75+
### Environment Variables
76+
77+
Configure the MCP server using these environment variables:
78+
79+
- `CODEGEN_API_KEY`: Your Codegen API key for authentication
80+
- `CODEGEN_API_BASE_URL`: Base URL for the Codegen API (defaults to `https://api.codegen.com`)
81+
82+
## Available Tools
83+
84+
The MCP server provides the following tools for AI agents:
85+
86+
### Agent Management
87+
88+
- **create_agent_run**: Create a new agent run in your organization
89+
- **get_agent_run**: Get details of a specific agent run
90+
91+
### Organization Management
92+
93+
- **get_organizations**: List organizations you have access to
94+
- **get_users**: List users in an organization
95+
- **get_user**: Get details of a specific user
96+
97+
## Transport Options
98+
99+
The MCP server supports two transport methods:
100+
101+
### stdio (Default)
102+
- Best for most AI agents and IDE integrations
103+
- Direct communication through standard input/output
104+
- No network configuration required
105+
106+
### HTTP
107+
- Useful for web-based integrations
108+
- Requires specifying host and port
109+
- Currently falls back to stdio (HTTP support coming soon)
110+
111+
## Authentication
112+
113+
The MCP server uses your Codegen API key for authentication. You can obtain your API key from the [Codegen dashboard](https://codegen.com/settings).
114+
115+
Set your API key as an environment variable:
116+
117+
```bash
118+
export CODEGEN_API_KEY="your-api-key-here"
119+
```
120+
121+
## Troubleshooting
122+
123+
### Common Issues
124+
125+
**Server won't start**
126+
- Ensure the Codegen CLI is properly installed
127+
- Check that your API key is set correctly
128+
- Verify network connectivity to the Codegen API
129+
130+
**Authentication errors**
131+
- Verify your API key is valid and not expired
132+
- Check that the API key has the necessary permissions
133+
- Ensure the `CODEGEN_API_KEY` environment variable is set
134+
135+
**Connection issues**
136+
- For stdio transport, ensure your AI agent supports MCP
137+
- For HTTP transport, check firewall settings and port availability
138+
- Verify the host and port configuration
139+
140+
### Getting Help
141+
142+
If you encounter issues with the MCP server:
143+
144+
1. Check the [Codegen documentation](https://docs.codegen.com)
145+
2. Join our [community Slack](https://community.codegen.com)
146+
3. Report issues on [GitHub](https://github.com/codegen-sh/codegen)
147+
148+
## Examples
149+
150+
### Creating an Agent Run
151+
152+
```python
153+
# Example of how an AI agent might use the MCP server
154+
# This would be handled automatically by your AI agent
155+
156+
{
157+
"tool": "create_agent_run",
158+
"arguments": {
159+
"org_id": 123,
160+
"prompt": "Review the latest pull request and suggest improvements",
161+
"repo_name": "my-project",
162+
"branch_name": "feature-branch"
163+
}
164+
}
165+
```
166+
167+
### Getting Organization Information
168+
169+
```python
170+
{
171+
"tool": "get_organizations",
172+
"arguments": {
173+
"page": 1,
174+
"limit": 10
175+
}
176+
}
177+
```
178+
179+
The MCP server makes it easy to integrate Codegen's powerful AI development capabilities into your existing AI agent workflows.

ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ exclude = [
4949
"*.ipynb",
5050
] # disable just linting for notebooks (allow for formatting)
5151
[lint.per-file-ignores]
52-
"src/codegen/cli/mcp/resources/system_prompt.py" = ["E501"]
5352
[lint.pydocstyle]
5453
convention = "google"
5554
[lint.pyflakes]

src/codegen/cli/commands/mcp/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def mcp(
1919
if transport == "stdio":
2020
console.print("📡 Using stdio transport", style="dim")
2121
else:
22+
if port is None:
23+
port = 8000
2224
console.print(f"📡 Using HTTP transport on {host}:{port}", style="dim")
2325

2426
# Validate transport

src/codegen/cli/mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Codegen MCP server
22

3-
A MCP server implementation that provides tools and resources for using and working with the Codegen CLI and SDK, enabling AI agents to iterate quickly on writing codemods with the codegen sdk.
3+
A MCP server implementation that provides tools and resources for interacting with the Codegen platform APIs, enabling AI agents to manage development workflows and access Codegen services.
44

55
### Dependencies
66

0 commit comments

Comments
 (0)