Skip to content

Commit d31e69a

Browse files
Upgrade codegen MCP server - remove codemods, add docs (#1162)
Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
1 parent 53af51f commit d31e69a

File tree

17 files changed

+209
-10031
lines changed

17 files changed

+209
-10031
lines changed

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.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ dependencies = [
2323
"codeowners>=0.6.0",
2424
"unidiff>=0.7.5",
2525
"datamodel-code-generator>=0.26.5",
26-
"mcp[cli]==1.9.4",
2726
"fastmcp>=2.9.0",
2827
# Utility dependencies
2928
"colorlog>=6.9.0",

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/init/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pathlib import Path
2-
from typing import Optional
32

43
import rich
54
import typer
@@ -10,9 +9,9 @@
109

1110

1211
def init(
13-
path: Optional[str] = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
14-
token: Optional[str] = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
15-
language: Optional[str] = typer.Option(None, help="Override automatic language detection (python or typescript)"),
12+
path: str | None = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
13+
token: str | None = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
14+
language: str | None = typer.Option(None, help="Override automatic language detection (python or typescript)"),
1615
fetch_docs: bool = typer.Option(False, "--fetch-docs", help="Fetch docs and examples (requires auth)"),
1716
):
1817
"""Initialize or update the Codegen folder."""

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Optional
21

32
import rich
43
import typer
@@ -7,7 +6,7 @@
76
from codegen.cli.auth.token_manager import get_current_token
87

98

10-
def login(token: Optional[str] = typer.Option(None, help="API token for authentication")):
9+
def login(token: str | None = typer.Option(None, help="API token for authentication")):
1110
"""Store authentication token."""
1211
# Check if already authenticated
1312
if get_current_token():
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
2-

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""MCP server command for the Codegen CLI."""
22

3-
from typing import Optional
43

54
import typer
65
from rich.console import Console
@@ -10,7 +9,7 @@
109

1110
def mcp(
1211
host: str = typer.Option("localhost", help="Host to bind the MCP server to"),
13-
port: Optional[int] = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
12+
port: int | None = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
1413
transport: str = typer.Option("stdio", help="Transport protocol to use (stdio or http)"),
1514
):
1615
"""Start the Codegen MCP server."""
@@ -19,6 +18,8 @@ def mcp(
1918
if transport == "stdio":
2019
console.print("📡 Using stdio transport", style="dim")
2120
else:
21+
if port is None:
22+
port = 8000
2223
console.print(f"📡 Using HTTP transport on {host}:{port}", style="dim")
2324

2425
# Validate transport

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22
import sys
33
from importlib.metadata import distribution
4-
from typing import Optional
54

65
import requests
76
import rich
@@ -33,7 +32,7 @@ def install_package(package: str, *args: str) -> None:
3332

3433
def update(
3534
list_: bool = typer.Option(False, "--list", "-l", help="List all supported versions of the codegen"),
36-
version: Optional[str] = typer.Option(None, "--version", "-v", help="Update to a specific version of the codegen"),
35+
version: str | None = typer.Option(None, "--version", "-v", help="Update to a specific version of the codegen"),
3736
):
3837
"""Update Codegen to the latest or specified version
3938

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)