sacl
SACL (Semantic-Augmented Code Localization) - A bias-aware code retrieval framework with MCP server integration for AI assistants
Documentation
SACL MCP Server
Semantic-Augmented Reranking and Localization for Code Retrieval
A Model Context Protocol (MCP) server that implements the SACL research framework to provide bias-aware code retrieval for AI coding assistants like Claude Code, Cursor, and other MCP-enabled tools.
๐ฏ Overview
SACL addresses the critical problem of textual bias in code retrieval systems. Traditional systems over-rely on surface-level features like docstrings, comments, and variable names, leading to biased results that favor well-documented code regardless of functional relevance.
Key Features
- ๐ง Bias Detection: Identifies over-reliance on textual features
- ๐ Semantic Augmentation: Enriches code understanding beyond surface text
- ๐ Intelligent Reranking: Prioritizes functional relevance over documentation
- ๐ฏ Code Localization: Pinpoints functionally relevant code segments
- ๐ Relationship Analysis: Maps code dependencies and relationships
- ๐จ Context-Aware Retrieval: Returns results with related components
- ๐ Agent-Controlled Updates: Explicit file updates for Docker compatibility
- ๐๏ธ Knowledge Graph: Persistent semantic storage with Graphiti/Neo4j
- ๐ง MCP Integration: Works with Claude Code, Cursor, and other AI tools
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ AI Assistant โโโโโโ SACL MCP Server โโโโโโ Graphiti/Neo4j โ
โ (Claude, Cursor)โ โ โ โ Knowledge Graph โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโ
โ SACL Framework โ
โ โ
โ โข Bias Detectionโ
โ โข Semantic Aug. โ
โ โข Reranking โ
โ โข Localization โ
โ โข Relationships โ
โ โข Context-Aware โ
โโโโโโโโโโโโโโโโโโโ๐ Quick Start
Prerequisites
- Node.js 18+
- Neo4j database
- OpenAI API key
Installation
# Clone the repository
git clone
cd sacl
# Install dependencies
npm install
# Copy environment configuration
cp .env.example .env
# Edit .env with your settings
OPENAI_API_KEY=your_key_here
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_passwordUsing Docker (Recommended)
# Start Neo4j and SACL server
docker-compose up -d
# Check logs
docker-compose logs -f sacl-mcp-serverManual Setup
# Build the project
npm run build
# Start the server
npm start๐ง Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
| `OPENAI_API_KEY` | OpenAI API key (required) | - |
| `SACL_REPO_PATH` | Repository to analyze | Current directory |
| `SACL_NAMESPACE` | Unique namespace | Auto-generated |
| `SACL_LLM_MODEL` | LLM model for analysis | `gpt-4` |
| `SACL_EMBEDDING_MODEL` | Embedding model | `text-embedding-3-small` |
| `SACL_BIAS_THRESHOLD` | Bias detection sensitivity (0-1) | `0.5` |
| `SACL_MAX_RESULTS` | Maximum search results | `10` |
| `SACL_CACHE_ENABLED` | Enable embedding cache | `true` |
| `NEO4J_URI` | Neo4j connection URI | `bolt://localhost:7687` |
| `NEO4J_USER` | Neo4j username | `neo4j` |
| `NEO4J_PASSWORD` | Neo4j password | `password` |
๐ฎ Usage
MCP Tools
The SACL server provides comprehensive MCP tools for bias-aware code analysis:
1. `analyze_repository`
Performs full SACL analysis of a repository:
{
"repositoryPath": "/path/to/repo",
"incremental": false
}2. `query_code`
Bias-aware code search with optional context:
{
"query": "function that sorts arrays efficiently",
"repositoryPath": "/path/to/repo",
"maxResults": 10,
"includeContext": false // Set true for relationship context
}3. `query_code_with_context` ๐
Enhanced search with relationship context and related components:
{
"query": "authentication middleware",
"repositoryPath": "/path/to/repo",
"maxResults": 10,
"includeRelated": true
}4. `update_file` ๐
Explicitly update single file analysis when changes are made:
{
"filePath": "src/services/auth.js",
"changeType": "modified" // "created", "modified", or "deleted"
}5. `update_files` ๐
Batch update multiple files:
{
"files": [
{ "filePath": "src/index.js", "changeType": "modified" },
{ "filePath": "src/utils/new.js", "changeType": "created" }
]
}6. `get_relationships` ๐
Analyze code relationships and dependencies:
{
"filePath": "src/controllers/UserController.js",
"maxDepth": 3,
"relationshipTypes": ["imports", "calls", "extends"] // Optional filter
}7. `get_file_context` ๐
Get comprehensive context for a file:
{
"filePath": "src/models/User.js",
"includeSnippets": true // Include code previews
}8. `get_bias_analysis`
Detailed bias metrics and debugging:
{
"filePath": "src/utils/sort.js" // Optional
}9. `get_system_stats`
System performance and statistics:
{}MCP Client Configuration
Claude Desktop
Add to your `claude_desktop_config.json`:
{
"mcpServers": {
"sacl": {
"command": "node",
"args": ["/path/to/sacl/dist/index.js"],
"env": {
"OPENAI_API_KEY": "your-key",
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "password"
}
}
}
}Cursor IDE
Configure in your Cursor settings to connect to the SACL MCP server.
๐ SACL Framework
Stage 1: Bias Detection
Identifies three types of textual bias:
- Docstring Dependency: Over-reliance on documentation
- Identifier Name Bias: Focusing on variable/function names
- Comment Over-reliance: Prioritizing commented code
Stage 2: Semantic Augmentation
Enriches code representations with:
- Functional Signatures: What the code actually does
- Behavior Patterns: Computational patterns (iteration, recursion, etc.)
- Structural Features: Complexity metrics, AST analysis
- Augmented Embeddings: Bias-adjusted semantic vectors
Stage 3: Reranking & Localization
- Bias-Aware Ranking: Reduces textual weight based on bias score
- Code Localization: Identifies functionally relevant segments
- Semantic Similarity: Uses augmented embeddings
- Functional Relevance: Considers computational patterns
Stage 4: Relationship Analysis ๐
Maps code relationships and dependencies:
- Import/Export Analysis: Module dependencies and exports
- Function Call Mapping: Call graphs and method invocations
- Class Inheritance: Extends/implements relationships
- Dependency Tracking: External and internal dependencies
- Context-Aware Results: Related components with each query result
๐งช Example Workflow
1. Repository Analysis:
AI Assistant โ analyze_repository โ SACL processes all files โ Knowledge graph populated2. Code Query with Context:
AI Assistant โ query_code_with_context("authentication") โ SACL retrieval โ Context-aware results3. File Updates:
AI modifies code โ update_file("src/auth.js", "modified") โ SACL re-analyzes โ Relationships updated4. Relationship Exploration:
AI Assistant โ get_relationships("UserController.js") โ Dependency graph โ Related components5. Results Include:
๐ Performance
Based on SACL research benchmarks:
- 12.8% improvement in Recall@1 on HumanEval
- 9.4% improvement on MBPP
- 7.0% improvement on SWE-Bench-Lite
- P95 latency: 10k files)
- [ ] Real-time bias notifications during code writing
- [ ] Custom relationship type definitions
SACL MCP Server - Bringing research-backed bias-aware code retrieval to AI coding assistants.
Frequently asked questions
What is sacl?
sacl is SACL (Semantic-Augmented Code Localization) - A bias-aware code retrieval framework with MCP server integration for AI assistants
How do I install sacl?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is sacl open source?
Yes โ it is hosted on GitHub at https://github.com/ulasbilgen/sacl.
Related MCP tools
Model Context Protocol Servers
The Open-Source Multimodal AI Agent Stack: Connecting Cutting-Edge AI Models and Agent Infra
A MCP for Claude Desktop / Claude Code / Windsurf / Cursor to build n8n workflows for you
MCP server to provide Figma layout information to AI coding agents like Cursor
The world's best AI personal assistant for email. Open source app to help you reach inbox zero fast.
Instant is the best backend for AI-coded apps. You get auth, permissions, storage, presence, and streams โ everything you need to ship apps your users will love.
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP