MCP server for source code analysis
Project description
optix-mcp-server
MCP server for source code analysis.
Prerequisites
- Python 3.10 or higher (3.13.11 recommended via pyenv)
- pip or uv package manager
- Git
Quick Start
1. Clone and Setup Environment
# Clone repository
git clone <repository-url>
cd optix-mcp-server
# Setup Python version (if using pyenv)
pyenv install 3.13.11
pyenv local 3.13.11
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
2. Install Dependencies
# Install package with dev dependencies
pip install -e ".[dev]"
# Or with uv (recommended)
uv pip install -e ".[dev]"
3. Configure Environment (Optional)
For features requiring API keys (like security_audit tool with LLM expert analysis):
# Copy the example environment file
cp .env.example .env
# Edit .env and add your API keys
# Example:
# OPENAI_API_KEY=sk-...
# OPTIX_LLM_PROVIDER=openai
The server automatically loads variables from .env file using python-dotenv.
4. Start Server
# Start with default settings (stdio transport)
python server.py
# Start with custom settings via environment variables
export SERVER_NAME=my-server
export LOG_LEVEL=DEBUG
python server.py
5. Run Tests
Note: Ensure the virtual environment is activated before running tests. If you see
ModuleNotFoundError: No module named 'mcp', runsource .venv/bin/activatefirst.
# Activate venv (if not already active)
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Run all tests
pytest
# Run only unit tests (fast)
pytest tests/unit/
# Run only integration tests
pytest tests/integration/
# Run with verbose output
pytest -v
Environment Variables
Server Configuration
| Variable | Default | Description |
|---|---|---|
SERVER_NAME |
optix-mcp-server | Server name for MCP |
OPTIX_LOG_LEVEL |
INFO | Logging level (DEBUG, INFO, WARN) |
LOG_LEVEL |
INFO | Fallback logging level if OPTIX_LOG_LEVEL not set |
TRANSPORT |
stdio | Transport type (stdio, sse, http) |
DISABLED_TOOLS |
(empty) | Comma-separated list of tools to disable |
API Keys (Optional)
Required for specific features like LLM expert analysis in audit tools (security_audit, devops_audit, a11y_audit):
| Variable | Description |
|---|---|
OPENAI_API_KEY |
OpenAI API key for GPT models |
GEMINI_API_KEY |
Google Gemini API key |
ANTHROPIC_API_KEY |
Anthropic Claude API key |
OPTIX_LLM_PROVIDER |
LLM provider to use (openai, gemini, anthropic) |
Expert Analysis Configuration
Optional settings for LLM-based expert validation of audit findings:
| Variable | Default | Description |
|---|---|---|
EXPERT_ANALYSIS_ENABLED |
false | Enable expert LLM analysis of audit findings |
EXPERT_ANALYSIS_TIMEOUT |
30 | Timeout for expert analysis in seconds |
EXPERT_ANALYSIS_MAX_FINDINGS |
50 | Maximum number of findings to analyze |
Note: Expert analysis requires EXPERT_ANALYSIS_ENABLED=true and a configured LLM provider (OPTIX_LLM_PROVIDER + corresponding API key). The expert analysis feature works with all audit tools (security_audit, devops_audit, a11y_audit) to provide LLM-validated assessments of findings, identify additional concerns, and prioritize remediation efforts.
Configuration via .env file (recommended):
- Copy
.env.exampleto.env - Add your API keys
- The server automatically loads
.envusingpython-dotenv
Logging Configuration
Setting Log Level
Control logging verbosity via the OPTIX_LOG_LEVEL environment variable:
# In .env file or shell
export OPTIX_LOG_LEVEL=DEBUG # Most verbose - detailed execution info
export OPTIX_LOG_LEVEL=INFO # Default - summary info
export OPTIX_LOG_LEVEL=WARN # Warnings only
Log Output
Logs are written to:
- File:
logs/optix.log(for real-time monitoring) - Stderr: Always enabled for immediate feedback
Log format:
2026-01-18 10:30:45 - INFO - [security_audit] Step 1 completed: 3 findings
Real-Time Log Monitoring
Monitor logs in real-time while the server is running:
# All logs from all tools
./watch-logs.sh all
# Filter by specific tool
./watch-logs.sh security # security_audit only
./watch-logs.sh a11y # a11y_audit only
./watch-logs.sh devops # devops_audit only
./watch-logs.sh health # health_check only
Development Workflow
Adding a New Tool
Tools in optix-mcp-server are MCP-agnostic, meaning they can be tested independently without MCP context.
-
Create tool directory:
tools/ └── my_tool/ ├── __init__.py ├── core.py # Business logic (no MCP imports) └── spec.md # Documentation -
Implement in
core.py(no MCP imports):def my_tool_impl(param: str) -> dict: """Pure business logic.""" return {"result": param.upper()}
-
Register in
server.py:from tools.my_tool.core import my_tool_impl from tools import register_tool @mcp.tool() def my_tool(param: str) -> str: return json.dumps(my_tool_impl(param)) register_tool("my_tool", impl=my_tool_impl, description="My tool description")
-
Add unit test in
tests/unit/tools/test_my_tool.py:from tools.my_tool.core import my_tool_impl def test_my_tool_impl(): result = my_tool_impl("hello") assert result["result"] == "HELLO"
Running Tests
# Full test suite
pytest tests/ -v
# Integration tests only
pytest tests/integration/ -v
# Unit tests only
pytest tests/unit/ -v
# Specific test file
pytest tests/unit/tools/test_health_check.py -v
Troubleshooting
Server won't start
- Check Python version:
python --version(needs 3.10+) - Verify dependencies:
pip list | grep mcp - Check configuration:
python -c "from config.defaults import ServerConfiguration; print(ServerConfiguration.from_env())"
Tests failing
- Ensure dev dependencies installed:
pip install -e ".[dev]"oruv pip install -e ".[dev]" - Check pytest version:
pytest --version(needs 7.0+) - Run single test for details:
pytest tests/unit/tools/test_health_check.py -v
Import errors
ModuleNotFoundError: No module named 'mcp'
- Virtual environment not activated. Run:
source .venv/bin/activate - Dependencies not installed. Run:
pip install -e ".[dev]"
Other import errors
- Ensure package is installed in editable mode:
pip install -e . - Check PYTHONPATH includes project root
- Verify
__init__.pyfiles exist in all packages
Configuration errors
If you see "server_name must be alphanumeric with hyphens allowed":
- Ensure
SERVER_NAMEenvironment variable uses only letters, numbers, and hyphens - Example valid names:
my-server,optix-mcp-server,server123
Quick Verification
Run this to verify everything is set up correctly:
# 1. Check Python
python --version
# 2. Check dependencies
python -c "from mcp.server.fastmcp import FastMCP; print('MCP OK')"
# 3. Check tools
python -c "import server; from tools import get_available_tools; print(get_available_tools())"
# 4. Run tests
pytest tests/ -v --tb=short
Expected output: All tests pass, health_check in available tools list.
Project Structure
optix-mcp-server/
├── server.py # MCP server entry point
├── config/
│ └── defaults.py # Configuration classes
├── tools/
│ ├── __init__.py # Tool registry
│ ├── base.py # Tool Protocol interface
│ └── health_check/ # health_check tool
│ ├── __init__.py
│ ├── core.py # Business logic (MCP-agnostic)
│ └── spec.md # Tool specification
└── tests/
├── integration/ # Integration tests
│ ├── conftest.py # Test fixtures
│ └── test_server_startup.py
└── unit/ # Unit tests
└── tools/
├── test_health_check.py
└── test_registry.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optix_mcp_server-0.1.1.tar.gz.
File metadata
- Download URL: optix_mcp_server-0.1.1.tar.gz
- Upload date:
- Size: 168.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d753531236286f263ebdb02d66198b3a5aeaabb8e40c6f660ba82f413fa0dd3
|
|
| MD5 |
a81d8059f31bde867a90d03082f3c9a5
|
|
| BLAKE2b-256 |
c9847fe57c7757754761d427a7ffa8502482daef63721c2c14215fcb3c89dc45
|
File details
Details for the file optix_mcp_server-0.1.1-py3-none-any.whl.
File metadata
- Download URL: optix_mcp_server-0.1.1-py3-none-any.whl
- Upload date:
- Size: 156.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c2f312dc1f2f5f2d0225a881570c2eba77697edb7c62e40030e3ca9701da0b1
|
|
| MD5 |
0f72f6b19046f2fdd0c8f8e0cc5992db
|
|
| BLAKE2b-256 |
bda0b7cae4857fbae8c3999eef550a49b715d183f13787426d80885714ed8d56
|