# Schemap — AI Database Context & Intelligence Layer

> Schemap is the Database Intelligence Layer for AI Coding Agents. It compiles database schemas into compact, deterministic context maps (`schemap_database_context.md`, `CLAUDE.md`, `AGENTS.md`, `.cursor/rules/schemap.mdc`) for Claude Code, Cursor, Codex, and GitHub Copilot.

## Key Features & Capabilities

- **AI Safety & Anti-Hallucination Guardrails (`schemap agents`)**: Injects negative safety rules into agent config files to prevent broken JOINs, credential leaks (`password_hash`), and financial record mutation.
- **Role-Scoped Context Profiles (`schemap context --scope`)**: Filters schema compilation to role-specific views (`analytics`, `backend`, `core`, `all`), saving 80% on LLM prompt token costs.
- **Monetary Cost & Token Inspector (`schemap benchmark --cost`)**: Calculates tokens saved per prompt and estimated monthly dollar savings per developer.
- **Canonical Reference Query Generator (`schemap examples`)**: Auto-generates standard SQL JOIN queries derived from foreign key graphs.
- **Git Pre-Commit Automation (`schemap hook install`)**: One-command Git pre-commit hook installer to sync context maps on migration commits.
- **AI Readiness Diagnostics (`schemap doctor`)**: Diagnoses schema clarity (0-100 score), detects missing foreign keys, unmapped abbreviations, and un-commented tables.
- **Shortest JOIN Path Solver (`schemap join`)**: Resolves multi-hop relationship paths across foreign key graphs.
- **Model Context Protocol (MCP) Server (`schemap mcp`)**: Dynamic JSON-RPC 2.0 tool endpoints for Claude Desktop, Cursor, and Windsurf (`schemap_get_schema`, `schemap_get_join_path`, `schemap_validate_query`, `schemap_check_blast_radius`).

## Supported Databases & Platforms
- PostgreSQL, Supabase, Neon
- SQLite, Turso / libSQL
- MySQL
- Oracle

## Quickstart & Installation

```bash
# Install globally via pipx (recommended)
pipx install schemap-tool

# Or using uv
uv tool install schemap-tool

# Run as Model Context Protocol (MCP) server
uvx schemap-tool mcp --config ./schemap.yaml

# Onboarding pipeline
schemap quickstart

# Compile AI context map
schemap context --scope analytics

# Self-update or cleanly uninstall
schemap update
schemap uninstall --purge
```

## Competitor Comparisons & Technical Guides
- Technical Guide: Preventing Destructive AI SQL Queries in Claude Code & Cursor: https://schemap-tool.pages.dev/guide-preventing-destructive-ai-sql-queries.html
- Technical Guide: How to Set Up Schemap MCP Server in Cursor & Claude Desktop: https://schemap-tool.pages.dev/guide-setup-schemap-mcp-cursor-claude.html
- Guide: How to Provide Database Schema Context in Cursor (.cursor/rules/*.mdc): https://schemap-tool.pages.dev/guide-cursor-database-rules.html
- Guide: How to Give Claude Code Database Schema Context (CLAUDE.md vs MCP): https://schemap-tool.pages.dev/guide-claude-code-database-context.html
- Stop Maintaining Custom Schema Scripts: https://schemap-tool.pages.dev/vs-custom-scripts.html
- Security & Privacy Guide (Where Does Your Schema Go?): https://schemap-tool.pages.dev/security.html
- Schemap vs dbctx (Native Rules vs Binary SQLite Indexes): https://schemap-tool.pages.dev/vs-dbctx.html
- Schemap vs db2md (AI Intelligence Layer vs Markdown Tables): https://schemap-tool.pages.dev/vs-db2md.html
- Schemap vs LLMSchema & DbSketch: https://schemap-tool.pages.dev/vs-llmschema.html
- Schemap vs tbls (Human Documentation vs AI Context): https://schemap-tool.pages.dev/vs-tbls.html
- Schemap vs Raw pg_dump SQL DDL: https://schemap-tool.pages.dev/vs-pg-dump.html
- Schemap vs Model Context Protocol (MCP) Servers: https://schemap-tool.pages.dev/vs-mcp-sql.html
- Technical Guide: Stop AI Coding Agents from Hallucinating SQL JOINs: https://schemap-tool.pages.dev/blog-preventing-ai-sql-hallucinations.html
- Technical Guide: Cutting AI API Token Costs by 80% on Production Schemas: https://schemap-tool.pages.dev/blog-token-optimization-db-context.html

## Licensing & Links
- Website: https://schemap-tool.pages.dev/
- Documentation: https://schemap-tool.pages.dev/docs.html
- GitHub Repository: https://github.com/alansyahmi/Schemap
- PyPI Package: https://pypi.org/project/schemap-tool/
- Pricing: Free tier ($0 up to 100 tables) / Pro ($1.99/mo for unlimited tables & CI/CD)

