Expose djangorestframework-services services and selectors as an MCP (Model Context Protocol) server.
Project description
djangorestframework-mcp-server
Expose djangorestframework-services
services and selectors as a Model Context Protocol
(MCP) server, conforming to MCP 2025-11-25 (Streamable HTTP).
Status: alpha. API surfaces and wire details may shift before
0.1is tagged.
Idea
Register ServiceSpec instances directly — no DRF router or viewset
involvement. The unit of registration is the ServiceSpec, not a view.
from django.urls import include, path
from rest_framework_services.types.service_spec import ServiceSpec
from rest_framework_mcp import MCPServer
server = MCPServer(name="my-app")
server.register_tool(
name="invoices.create",
spec=ServiceSpec(
service=create_invoice,
input_serializer=InvoiceInputSerializer,
output_serializer=InvoiceOutputSerializer,
),
)
server.register_resource(
name="invoice",
uri_template="invoices://{pk}",
selector=get_invoice,
output_serializer=InvoiceOutputSerializer,
)
urlpatterns = [path("mcp/", include(server.urls))]
A decorator form is also supported (@server.tool(...) / @server.resource(...)).
See the quickstart for the full end-to-end recipe.
- Services (mutations) → MCP tools.
- Selectors (reads) → MCP resources.
- A single
/mcpendpoint speaks Streamable HTTP. The/.well-known/oauth-protected-resourceendpoint comes mounted alongside.
What ships in v1
tools/list,tools/call,resources/list,resources/templates/list,resources/read.- Pluggable auth:
DjangoOAuthToolkitBackend(default when DOT is installed) andAllowAnyBackend(dev only). Per-bindingMCPPermissionclasses (ScopeRequired,DjangoPermRequired) plus your own. - RFC 8707 audience binding when
RESOURCE_URLis configured; RFC 9728 PRM served from the configured backend. - Output formats: JSON (default) and TOON (token-oriented; optional extra with safe JSON fallback).
- Origin allowlist + protocol-version validation + session lifecycle per the 2025-11-25 transport rules.
Install
pip install djangorestframework-mcp-server # JSON only
pip install "djangorestframework-mcp-server[toon]" # +TOON encoder
pip install "djangorestframework-mcp-server[oauth]" # +django-oauth-toolkit backend
pip install "djangorestframework-mcp-server[redis]" # +Redis SSE broker for multi-worker ASGI
pip install "djangorestframework-mcp-server[otel]" # +OpenTelemetry instrumentation
pip install "djangorestframework-mcp-server[toon,oauth,redis,otel]" # all optional extras
Optional extras degrade gracefully: TOON falls back to JSON with a runtime
warning if python-toon is not installed, and the OAuth backend module
imports cleanly without oauth2_provider — the ImportError only fires when
you actually configure it.
Try it
Install mcp-inspector and point it at your dev server:
npx @modelcontextprotocol/inspector --url http://localhost:8000/mcp/
Inspector lists tools, fills in arguments from the generated JSON Schema, and walks the OAuth auth flow against your configured Authorization Server.
Documentation
- Quickstart — copy-pasteable end-to-end.
- Concepts — tools vs resources, sessions, output formats.
- Authentication — backends, permissions, audience binding, bring-your-own AS recipe.
- Recipes — focused cookbook entries.
- Reference — autodocs for every public symbol.
License
MIT.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djangorestframework_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: djangorestframework_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 209.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a257c667f62c33e76b60af85d92cd51211c89ad848898ffb3a864dc14cd747e1
|
|
| MD5 |
aa60426b020d6e898d99e7b00abf684b
|
|
| BLAKE2b-256 |
b08070ab51f085978e200579f884467edc6c573a8717c072a3109587819dad91
|
File details
Details for the file djangorestframework_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: djangorestframework_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 109.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
391bff5ad560cef708230000a75dfde11a9a053bbe9eeacef9f75dcaef14eb71
|
|
| MD5 |
25ec5fef0c1070f7b8dbcbcf2f1f2285
|
|
| BLAKE2b-256 |
9ae0085e649aee4842ba6203f0a52306de5280abe2c7cb74940f28fffd24e1b2
|