@payloadcms/plugin-mcp 4.0.0-internal.2fddfc0 → 4.0.0-internal.3aa3d85

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 (150) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/endpoint/access.d.ts +2 -7
  3. package/dist/endpoint/access.d.ts.map +1 -1
  4. package/dist/endpoint/access.js +4 -11
  5. package/dist/endpoint/access.js.map +1 -1
  6. package/dist/endpoint/index.d.ts +1 -1
  7. package/dist/endpoint/index.d.ts.map +1 -1
  8. package/dist/endpoint/index.js +57 -17
  9. package/dist/endpoint/index.js.map +1 -1
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/mcp/buildMcpServer.d.ts +4 -4
  15. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  16. package/dist/mcp/buildMcpServer.js +32 -10
  17. package/dist/mcp/buildMcpServer.js.map +1 -1
  18. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  19. package/dist/mcp/builtin/collections/countTool.js +1 -2
  20. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  21. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  22. package/dist/mcp/builtin/collections/countVersionsTool.js +1 -2
  23. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  24. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  25. package/dist/mcp/builtin/collections/createTool.js +1 -2
  26. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  27. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  28. package/dist/mcp/builtin/collections/deleteTool.js +1 -2
  29. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  30. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  31. package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
  32. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  33. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  34. package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
  35. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  36. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  37. package/dist/mcp/builtin/collections/findTool.js +2 -3
  38. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  39. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  40. package/dist/mcp/builtin/collections/findVersionByIDTool.js +1 -2
  41. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  42. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  43. package/dist/mcp/builtin/collections/findVersionsTool.js +1 -2
  44. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  45. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  46. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +21 -3
  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 +2 -3
  53. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  54. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  55. package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
  56. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  57. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  58. package/dist/mcp/builtin/globals/countVersionsTool.js +1 -2
  59. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  60. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  61. package/dist/mcp/builtin/globals/findTool.js +2 -2
  62. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  63. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  64. package/dist/mcp/builtin/globals/findVersionByIDTool.js +1 -2
  65. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  66. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  67. package/dist/mcp/builtin/globals/findVersionsTool.js +1 -2
  68. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  69. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  70. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +21 -3
  71. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  72. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  73. package/dist/mcp/builtin/globals/restoreVersionTool.js +1 -2
  74. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  75. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  76. package/dist/mcp/builtin/globals/updateTool.js +2 -2
  77. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  78. package/dist/mcp/builtin/validateEntityData.js +1 -1
  79. package/dist/mcp/builtin/validateEntityData.js.map +1 -1
  80. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  81. package/dist/mcp/sanitizeMCPConfig.js +1 -0
  82. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  83. package/dist/stdio.d.ts +3 -4
  84. package/dist/stdio.d.ts.map +1 -1
  85. package/dist/stdio.js +59 -41
  86. package/dist/stdio.js.map +1 -1
  87. package/dist/types.d.ts +57 -9
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js +2 -4
  90. package/dist/types.js.map +1 -1
  91. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  92. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  93. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  94. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  95. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
  96. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  97. package/dist/utils/schemaConversion/getEntityInputSchema.js +44 -12
  98. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
  99. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  100. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  101. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  102. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  103. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  104. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  105. package/package.json +8 -10
  106. package/src/endpoint/access.ts +3 -10
  107. package/src/endpoint/index.ts +45 -16
  108. package/src/index.ts +4 -4
  109. package/src/mcp/buildMcpServer.ts +40 -20
  110. package/src/mcp/builtin/collections/countTool.ts +1 -2
  111. package/src/mcp/builtin/collections/countVersionsTool.ts +1 -2
  112. package/src/mcp/builtin/collections/createTool.ts +1 -2
  113. package/src/mcp/builtin/collections/deleteTool.ts +1 -2
  114. package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
  115. package/src/mcp/builtin/collections/findDistinctTool.ts +1 -2
  116. package/src/mcp/builtin/collections/findTool.ts +2 -3
  117. package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
  118. package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
  119. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +25 -8
  120. package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
  121. package/src/mcp/builtin/collections/updateTool.ts +2 -3
  122. package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
  123. package/src/mcp/builtin/globals/countVersionsTool.ts +1 -2
  124. package/src/mcp/builtin/globals/findTool.ts +2 -2
  125. package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
  126. package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
  127. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
  128. package/src/mcp/builtin/globals/restoreVersionTool.ts +1 -2
  129. package/src/mcp/builtin/globals/updateTool.ts +2 -2
  130. package/src/mcp/builtin/validateEntityData.ts +1 -1
  131. package/src/mcp/sanitizeMCPConfig.ts +1 -0
  132. package/src/stdio.ts +59 -42
  133. package/src/types.ts +57 -9
  134. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  135. package/src/utils/schemaConversion/getEntityInputSchema.ts +45 -27
  136. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  137. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  138. package/dist/@types/assets.d.js +0 -2
  139. package/dist/@types/assets.d.js.map +0 -1
  140. package/dist/utils/localAPIDefaults.d.ts +0 -20
  141. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  142. package/dist/utils/localAPIDefaults.js +0 -19
  143. package/dist/utils/localAPIDefaults.js.map +0 -1
  144. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  145. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  146. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  147. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  148. package/src/@types/assets.d.ts +0 -3
  149. package/src/utils/localAPIDefaults.ts +0 -22
  150. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -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,EAAE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AIC,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,qBAAqBU,YAAY;gBAAEV;YAAiB,IAAI,CAAC,CAAC;QAChE;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAE/B,GAAG,uCAAuC,EAAEX,eAAe,oCAAoC,EAAE2C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBACrJ;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,wBAAwB,EAAEnC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAE+C,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAE/B,GAAG,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,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,QAAQ,CAAC,6CACTM,QAAQ,GACRC,OAAO,CAAC;QACXG,gBAAgBlC,EACbuB,MAAM,GACNC,QAAQ,CAAC,gFACTM,QAAQ;QACXK,QAAQnC,EACLuB,MAAM,GACNC,QAAQ,CAAC,0DACTM,QAAQ;QACXM,UAAUpC,EACPqC,MAAM,CAACrC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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":"AAoBA,eAAO,MAAM,kBAAkB,4CA6L7B,CAAA"}
@@ -3,7 +3,6 @@ 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';
@@ -74,9 +73,9 @@ export const updateDocumentTool = defineCollectionTool({
74
73
  data: parsedData,
75
74
  depth,
76
75
  draft,
76
+ overrideAccess: authorizedMCP.overrideAccess,
77
77
  overrideLock,
78
78
  req,
79
- ...localAPIDefaults(authorizedMCP),
80
79
  ...filePath ? {
81
80
  filePath
82
81
  } : {},
@@ -108,10 +107,10 @@ export const updateDocumentTool = defineCollectionTool({
108
107
  data: parsedData,
109
108
  depth,
110
109
  draft,
110
+ overrideAccess: authorizedMCP.overrideAccess,
111
111
  overrideLock,
112
112
  req,
113
113
  where: whereClause,
114
- ...localAPIDefaults(authorizedMCP),
115
114
  ...filePath ? {
116
115
  filePath
117
116
  } : {},
@@ -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,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAO5B,EAAE6B,MAAM,CAAC;QACdC,IAAI9B,EAAE+B,KAAK,CAAC;YAAC/B,EAAEgC,MAAM;YAAIhC,EAAEiC,MAAM;SAAG,E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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 { 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 overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\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 overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n where: whereClause,\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","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","overrideAccess","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBV,qBAAqB;IACrDW,QAAQ,CAACC,OACPb,cAAca,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,OAAO3B,EAAE4B,MAAM,CAAC;QACdC,IAAI7B,EAAE8B,KAAK,CAAC;YA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QAAQH;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLpB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMgB;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D7B,OAAO0B,KAAK,CAAC,CAAC,2BAA2B,EAAE7D,eAAe,EAAE,EAAE8D,cAAc;QAC5E,OAAOtE,sBAAsB;YAAEyE,QAAQ;YAAYjE;YAAgB6D;YAAO5B;QAAI;IAChF;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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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,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 +1 @@
1
- {"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,uBAAuB,wCAyDlC,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.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 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,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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;IACb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AAU,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;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;YAC5DC,MAAMjC;YACNW;YACAuB,gBAAgBP,cAAcO,cAAc;YAC5CN;QACF;QAEA,IAAIP,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,MAAMa,SAAS,MAAMN,QAAQO,UAAU,CAACJ;QAExC,OAAO;YACLK,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAEvC,WAAW,gBAAgB,EAAEwC,KAAKC,SAAS,CAACN,QAAQ,QAAQ,CAAC;gBAChF;aACD;YACDO,KAAKP;QACP;IACF,EAAE,OAAOQ,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,qBAAqB,EAAE3C,WAAW,EAAE,EAAE4C,cAAc;QAClE,OAAO;YACLP,SAAS;gBACP;oBAAEC,MAAM;oBAAQC,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
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/findVersionByIDTool.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 =\n 'Find a specific global version in any version-enabled global by passing the global slug and version ID.'\n\nexport const findGlobalVersionByIDTool = 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: 'Find Global Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the global version to retrieve'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in the global version document')\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., {\"version.siteName\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned global version document')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Finding version for global: ${globalSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findGlobalVersionByID({\n id,\n slug: globalSlug,\n depth,\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}\" from global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding version ${id} for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findGlobalVersionByIDTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","boolean","handler","authorizedMCP","req","payload","logger","info","result","findGlobalVersionByID","slug","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,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,4BAA4BJ,iBAAiB;IACxDK,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,IAAIvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAO1B,EACJ2B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,iFACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgBjC,EACbwB,MAAM,GACNC,QAAQ,CAAC,gFACTM,QAAQ;QACXG,QAAQlC,EACLwB,MAAM,GACNC,QAAQ,CACP,wHAEDM,QAAQ;QACXI,UAAUnC,EACPoC,MAAM,CAACpC,EAAEwB,MAAM,IAAIxB,EAAEqC,OAAO,IAC5BZ,QAAQ,CACP,8FAEDM,QAAQ;QACXO,QAAQtC,EACLoC,MAAM,CAACpC,EAAEwB,MAAM,IAAIxB,EAAEqC,OAAO,IAC5BZ,QAAQ,CACP,iHAEDM,QAAQ;QACXQ,kBAAkBvC,EACfwC,OAAO,GACPf,QAAQ,CAAC,2EACTM,QAAQ;IACb;AACF,GAAGU,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAE9B,UAAU,EAAES,KAAK,EAAEsB,GAAG,EAAE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AAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/findVersionByIDTool.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 =\n 'Find a specific global version in any version-enabled global by passing the global slug and version ID.'\n\nexport const findGlobalVersionByIDTool = 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: 'Find Global Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the global version to retrieve'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in the global version document')\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., {\"version.siteName\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned global version document')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Finding version for global: ${globalSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findGlobalVersionByID({\n id,\n slug: globalSlug,\n depth,\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}\" from global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding version ${id} for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","DEFAULT_DESCRIPTION","findGlobalVersionByIDTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","boolean","handler","authorizedMCP","req","payload","logger","info","result","findGlobalVersionByID","slug","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,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,4BAA4BH,iBAAiB;IACxDI,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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CAAC;YAC5B,GAAIC,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,SAAS;gBAAEA,QAAQA;YAAqB,IAAI,CAAC,CAAC;YAClD,GAAIC,qBAAqBY,YAAY;gBAAEZ;YAAiB,IAAI,CAAC,CAAC;QAChE;QAEA,OAAO;YACLa,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAE/B,GAAG,eAAe,EAAEX,WAAW,gBAAgB,EAAE2C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,sBAAsB,EAAEnC,GAAG,YAAY,EAAEX,WAAW,EAAE,EAAE+C,cAAc;QACpF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAE/B,GAAG,cAAc,EAAEX,WAAW,KAAK,EAAE+C,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findVersionsTool.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,sBAAsB,wCAsIjC,CAAA"}
1
+ {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findVersionsTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,sBAAsB,wCAsIjC,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 = 'Find global versions in any version-enabled global by passing the global slug and optional where clause.';
8
7
  export const findGlobalVersionsTool = defineGlobalTool({
@@ -40,9 +39,9 @@ export const findGlobalVersionsTool = defineGlobalTool({
40
39
  slug: globalSlug,
41
40
  depth,
42
41
  limit,
42
+ overrideAccess: authorizedMCP.overrideAccess,
43
43
  page,
44
44
  req,
45
- ...localAPIDefaults(authorizedMCP),
46
45
  ...fallbackLocale ? {
47
46
  fallbackLocale
48
47
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/findVersionsTool.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'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const findGlobalVersionsTool = 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: 'Find Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in global version documents')\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 limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of versions to return (default: 10, max: 100)')\n .optional()\n .default(10),\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 page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\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., {\"version.siteName\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned global version documents')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"-updatedAt\", \"-version.updatedAt\" for descending)')\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 {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n where,\n } = input\n\n logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findGlobalVersions({\n slug: globalSlug,\n depth,\n limit,\n page,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","findGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","limit","locale","page","pagination","boolean","populate","record","unknown","select","showHiddenFields","sort","where","handler","authorizedMCP","req","payload","logger","info","result","findGlobalVersions","slug","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,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,yBAAyBL,iBAAiB;IACrDM,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,OAAOxB,EACJyB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,8EACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgBhC,EACbiC,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,OAAOlC,EACJyB,MAAM,GACNC,GAAG,GACHC,GAAG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YACAE;YACAY;YACA,GAAG5C,iBAAiB2C,cAAc;YAClC,GAAIf,iBAAiB;gBAAEA;YAAe,IAAI,CAAC,CAAC;YAC5C,GAAIG,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIE,eAAekB,YAAY;gBAAElB;YAAW,IAAI,CAAC,CAAC;YAClD,GAAIE,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,SAAS;gBAAEA,QAAQA;YAAqB,IAAI,CAAC,CAAC;YAClD,GAAIC,qBAAqBY,YAAY;gBAAEZ;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,qBAAqB,EAAE7C,WAAW,gBAAgB,EAAE8C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBAC7F;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,kCAAkC,EAAEjD,WAAW,EAAE,EAAEkD,cAAc;QAC/E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,uCAAuC,EAAE7C,WAAW,KAAK,EAAEkD,cAAc;gBAClF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/findVersionsTool.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 { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const findGlobalVersionsTool = 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: 'Find Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in global version documents')\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 limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of versions to return (default: 10, max: 100)')\n .optional()\n .default(10),\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 page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\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., {\"version.siteName\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned global version documents')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"-updatedAt\", \"-version.updatedAt\" for descending)')\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 {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n where,\n } = input\n\n logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findGlobalVersions({\n slug: globalSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","limit","locale","page","pagination","boolean","populate","record","unknown","select","showHiddenFields","sort","where","handler","authorizedMCP","req","payload","logger","info","result","findGlobalVersions","slug","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,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AAC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AC7F;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,kCAAkC,EAAElD,WAAW,EAAE,EAAEmD,cAAc;QAC/E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,uCAAuC,EAAE9C,WAAW,KAAK,EAAEmD,cAAc;gBAClF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"getGlobalSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/getGlobalSchemaTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,wCAoC9B,CAAA"}
1
+ {"version":3,"file":"getGlobalSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/getGlobalSchemaTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,wCAwD9B,CAAA"}
@@ -1,10 +1,11 @@
1
+ import { getAccessResults } from 'payload';
1
2
  import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineGlobalTool } from '../../../defineTool.js';
3
4
  import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
4
5
  export const getGlobalSchemaTool = defineGlobalTool({
5
6
  access: (args)=>{
6
7
  const permissions = args.permissions?.globals?.[args.globalSlug];
7
- return defaultAccess(args) && Boolean(permissions?.read || permissions?.update);
8
+ return defaultAccess(args) && Boolean(permissions?.update);
8
9
  },
9
10
  annotations: {
10
11
  destructiveHint: false,
@@ -14,10 +15,27 @@ export const getGlobalSchemaTool = defineGlobalTool({
14
15
  title: 'Get Global Schema'
15
16
  },
16
17
  description: 'Get the input schema for updating a global.'
17
- }).handler(({ globalSlug, req })=>{
18
+ }).handler(async ({ authorizedMCP, globalSlug, req })=>{
19
+ const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
+ req
21
+ })).globals?.[globalSlug];
22
+ if (!authorizedMCP.overrideAccess && !permissions?.update) {
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${globalSlug}"`
28
+ }
29
+ ],
30
+ isError: true
31
+ };
32
+ }
18
33
  const inputSchema = getGlobalInputSchema({
19
34
  globalSlug,
20
- req
35
+ req,
36
+ ...permissions ? {
37
+ permissions
38
+ } : {}
21
39
  });
22
40
  if (!inputSchema) {
23
41
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/getGlobalSchemaTool.ts"],"sourcesContent":["import { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getGlobalSchemaTool = defineGlobalTool({\n access: (args) => {\n const permissions = args.permissions?.globals?.[args.globalSlug]\n\n return defaultAccess(args) && Boolean(permissions?.read || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Global Schema',\n },\n description: 'Get the input schema for updating a global.',\n}).handler(({ globalSlug, req }) => {\n const inputSchema = getGlobalInputSchema({ globalSlug, req })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Global \"${globalSlug}\" not found` }],\n isError: true,\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n globalSlug,\n schema: inputSchema,\n },\n }\n})\n"],"names":["defaultAccess","defineGlobalTool","getGlobalInputSchema","getGlobalSchemaTool","access","args","permissions","globals","globalSlug","Boolean","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,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,oBAAoB,QAAQ,0DAAyD;AAE9F,OAAO,MAAMC,sBAAsBF,iBAAiB;IAClDG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,SAAS,CAACF,KAAKG,UAAU,CAAC;QAEhE,OAAOR,cAAcK,SAASI,QAAQH,aAAaI,QAAQJ,aAAaK;IAC1E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,CAAC,EAAEX,UAAU,EAAEY,GAAG,EAAE;IAC7B,MAAMC,cAAcnB,qBAAqB;QAAEM;QAAYY;IAAI;IAE3D,IAAI,CAACC,aAAa;QAChB,OAAO;YACLC,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,eAAe,EAAEhB,WAAW,WAAW,CAAC;gBAAC;aAAE;YAC5EiB,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,mBAAmB,EAAEhB,WAAW,gBAAgB,EAAEkB,KAAKC,SAAS,CAACN,aAAa,QAAQ,CAAC;YAChG;SACD;QACDO,mBAAmB;YACjBpB;YACAqB,QAAQR;QACV;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/getGlobalSchemaTool.ts"],"sourcesContent":["import { getAccessResults } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getGlobalSchemaTool = defineGlobalTool({\n access: (args) => {\n const permissions = args.permissions?.globals?.[args.globalSlug]\n\n return defaultAccess(args) && Boolean(permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Global Schema',\n },\n description: 'Get the input schema for updating a global.',\n}).handler(async ({ authorizedMCP, globalSlug, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).globals?.[globalSlug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getGlobalSchema\" is not enabled for global \"${globalSlug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getGlobalInputSchema({\n globalSlug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Global \"${globalSlug}\" not found` }],\n isError: true,\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n globalSlug,\n schema: inputSchema,\n },\n }\n})\n"],"names":["getAccessResults","defaultAccess","defineGlobalTool","getGlobalInputSchema","getGlobalSchemaTool","access","args","permissions","globals","globalSlug","Boolean","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,UAAS;AAE1C,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,oBAAoB,QAAQ,0DAAyD;AAE9F,OAAO,MAAMC,sBAAsBF,iBAAiB;IAClDG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,SAAS,CAACF,KAAKG,UAAU,CAAC;QAEhE,OAAOR,cAAcK,SAASI,QAAQH,aAAaI;IACrD;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEX,UAAU,EAAEY,GAAG,EAAE;IAClD,MAAMd,cAAca,cAAcE,cAAc,GAC5C,OACA,AAAC,CAAA,MAAMtB,iBAAiB;QAAEqB;IAAI,EAAC,EAAGb,OAAO,EAAE,CAACC,WAAW;IAE3D,IAAI,CAACW,cAAcE,cAAc,IAAI,CAACf,aAAaI,QAAQ;QACzD,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,kEAAkE,EAAEhB,WAAW,CAAC,CAAC;gBAC1F;aACD;YACDiB,SAAS;QACX;IACF;IAEA,MAAMC,cAAcxB,qBAAqB;QACvCM;QACAY;QACA,GAAId,cAAc;YAAEA;QAAY,IAAI,CAAC,CAAC;IACxC;IAEA,IAAI,CAACoB,aAAa;QAChB,OAAO;YACLJ,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,eAAe,EAAEhB,WAAW,WAAW,CAAC;gBAAC;aAAE;YAC5EiB,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,mBAAmB,EAAEhB,WAAW,gBAAgB,EAAEmB,KAAKC,SAAS,CAACF,aAAa,QAAQ,CAAC;YAChG;SACD;QACDG,mBAAmB;YACjBrB;YACAsB,QAAQJ;QACV;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/restoreVersionTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,wBAAwB,wCAuFnC,CAAA"}
1
+ {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/restoreVersionTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,wBAAwB,wCAuFnC,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 = 'Restore a global from a previous version in any version-enabled global.';
7
6
  export const restoreGlobalVersionTool = defineGlobalTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
@@ -34,8 +33,8 @@ export const restoreGlobalVersionTool = defineGlobalTool({
34
33
  id,
35
34
  slug: globalSlug,
36
35
  depth,
36
+ overrideAccess: authorizedMCP.overrideAccess,
37
37
  req,
38
- ...localAPIDefaults(authorizedMCP),
39
38
  ...fallbackLocale ? {
40
39
  fallbackLocale
41
40
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType } 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 =\n 'Restore a global from a previous version in any version-enabled global.'\n\nexport const restoreGlobalVersionTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Global Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the global 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 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 showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored global response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input\n\n logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreGlobalVersion({\n id,\n slug: globalSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n const resultObject = result as Record<string, unknown>\n const restoredGlobal =\n resultObject.version && typeof resultObject.version === 'object'\n ? (resultObject.version as Record<string, unknown>)\n : resultObject\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully for global \"${globalSlug}\"!\\nRestored global:\\n\\`\\`\\`json\\n${JSON.stringify(restoredGlobal)}\\n\\`\\`\\``,\n },\n ],\n doc: restoredGlobal,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","restoreGlobalVersionTool","access","args","Boolean","permissions","globals","globalSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","showHiddenFields","boolean","handler","authorizedMCP","req","payload","logger","info","result","restoreGlobalVersion","slug","undefined","resultObject","restoredGlobal","version","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"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,sBACJ;AAEF,OAAO,MAAMC,2BAA2BJ,iBAAiB;IACvDK,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,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,gBAAgBjC,EACbwB,MAAM,GACNC,QAAQ,CAAC,gFACTM,QAAQ;QACXG,QAAQlC,EACLwB,MAAM,GACNC,QAAQ,CAAC,0DACTM,QAAQ;QACXI,UAAUnC,EACPoC,MAAM,CAACpC,EAAEwB,MAAM,IAAIxB,EAAEqC,OAAO,IAC5BZ,QAAQ,CACP,8FAEDM,QAAQ;QACXO,kBAAkBtC,EACfuC,OAAO,GACPd,QAAQ,CAAC,mEACTM,QAAQ;IACb;AACF,GAAGS,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAE7B,UAAU,EAAES,KAAK,EAAEqB,GAAG,EAAE;IACzD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAASzC,UAAU;QAAEwC;IAAQ;IACnC,MAAM,EAAEpB,EAAE,E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ool.ts"],"sourcesContent":["import type { PopulateType } 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 =\n 'Restore a global from a previous version in any version-enabled global.'\n\nexport const restoreGlobalVersionTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Global Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the global 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 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 showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored global response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input\n\n logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreGlobalVersion({\n id,\n slug: globalSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n const resultObject = result as Record<string, unknown>\n const restoredGlobal =\n resultObject.version && typeof resultObject.version === 'object'\n ? (resultObject.version as Record<string, unknown>)\n : resultObject\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully for global \"${globalSlug}\"!\\nRestored global:\\n\\`\\`\\`json\\n${JSON.stringify(restoredGlobal)}\\n\\`\\`\\``,\n },\n ],\n doc: restoredGlobal,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","DEFAULT_DESCRIPTION","restoreGlobalVersionTool","access","args","Boolean","permissions","globals","globalSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","showHiddenFields","boolean","handler","authorizedMCP","req","payload","logger","info","result","restoreGlobalVersion","slug","overrideAccess","undefined","resultObject","restoredGlobal","version","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,2BAA2BH,iBAAiB;IACvDI,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,IAAItB,EAAEuB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAOzB,EACJ0B,MAAM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,GACrBF;QAEN,OAAO;YACLG,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEjC,GAAG,oCAAoC,EAAEX,WAAW,kCAAkC,EAAE6C,KAAKC,SAAS,CAACN,gBAAgB,QAAQ,CAAC;gBACpJ;aACD;YACDO,KAAKP;QACP;IACF,EAAE,OAAOQ,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DnB,OAAOgB,KAAK,CAAC,CAAC,wBAAwB,EAAErC,GAAG,YAAY,EAAEX,WAAW,EAAE,EAAEiD,cAAc;QACtF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAEjC,GAAG,cAAc,EAAEX,WAAW,KAAK,EAAEiD,cAAc;gBAC3F;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,gBAAgB,wCAiG3B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,wCAkG3B,CAAA"}