Skip to main content
Glama
django-admin-mcp
by dbuxton
README.md
# django-admin-mcp

An MCP server that wraps **any stock Django admin** — no server-side changes required.

It parses the admin HTML to discover schemas and uses session-based HTTP to read and create records. Stop hand-wiring configurations. Claude reproduces your real-world process, model by model.

---

## Why this exists

You want your team to AI-ify your app — letting Claude (or another agent) populate records, bulk-import data, and handle the tedious admin drudgery that eats up your day.

The "right" way to do that is to have your tech team build proper API endpoints and integrations. But that takes engineering time, which means deprioritizing something else. It's a real trade-off, and it's often hard to justify when the goal is just "I want an AI to fill in these records for me."

This is the workaround: **every Django app already ships with an admin UI**. This MCP server points Claude at that existing interface and drives it like a human would — discovering models, reading field schemas, resolving foreign keys, and submitting forms. Zero server-side changes. Zero new endpoints. Nothing for your tech team to build.

You get the AI-assisted workflow now, without it costing the team a sprint.

---

## Compatibility

Tested with **Django 5.2**. It should work with any Django version that uses the standard admin HTML structure, but only 5.2 has been verified. Reports and PRs for other versions are welcome.

---

## Quick start (uvx, local)

No PyPI publish needed — point `uvx` straight at the local directory.

```bash
# One-time browser auth (Okta/SSO flow → saves session cookie)
DJANGO_ADMIN_URL=https://example.com/admin \
  uvx --from /path/to/django-updater --with playwright django-admin-mcp auth

# Install Playwright's Chromium browser the first time
uvx playwright install chromium
```

After that the MCP server starts in one line:

```bash
DJANGO_ADMIN_URL=https://example.com/admin \
  uvx --from /path/to/django-updater django-admin-mcp
```

> **Tip:** use `.` instead of the full path when your shell is already in the project directory.

---

## Claude Desktop / Claude Code configuration

Add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "django-admin": {
      "command": "uvx",
      "args": [
        "--from", "/path/to/django-updater",
        "django-admin-mcp"
      ],
      "env": {
        "DJANGO_ADMIN_URL": "https://example.com/admin"
      }
    }
  }
}
```

Or add to your project's `.mcp.json` for Claude Code:

```json
{
  "mcpServers": {
    "django-admin": {
      "command": "uvx",
      "args": [
        "--from", "/path/to/django-updater",
        "django-admin-mcp"
      ],
      "env": {
        "DJANGO_ADMIN_URL": "https://example.com/admin"
      }
    }
  }
}
```

---

## Authentication

Django admin sessions are obtained via a **one-time browser flow** (supports Okta and any other SSO provider):

```bash
DJANGO_ADMIN_URL=https://example.com/admin \
  uvx --from /path/to/django-updater --with playwright django-admin-mcp auth
```

1. A headed Chromium window opens and navigates to your admin URL
2. Complete the login / SSO flow in the browser
3. Once redirected to the admin index, the script saves all cookies to `~/.django-admin-mcp/session.json` (mode 0600)
4. The MCP server loads those cookies on every startup

Re-run the `auth` command when the session expires.

---

## Available tools

| Tool | Description |
|------|-------------|
| `list_models` | List all admin-registered models with their app, name, and URLs |
| `describe_model(app, model)` | Introspect the add-form: field types, required flags, choices, autocomplete URLs |
| `autocomplete(app, model, field_name, term)` | Resolve FK/M2M names → PKs via the Django admin Select2 endpoint |
| `list_records(app, model, search?, page?)` | Paginated change-list query |
| `get_record(app, model, id)` | Read a single record's current field values |
| `create_record(app, model, data)` | POST a new record; returns `{success, id}` or `{success, errors}` |

---

## Environment variables

| Variable | Required | Description |
|----------|----------|-------------|
| `DJANGO_ADMIN_URL` | Yes | Full URL to the Django admin root (e.g. `https://example.com/admin`) |

Variables can be exported in the shell or placed in a `.env` file in the working directory.

---

## Development

```bash
cd /path/to/django-updater
uv sync --extra auth
uv run playwright install chromium
uv run django-admin-mcp auth
uv run django-admin-mcp
```