Change the schema
Add, change and remove collections through MCP, with a preview before anything is applied.
The schema is the list of your app's collections and the fields in each one. Two tools read and change it: get_schema and change_schema. A third, undo_schema_change, takes back the last change.
What a collection looks like#
A collection has a name, a set of fields, a list of required fields, and two switches that control guest access.
{"name":"ContactMessage","properties":{"name":{"type":"string","maxLength":120},"email":{"type":"email"},"message":{"type":"text"},"status":{"type":"enum","values":["new","answered"]}},"required":["email","message"],"publicRead":false,"publicCreate":true}namestringrequiredThe collection name, for example ContactMessage.
propertiesobjectThe fields, keyed by field name. Each one has a type and, depending on the type, extra options.
requiredarray of stringsThe names of the fields a record must have.
publicReadbooleanGuests may read records without signing in.
publicCreatebooleanGuests may create records without signing in. This is what a public form needs.
Field types#
A field's type is one of string, text, number, integer, boolean, date, datetime, enum, relation, array, object, email, phone or url.
Three types take an extra option:
| Type | Option | What it sets |
|---|---|---|
string | maxLength | The longest value allowed |
enum | values | The list of allowed values |
relation | ref | The collection the field points to |
Preview, then apply#
Ask for the plan
Call
change_schemawith the collection and withoutapply. The response lists each change with its kind and the number of records it affects. Nothing has changed yet.Read the plan
The assistant shows you what would change. This is the moment to catch a field that was left out by mistake.
Apply
Call
change_schemaagain withapplyset totrue. An additive change, such as a new collection or a new optional field, goes through. A breaking or security change also needsuser_confirmed.
Changes that need your confirmation#
These changes are applied only with user_confirmed set to true, and the assistant sets it only after you agree in the conversation:
- Changing a field's type
- Removing a field
- Making an existing field required
- Turning on
publicReadorpublicCreate
Remove a collection#
Pass remove_collection with the collection's name instead of collection. The collection leaves the schema. Its records stay.
Undo the last change#
undo_schema_change puts back the schema from before the last change_schema. Records that were converted by that change stay converted.