Skip to main content

django-mcp-wrapper

PyPI Tests Changelog License

Django views that wrap MCP stdio servers and expose them over Streamable HTTP.

Installation

pip install django-mcp-wrapper

For OAuth 2.0 support (Claude for Web, dynamic client registration):

pip install django-mcp-wrapper[oauth]

Quick Start

Define a wrapper class and mount it at a URL path:

# mcp_wrappers.py
from django_mcp_wrapper import StdioMcpWrapper

class FileSystemMcp(StdioMcpWrapper):
    command = "npx"
    args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
# urls.py
from django.urls import path
from .mcp_wrappers import FileSystemMcp

urlpatterns = [
    path("mcp", FileSystemMcp.as_view()),
]

Override get_command(), get_args(), or get_env() for per-request customization:

class DynamicMcp(StdioMcpWrapper):
    command = "npx"

    def get_args(self):
        directory = os.environ.get("MCP_DIR", os.getcwd())
        return ["-y", "@modelcontextprotocol/server-filesystem", directory]

Mount multiple wrappers at different paths:

urlpatterns = [
    path("desktop/mcp", DesktopMcp.as_view()),
    path("project/mcp", ProjectMcp.as_view()),
]

Authentication

API Key

Override authenticate() to add request-level auth. Return None to allow the request, or an HttpResponse to reject it:

class SecureMcp(StdioMcpWrapper):
    command = "npx"
    args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

    def authenticate(self, request):
        valid_keys = {"my-secret-key"}
        if request.GET.get("apiKey") not in valid_keys:
            return HttpResponse("Invalid API key", status=401)
        return None

See examples/apikey/ for a full working example.

OAuth 2.0 with Dynamic Client Registration (Claude for Web)

For MCP clients that use OAuth (like Claude for Web), django-mcp-wrapper provides RFC 9728 protected resource metadata and bearer token validation, with RFC 7591 dynamic client registration via django-oauth-toolkit-dcr, all backed by django-oauth-toolkit:

# mcp_wrappers.py
from django_mcp_wrapper import StdioMcpWrapper
from django_mcp_wrapper.oauth import bearer_token_authenticate

class OAuthMcp(StdioMcpWrapper):
    command = "npx"
    args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

    def authenticate(self, request):
        return bearer_token_authenticate(request)
# urls.py
from django_mcp_wrapper.oauth import oauth_urlpatterns

urlpatterns = [
    path("mcp", OAuthMcp.as_view()),
    *oauth_urlpatterns(
        resource_url="https://yourserver.com/mcp",
        authorization_server_url="https://yourserver.com/o",
    ),
]

This wires up:

  • /.well-known/oauth-protected-resource/mcp — resource metadata (RFC 9728)
  • /o/register/ — dynamic client registration (RFC 7591, via django-oauth-toolkit-dcr)
  • /o/authorize/, /o/token/ — authorization code + PKCE flow (django-oauth-toolkit)

See examples/oauth/ for a full working example with settings.

Development

cd django-mcp-wrapper
python -m venv venv
source venv/bin/activate
pip install -e '.[dev]'
python -m pytest

Metadata

Release files for django-mcp-wrapper 0.2.1

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-mcp-wrapper 0.2.1
File Size Uploaded
django_mcp_wrapper-0.2.1.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-mcp-wrapper 0.2.1
File Interpreter ABI Platform
django_mcp_wrapper-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / django_mcp_wrapper-0.2.1.tar.gz

Download URL django_mcp_wrapper-0.2.1.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b9519e61fd6e5214f56577d58bd25400aa457c3bea26aa7c5eb5edd15cdb3f1
BLAKE2b-256 checksum
How to use checksums
3d5954cb2c647751f043e282ce35384902893ce0c9731dfef03cd220b02c206f
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 9, 2026.

Transparency log

Release files / django_mcp_wrapper-0.2.1-py3-none-any.whl

Download URL django_mcp_wrapper-0.2.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68d21cd22f8ab7765990e1b286d32ad7b629114a03a976ebc65f7e2f477d630d
BLAKE2b-256 checksum
How to use checksums
8b076dc606b5a2a09a19e837499868df76c8b84d200841e36050dd5eb0d1df91
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 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1

2 release files

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