slugaudit-mcp
Enables AI-assisted code audits by extracting signatures and dependencies from source files, tracking changes, and generating structured briefings for review.
README
slugaudit-mcp
A PostgreSQL-backed code audit system for AI-assisted code reviews. Extracts code signatures and import dependencies from source files using tree-sitter, builds a dependency graph, tracks changes between imports, and generates structured briefings for AI auditors.
Available as both a CLI tool (slugaudit-mcp) and an MCP server (slugaudit-mcp).
Quick Start
# 1. Install dependencies (system packages, Python deps, tree-sitter parsers)
bash setup.sh
# 2. Set up PostgreSQL connection
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=my_audit_db
export PGUSER=my_user
export PGPASSWORD=my_password
# 3. Import a project (schema auto-creates on first use!)
slugaudit-mcp import /path/to/your/project --project-name "My Project"
# 4. Check project status
slugaudit-mcp status --project "My Project"
# 5. Generate an AI audit briefing
slugaudit-mcp briefing --project "My Project" --output briefing.md
MCP Server Mode (Recommended for AI Assistants)
# Run the MCP server
python3 mcp_server.py
Then in your AI client (Claude Desktop, VS Code, Cursor, Codebuff, etc.), configure the MCP server:
{
"mcpServers": {
"slugaudit-mcp": {
"command": "python3",
"args": ["/path/to/slugaudit-mcp/mcp_server.py"],
"env": {
"PGHOST": "localhost",
"PGPORT": "5432",
"PGDATABASE": "my_audit_db",
"PGUSER": "my_user",
"PGPASSWORD": "my_password"
}
}
}
}
Once configured, the AI can use these tools directly:
audit_import— Import a codebaseaudit_brief— Generate an audit briefingaudit_status— Show project statusaudit_changed— List changed filesaudit_list— List all projectsaudit_init_db— Manually initialize schema (usually auto-done)
Architecture
The system follows a layered architecture with clear separation of concerns:
[CLI / MCP] → [Services] → [Repositories] → [Infrastructure]
↓
[Languages] → [Source Files]
| Package | Role |
|---|---|
infrastructure/ |
Connection management, input validation, file I/O abstraction |
domain/ |
Entity models: Project, File, Signature, ImportRecord, DependencyEdge |
repositories/ |
Data access: ProjectRepository, FileRepository, ImportRepository, FindingRepository, ArchitectureRepository |
services/ |
Application services: SchemaService, ImportService, BriefingService |
briefing/ |
Briefing assembly: data providers + Markdown formatters |
languages/ |
8 language extractors with shared BaseExtractor |
Commands
| Command | Description |
|---|---|
init-db |
Initialize the database schema (idempotent) |
import |
Scan a project, extract signatures/imports, build dependency graph |
status |
Show project overview (files, signatures, imports, edges, changes) |
changed |
List files changed since last import |
briefing |
Generate structured Markdown briefing for AI audit |
list |
List all projects in the database |
Supported Languages
| Language | Detection | Key Features |
|---|---|---|
| Rust | Cargo.toml, .rs |
use, pub, struct, fn, impl, trait, enum |
| Python | pyproject.toml, .py |
import, from X import Y, class/fn signatures |
| TypeScript | package.json, .ts |
import, export, interfaces, types, functions |
| Go | go.mod, .go |
Functions, methods, structs, interfaces, imports |
| Java | pom.xml, .java |
Classes, interfaces, enums, records, methods |
| C | .c, .h |
Functions, structs, unions, enums, #include |
| C++ | .cpp, .hpp |
Functions, classes, templates, namespaces |
| Ruby | Gemfile, .rb |
Methods, classes, modules, require |
Key Concepts
- Signature cache: Public API surface of each file stored as JSONB. Lets the AI understand a file's interface without reading its full source.
- Dependency edges: File-to-file dependencies resolved from import statements. Enables blast radius computation.
- Change detection: SHA-256 hash compared against
last_audited_hash. Only changed files become audit targets. - Blast radius: Files that depend on changed files, computed from dependency edges.
- Ghost context: Signatures of unchanged files provided for AI reference — reduces token usage by avoiding full source reads.
Configuration
Environment Variables
| Variable | Required | Default |
|---|---|---|
PGHOST |
Yes | — |
PGPORT |
No | 5432 |
PGDATABASE |
Yes | — |
PGUSER |
Yes | — |
PGPASSWORD |
Yes | — |
PGSSLMODE |
No | — |
Connection String
Override env vars with --connection:
slugaudit-mcp import . --connection "postgresql://user:pass@host:5432/dbname?sslmode=require"
Database Schema
All projects share one database. Each project's data is isolated via project_id foreign keys with ON DELETE CASCADE:
| Table | Purpose |
|---|---|
projects |
One row per project — the root entity |
files |
File metadata, hashes, signature cache (JSONB) |
file_imports |
Import statements extracted from files |
dependency_edges |
Resolved file-to-file dependency graph |
findings |
Audit findings with severity, category, location |
architecture_state |
Architecture summaries and layer maps (reserved) |
audit_configs |
Audit configuration per project (reserved) |
audit_runs |
Individual audit execution tracking (reserved) |
file_staleness |
Files that may be stale due to changes (reserved) |
static_tool_results |
Raw output from static analysis tools (reserved) |
ingestor_rejections |
Failed ingestion attempts (reserved) |
Workflow
First-time audit
# 1. Import the baseline
slugaudit-mcp import /path/to/project --project-name "My Project"
# 2. Make edits to the codebase...
# 3. Re-import to sync
slugaudit-mcp import /path/to/project
# 4. Generate briefing for changed files
slugaudit-mcp briefing --project "My Project" --output briefing.md
# 5. Feed briefing.md to an AI for audit
Continuous audit with MCP
- Call
audit_importto scan the project - Call
audit_statusto verify the import - After code changes, call
audit_importagain to sync - Call
audit_briefto get the generated briefing - The AI returns findings directly in conversation
Adding a New Language
- Create
languages/yourlang.pyextendingBaseExtractor - Implement:
name(),source_extensions(),find_source_files(),extract_signatures(),extract_imports(),resolve_import(),hash_file() - Register in
LANG_MAPinlanguages/__init__.py - Install tree-sitter grammar:
pip install tree-sitter-yourlang
Testing
110 tests using unittest with mocking — no database required:
python3 -m pytest tests/ -v # preferred
python3 -m unittest tests # alternative
Code Quality
# Linting
ruff check .
# Type checking
mypy .
# Pre-commit hooks
pre-commit install
pre-commit run --all-files
Configured tools: ruff (E/W/F/UP/S/B/C4 rules, line-length=100), mypy (strict mode), pre-commit (trailing-whitespace, end-of-file-fixer, check-yaml, ruff, mypy).
Requirements
- Python 3.10+
- PostgreSQL 15+ (uses UUID, JSONB,
gen_random_uuid()) - tree-sitter parsers for each supported language
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。