@payloadcms/plugin-mcp 4.0.0-internal.567a487 → 4.0.0-internal.5a4aa81
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/endpoint/access.js +2 -2
- package/dist/endpoint/access.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +35 -23
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +79 -56
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +9 -14
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +48 -49
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +40 -43
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +26 -36
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.js +19 -20
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.spec.js +2 -2
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +21 -43
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +12 -12
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +50 -86
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +10 -16
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +27 -36
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -6
- package/src/endpoint/access.ts +2 -3
- package/src/mcp/buildMcpServer.ts +39 -29
- package/src/mcp/builtin/collections/authTools.ts +77 -69
- package/src/mcp/builtin/collections/countTool.ts +9 -21
- package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
- package/src/mcp/builtin/collections/createTool.ts +73 -96
- package/src/mcp/builtin/collections/deleteTool.ts +36 -64
- package/src/mcp/builtin/collections/duplicateTool.ts +33 -84
- package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
- package/src/mcp/builtin/collections/fileInput.ts +30 -25
- package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
- package/src/mcp/builtin/collections/findTool.ts +21 -103
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
- package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +11 -11
- package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
- package/src/mcp/builtin/collections/updateTool.ts +53 -108
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
- package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
- package/src/mcp/builtin/globals/findTool.ts +12 -51
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
- package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
- package/src/mcp/builtin/globals/updateTool.ts +37 -60
- package/src/types.ts +4 -4
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,4CA0ElC,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { getAccessResults } from 'payload';
|
|
1
|
+
import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload';
|
|
2
2
|
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
3
|
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
-
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
5
4
|
export const getCollectionSchemaTool = defineCollectionTool({
|
|
6
5
|
access: (args)=>{
|
|
7
|
-
const permissions = args.permissions?.collections?.[args.
|
|
6
|
+
const permissions = args.permissions?.collections?.[args.slug];
|
|
8
7
|
return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
|
|
9
8
|
},
|
|
10
9
|
annotations: {
|
|
@@ -14,24 +13,25 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
14
13
|
readOnlyHint: true,
|
|
15
14
|
title: 'Get Collection Schema'
|
|
16
15
|
},
|
|
17
|
-
description: 'Get the input schema for creating or updating documents in a collection.'
|
|
18
|
-
|
|
16
|
+
description: 'Get the input schema for creating or updating documents in a collection.',
|
|
17
|
+
input: getCollectionSchemaInputSchema
|
|
18
|
+
}).handler(async ({ slug, authorizedMCP, req })=>{
|
|
19
19
|
const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
|
|
20
20
|
req
|
|
21
|
-
})).collections?.[
|
|
21
|
+
})).collections?.[slug];
|
|
22
22
|
if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
|
|
23
23
|
return {
|
|
24
24
|
content: [
|
|
25
25
|
{
|
|
26
26
|
type: 'text',
|
|
27
|
-
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${
|
|
27
|
+
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${slug}"`
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
30
|
isError: true
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
const inputSchema = getCollectionInputSchema({
|
|
34
|
-
collectionSlug,
|
|
34
|
+
collectionSlug: slug,
|
|
35
35
|
req,
|
|
36
36
|
...permissions ? {
|
|
37
37
|
permissions
|
|
@@ -42,13 +42,13 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
42
42
|
content: [
|
|
43
43
|
{
|
|
44
44
|
type: 'text',
|
|
45
|
-
text: `Error: Collection "${
|
|
45
|
+
text: `Error: Collection "${slug}" not found`
|
|
46
46
|
}
|
|
47
47
|
],
|
|
48
48
|
isError: true
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
const uploadConfig = req.payload.collections[
|
|
51
|
+
const uploadConfig = req.payload.collections[slug]?.config.upload;
|
|
52
52
|
const maxFileSize = req.payload.config.upload.limits?.fileSize;
|
|
53
53
|
const upload = uploadConfig ? {
|
|
54
54
|
enabled: true,
|
|
@@ -73,11 +73,11 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
73
73
|
content: [
|
|
74
74
|
{
|
|
75
75
|
type: 'text',
|
|
76
|
-
text: `Schema for collection "${
|
|
76
|
+
text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
|
|
77
77
|
}
|
|
78
78
|
],
|
|
79
79
|
structuredContent: {
|
|
80
|
-
|
|
80
|
+
slug,
|
|
81
81
|
schema: inputSchema,
|
|
82
82
|
upload
|
|
83
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.slug]\n\n return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description: 'Get the input schema for creating or updating documents in a collection.',\n input: getCollectionSchemaInputSchema,\n}).handler(async ({ slug, authorizedMCP, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[slug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getCollectionSchema\" is not enabled for collection \"${slug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug: slug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${slug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[slug]?.config.upload\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n const upload = uploadConfig\n ? {\n enabled: true,\n filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,\n mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],\n sources: [\n ...(uploadConfig.pasteURL !== false ? ['externalURL'] : []),\n 'base64',\n 'uploadReference',\n ],\n ...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),\n }\n : { enabled: false }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n slug,\n schema: inputSchema,\n upload,\n },\n }\n})\n"],"names":["getAccessResults","getCollectionInputSchema","getCollectionSchemaInputSchema","defaultAccess","defineCollectionTool","getCollectionSchemaTool","access","args","permissions","collections","slug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","collectionSlug","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,wBAAwB,EAAEC,8BAA8B,QAAQ,UAAS;AAEpG,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAE7D,OAAO,MAAMC,0BAA0BD,qBAAqB;IAC1DE,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,IAAI,CAAC;QAE9D,OAAOP,cAAcI,SAASI,QAAQH,aAAaI,UAAUJ,aAAaK;IAC5E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;IACbC,OAAOnB;AACT,GAAGoB,OAAO,CAAC,OAAO,EAAEZ,IAAI,EAAEa,aAAa,EAAEC,GAAG,EAAE;IAC5C,MAAMhB,cAAce,cAAcE,cAAc,GAC5C,OACA,AAAC,CAAA,MAAMzB,iBAAiB;QAAEwB;IAAI,EAAC,EAAGf,WAAW,EAAE,CAACC,KAAK;IAEzD,IAAI,CAACa,cAAcE,c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@@
|
|
|
1
|
-
{"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,4CAuD7B,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { restoreVersionInputSchema } from 'payload';
|
|
2
2
|
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
3
|
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
4
|
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
5
|
const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
|
|
6
6
|
export const restoreVersionTool = defineCollectionTool({
|
|
7
|
-
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.
|
|
7
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
8
8
|
annotations: {
|
|
9
9
|
destructiveHint: true,
|
|
10
10
|
idempotentHint: false,
|
|
@@ -13,64 +13,52 @@ export const restoreVersionTool = defineCollectionTool({
|
|
|
13
13
|
title: 'Restore Version'
|
|
14
14
|
},
|
|
15
15
|
description: DEFAULT_DESCRIPTION,
|
|
16
|
-
input:
|
|
17
|
-
|
|
18
|
-
depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in response').optional().default(0),
|
|
19
|
-
draft: z.boolean().describe('Whether to restore the version as a draft').optional().default(false),
|
|
20
|
-
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
21
|
-
locale: z.string().describe('Optional: locale code to restore in (e.g., "en", "es")').optional(),
|
|
22
|
-
populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
|
|
23
|
-
select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
|
|
24
|
-
showHiddenFields: z.boolean().describe('Optional: include hidden fields in the restored document response').optional()
|
|
25
|
-
})
|
|
26
|
-
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
16
|
+
input: restoreVersionInputSchema
|
|
17
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
27
18
|
const payload = req.payload;
|
|
28
19
|
const logger = getLogger({
|
|
29
20
|
payload
|
|
30
21
|
});
|
|
31
|
-
const { id, depth, draft, fallbackLocale, locale, populate, select
|
|
32
|
-
logger.info(`Restoring version in collection: ${
|
|
22
|
+
const { id, depth, draft, fallbackLocale, locale, populate, select } = input;
|
|
23
|
+
logger.info(`Restoring version in collection: ${slug} with ID: ${id}`);
|
|
33
24
|
try {
|
|
34
25
|
const result = await payload.restoreVersion({
|
|
35
|
-
id,
|
|
36
|
-
collection:
|
|
26
|
+
id: String(id),
|
|
27
|
+
collection: slug,
|
|
37
28
|
depth,
|
|
38
29
|
draft,
|
|
39
30
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
40
31
|
req,
|
|
41
|
-
...fallbackLocale ? {
|
|
32
|
+
...fallbackLocale !== undefined ? {
|
|
42
33
|
fallbackLocale
|
|
43
34
|
} : {},
|
|
44
35
|
...locale ? {
|
|
45
36
|
locale
|
|
46
37
|
} : {},
|
|
47
38
|
...populate ? {
|
|
48
|
-
populate
|
|
39
|
+
populate
|
|
49
40
|
} : {},
|
|
50
41
|
...select ? {
|
|
51
|
-
select
|
|
52
|
-
} : {},
|
|
53
|
-
...showHiddenFields !== undefined ? {
|
|
54
|
-
showHiddenFields
|
|
42
|
+
select
|
|
55
43
|
} : {}
|
|
56
44
|
});
|
|
57
45
|
return {
|
|
58
46
|
content: [
|
|
59
47
|
{
|
|
60
48
|
type: 'text',
|
|
61
|
-
text: `Version "${id}" restored successfully in collection "${
|
|
49
|
+
text: `Version "${id}" restored successfully in collection "${slug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
62
50
|
}
|
|
63
51
|
],
|
|
64
52
|
doc: result
|
|
65
53
|
};
|
|
66
54
|
} catch (error) {
|
|
67
55
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
68
|
-
logger.error(`Error restoring version ${id} in ${
|
|
56
|
+
logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`);
|
|
69
57
|
return {
|
|
70
58
|
content: [
|
|
71
59
|
{
|
|
72
60
|
type: 'text',
|
|
73
|
-
text: `❌ **Error restoring version "${id}" in collection "${
|
|
61
|
+
text: `❌ **Error restoring version "${id}" in collection "${slug}":** ${errorMessage}`
|
|
74
62
|
}
|
|
75
63
|
],
|
|
76
64
|
isError: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import { restoreVersionInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: restoreVersionInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select } = input\n\n logger.info(`Restoring version in collection: ${slug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id: String(id),\n collection: slug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${slug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["restoreVersionInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","slug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","locale","populate","select","info","result","restoreVersion","String","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,UAAS;AAEnD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBH,qBAAqB;IACrDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,E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X;IACF;AACF,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,4CAuJ7B,CAAA"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCollectionInputSchema, getCollectionVirtualFieldNames, stripVirtualFields, transformPointDataToPayload, updateDocumentInputSchema, validateCollectionData } from 'payload';
|
|
2
2
|
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
3
|
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
4
|
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
-
import {
|
|
6
|
-
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
7
|
-
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
|
|
8
|
-
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
9
|
-
import { validateCollectionData } from '../validateEntityData.js';
|
|
5
|
+
import { formatEntityError } from '../formatEntityError.js';
|
|
10
6
|
import { fileInputSchema, resolveFile } from './fileInput.js';
|
|
11
|
-
import { formatCollectionError } from './formatCollectionError.js';
|
|
12
7
|
const DEFAULT_DESCRIPTION = 'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.';
|
|
13
8
|
export const updateDocumentTool = defineCollectionTool({
|
|
14
|
-
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.
|
|
9
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
15
10
|
annotations: {
|
|
16
11
|
destructiveHint: true,
|
|
17
12
|
idempotentHint: false,
|
|
@@ -20,136 +15,104 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
20
15
|
title: 'Update Document'
|
|
21
16
|
},
|
|
22
17
|
description: DEFAULT_DESCRIPTION,
|
|
23
|
-
input:
|
|
24
|
-
|
|
25
|
-
z.string(),
|
|
26
|
-
z.number()
|
|
27
|
-
]).describe('The ID of the document to update').optional(),
|
|
28
|
-
data: z.record(z.string(), z.unknown()).describe('The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.'),
|
|
29
|
-
depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
|
|
30
|
-
draft: z.boolean().describe('Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: "published" overrides true.').optional().default(false),
|
|
31
|
-
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
32
|
-
file: fileInputSchema.optional(),
|
|
33
|
-
locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
|
|
34
|
-
overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
|
|
35
|
-
overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
|
|
36
|
-
publishAllLocales: z.boolean().describe('For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.').optional(),
|
|
37
|
-
select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
|
|
38
|
-
where: whereSchema.describe('Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
|
|
18
|
+
input: updateDocumentInputSchema({
|
|
19
|
+
file: fileInputSchema
|
|
39
20
|
})
|
|
40
|
-
}).handler(async ({
|
|
21
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
41
22
|
const payload = req.payload;
|
|
42
23
|
const logger = getLogger({
|
|
43
24
|
payload
|
|
44
25
|
});
|
|
45
|
-
const { id, data, depth, draft, fallbackLocale, file: fileInput, locale, overrideLock,
|
|
46
|
-
logger.info(`Updating document in collection: ${
|
|
26
|
+
const { id, data, depth, draft, fallbackLocale, file: fileInput, limit, locale, overrideLock, populate, publishAllLocales, returning, select, sort, trash, unpublishAllLocales, where } = input;
|
|
27
|
+
logger.info(`Updating document in collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
47
28
|
try {
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
content: [
|
|
51
|
-
{
|
|
52
|
-
type: 'text',
|
|
53
|
-
text: 'Error: Either id or where clause must be provided'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
|
|
29
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug);
|
|
59
30
|
const inputData = stripVirtualFields(data, virtualFieldNames);
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
validateCollectionData({
|
|
32
|
+
slug,
|
|
62
33
|
data: inputData,
|
|
63
34
|
partial: true,
|
|
64
35
|
req
|
|
65
36
|
});
|
|
66
|
-
if (validationError) {
|
|
67
|
-
return validationError;
|
|
68
|
-
}
|
|
69
37
|
const parsedData = transformPointDataToPayload(inputData);
|
|
70
38
|
const file = await resolveFile({
|
|
71
|
-
|
|
39
|
+
slug,
|
|
72
40
|
input: fileInput,
|
|
73
41
|
req
|
|
74
42
|
});
|
|
75
43
|
const whereClause = where ?? {};
|
|
76
|
-
if (id) {
|
|
44
|
+
if (id !== undefined) {
|
|
77
45
|
const result = await payload.update({
|
|
78
46
|
id,
|
|
79
|
-
collection:
|
|
47
|
+
collection: slug,
|
|
80
48
|
data: parsedData,
|
|
81
49
|
depth,
|
|
82
50
|
draft,
|
|
51
|
+
fallbackLocale,
|
|
52
|
+
locale,
|
|
83
53
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
84
54
|
overrideLock,
|
|
55
|
+
populate,
|
|
56
|
+
publishAllLocales,
|
|
85
57
|
req,
|
|
58
|
+
select: returning ? select : {
|
|
59
|
+
id: true
|
|
60
|
+
},
|
|
61
|
+
trash,
|
|
62
|
+
unpublishAllLocales,
|
|
86
63
|
...file ? {
|
|
87
64
|
file
|
|
88
|
-
} : {},
|
|
89
|
-
...overwriteExistingFiles ? {
|
|
90
|
-
overwriteExistingFiles
|
|
91
|
-
} : {},
|
|
92
|
-
...publishAllLocales !== undefined ? {
|
|
93
|
-
publishAllLocales
|
|
94
|
-
} : {},
|
|
95
|
-
...locale ? {
|
|
96
|
-
locale
|
|
97
|
-
} : {},
|
|
98
|
-
...fallbackLocale ? {
|
|
99
|
-
fallbackLocale
|
|
100
|
-
} : {},
|
|
101
|
-
...select ? {
|
|
102
|
-
select: select
|
|
103
65
|
} : {}
|
|
104
66
|
});
|
|
67
|
+
const responseResult = returning ? result : {
|
|
68
|
+
id: result.id
|
|
69
|
+
};
|
|
105
70
|
return {
|
|
106
71
|
content: [
|
|
107
72
|
{
|
|
108
73
|
type: 'text',
|
|
109
|
-
text: `Document updated successfully in collection "${
|
|
74
|
+
text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``
|
|
110
75
|
}
|
|
111
76
|
],
|
|
112
|
-
doc:
|
|
77
|
+
doc: responseResult
|
|
113
78
|
};
|
|
114
79
|
}
|
|
115
80
|
const result = await payload.update({
|
|
116
|
-
collection:
|
|
81
|
+
collection: slug,
|
|
117
82
|
data: parsedData,
|
|
118
83
|
depth,
|
|
119
84
|
draft,
|
|
85
|
+
fallbackLocale,
|
|
86
|
+
limit,
|
|
87
|
+
locale,
|
|
120
88
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
121
89
|
overrideLock,
|
|
90
|
+
populate,
|
|
91
|
+
publishAllLocales,
|
|
122
92
|
req,
|
|
93
|
+
select: returning ? select : {
|
|
94
|
+
id: true
|
|
95
|
+
},
|
|
96
|
+
sort,
|
|
97
|
+
trash,
|
|
98
|
+
unpublishAllLocales,
|
|
123
99
|
where: whereClause,
|
|
124
100
|
...file ? {
|
|
125
101
|
file
|
|
126
|
-
} : {},
|
|
127
|
-
...overwriteExistingFiles ? {
|
|
128
|
-
overwriteExistingFiles
|
|
129
|
-
} : {},
|
|
130
|
-
...publishAllLocales !== undefined ? {
|
|
131
|
-
publishAllLocales
|
|
132
|
-
} : {},
|
|
133
|
-
...locale ? {
|
|
134
|
-
locale
|
|
135
|
-
} : {},
|
|
136
|
-
...fallbackLocale ? {
|
|
137
|
-
fallbackLocale
|
|
138
|
-
} : {},
|
|
139
|
-
...select ? {
|
|
140
|
-
select: select
|
|
141
102
|
} : {}
|
|
142
103
|
});
|
|
143
|
-
const docs = result.docs
|
|
104
|
+
const docs = returning ? result.docs : result.docs.map(({ id })=>({
|
|
105
|
+
id
|
|
106
|
+
}));
|
|
144
107
|
const errors = result.errors || [];
|
|
145
|
-
let responseText = `Multiple documents updated in collection "${
|
|
108
|
+
let responseText = `Multiple documents updated in collection "${slug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
|
|
146
109
|
if (docs.length > 0) {
|
|
147
110
|
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
|
|
148
111
|
}
|
|
149
112
|
if (errors.length > 0) {
|
|
150
113
|
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
|
|
151
114
|
const errorSchema = getCollectionInputSchema({
|
|
152
|
-
collectionSlug,
|
|
115
|
+
collectionSlug: slug,
|
|
153
116
|
req
|
|
154
117
|
});
|
|
155
118
|
if (errorSchema) {
|
|
@@ -169,7 +132,7 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
169
132
|
isError: true,
|
|
170
133
|
...errorSchema ? {
|
|
171
134
|
structuredContent: {
|
|
172
|
-
|
|
135
|
+
slug,
|
|
173
136
|
docs,
|
|
174
137
|
errors,
|
|
175
138
|
schema: errorSchema
|
|
@@ -191,10 +154,11 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
191
154
|
};
|
|
192
155
|
} catch (error) {
|
|
193
156
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
194
|
-
logger.error(`Error updating document in ${
|
|
195
|
-
return
|
|
157
|
+
logger.error(`Error updating document in ${slug}: ${errorMessage}`);
|
|
158
|
+
return formatEntityError({
|
|
159
|
+
slug,
|
|
196
160
|
action: 'updating',
|
|
197
|
-
|
|
161
|
+
entity: 'collection',
|
|
198
162
|
error,
|
|
199
163
|
req
|
|
200
164
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType, Where } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { fileInputSchema, resolveFile } from './fileInput.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.'\n\nexport const updateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z\n .record(z.string(), z.unknown())\n .describe(\n 'The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.',\n ),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: \"published\" overrides true.',\n )\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n file: fileInputSchema.optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\n publishAllLocales: z\n .boolean()\n .describe(\n 'For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n where: whereSchema\n .describe(\n 'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n file: fileInput,\n locale,\n overrideLock,\n overwriteExistingFiles,\n publishAllLocales,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n const validationError = validateCollectionData({\n collectionSlug,\n data: inputData,\n partial: true,\n req,\n })\n\n if (validationError) {\n return validationError\n }\n\n const parsedData = transformPointDataToPayload(inputData)\n const file = await resolveFile({ collectionSlug, input: fileInput, req })\n\n const whereClause: Where = where ?? {}\n\n if (id) {\n const result = await payload.update({\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n where: whereClause,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n const docs = result.docs || []\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n\n const errorSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n collectionSlug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\n }\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'updating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","fileInputSchema","resolveFile","formatCollectionError","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","data","record","unknown","depth","default","draft","boolean","fallbackLocale","file","locale","overrideLock","overwriteExistingFiles","publishAllLocales","select","where","handler","authorizedMCP","req","payload","logger","fileInput","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","overrideAccess","undefined","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,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payload'\n\nimport {\n getCollectionInputSchema,\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n transformPointDataToPayload,\n updateDocumentInputSchema,\n validateCollectionData,\n} from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { formatEntityError } from '../formatEntityError.js'\nimport { fileInputSchema, resolveFile } from './fileInput.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.'\n\nexport const updateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: updateDocumentInputSchema({ file: fileInputSchema }),\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n file: fileInput,\n limit,\n locale,\n overrideLock,\n populate,\n publishAllLocales,\n returning,\n select,\n sort,\n trash,\n unpublishAllLocales,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n validateCollectionData({\n slug,\n data: inputData,\n partial: true,\n req,\n })\n\n const parsedData = transformPointDataToPayload(inputData)\n const file = await resolveFile({ slug, input: fileInput, req })\n\n const whereClause: Where = where ?? {}\n\n if (id !== undefined) {\n const result = await payload.update({\n id,\n collection: slug,\n data: parsedData,\n depth,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n populate,\n publishAllLocales,\n req,\n select: returning ? select : { id: true },\n trash,\n unpublishAllLocales,\n ...(file ? { file } : {}),\n })\n\n const responseResult = returning ? result : { id: result.id }\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${slug}\"!\\nResult:\\n\\`\\`\\`json\\n${JSON.stringify(responseResult)}\\n\\`\\`\\``,\n },\n ],\n doc: responseResult as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: slug,\n data: parsedData,\n depth,\n draft,\n fallbackLocale,\n limit,\n locale,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n populate,\n publishAllLocales,\n req,\n select: returning ? select : { id: true },\n sort,\n trash,\n unpublishAllLocales,\n where: whereClause,\n ...(file ? { file } : {}),\n })\n\n const docs = returning ? result.docs : result.docs.map(({ id }) => ({ id }))\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${slug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n\n const errorSchema = getCollectionInputSchema({ collectionSlug: slug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n slug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\n }\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${slug}: ${errorMessage}`)\n return formatEntityError({ slug, action: 'updating', entity: 'collection', error, req })\n }\n})\n"],"names":["getCollectionInputSchema","getCollectionVirtualFieldNames","stripVirtualFields","transformPointDataToPayload","updateDocumentInputSchema","validateCollectionData","defaultAccess","defineCollectionTool","getLogger","formatEntityError","fileInputSchema","resolveFile","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","slug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","file","handler","authorizedMCP","req","payload","logger","id","data","depth","draft","fallbackLocale","fileInput","limit","locale","overrideLock","populate","publishAllLocales","returning","select","sort","trash","unpublishAllLocales","where","info","virtualFieldNames","config","inputData","partial","parsedData","whereClause","undefined","result","collection","overrideAccess","responseResult","content","type","text","JSON","stringify","doc","docs","map","errors","responseText","length","errorSchema","collectionSlug","isError","structuredContent","schema","error","errorMessage","Error","message","action","entity"],"mappings":"AAEA,SACEA,wBAAwB,EACxBC,8BAA8B,EAC9BC,kBAAkB,EAClBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,sBAAsB,QACjB,UAAS;AAEhB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,eAAe,EAAEC,WAAW,QAAQ,iBAAgB;AAE7D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBN,qBAAqB;IACrDO,QAAQ,CAACC,OACPT,cAAcS,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOxB,0BAA0B;QAAEyB,MAAMnB;IAAgB;AAC3D,GAAGoB,OAAO,CAAC,OAAO,EAAEX,IAAI,EAAEY,aAAa,EAAEH,KAAK,EAA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YAEA,OAAO;gBACLX,SAAS;oBAAC;wBAAEC,MAAM;wBAAQC,MAAMO;oBAAa;iBAAE;gBAC/CJ,KAAK;oBAAEC;oBAAME;gBAAO;gBACpBK,SAAS;gBACT,GAAIF,cACA;oBACEG,mBAAmB;wBACjB3D;wBACAmD;wBACAE;wBACAO,QAAQJ;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLX,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMO;gBAAa;aAAE;YAC/CJ,KAAK;gBAAEC;gBAAME;YAAO;QACtB;IACF,EAAE,OAAOQ,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DjD,OAAO8C,KAAK,CAAC,CAAC,2BAA2B,EAAE7D,KAAK,EAAE,EAAE8D,cAAc;QAClE,OAAOxE,kBAAkB;YAAEU;YAAMiE,QAAQ;YAAYC,QAAQ;YAAcL;YAAOhD;QAAI;IACxF;AACF,GAAE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { strictObject, z } from 'payload';
|
|
1
2
|
import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal';
|
|
2
|
-
import { z } from 'zod';
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js';
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js';
|
|
5
5
|
export const getUploadInstructionsTool = defineCollectionTool({
|
|
6
|
-
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.
|
|
6
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.create || args.permissions?.collections?.[args.slug]?.update),
|
|
7
7
|
annotations: {
|
|
8
8
|
destructiveHint: false,
|
|
9
9
|
idempotentHint: false,
|
|
@@ -12,17 +12,17 @@ export const getUploadInstructionsTool = defineCollectionTool({
|
|
|
12
12
|
title: 'Get Upload Instructions'
|
|
13
13
|
},
|
|
14
14
|
description: 'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
|
|
15
|
-
input:
|
|
16
|
-
docPrefix: z.string().describe('
|
|
17
|
-
filename: z.string().describe('The original file name'),
|
|
18
|
-
filesize: z.
|
|
19
|
-
mimeType: z.string().describe('The file MIME type')
|
|
15
|
+
input: strictObject({
|
|
16
|
+
docPrefix: z.optional(z.string()).check(z.describe('Document folder or prefix.')),
|
|
17
|
+
filename: z.string().check(z.describe('The original file name.')),
|
|
18
|
+
filesize: z.int().check(z.nonnegative(), z.describe('The file size in bytes.')),
|
|
19
|
+
mimeType: z.string().check(z.describe('The file MIME type.'))
|
|
20
20
|
})
|
|
21
|
-
}).handler(async ({
|
|
21
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
22
22
|
try {
|
|
23
23
|
const instructions = await getPayloadUploadInstructions({
|
|
24
24
|
...input,
|
|
25
|
-
collectionSlug,
|
|
25
|
+
collectionSlug: slug,
|
|
26
26
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
27
27
|
req
|
|
28
28
|
});
|
|
@@ -31,7 +31,7 @@ export const getUploadInstructionsTool = defineCollectionTool({
|
|
|
31
31
|
content: [
|
|
32
32
|
{
|
|
33
33
|
type: 'text',
|
|
34
|
-
text: `Upload instructions for collection "${
|
|
34
|
+
text: `Upload instructions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
37
|
structuredContent: {
|
|
@@ -44,7 +44,7 @@ export const getUploadInstructionsTool = defineCollectionTool({
|
|
|
44
44
|
content: [
|
|
45
45
|
{
|
|
46
46
|
type: 'text',
|
|
47
|
-
text: `Error getting upload instructions for collection "${
|
|
47
|
+
text: `Error getting upload instructions for collection "${slug}": ${message}`
|
|
48
48
|
}
|
|
49
49
|
],
|
|
50
50
|
isError: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"sourcesContent":["import { strictObject, z } from 'payload'\nimport { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\n\nexport const getUploadInstructionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(\n args.permissions?.collections?.[args.slug]?.create ||\n args.permissions?.collections?.[args.slug]?.update,\n ),\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n readOnlyHint: false,\n title: 'Get Upload Instructions',\n },\n description:\n 'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',\n input: strictObject({\n docPrefix: z.optional(z.string()).check(z.describe('Document folder or prefix.')),\n filename: z.string().check(z.describe('The original file name.')),\n filesize: z.int().check(z.nonnegative(), z.describe('The file size in bytes.')),\n mimeType: z.string().check(z.describe('The file MIME type.')),\n }),\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n try {\n const instructions = await getPayloadUploadInstructions({\n ...input,\n collectionSlug: slug,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n })\n\n const nextStep =\n instructions.type === 'http'\n ? 'Upload bytes with instructions.request. After success, pass { source: \"uploadReference\", file: instructions.file }.'\n : `Call \"${instructions.name}\" with file and data. After success, pass { source: \"uploadReference\", file: instructions.file }.`\n\n return {\n content: [\n {\n type: 'text',\n text: `Upload instructions for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(instructions)}\\n\\`\\`\\`\\n${nextStep}`,\n },\n ],\n structuredContent: { instructions },\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error'\n return {\n content: [\n {\n type: 'text',\n text: `Error getting upload instructions for collection \"${slug}\": ${message}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["strictObject","z","getUploadInstructions","getPayloadUploadInstructions","defaultAccess","defineCollectionTool","getUploadInstructionsTool","access","args","Boolean","permissions","collections","slug","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","docPrefix","optional","string","check","describe","filename","filesize","int","nonnegative","mimeType","handler","authorizedMCP","req","instructions","collectionSlug","overrideAccess","nextStep","type","name","content","text","JSON","stringify","structuredContent","error","message","Error","isError"],"mappings":"AAAA,SAASA,YAAY,EAAEC,CAAC,QAAQ,UAAS;AACzC,SAASC,yBAAyBC,4BAA4B,QAAQ,mBAAkB;AAExF,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAE7D,OAAO,MAAMC,4BAA4BD,qBAAqB;IAC5DE,QAAQ,CAACC,OACPJ,cAAcI,SACdC,QACED,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC,UAC1CL,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEE;IAElDC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aACE;IACFC,OAAOtB,aAAa;QAClBuB,WAAWtB,EAAEuB,QAAQ,CAACvB,EAAEwB,MAAM,IAAIC,KAAK,CAACzB,EAAE0B,QAAQ,CAAC;QACnDC,UAAU3B,EAAEwB,MAAM,GAAGC,KAAK,CAACzB,EAAE0B,QAAQ,CAAC;QACtCE,UAAU5B,EAAE6B,GAAG,GAAGJ,KAAK,CAACzB,EAAE8B,WAAW,IAAI9B,EAAE0B,QAAQ,CAAC;QACpDK,UAAU/B,EAAEwB,MAAM,GAAGC,KAAK,CAACzB,EAAE0B,QAAQ,CAAC;IACxC;AACF,GAAGM,OAAO,CAAC,OAAO,EAAErB,IAAI,EAAEsB,aAAa,EAAEZ,KAAK,EAAEa,GAAG,EAAE;IACnD,IAAI;QACF,MAAMC,eAAe,MAAMjC,6BAA6B;YACtD,GAAGmB,KAA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