@payloadcms/plugin-mcp 4.0.0-internal.811e0a4 → 4.0.0-internal.8867dba

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.
Files changed (142) hide show
  1. package/bin.js +7 -0
  2. package/dist/defaultAccess.d.ts.map +1 -1
  3. package/dist/defineTool.d.ts +8 -8
  4. package/dist/defineTool.d.ts.map +1 -1
  5. package/dist/endpoint/access.d.ts +2 -7
  6. package/dist/endpoint/access.d.ts.map +1 -1
  7. package/dist/endpoint/access.js +4 -11
  8. package/dist/endpoint/access.js.map +1 -1
  9. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  10. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  11. package/dist/mcp/builtin/collections/countTool.js +1 -2
  12. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  13. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  14. package/dist/mcp/builtin/collections/countVersionsTool.js +1 -2
  15. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  16. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  17. package/dist/mcp/builtin/collections/createTool.js +15 -6
  18. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  19. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  20. package/dist/mcp/builtin/collections/deleteTool.js +1 -2
  21. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  22. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  23. package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
  24. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  25. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  26. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  27. package/dist/mcp/builtin/collections/fileInput.js +117 -0
  28. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  29. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  30. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  31. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  32. package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
  33. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  34. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  35. package/dist/mcp/builtin/collections/findTool.js +3 -4
  36. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  37. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  38. package/dist/mcp/builtin/collections/findVersionByIDTool.js +1 -2
  39. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  40. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  41. package/dist/mcp/builtin/collections/findVersionsTool.js +1 -2
  42. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  43. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  44. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  46. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +45 -5
  47. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  48. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  49. package/dist/mcp/builtin/collections/restoreVersionTool.js +1 -2
  50. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  51. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  52. package/dist/mcp/builtin/collections/updateTool.js +24 -12
  53. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  54. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  55. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  56. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  57. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  58. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  59. package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
  60. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  61. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  62. package/dist/mcp/builtin/globals/countVersionsTool.js +1 -2
  63. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  64. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  65. package/dist/mcp/builtin/globals/findTool.js +2 -2
  66. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  67. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  68. package/dist/mcp/builtin/globals/findVersionByIDTool.js +1 -2
  69. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  70. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  71. package/dist/mcp/builtin/globals/findVersionsTool.js +1 -2
  72. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  73. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +21 -3
  75. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/restoreVersionTool.js +1 -2
  77. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  78. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  79. package/dist/mcp/builtin/globals/updateTool.js +2 -2
  80. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  81. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  82. package/dist/mcp/builtinTools.d.ts +6 -0
  83. package/dist/mcp/builtinTools.d.ts.map +1 -1
  84. package/dist/mcp/builtinTools.js +6 -0
  85. package/dist/mcp/builtinTools.js.map +1 -1
  86. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  87. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  88. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  89. package/dist/types.d.ts +44 -7
  90. package/dist/types.d.ts.map +1 -1
  91. package/dist/types.js +2 -4
  92. package/dist/types.js.map +1 -1
  93. package/dist/utils/camelCase.d.ts.map +1 -1
  94. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  95. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  96. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  97. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  98. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  99. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
  100. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  101. package/dist/utils/schemaConversion/getEntityInputSchema.js +40 -6
  102. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
  103. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  104. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +2 -2
  105. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  106. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  107. package/package.json +4 -4
  108. package/src/endpoint/access.ts +3 -10
  109. package/src/mcp/builtin/collections/countTool.ts +1 -2
  110. package/src/mcp/builtin/collections/countVersionsTool.ts +2 -6
  111. package/src/mcp/builtin/collections/createTool.ts +15 -6
  112. package/src/mcp/builtin/collections/deleteTool.ts +1 -2
  113. package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
  114. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  115. package/src/mcp/builtin/collections/fileInput.ts +154 -0
  116. package/src/mcp/builtin/collections/findDistinctTool.ts +3 -3
  117. package/src/mcp/builtin/collections/findTool.ts +3 -4
  118. package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
  119. package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
  120. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +43 -9
  121. package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
  122. package/src/mcp/builtin/collections/updateTool.ts +26 -10
  123. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  124. package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
  125. package/src/mcp/builtin/globals/countVersionsTool.ts +2 -6
  126. package/src/mcp/builtin/globals/findTool.ts +2 -2
  127. package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
  128. package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
  129. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
  130. package/src/mcp/builtin/globals/restoreVersionTool.ts +3 -3
  131. package/src/mcp/builtin/globals/updateTool.ts +2 -2
  132. package/src/mcp/builtinTools.ts +7 -0
  133. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  134. package/src/types.ts +43 -7
  135. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  136. package/src/utils/schemaConversion/getEntityInputSchema.ts +47 -13
  137. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +2 -2
  138. package/dist/utils/localAPIDefaults.d.ts +0 -20
  139. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  140. package/dist/utils/localAPIDefaults.js +0 -19
  141. package/dist/utils/localAPIDefaults.js.map +0 -1
  142. package/src/utils/localAPIDefaults.ts +0 -22
@@ -1,10 +1,11 @@
1
+ import { getAccessResults } from 'payload';
1
2
  import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineCollectionTool } from '../../../defineTool.js';
3
4
  import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
4
5
  export const getCollectionSchemaTool = defineCollectionTool({
5
6
  access: (args)=>{
6
7
  const permissions = args.permissions?.collections?.[args.collectionSlug];
7
- return defaultAccess(args) && Boolean(permissions?.create || permissions?.delete || permissions?.read || permissions?.update);
8
+ return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
8
9
  },
9
10
  annotations: {
10
11
  destructiveHint: false,
@@ -14,10 +15,27 @@ export const getCollectionSchemaTool = defineCollectionTool({
14
15
  title: 'Get Collection Schema'
15
16
  },
16
17
  description: 'Get the input schema for creating or updating documents in a collection.'
17
- }).handler(({ collectionSlug, req })=>{
18
+ }).handler(async ({ authorizedMCP, collectionSlug, req })=>{
19
+ const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
+ req
21
+ })).collections?.[collectionSlug];
22
+ if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`
28
+ }
29
+ ],
30
+ isError: true
31
+ };
32
+ }
18
33
  const inputSchema = getCollectionInputSchema({
19
34
  collectionSlug,
20
- req
35
+ req,
36
+ ...permissions ? {
37
+ permissions
38
+ } : {}
21
39
  });
22
40
  if (!inputSchema) {
23
41
  return {
@@ -30,16 +48,38 @@ export const getCollectionSchemaTool = defineCollectionTool({
30
48
  isError: true
31
49
  };
32
50
  }
51
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
52
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
53
+ const upload = uploadConfig ? {
54
+ enabled: true,
55
+ filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
56
+ mimeTypes: uploadConfig.mimeTypes ?? [
57
+ '*/*'
58
+ ],
59
+ sources: [
60
+ ...uploadConfig.pasteURL !== false ? [
61
+ 'externalURL'
62
+ ] : [],
63
+ 'base64',
64
+ 'uploadReference'
65
+ ],
66
+ ...typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? {
67
+ maxFileSize
68
+ } : {}
69
+ } : {
70
+ enabled: false
71
+ };
33
72
  return {
34
73
  content: [
35
74
  {
36
75
  type: 'text',
37
- text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``
76
+ text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
38
77
  }
39
78
  ],
40
79
  structuredContent: {
41
80
  collectionSlug,
42
- schema: inputSchema
81
+ schema: inputSchema,
82
+ upload
43
83
  }
44
84
  };
45
85
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\n\n return (\n defaultAccess(args) &&\n Boolean(\n permissions?.create || permissions?.delete || permissions?.read || permissions?.update,\n )\n )\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}).handler(({ collectionSlug, req }) => {\n const inputSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n },\n }\n})\n"],"names":["defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","delete","read","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","req","inputSchema","content","type","text","isError","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,cAAc,CAAC;QAExE,OACER,cAAcK,SACdI,QACEH,aAAaI,UAAUJ,aAAaK,UAAUL,aAAaM,QAAQN,aAAaO;IAGtF;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,CAAC,EAAEb,cAAc,EAAEc,GAAG,EAAE;IACjC,MAAMC,cAAcrB,yBAAyB;QAAEM;QAAgBc;IAAI;IAEnE,IAAI,CAACC,aAAa;QAChB,OAAO;YACLC,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAElB,eAAe,WAAW,CAAC;gBAAC;aAAE;YACpFmB,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAElB,eAAe,gBAAgB,EAAEoB,KAAKC,SAAS,CAACN,aAAa,QAAQ,CAAC;YACxG;SACD;QACDO,mBAAmB;YACjBtB;YACAuB,QAAQR;QACV;IACF;AACF,GAAE"}
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'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\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}).handler(async ({ authorizedMCP, collectionSlug, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[collectionSlug]\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 \"${collectionSlug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[collectionSlug]?.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 \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n upload,\n },\n }\n})\n"],"names":["getAccessResults","defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,UAAS;AAE1C,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,cAAc,CAAC;QAExE,OAAOR,cAAcK,SAASI,QAAQH,aAAaI,UAAUJ,aAAaK;IAC5E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEZ,cAAc,EAAEa,GAAG,EAAE;IACtD,MAAMf,cAAcc,cAAcE,cAAc,GAC5C,OACA,AAAC,CAAA,MAAMvB,iBAAiB;QAAEsB;IAAI,EAAC,EAAGd,WAAW,EAAE,CAACC,eAAe;IAEnE,IAAI,CAACY,cAAcE,cAAc,IAAI,CAAChB,aAAaI,UAAU,CAACJ,aAAaK,QAAQ;QACjF,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0EAA0E,EAAEjB,eAAe,CAAC,CAAC;gBACtG;aACD;YACDkB,SAAS;QACX;IACF;IAEA,MAAMC,cAAczB,yBAAyB;QAC3CM;QACAa;QACA,GAAIf,cAAc;YAAEA;QAAY,IAAI,CAAC,CAAC;IACxC;IAEA,IAAI,CAACqB,aAAa;QAChB,OAAO;YACLJ,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAEjB,eAAe,WAAW,CAAC;gBAAC;aAAE;YACpFkB,SAAS;QACX;IACF;IAEA,MAAME,eAAeP,IAAIQ,OAAO,CAACtB,WAAW,CAACC,eAAe,EAAEsB,OAAOC;IACrE,MAAMC,cAAcX,IAAIQ,OAAO,CAACC,MAAM,CAACC,MAAM,CAACE,MAAM,EAAEC;IACtD,MAAMH,SAASH,eACX;QACEO,SAAS;QACTC,uBAAuBR,aAAaQ,qBAAqB,KAAK;QAC9DC,WAAWT,aAAaS,SAAS,IAAI;YAAC;SAAM;QAC5CC,SAAS;eACHV,aAAaW,QAAQ,KAAK,QAAQ;gBAAC;aAAc,GAAG,EAAE;YAC1D;YACA;SACD;QACD,GAAI,OAAOP,gBAAgB,YAAYQ,OAAOC,QAAQ,CAACT,eAAe;YAAEA;QAAY,IAAI,CAAC,CAAC;IAC5F,IACA;QAAEG,SAAS;IAAM;IAErB,OAAO;QACLZ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAEjB,eAAe,gBAAgB,EAAEkC,KAAKC,SAAS,CAAChB,aAAa,6CAA6C,EAAEe,KAAKC,SAAS,CAACZ,QAAQ,QAAQ,CAAC;YAC9K;SACD;QACDa,mBAAmB;YACjBpC;YACAqC,QAAQlB;YACRI;QACF;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
1
+ {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
7
6
  export const restoreVersionTool = defineCollectionTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
@@ -37,8 +36,8 @@ export const restoreVersionTool = defineCollectionTool({
37
36
  collection: collectionSlug,
38
37
  depth,
39
38
  draft,
39
+ overrideAccess: authorizedMCP.overrideAccess,
40
40
  req,
41
- ...localAPIDefaults(authorizedMCP),
42
41
  ...fallbackLocale ? {
43
42
  fallbackLocale
44
43
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } 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 { localAPIDefaults } from '../../../utils/localAPIDefaults.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.collectionSlug]?.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: z.object({\n id: z.string().describe('The ID of the version to restore'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in response')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to restore the version as a draft')\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 locale: z\n .string()\n .describe('Optional: locale code to restore in (e.g., \"en\", \"es\")')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\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 showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id,\n collection: collectionSlug,\n depth,\n draft,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${collectionSlug}\"!\\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 ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","draft","boolean","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","result","restoreVersion","collection","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBJ,qBAAqB;IACrDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAO1B,EACJ2B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,8DACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAOjC,EACJkC,OAAO,GACPT,QAAQ,CAAC,6CACTM,QAAQ,GACRC,OAAO,CAAC;QACXG,gBAAgBnC,EACbwB,MAAM,GACNC,QAAQ,CAAC,gFACTM,QAAQ;QACXK,QAAQpC,EACLwB,MAAM,GACNC,QAAQ,CAAC,0DACTM,QAAQ;QACXM,UAAUrC,EACPsC,MAAM,CAACtC,EAAEwB,MAAM,IAAIxB,EAAEuC,OAAO,IAC5Bd,QAAQ,CACP,8FAEDM,QAAQ;QACXS,QAAQxC,EACLsC,MAAM,CAACtC,EAAEwB,MAAM,IAAIxB,EAAEuC,OAAO,IAC5Bd,QAAQ,CACP,sGAEDM,QAAQ;QACXU,kBAAkBzC,EACfkC,OAAO,GACPT,QAAQ,CAAC,qEACTM,QAAQ;IACb;AACF,GAAGW,OAAO,CAAC,OAAO,EAAE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,iBAAiB,EAAEX,eAAe,KAAK,EAAE+C,cAAc;gBAClG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\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.collectionSlug]?.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: z.object({\n id: z.string().describe('The ID of the version to restore'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in response')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to restore the version as a draft')\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 locale: z\n .string()\n .describe('Optional: locale code to restore in (e.g., \"en\", \"es\")')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\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 showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id,\n collection: collectionSlug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${collectionSlug}\"!\\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 ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","draft","boolean","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","result","restoreVersion","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,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,cAAc,CAAC,EAAEC;IACvFC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Ac,CAAC;YAC1C1B;YACA2B,YAAYtC;YACZc;YACAO;YACAkB,gBAAgBR,cAAcQ,cAAc;YAC5CP;YACA,GAAIT,iBAAiB;gBAAEA;YAAe,IAAI,CAAC,CAAC;YAC5C,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,SAAS;gBAAEA,QAAQA;YAAqB,IAAI,CAAC,CAAC;YAClD,GAAIC,qBAAqBW,YAAY;gBAAEX;YAAiB,IAAI,CAAC,CAAC;QAChE;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEhC,GAAG,uCAAuC,EAAEX,eAAe,oCAAoC,EAAE4C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBACrJ;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,wBAAwB,EAAEpC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAEgD,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAEhC,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAEgD,cAAc;gBAClG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6L7B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6M7B,CAAA"}
@@ -3,13 +3,13 @@ import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
5
  import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
6
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
7
6
  import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
8
7
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
9
8
  import { whereSchema } from '../../../utils/whereSchema.js';
10
9
  import { validateCollectionData } from '../validateEntityData.js';
10
+ import { fileInputSchema, resolveFile } from './fileInput.js';
11
11
  import { formatCollectionError } from './formatCollectionError.js';
12
- const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
12
+ const DEFAULT_DESCRIPTION = 'Update documents in any collection. Files can use a URL, base64, or an upload prepared by getUploadInstructions.';
13
13
  export const updateDocumentTool = defineCollectionTool({
14
14
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
15
15
  annotations: {
@@ -25,14 +25,15 @@ export const updateDocumentTool = defineCollectionTool({
25
25
  z.string(),
26
26
  z.number()
27
27
  ]).describe('The ID of the document to update').optional(),
28
- data: z.record(z.string(), z.unknown()).describe('The fields to update'),
28
+ data: z.record(z.string(), z.unknown()).describe('The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.'),
29
29
  depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
30
- draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
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
31
  fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
32
- filePath: z.string().describe('File path for file uploads').optional(),
32
+ file: fileInputSchema.optional(),
33
33
  locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
34
34
  overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
35
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(),
36
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(),
37
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()
38
39
  })
@@ -41,7 +42,7 @@ export const updateDocumentTool = defineCollectionTool({
41
42
  const logger = getLogger({
42
43
  payload
43
44
  });
44
- const { id, data, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, select, where } = input;
45
+ const { id, data, depth, draft, fallbackLocale, file: fileInput, locale, overrideLock, overwriteExistingFiles, publishAllLocales, select, where } = input;
45
46
  logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
46
47
  try {
47
48
  if (!id && !where) {
@@ -66,6 +67,11 @@ export const updateDocumentTool = defineCollectionTool({
66
67
  return validationError;
67
68
  }
68
69
  const parsedData = transformPointDataToPayload(inputData);
70
+ const file = await resolveFile({
71
+ collectionSlug,
72
+ input: fileInput,
73
+ req
74
+ });
69
75
  const whereClause = where ?? {};
70
76
  if (id) {
71
77
  const result = await payload.update({
@@ -74,15 +80,18 @@ export const updateDocumentTool = defineCollectionTool({
74
80
  data: parsedData,
75
81
  depth,
76
82
  draft,
83
+ overrideAccess: authorizedMCP.overrideAccess,
77
84
  overrideLock,
78
85
  req,
79
- ...localAPIDefaults(authorizedMCP),
80
- ...filePath ? {
81
- filePath
86
+ ...file ? {
87
+ file
82
88
  } : {},
83
89
  ...overwriteExistingFiles ? {
84
90
  overwriteExistingFiles
85
91
  } : {},
92
+ ...publishAllLocales !== undefined ? {
93
+ publishAllLocales
94
+ } : {},
86
95
  ...locale ? {
87
96
  locale
88
97
  } : {},
@@ -108,16 +117,19 @@ export const updateDocumentTool = defineCollectionTool({
108
117
  data: parsedData,
109
118
  depth,
110
119
  draft,
120
+ overrideAccess: authorizedMCP.overrideAccess,
111
121
  overrideLock,
112
122
  req,
113
123
  where: whereClause,
114
- ...localAPIDefaults(authorizedMCP),
115
- ...filePath ? {
116
- filePath
124
+ ...file ? {
125
+ file
117
126
  } : {},
118
127
  ...overwriteExistingFiles ? {
119
128
  overwriteExistingFiles
120
129
  } : {},
130
+ ...publishAllLocales !== undefined ? {
131
+ publishAllLocales
132
+ } : {},
121
133
  ...locale ? {
122
134
  locale
123
135
  } : {},
@@ -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 { localAPIDefaults } from '../../../utils/localAPIDefaults.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 { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents in any collection by passing the collection slug and data.'\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.record(z.string(), z.unknown()).describe('The fields to update'),\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('Whether to update the document as a draft')\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 filePath: z.string().describe('File path for file uploads').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 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 filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\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\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 overrideLock,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\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 overrideLock,\n req,\n where: whereClause,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\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","localAPIDefaults","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","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","filePath","locale","overrideLock","overwriteExistingFiles","select","where","handler","authorizedMCP","req","payload","logger","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","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,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBX,qBAAqB;IACrDY,QAAQ,CAACC,OACPd,cAAcc,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAE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AC;wBAAEC,MAAM;wBAAQC,MAAMe;oBAAa;iBAAE;gBAC/CH,KAAK;oBAAEC;oBAAMC;gBAAO;gBACpBI,SAAS;gBACT,GAAID,cACA;oBACEE,mBAAmB;wBACjB1D;wBACAoD;wBACAC;wBACAM,QAAQH;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLnB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMe;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,2BAA2B,EAAE5D,eAAe,EAAE,EAAE6D,cAAc;QAC5E,OAAOrE,sBAAsB;YAAEwE,QAAQ;YAAYhE;YAAgB4D;YAAO3B;QAAI;IAChF;AACF,GAAE"}
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 in any collection. Files can use a URL, base64, or an upload prepared by getUploadInstructions.'\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,oBA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E,eAAe,EAAE,EAAEiE,cAAc;QAC5E,OAAOzE,sBAAsB;YAAE4E,QAAQ;YAAYpE;YAAgBgE;YAAO9B;QAAI;IAChF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const getUploadInstructionsTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=uploadInstructionsTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadInstructionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,4CAyDpC,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal';
2
+ import { z } from 'zod';
3
+ import { defaultAccess } from '../../../defaultAccess.js';
4
+ import { defineCollectionTool } from '../../../defineTool.js';
5
+ export const getUploadInstructionsTool = defineCollectionTool({
6
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create || args.permissions?.collections?.[args.collectionSlug]?.update),
7
+ annotations: {
8
+ destructiveHint: false,
9
+ idempotentHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ title: 'Get Upload Instructions'
13
+ },
14
+ description: 'Prepare a file upload before createDocument or updateDocument. Pass file metadata only, without base64 or file contents.',
15
+ input: z.object({
16
+ docPrefix: z.string().describe('Optional document folder or prefix').optional(),
17
+ filename: z.string().describe('The original file name'),
18
+ filesize: z.number().int().nonnegative().describe('The file size in bytes'),
19
+ mimeType: z.string().describe('The file MIME type')
20
+ })
21
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
22
+ try {
23
+ const instructions = await getPayloadUploadInstructions({
24
+ ...input,
25
+ collectionSlug,
26
+ overrideAccess: authorizedMCP.overrideAccess,
27
+ req
28
+ });
29
+ const nextStep = instructions.type === 'http' ? 'Send the exact file bytes using request, then pass { source: "uploadReference", file } to createDocument or updateDocument.' : `Call the local MCP tool named "${instructions.name}" with the file and data, then pass { source: "uploadReference", file } to createDocument or updateDocument.`;
30
+ return {
31
+ content: [
32
+ {
33
+ type: 'text',
34
+ text: `Upload instructions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`
35
+ }
36
+ ],
37
+ structuredContent: {
38
+ instructions
39
+ }
40
+ };
41
+ } catch (error) {
42
+ const message = error instanceof Error ? error.message : 'Unknown error';
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: `Error getting upload instructions for collection "${collectionSlug}": ${message}`
48
+ }
49
+ ],
50
+ isError: true
51
+ };
52
+ }
53
+ });
54
+
55
+ //# sourceMappingURL=uploadInstructionsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"sourcesContent":["import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'\nimport { z } from 'zod'\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.collectionSlug]?.create ||\n args.permissions?.collections?.[args.collectionSlug]?.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 a file upload before createDocument or updateDocument. Pass file metadata only, without base64 or file contents.',\n input: z.object({\n docPrefix: z.string().describe('Optional document folder or prefix').optional(),\n filename: z.string().describe('The original file name'),\n filesize: z.number().int().nonnegative().describe('The file size in bytes'),\n mimeType: z.string().describe('The file MIME type'),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n try {\n const instructions = await getPayloadUploadInstructions({\n ...input,\n collectionSlug,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n })\n\n const nextStep =\n instructions.type === 'http'\n ? 'Send the exact file bytes using request, then pass { source: \"uploadReference\", file } to createDocument or updateDocument.'\n : `Call the local MCP tool named \"${instructions.name}\" with the file and data, then pass { source: \"uploadReference\", file } to createDocument or updateDocument.`\n\n return {\n content: [\n {\n type: 'text',\n text: `Upload instructions for collection \"${collectionSlug}\":\\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 \"${collectionSlug}\": ${message}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["getUploadInstructions","getPayloadUploadInstructions","z","defaultAccess","defineCollectionTool","getUploadInstructionsTool","access","args","Boolean","permissions","collections","collectionSlug","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","docPrefix","string","describe","optional","filename","filesize","number","int","nonnegative","mimeType","handler","authorizedMCP","req","instructions","overrideAccess","nextStep","type","name","content","text","JSON","stringify","structuredContent","error","message","Error","isError"],"mappings":"AAAA,SAASA,yBAAyBC,4BAA4B,QAAQ,mBAAkB;AACxF,SAASC,CAAC,QAAQ,MAAK;AAEvB,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,cAAc,CAAC,EAAEC,UACpDL,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEE;IAE5DC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aACE;IACFC,OAAOnB,EAAEoB,MAAM,CAAC;QACdC,WAAWrB,EAAEsB,MAAM,GAAGC,QAAQ,CAAC,sCAAsCC,QAAQ;QAC7EC,UAAUzB,EAAEsB,MAAM,GAAGC,QAAQ,CAAC;QAC9BG,UAAU1B,EAAE2B,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGN,QAAQ,CAAC;QAClDO,UAAU9B,EAAEsB,MAAM,GAAGC,QAAQ,CAAC;IAChC;AACF,GAAGQ,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEvB,cAAc,EAAEU,KAAK,EAAEc,GAAG,EAAE;IAC7D,IAAI;QACF,MAAMC,eAAe,MAAMnC,6BAA6B;YACtD,GAAGoB,KAAK;YACRV;YACA0B,gBAAgBH,cAAcG,cAAc;YAC5CF;QACF;QAEA,MAAMG,WACJF,aAAaG,IAAI,KAAK,SAClB,gIACA,CAAC,+BAA+B,EAAEH,aAAaI,IAAI,CAAC,4GAA4G,CAAC;QAEvK,OAAO;YACLC,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,oCAAoC,EAAE/B,eAAe,gBAAgB,EAAEgC,KAAKC,SAAS,CAACR,cAAc,UAAU,EAAEE,UAAU;gBACnI;aACD;YACDO,mBAAmB;gBAAET;YAAa;QACpC;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAG;QACzD,OAAO;YACLN,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,kDAAkD,EAAE/B,eAAe,GAAG,EAAEoC,SAAS;gBAC1F;aACD;YACDE,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BAgE5B,CAAA"}
1
+ {"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BA8D5B,CAAA"}
@@ -10,12 +10,9 @@ export const getConfigInfoTool = defineTool({
10
10
  },
11
11
  description: 'List the Payload collection and global slugs visible to this MCP client.'
12
12
  }).handler(async ({ authorizedMCP, req })=>{
13
- const user = authorizedMCP.user;
13
+ const user = req.user;
14
14
  const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({
15
- req: {
16
- ...req,
17
- user
18
- }
15
+ req
19
16
  });
20
17
  const authorizedCollectionSlugs = new Set();
21
18
  const authorizedGlobalSlugs = new Set();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"sourcesContent":["import { getAccessResults, isEntityHidden } from 'payload'\n\nimport { defineTool } from '../../defineTool.js'\n\nexport const getConfigInfoTool = defineTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Config Info',\n },\n description: 'List the Payload collection and global slugs visible to this MCP client.',\n}).handler(async ({ authorizedMCP, req }) => {\n const user = authorizedMCP.user\n const permissions = authorizedMCP.overrideAccess\n ? null\n : await getAccessResults({ req: { ...req, user } })\n const authorizedCollectionSlugs = new Set<string>()\n const authorizedGlobalSlugs = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n if (item.type === 'collectionTool') {\n authorizedCollectionSlugs.add(item.collectionSlug)\n } else if (item.type === 'globalTool') {\n authorizedGlobalSlugs.add(item.globalSlug)\n }\n }\n\n const collections: string[] = []\n const globals: string[] = []\n\n for (const collection of req.payload.config.collections) {\n if (!authorizedCollectionSlugs.has(collection.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {\n continue\n }\n\n collections.push(collection.slug)\n }\n\n for (const global of req.payload.config.globals) {\n if (!authorizedGlobalSlugs.has(global.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {\n continue\n }\n\n globals.push(global.slug)\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Collections: ${collections.join(', ') || 'none'}\\nGlobals: ${globals.join(', ') || 'none'}`,\n },\n ],\n }\n})\n"],"names":["getAccessResults","isEntityHidden","defineTool","getConfigInfoTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","user","permissions","overrideAccess","authorizedCollectionSlugs","Set","authorizedGlobalSlugs","item","items","type","add","collectionSlug","globalSlug","collections","globals","collection","payload","config","has","slug","hidden","admin","read","push","global","content","text","join"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,UAAU,QAAQ,sBAAqB;AAEhD,OAAO,MAAMC,oBAAoBD,WAAW;IAC1CE,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,GAAG,EAAE;IACtC,MAAMC,OAAOF,cAAcE,IAAI;IAC/B,MAAMC,cAAcH,cAAcI,cAAc,GAC5C,OACA,MAAMhB,iBAAiB;QAAEa,KAAK;YAAE,GAAGA,GAAG;YAAEC;QAAK;IAAE;IACnD,MAAMG,4BAA4B,IAAIC;IACtC,MAAMC,wBAAwB,IAAID;IAElC,KAAK,MAAME,QAAQR,cAAcS,KAAK,CAAE;QACtC,IAAID,KAAKE,IAAI,KAAK,kBAAkB;YAClCL,0BAA0BM,GAAG,CAACH,KAAKI,cAAc;QACnD,OAAO,IAAIJ,KAAKE,IAAI,KAAK,cAAc;YACrCH,sBAAsBI,GAAG,CAACH,KAAKK,UAAU;QAC3C;IACF;IAEA,MAAMC,cAAwB,EAAE;IAChC,MAAMC,UAAoB,EAAE;IAE5B,KAAK,MAAMC,cAAcf,IAAIgB,OAAO,CAACC,MAAM,CAACJ,WAAW,CAAE;QACvD,IAAI,CAACT,0BAA0Bc,GAAG,CAACH,WAAWI,IAAI,GAAG;YACnD;QACF;QACA,IAAIlB,QAAQb,eAAe;YAAEgC,QAAQL,WAAWM,KAAK,CAACD,MAAM;YAAEnB;QAAK,IAAI;YACrE;QACF;QACA,IAAI,CAACF,cAAcI,cAAc,IAAI,CAACD,aAAaW,aAAa,CAACE,WAAWI,IAAI,CAAC,EAAEG,MAAM;YACvF;QACF;QAEAT,YAAYU,IAAI,CAACR,WAAWI,IAAI;IAClC;IAEA,KAAK,MAAMK,UAAUxB,IAAIgB,OAAO,CAACC,MAAM,CAACH,OAAO,CAAE;QAC/C,IAAI,CAACR,sBAAsBY,GAAG,CAACM,OAAOL,IAAI,GAAG;YAC3C;QACF;QACA,IAAIlB,QAAQb,eAAe;YAAEgC,QAAQI,OAAOH,KAAK,CAACD,MAAM;YAAEnB;QAAK,IAAI;YACjE;QACF;QACA,IAAI,CAACF,cAAcI,cAAc,IAAI,CAACD,aAAaY,SAAS,CAACU,OAAOL,IAAI,CAAC,EAAEG,MAAM;YAC/E;QACF;QAEAR,QAAQS,IAAI,CAACC,OAAOL,IAAI;IAC1B;IAEA,OAAO;QACLM,SAAS;YACP;gBACEhB,MAAM;gBACNiB,MAAM,CAAC,aAAa,EAAEb,YAAYc,IAAI,CAAC,SAAS,OAAO,WAAW,EAAEb,QAAQa,IAAI,CAAC,SAAS,QAAQ;YACpG;SACD;IACH;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"sourcesContent":["import { getAccessResults, isEntityHidden } from 'payload'\n\nimport { defineTool } from '../../defineTool.js'\n\nexport const getConfigInfoTool = defineTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Config Info',\n },\n description: 'List the Payload collection and global slugs visible to this MCP client.',\n}).handler(async ({ authorizedMCP, req }) => {\n const user = req.user\n const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })\n const authorizedCollectionSlugs = new Set<string>()\n const authorizedGlobalSlugs = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n if (item.type === 'collectionTool') {\n authorizedCollectionSlugs.add(item.collectionSlug)\n } else if (item.type === 'globalTool') {\n authorizedGlobalSlugs.add(item.globalSlug)\n }\n }\n\n const collections: string[] = []\n const globals: string[] = []\n\n for (const collection of req.payload.config.collections) {\n if (!authorizedCollectionSlugs.has(collection.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {\n continue\n }\n\n collections.push(collection.slug)\n }\n\n for (const global of req.payload.config.globals) {\n if (!authorizedGlobalSlugs.has(global.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {\n continue\n }\n\n globals.push(global.slug)\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Collections: ${collections.join(', ') || 'none'}\\nGlobals: ${globals.join(', ') || 'none'}`,\n },\n ],\n }\n})\n"],"names":["getAccessResults","isEntityHidden","defineTool","getConfigInfoTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","user","permissions","overrideAccess","authorizedCollectionSlugs","Set","authorizedGlobalSlugs","item","items","type","add","collectionSlug","globalSlug","collections","globals","collection","payload","config","has","slug","hidden","admin","read","push","global","content","text","join"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,UAAU,QAAQ,sBAAqB;AAEhD,OAAO,MAAMC,oBAAoBD,WAAW;IAC1CE,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,GAAG,EAAE;IACtC,M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,OAAO;QACLM,SAAS;YACP;gBACEhB,MAAM;gBACNiB,MAAM,CAAC,aAAa,EAAEb,YAAYc,IAAI,CAAC,SAAS,OAAO,WAAW,EAAEb,QAAQa,IAAI,CAAC,SAAS,QAAQ;YACpG;SACD;IACH;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,uBAAuB,wCA4DlC,CAAA"}
1
+ {"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,uBAAuB,wCAyDlC,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineGlobalTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  import { whereSchema } from '../../../utils/whereSchema.js';
7
6
  const DEFAULT_DESCRIPTION = 'Count global versions in any version-enabled global by passing the global slug and optional where clause.';
8
7
  export const countGlobalVersionsTool = defineGlobalTool({
@@ -29,8 +28,8 @@ export const countGlobalVersionsTool = defineGlobalTool({
29
28
  try {
30
29
  const result = await payload.countGlobalVersions({
31
30
  global: globalSlug,
31
+ overrideAccess: authorizedMCP.overrideAccess,
32
32
  req,
33
- ...localAPIDefaults(authorizedMCP),
34
33
  ...locale ? {
35
34
  locale
36
35
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Count global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const countGlobalVersionsTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Count Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n locale: z\n .string()\n .describe('Optional: locale code to count versions in')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.siteName\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { locale, where } = input\n\n logger.info(`Counting versions for global: ${globalSlug}`)\n\n try {\n const result = await payload.countGlobalVersions({\n global: globalSlug,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(locale ? { locale } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" contains ${result.totalDocs} matching versions.\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error counting versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","countGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","locale","string","describe","optional","where","handler","authorizedMCP","req","payload","logger","info","result","countGlobalVersions","global","content","type","text","totalDocs","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,0BAA0BL,iBAAiB;IACtDM,QAAQ,CAACC,OACPR,cAAcQ,SAASC,QAAQD,KAAKE,WAAW,EAAEC,SAAS,CAACH,KAAKI,UAAU,CAAC,EAAEC;IAC/EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,QAAQxB,EACLyB,MAAM,GACNC,QAAQ,CAAC,8CACTC,QAAQ;QACXC,OAAOvB,YACJqB,QAAQ,CACP,yJAEDC,QAAQ;IACb;AACF,GAAGE,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEjB,UAAU,EAAES,KAAK,EAAES,GAAG,EAAE;IACzD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAS9B,UAAU;QAAE6B;IAAQ;IACnC,MAAM,EAAER,MAAM,EAAEI,KAAK,EAAE,GAAGN;IAE1BW,OAAOC,IAAI,CAAC,CAAC,8BAA8B,EAAErB,YAAY;IAEzD,IAAI;QACF,MAAMsB,SAAS,MAAMH,QAAQI,mBAAmB,CAAC;YAC/CC,QAAQxB;YACRkB;YACA,GAAG3B,iBAAiB0B,cAAc;YAClC,GAAIN,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAII,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLU,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAE3B,WAAW,WAAW,EAAEsB,OAAOM,SAAS,CAAC,iCAAiC,EAAEC,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBAC/H;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,mCAAmC,EAAEhC,WAAW,EAAE,EAAEiC,cAAc;QAChF,OAAO;YACLR,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,wCAAwC,EAAE3B,WAAW,KAAK,EAAEiC,cAAc;gBACnF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Count global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const countGlobalVersionsTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Count Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n locale: z.string().describe('Optional: locale code to count versions in').optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.siteName\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { locale, where } = input\n\n logger.info(`Counting versions for global: ${globalSlug}`)\n\n try {\n const result = await payload.countGlobalVersions({\n global: globalSlug,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(locale ? { locale } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" contains ${result.totalDocs} matching versions.\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error counting versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","countGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","locale","string","describe","optional","where","handler","authorizedMCP","req","payload","logger","info","result","countGlobalVersions","global","overrideAccess","content","type","text","totalDocs","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,0BAA0BJ,iBAAiB;IACtDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,SAAS,CAACH,KAAKI,UAAU,CAAC,EAAEC;IAC/EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,QAAQvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC,8CAA8CC,QAAQ;QAClFC,OAAOvB,YACJqB,QAAQ,CACP,yJAEDC,QAAQ;IACb;AACF,GAAGE,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEjB,UAAU,EAAES,KAAK,EAAES,GAAG,EAAE;IACzD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAS7B,UAAU;QAAE4B;IAAQ;IACnC,MAAM,EAAER,MAAM,EAAEI,KAAK,EAAE,GAAGN;IAE1BW,OAAOC,IAAI,CAAC,CAAC,8BAA8B,EAAErB,YAAY;IAEzD,IAAI;QACF,MAAMsB,SAAS,MAAMH,QAAQI,mBAAmB,CAAC;YAC/CC,QAAQxB;YACRyB,gBAAgBR,cAAcQ,cAAc;YAC5CP;YACA,GAAIP,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAII,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAE5B,WAAW,WAAW,EAAEsB,OAAOO,SAAS,CAAC,iCAAiC,EAAEC,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC/H;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,mCAAmC,EAAEjC,WAAW,EAAE,EAAEkC,cAAc;QAChF,OAAO;YACLR,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,wCAAwC,EAAE5B,WAAW,KAAK,EAAEkC,cAAc;gBACnF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,cAAc,wCA6FzB,CAAA"}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,wCA8FzB,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineGlobalTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.';
7
6
  export const findGlobalTool = defineGlobalTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),
@@ -32,7 +31,8 @@ export const findGlobalTool = defineGlobalTool({
32
31
  const findOptions = {
33
32
  slug: globalSlug,
34
33
  depth,
35
- ...localAPIDefaults(authorizedMCP)
34
+ overrideAccess: authorizedMCP.overrideAccess,
35
+ req
36
36
  };
37
37
  if (locale) {
38
38
  findOptions.locale = locale;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'\n\nexport const findGlobalTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Global',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\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 }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { depth, fallbackLocale, locale, populate, select } = input\n\n logger.info(\n `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n ...localAPIDefaults(authorizedMCP),\n }\n\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (select) {\n findOptions.select = select as SelectType\n }\n if (populate) {\n findOptions.populate = populate as PopulateType\n }\n\n const result = await payload.findGlobal(findOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\":\\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 reading global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n { type: 'text', text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}` },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findGlobalTool","access","args","Boolean","permissions","globals","globalSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","locale","populate","record","unknown","select","handler","authorizedMCP","req","payload","logger","info","findOptions","slug","result","findGlobal","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,iBAAiBJ,iBAAiB;IAC7CK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,SAAS,CAACH,KAAKI,UAAU,CAAC,EAAEC;IAC/EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,OAAOvB,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,yCACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgB/B,EACbgC,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,QAAQjC,EACLgC,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXK,UAAUlC,EACPmC,MAAM,CAACnC,EAAEgC,MAAM,IAAIhC,EAAEoC,OAAO,IAC5BR,QAAQ,CACP,8FAEDC,QAAQ;QACXQ,QAAQrC,EACLmC,MAAM,CAACnC,EAAEgC,MAAM,IAAIhC,EAAEoC,OAAO,IAC5BR,QAAQ,CACP,sGAEDC,QAAQ;IACb;AACF,GAAGS,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAE3B,UAAU,EAAES,KAAK,EAAEmB,GAAG,EAAE;IACzD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAASvC,UAAU;QAAEsC;IAAQ;IAEnC,MAAM,EAAElB,KAAK,EAAEQ,cAAc,EAAEE,MAAM,EAAEC,QAAQ,EAAEG,MAAM,EAAE,GAAGhB;IAE5DqB,OAAOC,IAAI,CACT,CAAC,gBAAgB,EAAE/B,WAAW,SAAS,EAAEW,QAAQU,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;IAGxF,IAAI;QACF,MAAMW,cAAwD;YAC5DC,MAAMjC;YACNW;YACA,GAAGnB,iBAAiBmC,cAAc;QACpC;QAEA,IAAIN,QAAQ;YACVW,YAAYX,MAAM,GAAGA;QACvB;QACA,IAAIF,gBAAgB;YAClBa,YAAYb,cAAc,GAAGA;QAC/B;QACA,IAAIM,QAAQ;YACVO,YAAYP,MAAM,GAAGA;QACvB;QACA,IAAIH,UAAU;YACZU,YAAYV,QAAQ,GAAGA;QACzB;QAEA,MAAMY,SAAS,MAAML,QAAQM,UAAU,CAACH;QAExC,OAAO;YACLI,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAEtC,WAAW,gBAAgB,EAAEuC,KAAKC,SAAS,CAACN,QAAQ,QAAQ,CAAC;gBAChF;aACD;YACDO,KAAKP;QACP;IACF,EAAE,OAAOQ,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,qBAAqB,EAAE1C,WAAW,EAAE,EAAE2C,cAAc;QAClE,OAAO;YACLP,SAAS;gBACP;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,0BAA0B,EAAEtC,WAAW,KAAK,EAAE2C,cAAc;gBAAC;aACrF;QACH;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'\n\nexport const findGlobalTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Global',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\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 }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { depth, fallbackLocale, locale, populate, select } = input\n\n logger.info(\n `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n }\n\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (select) {\n findOptions.select = select as SelectType\n }\n if (populate) {\n findOptions.populate = populate as PopulateType\n }\n\n const result = await payload.findGlobal(findOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\":\\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 reading global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n { type: 'text', text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}` },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","DEFAULT_DESCRIPTION","findGlobalTool","access","args","Boolean","permissions","globals","globalSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","locale","populate","record","unknown","select","handler","authorizedMCP","req","payload","logger","info","findOptions","slug","overrideAccess","result","findGlobal","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,iBAAiBH,iBAAiB;IAC7CI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,SAAS,CAACH,KAAKI,UAAU,CAAC,EAAEC;IAC/EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB,EAAEqB,MAAM,CAAC;QACdC,OAAOtB,EACJuB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,yCACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgB9B,EACb+B,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,QAAQhC,EACL+B,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXK,UAAUjC,EACPkC,MAAM,CAAClC,EAAE+B,MAAM,IAAI/B,EAAEmC,OAAO,IAC5BR,QAAQ,CACP,8FAEDC,QAAQ;QACXQ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C,MAAM,CAAC,0BAA0B,EAAEvC,WAAW,KAAK,EAAE4C,cAAc;gBAAC;aACrF;QACH;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findVersionByIDTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,yBAAyB,wCA2FpC,CAAA"}
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findVersionByIDTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,yBAAyB,wCA2FpC,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineGlobalTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find a specific global version in any version-enabled global by passing the global slug and version ID.';
7
6
  export const findGlobalVersionByIDTool = defineGlobalTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
@@ -35,8 +34,8 @@ export const findGlobalVersionByIDTool = defineGlobalTool({
35
34
  id,
36
35
  slug: globalSlug,
37
36
  depth,
37
+ overrideAccess: authorizedMCP.overrideAccess,
38
38
  req,
39
- ...localAPIDefaults(authorizedMCP),
40
39
  ...fallbackLocale ? {
41
40
  fallbackLocale
42
41
  } : {},