|
| 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. |
0 commit comments