@payloadcms/plugin-mcp 4.0.0-internal.e55ccef → 4.0.0-internal.ea6e8f8

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 (176) hide show
  1. package/bin.js +0 -7
  2. package/dist/endpoint/access.js +2 -2
  3. package/dist/endpoint/access.js.map +1 -1
  4. package/dist/endpoint/index.d.ts.map +1 -1
  5. package/dist/endpoint/index.js +33 -4
  6. package/dist/endpoint/index.js.map +1 -1
  7. package/dist/mcp/buildMcpServer.d.ts +2 -2
  8. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  9. package/dist/mcp/buildMcpServer.js +36 -24
  10. package/dist/mcp/buildMcpServer.js.map +1 -1
  11. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  12. package/dist/mcp/builtin/collections/authTools.js +80 -56
  13. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  14. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  15. package/dist/mcp/builtin/collections/countTool.js +9 -14
  16. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  17. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  18. package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
  19. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  20. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  21. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  22. package/dist/mcp/builtin/collections/createTool.js +104 -63
  23. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  24. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  25. package/dist/mcp/builtin/collections/deleteTool.js +44 -43
  26. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  27. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  28. package/dist/mcp/builtin/collections/duplicateTool.js +31 -37
  29. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  30. package/dist/mcp/builtin/collections/fileInput.d.ts +21 -13
  31. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
  32. package/dist/mcp/builtin/collections/fileInput.js +52 -64
  33. package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
  34. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  35. package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
  36. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  37. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  38. package/dist/mcp/builtin/collections/findTool.js +27 -45
  39. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  40. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  41. package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
  42. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  43. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  44. package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
  45. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  46. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  47. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +33 -16
  48. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  49. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  51. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  53. package/dist/mcp/builtin/collections/updateTool.js +58 -90
  54. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  55. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  58. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  59. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  60. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  61. package/dist/mcp/builtin/formatEntityError.js +55 -0
  62. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  63. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  64. package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
  65. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  66. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  67. package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
  68. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  69. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  70. package/dist/mcp/builtin/globals/findTool.js +10 -16
  71. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  72. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  73. package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
  74. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  75. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  76. package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
  77. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  78. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  79. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +29 -13
  80. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  81. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  82. package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
  83. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  84. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  85. package/dist/mcp/builtin/globals/updateTool.js +27 -36
  86. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  87. package/dist/mcp/builtinTools.d.ts +6 -0
  88. package/dist/mcp/builtinTools.d.ts.map +1 -1
  89. package/dist/mcp/builtinTools.js +9 -3
  90. package/dist/mcp/builtinTools.js.map +1 -1
  91. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  92. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  93. package/dist/stdio.d.ts.map +1 -1
  94. package/dist/stdio.js +6 -4
  95. package/dist/stdio.js.map +1 -1
  96. package/dist/types.d.ts +14 -7
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/types.js.map +1 -1
  99. package/package.json +6 -8
  100. package/src/endpoint/access.ts +2 -3
  101. package/src/endpoint/index.ts +33 -3
  102. package/src/mcp/buildMcpServer.ts +40 -30
  103. package/src/mcp/builtin/collections/authTools.ts +80 -69
  104. package/src/mcp/builtin/collections/countTool.ts +9 -21
  105. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  106. package/src/mcp/builtin/collections/createTool.ts +110 -86
  107. package/src/mcp/builtin/collections/deleteTool.ts +36 -64
  108. package/src/mcp/builtin/collections/duplicateTool.ts +35 -85
  109. package/src/mcp/builtin/collections/fileInput.spec.ts +20 -6
  110. package/src/mcp/builtin/collections/fileInput.ts +64 -76
  111. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  112. package/src/mcp/builtin/collections/findTool.ts +23 -105
  113. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  114. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  115. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +28 -13
  116. package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
  117. package/src/mcp/builtin/collections/updateTool.ts +57 -111
  118. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  119. package/src/mcp/builtin/formatEntityError.ts +77 -0
  120. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  121. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  122. package/src/mcp/builtin/globals/findTool.ts +12 -51
  123. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  124. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  125. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +21 -11
  126. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  127. package/src/mcp/builtin/globals/updateTool.ts +37 -60
  128. package/src/mcp/builtinTools.ts +9 -2
  129. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  130. package/src/stdio.ts +4 -3
  131. package/src/types.ts +15 -7
  132. package/dist/mcp/builtin/collections/fileInput.spec.js +0 -72
  133. package/dist/mcp/builtin/collections/fileInput.spec.js.map +0 -1
  134. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  135. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  136. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  137. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  138. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  139. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  140. package/dist/mcp/builtin/validateEntityData.js +0 -82
  141. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  142. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  143. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  144. package/dist/utils/getVirtualFieldNames.js +0 -35
  145. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  146. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  147. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  148. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  149. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  150. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  151. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  152. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  153. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  154. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  155. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  156. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  157. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  158. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  159. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  160. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  161. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  162. package/dist/utils/transformPointDataToPayload.js +0 -28
  163. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  164. package/dist/utils/whereSchema.d.ts +0 -9
  165. package/dist/utils/whereSchema.d.ts.map +0 -1
  166. package/dist/utils/whereSchema.js +0 -13
  167. package/dist/utils/whereSchema.js.map +0 -1
  168. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  169. package/src/mcp/builtin/validateEntityData.ts +0 -132
  170. package/src/utils/getVirtualFieldNames.ts +0 -53
  171. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  172. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  173. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  174. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  175. package/src/utils/transformPointDataToPayload.ts +0 -40
  176. package/src/utils/whereSchema.ts +0 -24
@@ -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'\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,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB,EAAEqB,MAAM,CAAC;QACdC,IAAItB,EAAEuB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAOzB,EACJ0B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,8DACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAOhC,EACJiC,OAAO,GACPT,Q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Y;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
+ {"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,EAAEV,I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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,4CA6M7B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CAuJ7B,CAAA"}
@@ -1,17 +1,12 @@
1
- import { z } from 'zod';
1
+ import { getCollectionInputSchema, getCollectionVirtualFieldNames, parseDocumentID, 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 { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
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';
10
- import { fileInputSchema, resolveFileInput } from './fileInput.js';
11
- import { formatCollectionError } from './formatCollectionError.js';
12
- const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
5
+ import { formatEntityError } from '../formatEntityError.js';
6
+ import { fileInputSchema, resolveFile } from './fileInput.js';
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.collectionSlug]?.update),
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,108 @@ export const updateDocumentTool = defineCollectionTool({
20
15
  title: 'Update Document'
21
16
  },
22
17
  description: DEFAULT_DESCRIPTION,
23
- input: z.object({
24
- id: z.union([
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 ({ authorizedMCP, collectionSlug, input, req })=>{
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, overwriteExistingFiles, publishAllLocales, select, where } = input;
46
- logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
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
- if (!id && !where) {
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
- const validationError = validateCollectionData({
61
- collectionSlug,
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
- const file = await resolveFileInput({
71
- collectionSlug,
38
+ const file = await resolveFile({
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
- id,
79
- collection: collectionSlug,
46
+ id: parseDocumentID({
47
+ id,
48
+ collectionSlug: slug,
49
+ payload
50
+ }),
51
+ collection: slug,
80
52
  data: parsedData,
81
53
  depth,
82
54
  draft,
55
+ fallbackLocale,
56
+ locale,
83
57
  overrideAccess: authorizedMCP.overrideAccess,
84
58
  overrideLock,
59
+ populate,
60
+ publishAllLocales,
85
61
  req,
62
+ select: returning ? select : {
63
+ id: true
64
+ },
65
+ trash,
66
+ unpublishAllLocales,
86
67
  ...file ? {
87
68
  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
69
  } : {}
104
70
  });
71
+ const responseResult = returning ? result : {
72
+ id: result.id
73
+ };
105
74
  return {
106
75
  content: [
107
76
  {
108
77
  type: 'text',
109
- text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
78
+ text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``
110
79
  }
111
80
  ],
112
- doc: result
81
+ doc: responseResult
113
82
  };
114
83
  }
115
84
  const result = await payload.update({
116
- collection: collectionSlug,
85
+ collection: slug,
117
86
  data: parsedData,
118
87
  depth,
119
88
  draft,
89
+ fallbackLocale,
90
+ limit,
91
+ locale,
120
92
  overrideAccess: authorizedMCP.overrideAccess,
121
93
  overrideLock,
94
+ populate,
95
+ publishAllLocales,
122
96
  req,
97
+ select: returning ? select : {
98
+ id: true
99
+ },
100
+ sort,
101
+ trash,
102
+ unpublishAllLocales,
123
103
  where: whereClause,
124
104
  ...file ? {
125
105
  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
106
  } : {}
142
107
  });
143
- const docs = result.docs || [];
108
+ const docs = returning ? result.docs : result.docs.map(({ id })=>({
109
+ id
110
+ }));
144
111
  const errors = result.errors || [];
145
- let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
112
+ let responseText = `Multiple documents updated in collection "${slug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
146
113
  if (docs.length > 0) {
147
114
  responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
148
115
  }
149
116
  if (errors.length > 0) {
150
117
  responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
151
118
  const errorSchema = getCollectionInputSchema({
152
- collectionSlug,
119
+ collectionSlug: slug,
153
120
  req
154
121
  });
155
122
  if (errorSchema) {
@@ -169,7 +136,7 @@ export const updateDocumentTool = defineCollectionTool({
169
136
  isError: true,
170
137
  ...errorSchema ? {
171
138
  structuredContent: {
172
- collectionSlug,
139
+ slug,
173
140
  docs,
174
141
  errors,
175
142
  schema: errorSchema
@@ -191,10 +158,11 @@ export const updateDocumentTool = defineCollectionTool({
191
158
  };
192
159
  } catch (error) {
193
160
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
194
- logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`);
195
- return formatCollectionError({
161
+ logger.error(`Error updating document in ${slug}: ${errorMessage}`);
162
+ return formatEntityError({
163
+ slug,
196
164
  action: 'updating',
197
- collectionSlug,
165
+ entity: 'collection',
198
166
  error,
199
167
  req
200
168
  });
@@ -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, resolveFileInput } from './fileInput.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\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 resolveFileInput({ 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","resolveFileInput","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;AAEv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AC9D/B,OAAO4B,KAAK,CAAC,CAAC,2BAA2B,EAAEhE,eAAe,EAAE,EAAEiE,cAAc;QAC5E,OAAOzE,sBAAsB;YAAE4E,QAAQ;YAAYpE;YAAgBgE;YAAO9B;QAAI;IAChF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nimport {\n getCollectionInputSchema,\n getCollectionVirtualFieldNames,\n parseDocumentID,\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: parseDocumentID({ id, collectionSlug: slug, payload }),\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","parseDocumentID","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","collectionSlug","collection","overrideAccess","responseResult","content","type","text","JSON","stringify","doc","docs","map","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action","entity"],"mappings":"AAEA,SACEA,wBAAwB,EACxBC,8BAA8B,EAC9BC,eAAe,EACfC,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,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G;YACnBD,gBAAgB,CAAC,oCAAoC,EAAEN,KAAKC,SAAS,CAACE,MAAM,QAAQ,CAAC;QACvF;QACA,IAAIE,OAAOE,MAAM,GAAG,GAAG;YACrBD,gBAAgB,CAAC,yBAAyB,EAAEN,KAAKC,SAAS,CAACI,QAAQ,QAAQ,CAAC;YAE5E,MAAMG,cAAc7E,yBAAyB;gBAAE8D,gBAAgB1C;gBAAMa;YAAI;YAEzE,IAAI4C,aAAa;gBACfF,gBAAgB,CAAC,2CAA2C,EAAEN,KAAKC,SAAS,CAACO,aAAa,QAAQ,CAAC;YACrG;YAEA,OAAO;gBACLX,SAAS;oBAAC;wBAAEC,MAAM;wBAAQC,MAAMO;oBAAa;iBAAE;gBAC/CJ,KAAK;oBAAEC;oBAAME;gBAAO;gBACpBI,SAAS;gBACT,GAAID,cACA;oBACEE,mBAAmB;wBACjB3D;wBACAoD;wBACAE;wBACAM,QAAQH;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,OAAOO,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"}
@@ -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 { strictObject, z } from 'payload';
2
+ import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal';
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.slug]?.create || args.permissions?.collections?.[args.slug]?.update),
7
+ annotations: {
8
+ destructiveHint: false,
9
+ idempotentHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ title: 'Get Upload Instructions'
13
+ },
14
+ description: 'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
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
+ })
21
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
22
+ try {
23
+ const instructions = await getPayloadUploadInstructions({
24
+ ...input,
25
+ collectionSlug: slug,
26
+ overrideAccess: authorizedMCP.overrideAccess,
27
+ req
28
+ });
29
+ const nextStep = instructions.type === 'http' ? 'Upload bytes with instructions.request. After success, pass { source: "uploadReference", file: instructions.file }.' : `Call "${instructions.name}" with file and data. After success, pass { source: "uploadReference", file: instructions.file }.`;
30
+ return {
31
+ content: [
32
+ {
33
+ type: 'text',
34
+ text: `Upload instructions for collection "${slug}":\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 "${slug}": ${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 { 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,KAAK;YACRe,gBAAgBzB;YAChB0B,gBAAgBJ,cAAcI,cAAc;YAC5CH;QACF;QAEA,MAAMI,WACJH,aAAaI,IAAI,KAAK,SAClB,wHACA,CAAC,MAAM,EAAEJ,aAAaK,IAAI,CAAC,iGAAiG,CAAC;QAEnI,OAAO;YACLC,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,oCAAoC,EAAE/B,KAAK,gBAAgB,EAAEgC,KAAKC,SAAS,CAACT,cAAc,UAAU,EAAEG,UAAU;gBACzH;aACD;YACDO,mBAAmB;gBAAEV;YAAa;QACpC;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAG;QACzD,OAAO;YACLN,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,kDAAkD,EAAE/B,KAAK,GAAG,EAAEoC,SAAS;gBAChF;aACD;YACDE,SAAS;QACX;IACF;AACF,GAAE"}
@@ -0,0 +1,16 @@
1
+ import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload';
2
+ import type { MCPToolResponse } from '../../types.js';
3
+ export declare const formatEntityError: ({ slug, action, entity, error, req, }: {
4
+ action: 'creating' | 'duplicating' | 'updating';
5
+ entity: 'collection';
6
+ error: unknown;
7
+ req: PayloadRequest;
8
+ slug: CollectionSlug;
9
+ } | {
10
+ action: 'updating';
11
+ entity: 'global';
12
+ error: unknown;
13
+ req: PayloadRequest;
14
+ slug: GlobalSlug;
15
+ }) => MCPToolResponse;
16
+ //# sourceMappingURL=formatEntityError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatEntityError.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/formatEntityError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,eAAO,MAAM,iBAAiB,0CAO1B;IACE,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,cAAc,CAAA;CACrB,GACD;IACE,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,QAAQ,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;CACjB,KAAG,eAsCP,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { getCollectionInputSchema, getGlobalInputSchema, ValidationError } from 'payload';
2
+ export const formatEntityError = ({ slug, action, entity, error, req })=>{
3
+ const message = error instanceof Error ? error.message : 'Unknown error';
4
+ const target = entity === 'collection' ? `document in collection "${slug}"` : `global "${slug}"`;
5
+ if (!isValidationError(error, message)) {
6
+ return {
7
+ content: [
8
+ {
9
+ type: 'text',
10
+ text: `Error ${action} ${target}: ${message}`
11
+ }
12
+ ],
13
+ isError: true
14
+ };
15
+ }
16
+ const schema = entity === 'collection' ? getCollectionInputSchema({
17
+ collectionSlug: slug,
18
+ req
19
+ }) : getGlobalInputSchema({
20
+ globalSlug: slug,
21
+ req
22
+ });
23
+ const errors = error instanceof ValidationError ? error.data.errors : [
24
+ {
25
+ message
26
+ }
27
+ ];
28
+ const validationMessage = errors.map((issue)=>`${'path' in issue ? `${issue.path}: ` : ''}${issue.message}`).join('\n');
29
+ const schemaText = schema ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\`` : '';
30
+ return {
31
+ content: [
32
+ {
33
+ type: 'text',
34
+ text: `Error ${action} ${target}: ${validationMessage}${schemaText}`
35
+ }
36
+ ],
37
+ isError: true,
38
+ ...schema ? {
39
+ structuredContent: {
40
+ slug,
41
+ errors,
42
+ schema
43
+ }
44
+ } : {}
45
+ };
46
+ };
47
+ const isValidationError = (error, message)=>{
48
+ if (error instanceof ValidationError) {
49
+ return true;
50
+ }
51
+ const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined;
52
+ return name === 'CastError' || message.includes('Cast to ') || message.includes('validation failed');
53
+ };
54
+
55
+ //# sourceMappingURL=formatEntityError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/mcp/builtin/formatEntityError.ts"],"sourcesContent":["import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload'\n\nimport { getCollectionInputSchema, getGlobalInputSchema, ValidationError } from 'payload'\n\nimport type { MCPToolResponse } from '../../types.js'\n\nexport const formatEntityError = ({\n slug,\n action,\n entity,\n error,\n req,\n}:\n | {\n action: 'creating' | 'duplicating' | 'updating'\n entity: 'collection'\n error: unknown\n req: PayloadRequest\n slug: CollectionSlug\n }\n | {\n action: 'updating'\n entity: 'global'\n error: unknown\n req: PayloadRequest\n slug: GlobalSlug\n }): MCPToolResponse => {\n const message = error instanceof Error ? error.message : 'Unknown error'\n const target = entity === 'collection' ? `document in collection \"${slug}\"` : `global \"${slug}\"`\n\n if (!isValidationError(error, message)) {\n return {\n content: [{ type: 'text', text: `Error ${action} ${target}: ${message}` }],\n isError: true,\n }\n }\n\n const schema =\n entity === 'collection'\n ? getCollectionInputSchema({ collectionSlug: slug, req })\n : getGlobalInputSchema({ globalSlug: slug, req })\n const errors = error instanceof ValidationError ? error.data.errors : [{ message }]\n const validationMessage = errors\n .map((issue) => `${'path' in issue ? `${issue.path}: ` : ''}${issue.message}`)\n .join('\\n')\n const schemaText = schema\n ? `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``\n : ''\n\n return {\n content: [\n { type: 'text', text: `Error ${action} ${target}: ${validationMessage}${schemaText}` },\n ],\n isError: true,\n ...(schema\n ? {\n structuredContent: {\n slug,\n errors,\n schema,\n },\n }\n : {}),\n }\n}\n\nconst isValidationError = (error: unknown, message: string): boolean => {\n if (error instanceof ValidationError) {\n return true\n }\n\n const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined\n\n return (\n name === 'CastError' || message.includes('Cast to ') || message.includes('validation failed')\n )\n}\n"],"names":["getCollectionInputSchema","getGlobalInputSchema","ValidationError","formatEntityError","slug","action","entity","error","req","message","Error","target","isValidationError","content","type","text","isError","schema","collectionSlug","globalSlug","errors","data","validationMessage","map","issue","path","join","schemaText","JSON","stringify","structuredContent","name","undefined","includes"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,oBAAoB,EAAEC,eAAe,QAAQ,UAAS;AAIzF,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,GAAG,EAeA;IACH,MAAMC,UAAUF,iBAAiBG,QAAQH,MAAME,OAAO,GAAG;IACzD,MAAME,SAASL,WAAW,eAAe,CAAC,wBAAwB,EAAEF,KAAK,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAEA,KAAK,CAAC,CAAC;IAEhG,IAAI,CAACQ,kBAAkBL,OAAOE,UAAU;QACtC,OAAO;YACLI,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,MAAM,EAAEV,OAAO,CAAC,EAAEM,OAAO,EAAE,EAAEF,SAAS;gBAAC;aAAE;YAC1EO,SAAS;QACX;IACF;IAEA,MAAMC,SACJX,WAAW,eACPN,yBAAyB;QAAEkB,gBAAgBd;QAAMI;IAAI,KACrDP,qBAAqB;QAAEkB,YAAYf;QAAMI;IAAI;IACnD,MAAMY,SAASb,iBAAiBL,kBAAkBK,MAAMc,IAAI,CAACD,MAAM,GAAG;QAAC;YAAEX;QAAQ;KAAE;IACnF,MAAMa,oBAAoBF,OACvBG,GAAG,CAAC,CAACC,QAAU,GAAG,UAAUA,QAAQ,GAAGA,MAAMC,IAAI,CAAC,EAAE,CAAC,GAAG,KAAKD,MAAMf,OAAO,EAAE,EAC5EiB,IAAI,CAAC;IACR,MAAMC,aAAaV,SACf,CAAC,2CAA2C,EAAEW,KAAKC,SAAS,CAACZ,QAAQ,QAAQ,CAAC,GAC9E;IAEJ,OAAO;QACLJ,SAAS;YACP;gBAAEC,MAAM;gBAAQC,MAAM,CAAC,MAAM,EAAEV,OAAO,CAAC,EAAEM,OAAO,EAAE,EAAEW,oBAAoBK,YAAY;YAAC;SACtF;QACDX,SAAS;QACT,GAAIC,SACA;YACEa,mBAAmB;gBACjB1B;gBACAgB;gBACAH;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF,EAAC;AAED,MAAML,oBAAoB,CAACL,OAAgBE;IACzC,IAAIF,iBAAiBL,iBAAiB;QACpC,OAAO;IACT;IAEA,MAAM6B,OAAOxB,SAAS,OAAOA,UAAU,YAAY,UAAUA,QAAQA,MAAMwB,IAAI,GAAGC;IAElF,OACED,SAAS,eAAetB,QAAQwB,QAAQ,CAAC,eAAexB,QAAQwB,QAAQ,CAAC;AAE7E"}
@@ -1 +1 @@
1
- {"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BA8D5B,CAAA"}
1
+ {"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BA+D5B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { getAccessResults, isEntityHidden } from 'payload';
1
+ import { getAccessResults, getConfigInfoInputSchema, isEntityHidden } from 'payload';
2
2
  import { defineTool } from '../../defineTool.js';
3
3
  export const getConfigInfoTool = defineTool({
4
4
  annotations: {
@@ -8,7 +8,8 @@ export const getConfigInfoTool = defineTool({
8
8
  readOnlyHint: true,
9
9
  title: 'Config Info'
10
10
  },
11
- description: 'List the Payload collection and global slugs visible to this MCP client.'
11
+ description: 'List the Payload collection and global slugs visible to this MCP client.',
12
+ input: getConfigInfoInputSchema
12
13
  }).handler(async ({ authorizedMCP, req })=>{
13
14
  const user = req.user;
14
15
  const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({
@@ -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 = 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,MAAMC,OAAOD,IAAIC,IAAI;IACrB,MAAMC,cAAcH,cAAcI,cAAc,GAAG,OAAO,MAAMhB,iBAAiB;QAAEa;IAAI;IACvF,MAAMI,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, getConfigInfoInputSchema, 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 input: getConfigInfoInputSchema,\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","getConfigInfoInputSchema","isEntityHidden","defineTool","getConfigInfoTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","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,wBAAwB,EAAEC,cAAc,QAAQ,UAAS;AAEpF,SAASC,UAAU,QAAQ,sBAAqB;AAEhD,OAAO,MAAMC,oBAAoBD,WAAW;IAC1CE,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;IACbC,OAAOX;AACT,GAAGY,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,GAAG,EAAE;IACtC,MAAMC,OAAOD,IAAIC,IAAI;IACrB,MAAMC,cAAcH,cAAcI,cAAc,GAAG,OAAO,MAAMlB,iBAAiB;QAAEe;IAAI;IACvF,MAAMI,4BA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AQa,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":"AAUA,eAAO,MAAM,uBAAuB,wCAyDlC,CAAA"}
1
+ {"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,uBAAuB,wCAkDlC,CAAA"}
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { countGlobalVersionsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineGlobalTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { whereSchema } from '../../../utils/whereSchema.js';
6
5
  const DEFAULT_DESCRIPTION = 'Count global versions in any version-enabled global by passing the global slug and optional where clause.';
7
6
  export const countGlobalVersionsTool = defineGlobalTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.readVersions),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,20 +13,17 @@ export const countGlobalVersionsTool = defineGlobalTool({
14
13
  title: 'Count Global Versions'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- locale: z.string().describe('Optional: locale code to count versions in').optional(),
19
- where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}').optional()
20
- })
21
- }).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
16
+ input: countGlobalVersionsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
22
18
  const payload = req.payload;
23
19
  const logger = getLogger({
24
20
  payload
25
21
  });
26
22
  const { locale, where } = input;
27
- logger.info(`Counting versions for global: ${globalSlug}`);
23
+ logger.info(`Counting versions for global: ${slug}`);
28
24
  try {
29
25
  const result = await payload.countGlobalVersions({
30
- global: globalSlug,
26
+ global: slug,
31
27
  overrideAccess: authorizedMCP.overrideAccess,
32
28
  req,
33
29
  ...locale ? {
@@ -41,19 +37,19 @@ export const countGlobalVersionsTool = defineGlobalTool({
41
37
  content: [
42
38
  {
43
39
  type: 'text',
44
- text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
40
+ text: `Global "${slug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
45
41
  }
46
42
  ],
47
43
  doc: result
48
44
  };
49
45
  } catch (error) {
50
46
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
51
- logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`);
47
+ logger.error(`Error counting versions for global ${slug}: ${errorMessage}`);
52
48
  return {
53
49
  content: [
54
50
  {
55
51
  type: 'text',
56
- text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`
52
+ text: `❌ **Error counting versions for global "${slug}":** ${errorMessage}`
57
53
  }
58
54
  ],
59
55
  isError: true