Portable specs¶
One spec can be mounted unchanged on every transport: django-spec-rest, django-spec-html, django-spec-cli, django-spec-mcp, django-spec-agents and django-spec-tasks. This page lists what a spec declares to run on all of them, and then what no transport removes. The transports compared lists the differences between them.
Async is not a portability axis: dispatch runs an async service or selector
from sync code on every transport.
The seats that run everywhere¶
A write and a read declared with these seats were answered on all six transports, unchanged:
- A validator that reads its input as plain fields: a
FormValidatorover a plain form. - A kernel
PermissionCheck, declared on the spec. - A presenter over a dataclass, with one output field marked
FieldMarking.label(). - Flat scalar parameters: strings, numbers, booleans, and choices over them.
- A name that matches
PORTABLE_NAME, the pattern an agent tool name must match. - A list read that declares no
pageorlimit: the names inPAGING_ARGUMENTSare the paging a transport adds itself, so a read declaring one is refused by MCP for a tool it pages and by agents for a list tool.orderingstays the spec's to declare. - No callable that declares
requestorview, which the limits below explain.
from typing import Any
from django import forms
from django_service_specs import (
DataclassPresenter,
FormValidator,
Parameter,
Parameters,
SelectorKind,
SelectorSpec,
ServiceSpec,
)
from docs.examples.declaring import IsSignedIn, NoteRow, notes_of
from tests.dispatch_app.models import Note
class NoteForm(forms.Form):
title = forms.CharField(max_length=100)
def add_note(*, user: Any, data: dict[str, Any]) -> Note:
return Note.objects.create(owner=user, title=data["title"])
add_note_spec = ServiceSpec(
service=add_note,
permissions=[IsSignedIn()],
validator=FormValidator(NoteForm),
presenter=DataclassPresenter(NoteRow),
)
list_notes_spec = SelectorSpec(
kind=SelectorKind.LIST,
selector=notes_of,
permissions=[IsSignedIn()],
reads=Parameters.of(Parameter("search", "string")),
presenter=DataclassPresenter(NoteRow),
)
The same two specs are the REST routes, the HTML form and page, the CLI commands, the MCP tools, the agent tools and the task callers.
The limits that stay¶
A transport cannot remove these, so a spec meant to be portable plans around each.
- The request and the view. The CLI and tasks have neither, agents usually
have none, and
viewisNoneeverywhere but REST and HTML. A target lookup readingview.kwargsgets nothing off HTTP: declare the capture as a read, so it arrives as an argument. call_context["action"]is the DRF action on REST, the tool name on MCP and agents, andNoneon HTML, the CLI and tasks. Branch oncall_transport(), never onaction.- Asking mid-call. A call that needs more input ends the run on the CLI and
in tasks (the CLI exits with code 8, a task ends
INPUT_REQUIRED), and the caller runs it again with the answer. - Uploads cross only REST and HTML.
- Task semantics. A task whose run lapsed is run again only under
idempotent=True. Withatomic=Falseit can endABANDONED, its outcome unknown. Its output is capped bymax_output_bytes. Its validator runs in the worker, later than the enqueue. - Declared permissions. MCP and agents refuse a spec with
permissions=None; REST falls back to the permission classes of the view. - DRF seats.
SerializerValidatorandDRFPermissionCheckrun off HTTP through an offline request and view, wherever DRF is installed. django-spec-mcp is DRF-free by layer, so a spec bound for it declares kernel seats instead.