# Django ORM Lens

Statically parses Django models, relations, and migrations without database access. Catches N+1 loops and flags risky schema changes directly inside agent chats.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 93
- Author: FROWNINGdev
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/FROWNINGdev/django-orm-lens
- Updated: 2026-10-19
- HTML: https://affpapa.org/en/nevibecode/mcp/django-orm-lens

## What it 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.

## Requirements
- Needs: Python and uv (commands run via uvx)

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add django-orm-lens -- uvx django-orm-lens
```
uvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>

### Codex

**Platform CLI**
```bash
codex mcp add django-orm-lens -- uvx django-orm-lens
```
uvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "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>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "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>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add django-orm-lens uvx django-orm-lens
```
uvx runs the command named after the package; if the README names another one, use uvx --from django-orm-lens <command>

## When to use it
- detect N+1 loops and suggest appropriate `select_related` calls
- 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
- 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 `Order` model

## Similar
- [MCP Toolbox for Databases](https://affpapa.org/en/nevibecode/mcp/googleapis-mcp-toolbox-for-databases.md) — MCP server · ★ 16717
- [PostHog MCP Server](https://affpapa.org/en/nevibecode/mcp/posthog-mcp-server.md) — MCP server · ★ 40409
- [OpenWork MCP Gateway](https://affpapa.org/en/nevibecode/mcp/openwork-mcp-gateway.md) — MCP server · ★ 24242
- [Keploy](https://affpapa.org/en/nevibecode/mcp/keploy.md) — MCP server · ★ 18727
- [Nhost](https://affpapa.org/en/nevibecode/mcp/nhost.md) — MCP server · ★ 9366
- [basebalance.cloud — x402 RPC & MCP gateway](https://affpapa.org/en/nevibecode/mcp/basebalancecloud-x402-rpc-mcp-gateway.md) — MCP server · ★ 7506

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
