# ORM Lens

> Statically inspect Django and SQLAlchemy projects, visualize relations, and review query and migration risks.

- **URL**: https://followmcp.com/en/servers/frowningdev-cli
- **Category**: Dev Tools
- **Origin**: Community
- **Stars**: 114
- **FMRS Score**: 55/100 (Grade C)
- **Source**: https://github.com/FROWNINGdev/orm-lens/tree/main/cli
- **Transports**: stdio (local process)
- **Runtimes**: Python 3.10+
- **Auth**: No credential needed

## Overview
ORM Lens is a static ORM analysis tool for developers and AI coding agents, with an MCP server. It analyzes models, relations, migrations, and Alembic revisions; generates ER diagrams; and checks for N+1 issues, migration risks, schema drift, and field impact. The README says analysis does not require starting the application or connecting to a database. The MCP server provides read-only tools over stdio. SQLAlchemy support is marked preview.

## Best for
- Developers reviewing ORM models without starting the app or connecting to a database.
- AI coding-agent workflows that need MCP access to schema information in a codebase.

## Not for
- Runtime query performance profiling or monitoring real traffic.
- Use cases that require connecting to a database, reading live data, or running the app to verify behavior.

## Required permissions
- The tools are read-only and need access to project files in the selected workspace for static analysis.
- Set the workspace with ORM_LENS_ROOT or workspace_root; ORM_LENS_ALLOWED_ROOTS can restrict allowed paths.

## Risks
- Static analysis depends on how well the parser recognizes project code and migrations; it does not replace runtime verification.
- The README marks SQLAlchemy, Alembic, and other non-Django format support as preview.
- Configure the workspace path to point only to the project you intend to analyze.

## Client config (JSON)
```json
{"mcpServers":{"orm-lens":{"command":"orm-lens-mcp","env":{"ORM_LENS_ROOT":"/abs/path/to/your/project"}}}}
```

## Tools (14)
- `list_apps`: Lists Django apps in the workspace with model counts.
- `list_models`: Lists models, optionally filtered by app.
- `describe_model`: Returns field, relation, and Meta details for a model.
- `find_relations`: Finds inbound and outbound relations for a model.
- `cascade_preview`: Previews the cascade impact of a delete, grouped by on_delete behavior.
- `er_diagram`: Generates an ER diagram in Mermaid, DBML, D2, or PlantUML format.
- `describe_migration_dependency`: Describes an app's migration dependency graph, including roots, leaves, and cross-app dependencies.
- `suggest_indexes`: Suggests Meta.indexes based on observed QuerySet usage.
- `signal_graph`: Analyzes the graph of Django signal senders, signals, and handlers.
- `migration_risk`: Checks Django, Alembic, and SQL migrations for risky patterns.
- `blast_radius`: Analyzes destructive migration risks, affected code, and cascade impact.
- `drift`: Statically compares fields implied by migrations with fields declared in models.py.
- `impact`: Finds references to a field or model name, grouped by Django layer.
- `nplusone_scan`: Scans the workspace for static N+1 query issues.
