Django ORM Lens — Claude Code MCP server: what it does & setup
Statically parses Django models, relations, and migrations without database access. Catches N+1 loops and flags risky schema changes directly inside agent chats.
claude mcp add django-orm-lens -- uvx django-orm-lensWhat Django ORM Lens does
This tool inspects Django codebases purely through static analysis. It works without an active database connection or runserver. Source files are parsed directly to map models and migration chains.
Linked to an assistant, the server provides 13 read-only tools. These enable agents to discover N+1 query loops, suggest select_related arguments, detect table-locking migrations, and estimate the blast radius of schema edits.
Accurate analysis requires setting DJANGO_ORM_LENS_ROOT to the absolute path of your Django project. Without this variable, the tool cannot discover the target repository files.
What it helps with
- detect N+1 loops and suggest appropriate
select_relatedcalls - catch migrations that risk locking database tables
- evaluate the blast radius of removing model fields
- inspect relations and schema structure without booting a database
Example prompts for the agent
- Inspect recent querysets for N+1 issues and suggest optimizations
- Check new migrations for table locks before deployment
- Map out foreign key dependencies for the
Ordermodel
How to install Django ORM Lens
Platform CLI
claude mcp add django-orm-lens -- uvx django-orm-lensuvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>
Platform CLI
codex mcp add django-orm-lens -- uvx django-orm-lensuvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>
Config file
{
"mcpServers": {
"django-orm-lens": {
"command": "uvx",
"args": [
"django-orm-lens"
]
}
}
}uvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>
Config file
{
"servers": {
"django-orm-lens": {
"type": "stdio",
"command": "uvx",
"args": [
"django-orm-lens"
]
}
}
}uvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>
Platform CLI
gemini mcp add django-orm-lens uvx django-orm-lensuvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about Django ORM Lens
How do I install Django ORM Lens in Claude Code?
Run claude mcp add django-orm-lens -- uvx django-orm-lens. The CLI registers the server and executes it on demand via uvx.
What does Django ORM Lens do?
It gives AI assistants 13 read-only tools to examine Django schemas, queries, and migrations purely via static code inspection.
Does it require a running database or active venv?
Neither a database nor a Python virtual environment is required. The analyzer parses files statically directly from the repository.