This guide covers deploying semantic-code-mcp in production environments.
- Node.js: 18.0.0 or higher
- Memory: 4GB RAM minimum (8GB recommended for large codebases)
- Disk: 2x the size of your codebase for index storage
- CPU: 2 cores minimum (4+ recommended for faster indexing)
- Memory: 16GB RAM
- Disk: SSD storage for index (significantly faster queries)
- CPU: 8+ cores for parallel indexing
| Variable | Description | Default |
|---|---|---|
SEMANTIC_CODE_ROOT |
Root directory to index | Current working directory |
SEMANTIC_CODE_INDEX |
Custom index storage location | .semantic-code/index/ |
LOG_LEVEL |
Minimum log level (debug, info, warn, error) | info |
LOG_FORMAT |
Log format (text, json) | text |
npm install -g semantic-code-mcp
# Run from any project directory (uses cwd)
cd /path/to/project
semantic-code-mcp
# Or specify directory as argument
semantic-code-mcp /path/to/project
# Or use environment variable
SEMANTIC_CODE_ROOT=/path/to/project semantic-code-mcp# Uses current directory
cd /path/to/project
npx semantic-code-mcp
# Or specify directory as argument
npx semantic-code-mcp /path/to/project
# Or use environment variable
SEMANTIC_CODE_ROOT=/path/to/project npx semantic-code-mcpFROM node:20-slim
WORKDIR /app
# Install semantic-code-mcp
RUN npm install -g semantic-code-mcp
# Create directory for code and index
RUN mkdir -p /code /index
# Set environment variables
ENV SEMANTIC_CODE_ROOT=/code
ENV SEMANTIC_CODE_INDEX=/index
ENV LOG_FORMAT=json
ENV LOG_LEVEL=info
# Mount points:
# - /code: Your codebase (read-only recommended)
# - /index: Index storage (read-write)
ENTRYPOINT ["semantic-code-mcp"]Build and run:
# Build the image
docker build -t semantic-code-mcp .
# Run with mounted volumes
docker run -v /path/to/project:/code:ro \
-v /path/to/index:/index \
semantic-code-mcpversion: '3.8'
services:
semantic-code:
image: semantic-code-mcp
build: .
volumes:
- /path/to/project:/code:ro
- semantic-code-index:/index
environment:
- SEMANTIC_CODE_ROOT=/code
- SEMANTIC_CODE_INDEX=/index
- LOG_FORMAT=json
- LOG_LEVEL=info
restart: unless-stopped
volumes:
semantic-code-index:Add to ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"semantic-code": {
"command": "npx",
"args": ["semantic-code-mcp"]
}
}
}The server automatically uses your current working directory. To specify a different directory or customize settings:
{
"mcpServers": {
"semantic-code": {
"command": "npx",
"args": ["semantic-code-mcp", "/absolute/path/to/project"],
"env": {
"SEMANTIC_CODE_INDEX": "/absolute/path/to/index",
"LOG_LEVEL": "info"
}
}
}
}When indexing codebases with 100K+ files:
- Increase flush threshold: Lower
maxChunksInMemoryto reduce memory usage
await indexDirectory({
rootDir: '/path/to/monorepo',
store,
maxChunksInMemory: 200, // Default is 500
batchSize: 5, // Default is 10
});-
Use SSD storage: Index queries are I/O bound
-
Exclude unnecessary files: Add patterns to ignore
const ignorePatterns = [
'**/node_modules/**',
'**/dist/**',
'**/*.generated.*',
'**/vendor/**',
];The server uses approximately:
- Base: ~500MB for model loading
- Per 1000 chunks: ~3MB of embedding data
- Peak during indexing: Base + (maxChunksInMemory * 3KB)
To reduce memory usage:
- Lower
maxChunksInMemory(trades memory for more database writes) - Process files in smaller batches
- Use quantized embeddings (q8 is default, q4 uses less memory)
For fastest query performance:
- Limit result count: Use smaller
limitvalues when possible - Use filters: Language and path filters reduce search space
- Disable reranking for speed: Set
useReranking: falsefor faster results
All logs go to stderr (MCP protocol compatible). Example JSON log:
{
"timestamp": "2024-01-15T10:30:45.123Z",
"level": "info",
"component": "search",
"message": "Search complete",
"data": {
"resultCount": 10,
"latencyMs": 45
}
}The server tracks internal metrics accessible via the metrics module:
filesIndexed: Total files indexedchunksCreated: Total chunks createdqueriesTotal: Total search queriesqueryLatencyMs: Search latency samplesfallbacksTriggered: Keyword fallback counterrorsCount: Error count
- Read-only code access: Mount codebase as read-only where possible
- Index isolation: Store index in a separate directory
- Input validation: All user inputs are validated against injection
- Path traversal protection: Paths are validated to stay within root
The index is stored in LanceDB format under the index directory:
# Backup
tar -czf semantic-code-backup.tar.gz .semantic-code/index/
# Restore
tar -xzf semantic-code-backup.tar.gzIf the index becomes corrupted:
# Remove the index directory
rm -rf .semantic-code/index/
# The index will rebuild on next searchSee Troubleshooting Guide for common issues and solutions.