Skip to content

Upgrade codegen MCP server - remove codemods, add docs #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"integrations/figma",
"integrations/circleci",
"integrations/web-search",
"integrations/postgres"
"integrations/postgres",
"integrations/mcp"
]
},
{
Expand Down
179 changes: 179 additions & 0 deletions docs/integrations/mcp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
---
title: "MCP Server"
description: "Connect AI agents to Codegen using the Model Context Protocol (MCP) server"
---

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.

## Overview

The MCP server provides:
- **API Integration**: Direct access to Codegen platform APIs
- **Agent Management**: Create and monitor agent runs
- **Organization Management**: Access organization and user information
- **Workflow Integration**: Seamless integration with AI development tools

## Installation

The MCP server is included with the Codegen CLI. Install it using:

```bash
uv tool install codegen
```

## Configuration

### For Cline (VS Code Extension)

Add this to your `cline_mcp_settings.json` file:

```json
{
"mcpServers": {
"codegen": {
"command": "codegen",
"args": ["mcp"],
"cwd": "<path to your project>"
}
}
}
```

### For Claude Desktop

Under the `Settings` > `Feature` > `MCP Servers` section, click "Add New MCP Server" and add the following:

- **Server Name**: codegen-mcp
- **Command**: `codegen`
- **Arguments**: `["mcp"]`

## Usage

### Starting the Server

Start the MCP server using the Codegen CLI:

```bash
# Start with stdio transport (default)
codegen mcp

# Start with HTTP transport on a specific port
codegen mcp --transport http --port 8080

# Start with custom host and port
codegen mcp --transport http --host 0.0.0.0 --port 3000
```

The server will display the transport method and port information when it starts:

```
🚀 Starting Codegen MCP server...
📡 Using stdio transport
🚀 MCP server running on stdio transport
```

### Environment Variables

Configure the MCP server using these environment variables:

- `CODEGEN_API_KEY`: Your Codegen API key for authentication
- `CODEGEN_API_BASE_URL`: Base URL for the Codegen API (defaults to `https://api.codegen.com`)

## Available Tools

The MCP server provides the following tools for AI agents:

### Agent Management

- **create_agent_run**: Create a new agent run in your organization
- **get_agent_run**: Get details of a specific agent run

### Organization Management

- **get_organizations**: List organizations you have access to
- **get_users**: List users in an organization
- **get_user**: Get details of a specific user

## Transport Options

The MCP server supports two transport methods:

### stdio (Default)
- Best for most AI agents and IDE integrations
- Direct communication through standard input/output
- No network configuration required

### HTTP
- Useful for web-based integrations
- Requires specifying host and port
- Currently falls back to stdio (HTTP support coming soon)

## Authentication

The MCP server uses your Codegen API key for authentication. You can obtain your API key from the [Codegen dashboard](https://codegen.com/settings).

Set your API key as an environment variable:

```bash
export CODEGEN_API_KEY="your-api-key-here"
```

## Troubleshooting

### Common Issues

**Server won't start**
- Ensure the Codegen CLI is properly installed
- Check that your API key is set correctly
- Verify network connectivity to the Codegen API

**Authentication errors**
- Verify your API key is valid and not expired
- Check that the API key has the necessary permissions
- Ensure the `CODEGEN_API_KEY` environment variable is set

**Connection issues**
- For stdio transport, ensure your AI agent supports MCP
- For HTTP transport, check firewall settings and port availability
- Verify the host and port configuration

### Getting Help

If you encounter issues with the MCP server:

1. Check the [Codegen documentation](https://docs.codegen.com)
2. Join our [community Slack](https://community.codegen.com)
3. Report issues on [GitHub](https://github.com/codegen-sh/codegen)

## Examples

### Creating an Agent Run

```python
# Example of how an AI agent might use the MCP server
# This would be handled automatically by your AI agent

{
"tool": "create_agent_run",
"arguments": {
"org_id": 123,
"prompt": "Review the latest pull request and suggest improvements",
"repo_name": "my-project",
"branch_name": "feature-branch"
}
}
```

### Getting Organization Information

```python
{
"tool": "get_organizations",
"arguments": {
"page": 1,
"limit": 10
}
}
```

The MCP server makes it easy to integrate Codegen's powerful AI development capabilities into your existing AI agent workflows.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies = [
"codeowners>=0.6.0",
"unidiff>=0.7.5",
"datamodel-code-generator>=0.26.5",
"mcp[cli]==1.9.4",
"fastmcp>=2.9.0",
# Utility dependencies
"colorlog>=6.9.0",
Expand Down
1 change: 0 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ exclude = [
"*.ipynb",
] # disable just linting for notebooks (allow for formatting)
[lint.per-file-ignores]
"src/codegen/cli/mcp/resources/system_prompt.py" = ["E501"]
[lint.pydocstyle]
convention = "google"
[lint.pyflakes]
Expand Down
7 changes: 3 additions & 4 deletions src/codegen/cli/commands/init/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Optional

import rich
import typer
Expand All @@ -10,9 +9,9 @@


def init(
path: Optional[str] = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
token: Optional[str] = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
language: Optional[str] = typer.Option(None, help="Override automatic language detection (python or typescript)"),
path: str | None = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
token: str | None = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
language: str | None = typer.Option(None, help="Override automatic language detection (python or typescript)"),
fetch_docs: bool = typer.Option(False, "--fetch-docs", help="Fetch docs and examples (requires auth)"),
):
"""Initialize or update the Codegen folder."""
Expand Down
3 changes: 1 addition & 2 deletions src/codegen/cli/commands/login/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Optional

import rich
import typer
Expand All @@ -7,7 +6,7 @@
from codegen.cli.auth.token_manager import get_current_token


def login(token: Optional[str] = typer.Option(None, help="API token for authentication")):
def login(token: str | None = typer.Option(None, help="API token for authentication")):
"""Store authentication token."""
# Check if already authenticated
if get_current_token():
Expand Down
2 changes: 0 additions & 2 deletions src/codegen/cli/commands/mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@


5 changes: 3 additions & 2 deletions src/codegen/cli/commands/mcp/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""MCP server command for the Codegen CLI."""

from typing import Optional

import typer
from rich.console import Console
Expand All @@ -10,7 +9,7 @@

def mcp(
host: str = typer.Option("localhost", help="Host to bind the MCP server to"),
port: Optional[int] = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
port: int | None = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
transport: str = typer.Option("stdio", help="Transport protocol to use (stdio or http)"),
):
"""Start the Codegen MCP server."""
Expand All @@ -19,6 +18,8 @@
if transport == "stdio":
console.print("📡 Using stdio transport", style="dim")
else:
if port is None:
port = 8000

Check warning on line 22 in src/codegen/cli/commands/mcp/main.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/cli/commands/mcp/main.py#L21-L22

Added lines #L21 - L22 were not covered by tests
console.print(f"📡 Using HTTP transport on {host}:{port}", style="dim")

# Validate transport
Expand Down
3 changes: 1 addition & 2 deletions src/codegen/cli/commands/update/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess
import sys
from importlib.metadata import distribution
from typing import Optional

import requests
import rich
Expand Down Expand Up @@ -33,7 +32,7 @@ def install_package(package: str, *args: str) -> None:

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

Expand Down
2 changes: 1 addition & 1 deletion src/codegen/cli/mcp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Codegen MCP server

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.
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.

### Dependencies

Expand Down
Loading
Loading