|
| 1 | +# CLAUDE.md - Project Guidelines |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +**pgsql-mcp** is a PostgreSQL MCP (Model Context Protocol) server providing index tuning, query analysis, explain plans, and database health monitoring. |
| 6 | + |
| 7 | +## Build & Test Commands |
| 8 | + |
| 9 | +```bash |
| 10 | +# Install dependencies |
| 11 | +uv sync |
| 12 | + |
| 13 | +# Run tests |
| 14 | +uv run pytest -v |
| 15 | + |
| 16 | +# Run linting |
| 17 | +uv run ruff format --check . |
| 18 | +uv run ruff check . |
| 19 | + |
| 20 | +# Run type checking |
| 21 | +uv run pyright |
| 22 | + |
| 23 | +# Run the server locally |
| 24 | +uv run pgsql-mcp --help |
| 25 | +``` |
| 26 | + |
| 27 | +## Code Style |
| 28 | + |
| 29 | +- Python 3.12+ |
| 30 | +- Line length: 150 characters |
| 31 | +- Formatter: ruff/black |
| 32 | +- Type hints required |
| 33 | +- Google-style docstrings |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +``` |
| 38 | +src/postgres_mcp/ |
| 39 | +├── __init__.py # Entry point (main function) |
| 40 | +├── sql/ # SQL execution & safety |
| 41 | +├── index/ # Index optimization (DTA algorithm) |
| 42 | +├── explain/ # Query plan analysis |
| 43 | +├── database_health/ # Health check modules |
| 44 | +├── migrations/ # Schema migration support |
| 45 | +└── top_queries/ # pg_stat_statements analysis |
| 46 | +``` |
| 47 | + |
| 48 | +## Development Rules |
| 49 | + |
| 50 | +### SSOT (Single Source of Truth) - 100% Compliance |
| 51 | + |
| 52 | +1. **Configuration**: All config lives in `pyproject.toml` - no duplicate config files |
| 53 | +2. **Constants**: Define once, import everywhere - no magic strings/numbers scattered in code |
| 54 | +3. **Types**: Single type definition per concept - reuse via imports |
| 55 | +4. **Database schemas**: Schema definitions in one place, reference elsewhere |
| 56 | +5. **Error messages**: Centralized error definitions when used in multiple places |
| 57 | +6. **Version**: Single version in `pyproject.toml` only |
| 58 | + |
| 59 | +### DRY (Don't Repeat Yourself) - 100% Compliance |
| 60 | + |
| 61 | +1. **No copy-paste code**: Extract to functions/classes when logic repeats |
| 62 | +2. **Shared utilities**: Common operations go in dedicated utility modules |
| 63 | +3. **SQL patterns**: Reusable SQL builders instead of string concatenation |
| 64 | +4. **Test fixtures**: Shared fixtures in `conftest.py`, not duplicated per test |
| 65 | +5. **Configuration**: Environment handling in one module, imported by others |
| 66 | + |
| 67 | +### File Hygiene - Always Remove Unnecessary Files |
| 68 | + |
| 69 | +1. **Delete, don't comment**: Remove dead code entirely, don't comment it out |
| 70 | +2. **No orphan files**: Delete files that are no longer imported/used |
| 71 | +3. **No placeholder files**: Remove empty `__init__.py` if not needed for packaging |
| 72 | +4. **Clean imports**: Remove unused imports immediately |
| 73 | +5. **No backup files**: No `.bak`, `.old`, `.backup` files in repo |
| 74 | +6. **No generated files in git**: Add build artifacts to `.gitignore` |
| 75 | +7. **Remove deprecated code**: When replacing functionality, delete the old implementation |
| 76 | + |
| 77 | +### Before Every Commit |
| 78 | + |
| 79 | +- [ ] No duplicate logic exists |
| 80 | +- [ ] No unused imports |
| 81 | +- [ ] No commented-out code |
| 82 | +- [ ] No orphan files |
| 83 | +- [ ] All constants centralized |
| 84 | +- [ ] Types reused via imports |
| 85 | +- [ ] Tests pass: `uv run pytest` |
| 86 | +- [ ] Lint passes: `uv run ruff check .` |
| 87 | +- [ ] Types pass: `uv run pyright` |
0 commit comments