@directus/api 30.0.0 → 31.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +5 -0
- package/dist/auth/drivers/oauth2.js +17 -3
- package/dist/auth/drivers/openid.js +17 -3
- package/dist/controllers/mcp.d.ts +2 -0
- package/dist/controllers/mcp.js +33 -0
- package/dist/controllers/users.js +17 -7
- package/dist/controllers/versions.js +3 -2
- package/dist/database/errors/dialects/mssql.d.ts +1 -1
- package/dist/database/errors/dialects/mssql.js +18 -10
- package/dist/database/migrations/20250813A-add-mcp.d.ts +3 -0
- package/dist/database/migrations/20250813A-add-mcp.js +18 -0
- package/dist/database/run-ast/README.md +46 -0
- package/dist/mcp/define.d.ts +2 -0
- package/dist/mcp/define.js +3 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/schema.d.ts +485 -0
- package/dist/mcp/schema.js +219 -0
- package/dist/mcp/server.d.ts +97 -0
- package/dist/mcp/server.js +310 -0
- package/dist/mcp/tools/assets.d.ts +3 -0
- package/dist/mcp/tools/assets.js +54 -0
- package/dist/mcp/tools/collections.d.ts +84 -0
- package/dist/mcp/tools/collections.js +90 -0
- package/dist/mcp/tools/fields.d.ts +101 -0
- package/dist/mcp/tools/fields.js +157 -0
- package/dist/mcp/tools/files.d.ts +235 -0
- package/dist/mcp/tools/files.js +103 -0
- package/dist/mcp/tools/flows.d.ts +323 -0
- package/dist/mcp/tools/flows.js +85 -0
- package/dist/mcp/tools/folders.d.ts +95 -0
- package/dist/mcp/tools/folders.js +96 -0
- package/dist/mcp/tools/index.d.ts +15 -0
- package/dist/mcp/tools/index.js +29 -0
- package/dist/mcp/tools/items.d.ts +87 -0
- package/dist/mcp/tools/items.js +141 -0
- package/dist/mcp/tools/operations.d.ts +171 -0
- package/dist/mcp/tools/operations.js +77 -0
- package/dist/mcp/tools/prompts/assets.md +8 -0
- package/dist/mcp/tools/prompts/collections.md +336 -0
- package/dist/mcp/tools/prompts/fields.md +521 -0
- package/dist/mcp/tools/prompts/files.md +180 -0
- package/dist/mcp/tools/prompts/flows.md +495 -0
- package/dist/mcp/tools/prompts/folders.md +34 -0
- package/dist/mcp/tools/prompts/index.d.ts +16 -0
- package/dist/mcp/tools/prompts/index.js +19 -0
- package/dist/mcp/tools/prompts/items.md +317 -0
- package/dist/mcp/tools/prompts/operations.md +721 -0
- package/dist/mcp/tools/prompts/relations.md +386 -0
- package/dist/mcp/tools/prompts/schema.md +130 -0
- package/dist/mcp/tools/prompts/system-prompt-description.md +1 -0
- package/dist/mcp/tools/prompts/system-prompt.md +44 -0
- package/dist/mcp/tools/prompts/trigger-flow.md +214 -0
- package/dist/mcp/tools/relations.d.ts +73 -0
- package/dist/mcp/tools/relations.js +93 -0
- package/dist/mcp/tools/schema.d.ts +54 -0
- package/dist/mcp/tools/schema.js +317 -0
- package/dist/mcp/tools/system.d.ts +3 -0
- package/dist/mcp/tools/system.js +22 -0
- package/dist/mcp/tools/trigger-flow.d.ts +8 -0
- package/dist/mcp/tools/trigger-flow.js +48 -0
- package/dist/mcp/transport.d.ts +13 -0
- package/dist/mcp/transport.js +18 -0
- package/dist/mcp/types.d.ts +56 -0
- package/dist/mcp/types.js +1 -0
- package/dist/services/authentication.js +36 -0
- package/dist/services/fields.js +4 -4
- package/dist/services/items.js +14 -4
- package/dist/services/payload.d.ts +7 -3
- package/dist/services/payload.js +26 -12
- package/dist/services/server.js +1 -0
- package/dist/services/tfa.d.ts +1 -1
- package/dist/services/tfa.js +20 -5
- package/dist/services/versions.d.ts +6 -4
- package/dist/services/versions.js +84 -25
- package/dist/types/auth.d.ts +2 -1
- package/dist/utils/versioning/deep-map-with-schema.d.ts +23 -0
- package/dist/utils/versioning/deep-map-with-schema.js +81 -0
- package/dist/utils/versioning/handle-version.d.ts +2 -2
- package/dist/utils/versioning/handle-version.js +47 -43
- package/dist/utils/versioning/split-recursive.d.ts +4 -0
- package/dist/utils/versioning/split-recursive.js +27 -0
- package/package.json +30 -29
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
Perform CRUD operations on items within Directus collections
|
|
2
|
+
|
|
3
|
+
## Actions
|
|
4
|
+
|
|
5
|
+
- `read`: Query items with filtering/pagination/field selection
|
|
6
|
+
- `create`: Add items (single/batch) with nested relations
|
|
7
|
+
- `update`: Modify items with partial data
|
|
8
|
+
- `delete`: Remove items by primary keys
|
|
9
|
+
|
|
10
|
+
## Essential Query Patterns
|
|
11
|
+
|
|
12
|
+
### Field Selection (Always Use)
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{ "fields": ["title", "status", "author.name", "categories.*"] }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For M2A relations: `"sections.item:headings.title", "sections.item:paragraphs.body"`
|
|
19
|
+
|
|
20
|
+
### Filtering Operators
|
|
21
|
+
|
|
22
|
+
Core: `_eq`, `_neq`, `_in`, `_nin`, `_null`, `_nnull`, `_lt`, `_lte`, `_gt`, `_gte`, `_between`, `_contains`,
|
|
23
|
+
`_icontains`, `_starts_with`, `_ends_with`, `_empty`, `_nempty` Relations: `_some`, `_none` (O2M only) Logic: `_and`,
|
|
24
|
+
`_or`
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{"status": {"_eq": "published"}}
|
|
28
|
+
{"title": {"_icontains": "keyword"}}
|
|
29
|
+
{"categories": {"_some": {"name": {"_eq": "News"}}}}
|
|
30
|
+
{"_or": [{"status": {"_eq": "published"}}, {"featured": {"_eq": true}}]}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Deep Queries (Nested Relations)
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"fields": ["title", "comments.text", "comments.author.name"],
|
|
38
|
+
"deep": {
|
|
39
|
+
"comments": {
|
|
40
|
+
"_filter": { "status": { "_eq": "approved" } },
|
|
41
|
+
"_sort": ["-date_created"],
|
|
42
|
+
"_limit": 5
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Create/Update/Delete Best Practices
|
|
49
|
+
|
|
50
|
+
- ALWAYS show the item URL if it is present in the result for create or update
|
|
51
|
+
|
|
52
|
+
### Creating Items
|
|
53
|
+
|
|
54
|
+
- ALWAYS make sure you fully understand the collection's schema before trying to create items.
|
|
55
|
+
|
|
56
|
+
**✅ GOOD - Single with Relations:**
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"action": "create",
|
|
61
|
+
"collection": "posts",
|
|
62
|
+
"data": {
|
|
63
|
+
"title": "New Post",
|
|
64
|
+
"author": { "name": "John Doe", "email": "john@example.com" }, // Creates nested
|
|
65
|
+
"categories": [1, 2, { "name": "New Category" }], // Mix existing + new
|
|
66
|
+
"status": "draft"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**✅ GOOD - Batch Create:**
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"action": "create",
|
|
76
|
+
"collection": "posts",
|
|
77
|
+
"data": [
|
|
78
|
+
{ "title": "Post 1", "author_id": 1 },
|
|
79
|
+
{ "title": "Post 2", "author_id": 2 }
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**❌ BAD - Missing Required Fields:**
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
// Don't create without checking schema first
|
|
88
|
+
{ "title": "Post" } // Missing required fields like status
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Updating Items
|
|
92
|
+
|
|
93
|
+
**✅ GOOD - Update with Keys:**
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"action": "update",
|
|
98
|
+
"collection": "posts",
|
|
99
|
+
"keys": ["uuid-1", "uuid-2"],
|
|
100
|
+
"data": { "status": "published" } // Partial update
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**✅ GOOD - Batch Update (Different Data):**
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"action": "update",
|
|
109
|
+
"collection": "posts",
|
|
110
|
+
"data": [
|
|
111
|
+
{ "id": "uuid-1", "title": "Updated Title 1" },
|
|
112
|
+
{ "id": "uuid-2", "title": "Updated Title 2" }
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**✅ GOOD - Relational Updates:**
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"action": "update",
|
|
122
|
+
"collection": "posts",
|
|
123
|
+
"keys": ["uuid-1"],
|
|
124
|
+
"data": {
|
|
125
|
+
"categories": {
|
|
126
|
+
"create": [{ "name": "New Category" }],
|
|
127
|
+
"update": [{ "id": 3, "name": "Renamed" }],
|
|
128
|
+
"delete": [5]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**❌ BAD - Update Without Keys:**
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
// Don't update without specifying which items
|
|
138
|
+
{
|
|
139
|
+
"action": "update",
|
|
140
|
+
"data": { "status": "published" } // Will fail - no keys provided
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Deleting Items
|
|
145
|
+
|
|
146
|
+
- ALWAYS get written confirmation with the user before deleting any items.
|
|
147
|
+
|
|
148
|
+
**✅ GOOD - Delete by Keys:**
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"action": "delete",
|
|
153
|
+
"collection": "posts",
|
|
154
|
+
"keys": ["uuid-1", "uuid-2"]
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**❌ BAD - Delete All (Dangerous):**
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
// Never delete without keys - use query to get keys first
|
|
162
|
+
{
|
|
163
|
+
"action": "delete",
|
|
164
|
+
"collection": "posts" // Will fail - keys required
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Singleton Collections
|
|
169
|
+
|
|
170
|
+
**✅ GOOD - Singleton Read:**
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"action": "read",
|
|
175
|
+
"collection": "settings", // Singleton collection
|
|
176
|
+
"query": { "fields": ["site_name", "logo"] }
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**✅ GOOD - Singleton Update:**
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"action": "update",
|
|
185
|
+
"collection": "settings",
|
|
186
|
+
"data": { "site_name": "New Name" } // No keys needed for singleton
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Advanced Relationship Patterns
|
|
191
|
+
|
|
192
|
+
### Many-to-One (M2O)
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
// Create with nested author
|
|
196
|
+
{"title": "Article", "author": {"name": "New Author"}}
|
|
197
|
+
// Link existing author
|
|
198
|
+
{"title": "Article", "author": "existing-uuid"}
|
|
199
|
+
// Remove relation
|
|
200
|
+
{"author": null}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### One-to-Many (O2M)
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
// Link to existing comments
|
|
207
|
+
{"comments": [1, 5, 9]}
|
|
208
|
+
// Create/update/delete operations
|
|
209
|
+
{
|
|
210
|
+
"comments": {
|
|
211
|
+
"create": [{"text": "New comment"}],
|
|
212
|
+
"update": [{"id": 5, "text": "Updated"}],
|
|
213
|
+
"delete": [1, 9]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Many-to-Any (M2A)
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"sections": [
|
|
223
|
+
{ "collection": "headings", "item": { "text": "Title", "level": 1 } },
|
|
224
|
+
{ "collection": "paragraphs", "item": { "content": "Body text" } }
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Translations
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
// Create with multiple languages
|
|
233
|
+
{
|
|
234
|
+
"title": "Main Title",
|
|
235
|
+
"translations": [
|
|
236
|
+
{"languages_code": "en-US", "title": "English Title", "content": "English content"},
|
|
237
|
+
{"languages_code": "fr-FR", "title": "Titre Français", "content": "Contenu français"}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Read specific language
|
|
242
|
+
{
|
|
243
|
+
"fields": ["title", "translations.title", "translations.content"],
|
|
244
|
+
"deep": {
|
|
245
|
+
"translations": {
|
|
246
|
+
"_filter": {"languages_code": {"_eq": "fr-FR"}}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## LLM Decision Rules
|
|
253
|
+
|
|
254
|
+
### Schema-First Pattern (Critical)
|
|
255
|
+
|
|
256
|
+
1. **Always call `schema()` first** to discover collections
|
|
257
|
+
2. **Examine specific schemas**: `schema(keys: ["collection"])` for field details based on users query
|
|
258
|
+
3. **Follow relation chains**: Check `relation.related_collections` in field definitions when it's relevant to your task
|
|
259
|
+
4. **IMPORTANT: Never guess field names** - Always use exact names from schema. If you're not 100% sure, ask the user
|
|
260
|
+
|
|
261
|
+
### Before Creating Items
|
|
262
|
+
|
|
263
|
+
1. **Check required fields** in schema
|
|
264
|
+
2. **Validate field types** match schema definitions
|
|
265
|
+
3. **Check for singleton collections** (`collection.singleton: true`)
|
|
266
|
+
4. **Verify relation targets exist** before linking. You can also create new relation items by nesting
|
|
267
|
+
|
|
268
|
+
### Before Updating Items
|
|
269
|
+
|
|
270
|
+
1. **Use keys parameter** for bulk updates with same data
|
|
271
|
+
2. **Use data array** for batch updates with different data per item
|
|
272
|
+
3. **Include primary key in data** when using batch update
|
|
273
|
+
4. **Check field permissions** - some fields may be read-only
|
|
274
|
+
|
|
275
|
+
### Before Deleting Items
|
|
276
|
+
|
|
277
|
+
1. **Always require explicit keys** - never delete by query alone
|
|
278
|
+
2. **Check for related data** that might be affected
|
|
279
|
+
3. **Validate cascade behavior** for relationships
|
|
280
|
+
4. **Consider soft delete** if collection has status field
|
|
281
|
+
|
|
282
|
+
### Performance & Safety
|
|
283
|
+
|
|
284
|
+
- **Use `fields`** to minimize payload size
|
|
285
|
+
- **Apply `limit`** for large result sets (default: no limit)
|
|
286
|
+
- **Batch operations** are transactional - all succeed or all fail
|
|
287
|
+
- **Primary keys returned** from create/update operations for chaining
|
|
288
|
+
- **Validation errors** are thrown before database operations
|
|
289
|
+
|
|
290
|
+
### Error Patterns to Avoid
|
|
291
|
+
|
|
292
|
+
- Creating without checking required fields through `scehma(keys: ["collection"])`
|
|
293
|
+
- Updating without keys or with invalid primary keys
|
|
294
|
+
- Deleting system collections (directus\_\*)
|
|
295
|
+
- Assuming field names without schema verification
|
|
296
|
+
- Missing foreign key references in relations
|
|
297
|
+
- Exceeding mutation limits in batch operations
|
|
298
|
+
|
|
299
|
+
### Singleton vs Regular Collections
|
|
300
|
+
|
|
301
|
+
**Regular Collections**: Require keys for update/delete, return arrays **Singleton Collections**: No keys needed, return
|
|
302
|
+
single objects, auto-upsert behavior
|
|
303
|
+
|
|
304
|
+
## Functions & Aggregation
|
|
305
|
+
|
|
306
|
+
Date: `year(field)`, `month(field)`, `day(field)`, `hour(field)` Aggregate: `count`, `sum`, `avg`, `min`, `max`
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{"filter": {"year(date_created)": {"_eq": 2024}}}
|
|
310
|
+
{"aggregate": {"count": "*", "sum": "price"}, "groupBy": ["category"]}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Restrictions
|
|
314
|
+
|
|
315
|
+
- Cannot operate on `directus_*` collections
|
|
316
|
+
- Respects user permissions/RBAC
|
|
317
|
+
- Delete operations may be environment-disabled
|