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).
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.selector_spec import SelectorSpec
from rest_framework_services.types.service_spec import ServiceSpec
from rest_framework_mcp import MCPServer
server = MCPServer(name="my-app")
server.register_service_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=SelectorSpec(
selector=get_invoice,
output_serializer=InvoiceOutputSerializer,
),
)
urlpatterns = [path("mcp/", include(server.urls))]
A decorator form is also supported (@server.service_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[filter]" # +django-filter for selector-tool FilterSets
pip install "djangorestframework-mcp-server[spectacular]" # +drf-spectacular schema overrides
pip install "djangorestframework-mcp-server[toon,oauth,redis,otel,filter,spectacular]" # everything
…or with uv:
uv add djangorestframework-mcp-server # JSON only
uv add "djangorestframework-mcp-server[toon]" # +TOON encoder
uv add "djangorestframework-mcp-server[oauth]" # +django-oauth-toolkit backend
uv add "djangorestframework-mcp-server[redis]" # +Redis SSE broker for multi-worker ASGI
uv add "djangorestframework-mcp-server[otel]" # +OpenTelemetry instrumentation
uv add "djangorestframework-mcp-server[filter]" # +django-filter for selector-tool FilterSets
uv add "djangorestframework-mcp-server[spectacular]" # +drf-spectacular schema overrides
uv add "djangorestframework-mcp-server[toon,oauth,redis,otel,filter,spectacular]" # everything
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.2.1.tar.gz.
File metadata
- Download URL: djangorestframework_mcp_server-0.2.1.tar.gz
- Upload date:
- Size: 258.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39246a1cbd702037ac16008101fec4ff5c4adda12e22e021c1d0a35f6e22f4fa
|
|
| MD5 |
f39d8a40065ec55823828ecc1051f148
|
|
| BLAKE2b-256 |
6556688bfc047f07bc481ae83ce0515a3a51e275dd04350f531e301968c16396
|
Provenance
The following attestation bundles were made for djangorestframework_mcp_server-0.2.1.tar.gz:
Publisher:
release.yml on Artui/djangorestframework-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangorestframework_mcp_server-0.2.1.tar.gz -
Subject digest:
39246a1cbd702037ac16008101fec4ff5c4adda12e22e021c1d0a35f6e22f4fa - Sigstore transparency entry: 1399452875
- Sigstore integration time:
-
Permalink:
Artui/djangorestframework-mcp-server@9d73c9c0955e9fbe1330ef6e17cd915eb4e59150 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9d73c9c0955e9fbe1330ef6e17cd915eb4e59150 -
Trigger Event:
push
-
Statement type:
File details
Details for the file djangorestframework_mcp_server-0.2.1-py3-none-any.whl.
File metadata
- Download URL: djangorestframework_mcp_server-0.2.1-py3-none-any.whl
- Upload date:
- Size: 123.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6016ddd5be0c69ef6f42e5ac14d342ca6323eb186f08bdc42fd9c0d8dc707a2
|
|
| MD5 |
afd805c1967ce45eac38cf6471bded8d
|
|
| BLAKE2b-256 |
d171dfe5ac03929aa216bb983c41228543d4f49e6ad51680cc5f7c6c1209f93f
|
Provenance
The following attestation bundles were made for djangorestframework_mcp_server-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Artui/djangorestframework-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangorestframework_mcp_server-0.2.1-py3-none-any.whl -
Subject digest:
d6016ddd5be0c69ef6f42e5ac14d342ca6323eb186f08bdc42fd9c0d8dc707a2 - Sigstore transparency entry: 1399452882
- Sigstore integration time:
-
Permalink:
Artui/djangorestframework-mcp-server@9d73c9c0955e9fbe1330ef6e17cd915eb4e59150 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9d73c9c0955e9fbe1330ef6e17cd915eb4e59150 -
Trigger Event:
push
-
Statement type: