djangorestframework-pydantic-ai¶
Expose djangorestframework-services
services and selectors as a Pydantic-AI toolset, so a
plain pydantic_ai.Agent can call them as tools — no MCP server and no AG-UI
bridge in the path.
What this is¶
A single thin adapter, SpecToolset,
that turns a name -> spec mapping into agent tools. Every call routes through
drf-services' transport-neutral surface:
dispatch_specexecutes the service or selector (validation, instance resolution, output-selector re-fetch);build_offline_contextsupplies a synthetic request / view / principal sopermission_classes,extend_queryset, and context providers keep working;enforce_permissionsrunsspec.permission_classes—dispatch_specdeliberately does not, so building a toolset naively on it would skip authorization;spec_to_json_schemaderives each tool's parameter schema;render_spec_outputrenders the result through the spec's serializer.
The result is that an agent driving these tools sees exactly what an HTTP client
would: the same validation errors, the same permission_classes checks (both
class-level has_permission and object-level has_object_permission on the
resolved row), the same rendered payloads — without the network hop, and without
standing up an MCP server.
How it compares¶
If you already run an MCP server, django-ag-ui's DrfMcpToolset exposes its
tools to Pydantic-AI through the in-process MCP surface. SpecToolset is for the
case where you want the specs as tools without any MCP layer: it depends only
on djangorestframework-services and pydantic-ai-slim.
Next steps¶
- Quickstart — wire a toolset to an agent.
- Reference — the public API.