Skip to main content

django-xprez-mcp

Admin-style MCP servers for Django. Register providers, models, admin classes and plain functions on a server; they become MCP tools, resources and prompts, filtered by the calling user's permissions.

Early development: phases 1 (core), 2 (models) and 3 (admin). See docs/design.md for the full design and roadmap.

Guides: getting started, permissions, security checklist.

# settings.py
INSTALLED_APPS = [..., "xprez_mcp"]  # plus one or both sign-in apps below

XPREZ_MCP = {
    # required: who may use the server at all
    "PERMISSION": "xprez_mcp.permissions.allow_staff",
}

# urls.py
from xprez_mcp import mcp

urlpatterns = [path("mcp/", mcp.urls)]

Clients sign in one of two ways; enable one or both (details in getting started).

OAuth sign-in (xprez_mcp.contrib.oauth): the user pastes https://<site>/mcp/ into the assistant (claude.ai and ChatGPT connectors, Claude Code, Cursor), signs in with the site's login and clicks "Allow".

  1. Add "xprez_mcp.contrib.oauth" to INSTALLED_APPS and run migrate.
  2. Add path("", include("xprez_mcp.contrib.oauth.well_known")) to the root urls.py.
  3. Set XPREZ_MCP["AUTHENTICATION"] = ["xprez_mcp.contrib.oauth.auth.access_token"].

Override xprez_mcp/oauth/base.html to style the consent page, and schedule manage.py mcp_oauth_cleanup daily.

Bearer tokens (xprez_mcp.contrib.tokens): the user creates a key under "MCP tokens" in the admin and the client sends Authorization: Bearer <key>. Suits scripts, CI and clients without OAuth.

  1. Add "xprez_mcp.contrib.tokens" to INSTALLED_APPS and run migrate.
  2. Nothing else: xprez_mcp.auth.bearer_token is the default AUTHENTICATION.

Keys are shown once, stored hashed and revoked by deleting. Projects with their own token model leave the app out and set XPREZ_MCP["TOKEN_RESOLVER"] = "myapp.tokens.resolve" ((request, token) -> user | None).

Both: list OAuth first, ["xprez_mcp.contrib.oauth.auth.access_token", "xprez_mcp.auth.bearer_token"], since bearer_token rejects keys it does not know.

# myapp/mcp.py: discovered automatically, like admin.py
from xprez_mcp import Provider, mcp, prompt, resource, tool


@mcp.register
class NotesProvider(Provider):
    namespace = "notes"

    @tool(read_only=True, permission=lambda ctx: ctx.user.has_perm("myapp.view_note"))
    def search(self, ctx, query: str, limit: int = 20):
        """Search notes by title."""
        notes = Note.objects.filter(owner=ctx.user, title__icontains=query)
        return {"notes": list(notes.values("id", "title")[:limit])}

    @resource("notes://{id}", mime_type="text/markdown")
    def note(self, ctx, id: int):
        return Note.objects.get(owner=ctx.user, pk=id).text

    @prompt
    def summary(self, ctx, id: int):
        """Summarize one note."""
        return f"Summarize the note notes://{id}."


@mcp.tool
def ping(ctx) -> str:
    return "pong"
# myapp/mcp.py: tools generated from a model
from xprez_mcp import ModelProvider, mcp


@mcp.register(Note)
class NoteProvider(ModelProvider):
    fields = ["id", "title", "created"]
    search_fields = ["title"]
    filters = {"created_after": "created__gte"}
    actions = ["list", "get", "update"]  # notes_list, notes_get, notes_update

    def get_queryset(self, ctx):
        return Note.objects.filter(owner=ctx.user)

With many models, MCPServer(exposure="generic") exposes them through a few shared tools (models_list, records_search, record_get, ...) instead of tools per model. A provider can choose for itself with exposure.

# the admin, with exactly the permissions each user has there
from django.contrib import admin
from xprez_mcp import AdminProvider, mcp


@mcp.register(Note)
class NoteAdminProvider(AdminProvider):  # uses the registered NoteAdmin
    actions = ["list", "get", "update"]  # writes are opt-in
    admin_actions = ["publish"]          # ModelAdmin actions, opt-in


# the rest of admin.site (models registered above keep their own provider)
mcp.register_admin(admin.site, exposure="generic")

Write tools from installed third-party apps are held back until listed in XPREZ_MCP["ALLOW_WRITES"].

Development

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/python -m django test xprez_mcp.tests --settings=xprez_mcp.tests.settings
.venv/bin/black --check .

Metadata

Release files for django-xprez-mcp 0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-xprez-mcp 0.7.3
File Size Uploaded Provenance Actions
django_xprez_mcp-0.7.3.tar.gz 147.9 kB With provenance Details for django_xprez_mcp-0.7.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-xprez-mcp 0.7.3
File Interpreter ABI Platform Actions
django_xprez_mcp-0.7.3-py3-none-any.whl Python 3 none any Details for django_xprez_mcp-0.7.3-py3-none-any.whl

Total release size: 294.7 kB

Release files / django_xprez_mcp-0.7.3.tar.gz

Download URL django_xprez_mcp-0.7.3.tar.gz
Size 147.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2e27b62ecd3ccac1ad6dd18f0af8c4817c16cb3b38577b217e62d42636148331
BLAKE2b-256 checksum
How to use checksums
6711f143150297ddc1120811a11ea80ef9c4c8a71153ad00f87383c825fadbef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / django_xprez_mcp-0.7.3-py3-none-any.whl

Download URL django_xprez_mcp-0.7.3-py3-none-any.whl
Size 146.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e66245a9a87b2a3b2118f211245e7b8f96f4f57ca40814cdb18540a9b7c14f8a
BLAKE2b-256 checksum
How to use checksums
ec3fe5057f9d1b21a732a1a48af0af3725eb695fa3821ef94273b514006fd8a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for django-xprez-mcp 0.7.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_xprez_mcp-0.7.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page