Skip to main content

Stateless Model Context Protocol (MCP) server for Django, built on the 2026-07-28 spec.

Project description

django-stateless-mcp

PyPI version

A stateless Model Context Protocol 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 stateless

Before 2026-07-28, MCP needed a persistent connection: elicitation held an open stream and a blocked worker, so a reply that round-robined to another worker failed. The 2026-07-28 spec makes MCP plain request/response HTTP — Django's home turf — and turns elicitation into a retry any instance can serve. That is the change this package is built on; see Why stateless for the full story.

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.

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.12–3.14
  • 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. just demo-asgi starts it behind four worker processes; the example README 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_stateless_mcp-0.1.1.tar.gz (155.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_stateless_mcp-0.1.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file django_stateless_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: django_stateless_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 155.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for django_stateless_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e1ec6125ba22716f88f36a165fdd9f1c1c3033de314aa916f80177788fe495b8
MD5 43d4bff7aba0a9cf1e63c206b414bf53
BLAKE2b-256 f1f5b79495ececc2641b1da4f0df6c7e1312b8c7edb1eede0cd0c01e4f794c56

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_stateless_mcp-0.1.1.tar.gz:

Publisher: publish.yml on Streamlined-Analytics/django-stateless-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_stateless_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_stateless_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2de714c980c98829fb44804fcc063dd408ec3cc9e78d978095b566743630f347
MD5 12496777672d555b86e81a84a8e13700
BLAKE2b-256 aeb66f000803a172a5247451a2bd427a608d9433b85b1b76df468a2da23cbb2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_stateless_mcp-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Streamlined-Analytics/django-stateless-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page