Tags & custom attributes
Two ready-made resource subclasses for projects that use tags and user-defined custom fields.
BaseTagsResource
Adds the m2m tags relation to the response automatically. Use it when your model has a tags ManyToManyField:
from zeromcp.base import BaseTagsResource
class SpaceResource(BaseTagsResource):
model = Space
list_fields = ['id', 'name']Detail responses include "tags": ["foo", "bar"] even when tags is not in edit_fields.
BaseCustomResource
For models that use a custom-attributes pattern (custom fields defined per row, stored through a related model). The class:
- Reads custom-attribute definitions ordered by
fieldset.order. - Groups attributes into named fieldsets (with optional
card_typesegmentation when the model has a card type). - Resolves the value for each attribute on the current row.
- Returns a
custom_attributesdict on detail responses, structured by fieldset.
Response shape
{
"id": 42,
"name": "Some row",
"ca__priority": "High",
"custom_attributes": {
"default": {
"name": "Default",
"order": 100000,
"fields": [{"id": 1, "name": "priority", "value": "High"}]
},
"fieldset_a": {
"name": "Fieldset A",
"order": 10,
"hide_if_empty": false,
"fields": [...]
}
}
}Writing custom values
POST/PATCH bodies accept custom_<name> keys. The library splits them out, runs the regular CRUD pipeline, and saves them via obj._custom.aset(name, value):
POST /spaces
{"name": "Demo", "custom_priority": "High"}Validation errors raised by the custom field framework bubble as HTTPException(409, message).
Both classes are thin subclasses of BaseResource. Inspect zeromcp/base.py for the add_m2m implementation if you want to subclass them.
0-mcp by Stamatios Stamou Jr — github.com/ssjunior/0-mcp