Skip to main content

django-stateless-mcp

PyPI version Documentation status

An MCP (Model Context Protocol) server is how AI agents — Claude Code, ChatGPT, and the assistants built on them — connect to your application in a controlled way: they see and call only the tools you choose to expose, under the permissions you enforce. As your users lean on AI for more of their work, it pays to be ready to accommodate their agents without loosening the protections Django already gives your data and infrastructure — and that is what this package is for.

django-stateless-mcp is a stateless MCP server for Django, built on the 2026-07-28 spec. An MCP endpoint becomes an ordinary Django view — no sessions, no SSE, no sticky routing, and no dedicated single-process service.

Why use this

  • Your MCP server is an ordinary Django view — same deployment, same middleware, same monitoring, and tools call your models and business logic directly. No separate MCP service to build, secure, and operate.
  • It scales like the rest of your Django app — any worker on any instance can serve any request, including an elicitation answer. See Why stateless for what changed on 2026-07-28 to make that possible.
  • Tools can ask the user questions — fill in missing form fields, or require explicit confirmation before an update or delete, resuming on whichever worker the answer lands on: request_state_security() keys the resume state from SECRET_KEY. See the elicitation recipe.
  • Kick off a long job, keep chatting, and the result comes back when it's ready — see the long-running jobs recipe.
  • Your authentication and permissions work inside tools — bearer auth resolves to a real Django user, so user.has_perm(...) just works, and PermittedToolsFilter hides tools a user may not use from tools/list.
  • You can see what your MCP is doing — optional structlog middleware logs one queryable event per request.
  • Tools register the Django way — each app's mcp.py is discovered automatically, exactly like admin.py.

Usage

# myproject/mcp.py
from mcp.server.mcpserver import MCPServer

from django_stateless_mcp import request_state_security

server = MCPServer(
    name="my-server",
    version="1.0.0",
    request_state_security=request_state_security(),
)


@server.tool()
def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b
# urls.py
from django.urls import path

from django_stateless_mcp import mcp_view
from myproject.mcp import server

urlpatterns = [path("mcp/", mcp_view(server))]

That is the whole integration. The endpoint runs under both WSGI and ASGI.

What it provides

  • mcp_view(server) — serve an MCPServer as a stateless streamable-HTTP Django view, optionally requiring OAuth bearer auth via a token_verifier.
  • mcp.py autodiscovery — add django_stateless_mcp to INSTALLED_APPS and each app's mcp.py registers tools, like admin.py.
  • request_state_security() — key the SDK's elicitation-resume encryption from SECRET_KEY, so elicitation survives a multi-worker deployment.
  • django_request(ctx) — reach the authenticated Django request from inside a tool, with no global state.
  • StructlogRequestLogger — optional flow-logging middleware.
  • Subscription streams — clients can subscribe to server-pushed events under ASGI; under WSGI the endpoint declines cleanly rather than pinning a worker.

Tool registration, elicitation, resources and prompts are the MCP SDK's own API; this package is the Django layer around it.

Supported versions

  • Python 3.10–3.14 (3.10 and 3.11 with Django 5.2 LTS only, matching Django's own support)
  • Django 5.2 LTS and 6.0
  • mcp 2.0.x

Each is exercised in CI, along with an advisory job tracking the SDK's git main.

Try it live

The repo ships a runnable example project. docker compose up starts it behind four worker processes (no local uv or Python needed; just demo-asgi is the host-run equivalent); the example README quick start walks through watching an elicitation started on one worker resume on another — the package's thesis, observable with curl or any MCP client.

Documentation

Full documentation, including a worked elicitation example and the design decisions behind the package, is at https://django-stateless-mcp.readthedocs.io/.

Development

Contributors: ARCHITECTURE.md maps how the package works and the invariants every change must preserve; CONTRIBUTING.md covers the workflow.

git clone git@github.com:Streamlined-Analytics/django-stateless-mcp.git
cd django-stateless-mcp
uv sync

uv run pytest                        # quick run: locked Django
uvx --with tox-uv tox run -f py313   # the full matrix: Django 5.2 + 6.0
just qa                              # format, lint, type check, test
just conformance                     # the official MCP conformance suite

Author

django-stateless-mcp was created in 2026 by Ben Atkinson.

Started from the audreyfeldroy/cookiecutter-pypackage template.

Metadata

Release files for django-stateless-mcp 0.1.11

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-stateless-mcp 0.1.11
File Size Uploaded Provenance Actions
django_stateless_mcp-0.1.11.tar.gz 287.3 kB With provenance Details for django_stateless_mcp-0.1.11.tar.gz

Built distribution (wheel)

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

Total release size: 306.8 kB

Release files / django_stateless_mcp-0.1.11.tar.gz

Download URL django_stateless_mcp-0.1.11.tar.gz
Size 287.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8ba227fd8f6880bbfe8e3312a41afd5d1d509c82a426c3f5bcc2c3e95038fb22
BLAKE2b-256 checksum
How to use checksums
c7cabe9dc83d3c9b588a11addc91ee597d940f9232d3bc06068aba104a7f81c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 31, 2026.

Transparency log

Release files / django_stateless_mcp-0.1.11-py3-none-any.whl

Download URL django_stateless_mcp-0.1.11-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81652f07d2398a147df252387ce208ff8688a0f659ba66c366c161731bbe4723
BLAKE2b-256 checksum
How to use checksums
ffa804f90193ad4d3d35ed5ad8be30eee96e0d5ebf2527f09a107c2c788b681a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 31, 2026.

Transparency log

Security for django-stateless-mcp 0.1.11

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_stateless_mcp-0.1.11.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 Aug 31, 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