Ordering
?order_by= whitelisted against the resource's order_fields.
Usage
🤖 MCP — tools/call
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_user",
"arguments": {"order_by": "-created_at"}
}
}🌐 REST — Querystring
GET /users?order_by=email GET /users?order_by=-created_at # descending
Resource declares which fields are sortable:
class UserResource(BaseResource):
order_fields = ['id', 'email', 'created_at']
order_by = 'id' # defaultAnything outside order_fields is ignored — falls back to the resource's order_by.
Stable order
When order_by is not unique (e.g. created_at), pagination can drift. For deterministic order across pages, include the primary key:
class UserResource(BaseResource):
order_fields = ['id', 'created_at']
order_by = '-created_at'
async def get_objs(self, request):
self.queryset = self.queryset.order_by('-created_at', 'id')
return await super().get_objs(request)0-mcp by Stamatios Stamou Jr — github.com/ssjunior/0-mcp