|
2 | 2 |
|
3 | 3 | A containerized Model Context Protocol (MCP) server providing static code analysis using Joern's Code Property Graph (CPG) technology with support for Java, C/C++, JavaScript, Python, Go, Kotlin, C#, Ghidra, Jimple, PHP, Ruby, and Swift. |
4 | 4 |
|
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before you begin, make sure you have: |
| 8 | + |
| 9 | +- **Docker** and **Docker Compose** installed |
| 10 | +- **Python 3.10+** (Python 3.13 recommended) |
| 11 | +- **pip** (Python package manager) |
| 12 | + |
| 13 | +To verify your setup: |
| 14 | + |
| 15 | +```bash |
| 16 | +docker --version |
| 17 | +docker-compose --version |
| 18 | +python --version |
| 19 | +``` |
| 20 | + |
5 | 21 | ## Quick Start |
6 | 22 |
|
7 | | -### Build and Run the Container |
| 23 | +### 1. Install Python Dependencies |
| 24 | + |
| 25 | +```bash |
| 26 | +# Create a virtual environment (optional but recommended) |
| 27 | +python -m venv venv |
| 28 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 29 | + |
| 30 | +# Install dependencies |
| 31 | +pip install -r requirements.txt |
| 32 | +``` |
| 33 | + |
| 34 | +### 2. Start the Docker Services (Joern + Redis) |
8 | 35 |
|
9 | 36 | ```bash |
10 | | -docker compose up --build |
| 37 | +docker compose up -d |
| 38 | +``` |
| 39 | + |
| 40 | +This starts: |
| 41 | +- **Joern Server**: Static code analysis engine (runs CPG generation and queries) |
| 42 | +- **Redis**: Metadata storage (tracks codebases, ports, and CPG information) |
| 43 | + |
| 44 | +Verify services are running: |
| 45 | + |
| 46 | +```bash |
| 47 | +docker compose ps |
| 48 | +``` |
| 49 | + |
| 50 | +### 3. Start the MCP Server |
| 51 | + |
| 52 | +```bash |
| 53 | +# Set the correct Redis port (maps to container's 6379) |
| 54 | +REDIS_PORT=6380 python main.py |
11 | 55 | ``` |
12 | 56 |
|
13 | 57 | The MCP server will be available at `http://localhost:4242`. |
14 | 58 |
|
15 | | -### Stop the Service |
| 59 | +### 4. Stop All Services |
16 | 60 |
|
17 | 61 | ```bash |
18 | | -docker compose down |
| 62 | +# Stop MCP server (Ctrl+C in terminal) |
| 63 | + |
| 64 | +# Stop Docker services |
| 65 | +docker-compose down |
| 66 | + |
| 67 | +# Optional: Clean up everything |
| 68 | +bash cleanup.sh |
19 | 69 | ``` |
20 | 70 |
|
| 71 | +## Cleanup Script |
| 72 | + |
| 73 | +Use the provided cleanup script to reset your environment: |
| 74 | + |
| 75 | +```bash |
| 76 | +bash cleanup.sh |
| 77 | +``` |
| 78 | + |
| 79 | +This will: |
| 80 | +- Stop and remove Docker containers |
| 81 | +- Kill orphaned Joern/MCP processes |
| 82 | +- Clear Python cache (`__pycache__`, `.pytest_cache`) |
| 83 | +- Optionally clear the playground directory (CPGs and cached codebases) |
| 84 | + |
21 | 85 | ## Integrations |
22 | 86 |
|
23 | 87 | ### GitHub Copilot Integration |
@@ -100,49 +164,121 @@ Add the following: |
100 | 164 |
|
101 | 165 | Thanks for contributing! Here's a quick guide to get started with running tests and contributing code. |
102 | 166 |
|
103 | | -Prerequisites |
| 167 | +### Prerequisites |
| 168 | + |
104 | 169 | - Python 3.10+ (3.13 is used in CI) |
105 | 170 | - Docker and Docker Compose (for integration tests) |
106 | 171 |
|
107 | | -Local development |
| 172 | +### Local Development Setup |
| 173 | + |
108 | 174 | 1. Create a virtual environment and install dependencies |
109 | 175 |
|
110 | 176 | ```bash |
111 | 177 | python -m venv venv |
112 | | -source venv/bin/activate |
113 | 178 | pip install -r requirements.txt |
114 | 179 | ``` |
115 | 180 |
|
116 | | -2. Run unit tests |
| 181 | +2. Start Docker services (for integration tests) |
| 182 | + |
| 183 | +```bash |
| 184 | +docker-compose up -d |
| 185 | +``` |
| 186 | + |
| 187 | +3. Run unit tests |
| 188 | + |
| 189 | +```bash |
| 190 | +pytest tests/ -q |
| 191 | +``` |
| 192 | + |
| 193 | +4. Run integration tests (requires Docker Compose running) |
117 | 194 |
|
118 | 195 | ```bash |
119 | | -pytest -q |
| 196 | +# Start MCP server in background |
| 197 | +REDIS_PORT=6380 python main.py & |
| 198 | + |
| 199 | +# Run integration tests |
| 200 | +pytest tests/integration -q |
| 201 | + |
| 202 | +# Stop MCP server |
| 203 | +pkill -f "python main.py" |
120 | 204 | ``` |
121 | 205 |
|
122 | | -3. Run integration tests (requires Docker Compose) |
| 206 | +5. Run all tests |
123 | 207 |
|
124 | 208 | ```bash |
125 | | -docker compose up --build -d |
126 | | -pytest -q tests/integration |
127 | | -docker compose down |
| 209 | +pytest tests/ -q |
128 | 210 | ``` |
129 | 211 |
|
130 | | -4. Run all tests |
| 212 | +6. Cleanup after testing |
131 | 213 |
|
132 | 214 | ```bash |
133 | | -pytest -q |
| 215 | +bash cleanup.sh |
| 216 | +docker-compose down |
134 | 217 | ``` |
135 | 218 |
|
136 | | -Please follow the repository conventions and open a PR with a clear changelog and tests for changes that affect behavior. |
| 219 | +### Code Contributions |
| 220 | + |
| 221 | +Please follow these guidelines when contributing: |
| 222 | + |
| 223 | +1. Follow repository conventions |
| 224 | +2. Write tests for behavioral changes |
| 225 | +3. Ensure all tests pass before submitting PR |
| 226 | +4. Include a clear changelog in your PR description |
| 227 | +5. Update documentation if needed |
137 | 228 |
|
138 | 229 | ## Configuration |
139 | 230 |
|
140 | | -Optional configuration via `config.yaml` (copy from `config.example.yaml`). |
| 231 | +The MCP server can be configured via environment variables or `config.yaml`. |
| 232 | + |
| 233 | +### Environment Variables |
| 234 | + |
| 235 | +Key settings (optional - defaults shown): |
141 | 236 |
|
142 | | -Key settings: |
143 | | -- Server host/port |
144 | | -- Redis settings |
145 | | -- Session timeouts |
146 | | -- CPG generation settings |
| 237 | +```bash |
| 238 | +# Server |
| 239 | +MCP_HOST=0.0.0.0 |
| 240 | +MCP_PORT=4242 |
| 241 | + |
| 242 | +# Redis (running inside Docker container) |
| 243 | +REDIS_HOST=localhost |
| 244 | +REDIS_PORT=6380 # ⚠️ IMPORTANT: Port 6380 on host maps to 6379 in container |
| 245 | + |
| 246 | +# Joern |
| 247 | +JOERN_BINARY_PATH=joern |
| 248 | +JOERN_JAVA_OPTS="-Xmx4G -Xms2G -XX:+UseG1GC -Dfile.encoding=UTF-8" |
| 249 | + |
| 250 | +# CPG Generation |
| 251 | +CPG_GENERATION_TIMEOUT=600 |
| 252 | +MAX_REPO_SIZE_MB=500 |
| 253 | + |
| 254 | +# Query |
| 255 | +QUERY_TIMEOUT=30 |
| 256 | +QUERY_CACHE_ENABLED=true |
| 257 | +QUERY_CACHE_TTL=300 |
| 258 | +``` |
| 259 | + |
| 260 | +### Config File |
| 261 | + |
| 262 | +Create a `config.yaml` from `config.example.yaml`: |
| 263 | + |
| 264 | +```bash |
| 265 | +cp config.example.yaml config.yaml |
| 266 | +``` |
| 267 | + |
| 268 | +Then customize as needed. |
| 269 | + |
| 270 | +### Important: Redis Port Configuration |
| 271 | + |
| 272 | +Since Redis runs inside the Docker container: |
| 273 | + |
| 274 | +- **Inside container**: Redis listens on `6379` |
| 275 | +- **Host mapping**: Docker maps `6380:6379` |
| 276 | +- **MCP server should use**: `REDIS_PORT=6380` |
| 277 | + |
| 278 | +Always start the MCP server with: |
| 279 | + |
| 280 | +```bash |
| 281 | +REDIS_PORT=6380 python main.py |
| 282 | +``` |
147 | 283 |
|
148 | 284 |
|
0 commit comments