|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Installation and Setup |
| 8 | +```bash |
| 9 | +# Using uv (recommended) |
| 10 | +uv venv |
| 11 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 12 | +uv pip install -e . |
| 13 | + |
| 14 | +# Using pip |
| 15 | +python -m venv .venv |
| 16 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 17 | +pip install -e . |
| 18 | +``` |
| 19 | + |
| 20 | +### Running the MCP Server |
| 21 | +```bash |
| 22 | +# Basic run with stdio transport |
| 23 | +python src/codealive_mcp_server.py |
| 24 | + |
| 25 | +# With debug mode enabled |
| 26 | +python src/codealive_mcp_server.py --debug |
| 27 | + |
| 28 | +# With SSE transport |
| 29 | +python src/codealive_mcp_server.py --transport sse --host 0.0.0.0 --port 8000 |
| 30 | + |
| 31 | +# With custom API key and base URL |
| 32 | +python src/codealive_mcp_server.py --api-key YOUR_KEY --base-url https://custom.url |
| 33 | +``` |
| 34 | + |
| 35 | +### Docker Usage |
| 36 | +```bash |
| 37 | +# Build Docker image |
| 38 | +docker build -t codealive-mcp . |
| 39 | + |
| 40 | +# Run with Docker |
| 41 | +docker run --rm -i -e CODEALIVE_API_KEY=your_key_here codealive-mcp |
| 42 | +``` |
| 43 | + |
| 44 | +## Architecture |
| 45 | + |
| 46 | +This is a Model Context Protocol (MCP) server that provides AI clients with access to CodeAlive's semantic code search and analysis capabilities. |
| 47 | + |
| 48 | +### Core Components |
| 49 | + |
| 50 | +- **`codealive_mcp_server.py`**: Main server implementation using FastMCP framework |
| 51 | +- **Three main tools**: `chat_completions`, `search_code`, `get_data_sources` |
| 52 | +- **CodeAliveContext**: Manages HTTP client and API credentials |
| 53 | +- **Async lifespan management**: Handles client setup/teardown |
| 54 | + |
| 55 | +### Key Architectural Patterns |
| 56 | + |
| 57 | +1. **FastMCP Framework**: Uses modern async Python MCP implementation with lifespan context management |
| 58 | +2. **HTTP Client Management**: Single persistent httpx.AsyncClient with proper connection pooling |
| 59 | +3. **Streaming Support**: Implements streaming chat completions with proper chunk parsing |
| 60 | +4. **Environment Configuration**: Supports both .env files and command-line arguments with precedence |
| 61 | +5. **Error Handling**: Comprehensive HTTP status code handling with user-friendly error messages |
| 62 | + |
| 63 | +### Data Flow |
| 64 | + |
| 65 | +1. AI client connects to MCP server via stdio/SSE transport |
| 66 | +2. Client calls tools (`get_data_sources` → `search_code` → `chat_completions`) |
| 67 | +3. MCP server translates tool calls to CodeAlive API requests |
| 68 | +4. CodeAlive API returns semantic search results or chat completions |
| 69 | +5. Server formats and returns results to AI client |
| 70 | + |
| 71 | +### Environment Variables |
| 72 | + |
| 73 | +- `CODEALIVE_API_KEY`: Required API key for CodeAlive service |
| 74 | +- `CODEALIVE_BASE_URL`: API base URL (defaults to https://app.codealive.ai) |
| 75 | +- `CODEALIVE_IGNORE_SSL`: Set to disable SSL verification (debug mode) |
| 76 | + |
| 77 | +### Data Source Types |
| 78 | + |
| 79 | +- **Repository**: Individual code repositories with URL and repository ID |
| 80 | +- **Workspace**: Collections of repositories accessible via workspace ID |
| 81 | +- Tool calls can target specific repositories or entire workspaces for broader context |
| 82 | + |
| 83 | +### Integration Patterns |
| 84 | + |
| 85 | +The server is designed to integrate with: |
| 86 | +- Claude Desktop/Code (via settings.json configuration) |
| 87 | +- Cursor (via MCP settings panel) |
| 88 | +- VS Code with GitHub Copilot (via settings.json) |
| 89 | +- Continue (via config.yaml) |
| 90 | +- Any MCP-compatible AI client |
| 91 | + |
| 92 | +Key integration consideration: AI clients should use `get_data_sources` first to discover available repositories/workspaces, then use those IDs for targeted search and chat operations. |
0 commit comments