@payloadcms/plugin-mcp 4.0.0-internal.bc5cf8c → 4.0.0-internal.c7d5de4

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 (169) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +7 -0
  3. package/dist/defaultAccess.d.ts.map +1 -1
  4. package/dist/defineTool.d.ts +8 -8
  5. package/dist/defineTool.d.ts.map +1 -1
  6. package/dist/endpoint/access.d.ts +2 -7
  7. package/dist/endpoint/access.d.ts.map +1 -1
  8. package/dist/endpoint/access.js +4 -11
  9. package/dist/endpoint/access.js.map +1 -1
  10. package/dist/endpoint/index.d.ts +1 -1
  11. package/dist/endpoint/index.d.ts.map +1 -1
  12. package/dist/endpoint/index.js +57 -17
  13. package/dist/endpoint/index.js.map +1 -1
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/mcp/buildMcpServer.d.ts +4 -4
  19. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  20. package/dist/mcp/buildMcpServer.js +32 -10
  21. package/dist/mcp/buildMcpServer.js.map +1 -1
  22. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  23. package/dist/mcp/builtin/collections/countTool.js +1 -2
  24. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  25. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  26. package/dist/mcp/builtin/collections/countVersionsTool.js +1 -2
  27. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  28. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  29. package/dist/mcp/builtin/collections/createTool.js +14 -5
  30. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  31. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  32. package/dist/mcp/builtin/collections/deleteTool.js +1 -2
  33. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  34. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  35. package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
  36. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  37. package/dist/mcp/builtin/collections/fileInput.d.ts +20 -0
  38. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  39. package/dist/mcp/builtin/collections/fileInput.js +100 -0
  40. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  41. package/dist/mcp/builtin/collections/fileInput.spec.js +72 -0
  42. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  43. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  44. package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
  45. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  46. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  47. package/dist/mcp/builtin/collections/findTool.js +3 -4
  48. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  49. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/findVersionByIDTool.js +1 -2
  51. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  53. package/dist/mcp/builtin/collections/findVersionsTool.js +1 -2
  54. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  55. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  56. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  58. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +44 -5
  59. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  60. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  61. package/dist/mcp/builtin/collections/restoreVersionTool.js +1 -2
  62. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  63. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  64. package/dist/mcp/builtin/collections/updateTool.js +23 -11
  65. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  66. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  67. package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
  68. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  69. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  70. package/dist/mcp/builtin/globals/countVersionsTool.js +1 -2
  71. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  72. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  73. package/dist/mcp/builtin/globals/findTool.js +2 -2
  74. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  75. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  76. package/dist/mcp/builtin/globals/findVersionByIDTool.js +1 -2
  77. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  78. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  79. package/dist/mcp/builtin/globals/findVersionsTool.js +1 -2
  80. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  81. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  82. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +21 -3
  83. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  84. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  85. package/dist/mcp/builtin/globals/restoreVersionTool.js +1 -2
  86. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  87. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  88. package/dist/mcp/builtin/globals/updateTool.js +2 -2
  89. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  90. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  91. package/dist/mcp/builtin/validateEntityData.js +1 -1
  92. package/dist/mcp/builtin/validateEntityData.js.map +1 -1
  93. package/dist/mcp/builtinTools.d.ts.map +1 -1
  94. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  95. package/dist/mcp/sanitizeMCPConfig.js +1 -0
  96. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  97. package/dist/stdio.d.ts +3 -4
  98. package/dist/stdio.d.ts.map +1 -1
  99. package/dist/stdio.js +59 -41
  100. package/dist/stdio.js.map +1 -1
  101. package/dist/types.d.ts +57 -9
  102. package/dist/types.d.ts.map +1 -1
  103. package/dist/types.js +2 -4
  104. package/dist/types.js.map +1 -1
  105. package/dist/utils/camelCase.d.ts.map +1 -1
  106. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  107. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  108. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  109. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  110. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  111. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
  112. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  113. package/dist/utils/schemaConversion/getEntityInputSchema.js +44 -12
  114. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
  115. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  116. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  117. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  118. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  119. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  120. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  121. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  122. package/package.json +9 -11
  123. package/src/endpoint/access.ts +3 -10
  124. package/src/endpoint/index.ts +45 -16
  125. package/src/index.ts +4 -4
  126. package/src/mcp/buildMcpServer.ts +40 -20
  127. package/src/mcp/builtin/collections/countTool.ts +1 -2
  128. package/src/mcp/builtin/collections/countVersionsTool.ts +1 -2
  129. package/src/mcp/builtin/collections/createTool.ts +14 -5
  130. package/src/mcp/builtin/collections/deleteTool.ts +1 -2
  131. package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
  132. package/src/mcp/builtin/collections/fileInput.spec.ts +79 -0
  133. package/src/mcp/builtin/collections/fileInput.ts +139 -0
  134. package/src/mcp/builtin/collections/findDistinctTool.ts +1 -2
  135. package/src/mcp/builtin/collections/findTool.ts +3 -4
  136. package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
  137. package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
  138. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +39 -9
  139. package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
  140. package/src/mcp/builtin/collections/updateTool.ts +25 -9
  141. package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
  142. package/src/mcp/builtin/globals/countVersionsTool.ts +1 -2
  143. package/src/mcp/builtin/globals/findTool.ts +2 -2
  144. package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
  145. package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
  146. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
  147. package/src/mcp/builtin/globals/restoreVersionTool.ts +1 -2
  148. package/src/mcp/builtin/globals/updateTool.ts +2 -2
  149. package/src/mcp/builtin/validateEntityData.ts +1 -1
  150. package/src/mcp/sanitizeMCPConfig.ts +1 -0
  151. package/src/stdio.ts +59 -42
  152. package/src/types.ts +57 -9
  153. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  154. package/src/utils/schemaConversion/getEntityInputSchema.ts +45 -27
  155. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  156. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  157. package/dist/@types/assets.d.js +0 -2
  158. package/dist/@types/assets.d.js.map +0 -1
  159. package/dist/utils/localAPIDefaults.d.ts +0 -20
  160. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  161. package/dist/utils/localAPIDefaults.js +0 -19
  162. package/dist/utils/localAPIDefaults.js.map +0 -1
  163. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  164. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  165. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  166. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  167. package/src/@types/assets.d.ts +0 -3
  168. package/src/utils/localAPIDefaults.ts +0 -22
  169. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  import { whereSchema } from '../../../utils/whereSchema.js';
7
6
  const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
8
7
  export const findDocumentsTool = defineCollectionTool({
@@ -21,7 +20,7 @@ export const findDocumentsTool = defineCollectionTool({
21
20
  z.number()
22
21
  ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
23
22
  depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
24
- draft: z.boolean().describe('Optional: whether the document should be queried from the versions table/collection or not.').optional(),
23
+ draft: z.boolean().describe('For versioned collections, true returns the latest draft version when available. False reads the main document.').optional(),
25
24
  fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
26
25
  joins: z.union([
27
26
  z.record(z.string(), z.unknown()),
@@ -51,8 +50,8 @@ export const findDocumentsTool = defineCollectionTool({
51
50
  id,
52
51
  collection: collectionSlug,
53
52
  depth,
53
+ overrideAccess: authorizedMCP.overrideAccess,
54
54
  req,
55
- ...localAPIDefaults(authorizedMCP),
56
55
  ...select && {
57
56
  select: select
58
57
  },
@@ -100,9 +99,9 @@ export const findDocumentsTool = defineCollectionTool({
100
99
  collection: collectionSlug,
101
100
  depth,
102
101
  limit,
102
+ overrideAccess: authorizedMCP.overrideAccess,
103
103
  page,
104
104
  req,
105
- ...localAPIDefaults(authorizedMCP),
106
105
  ...select && {
107
106
  select: select
108
107
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { JoinQuery, 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'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in any collection by passing the collection slug and optional ID or where clause.'\n\nexport const findDocumentsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Documents',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Optional: whether the document should be queried from the versions table/collection or not.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n joins: z\n .union([z.record(z.string(), z.unknown()), z.literal(false)])\n .describe('Optional: configure join field queries, or pass false to disable all join fields.')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents 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., {\"title\": true}',\n )\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted documents when trash is enabled on the collection')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. 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 depth,\n draft,\n fallbackLocale,\n joins,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n page,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(pagination !== undefined && { pagination }),\n ...(trash !== undefined && { trash }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (where) {\n findOptions.where = where\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\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 reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","joins","record","unknown","literal","limit","locale","page","pagination","populate","select","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","doc","findByID","collection","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"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;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBL,qBAAqB;IACpDM,QAAQ,CAACC,OACPR,cAAcQ,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,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,IAAIxB,EACDyB,KAAK,CAAC;YAACzB,EAAE0B,MAAM;YAAI1B,EAAE2B,MAAM;SAAG,EAC9BC,QAAQ,CACP,sFAEDC,QAAQ;QACXC,OAAO9B,EACJ2B,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,+DACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOnC,EACJoC,OAAO,GACPR,QAAQ,CACP,+FAEDC,QAAQ;QACXQ,gBAAgBrC,EACb0B,MAAM,GACNE,QAAQ,CAAC,gFACTC,QAAQ;QACXS,OAAOtC,EACJyB,KAAK,CAAC;YAACzB,EAAEuC,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3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { JoinQuery, 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 { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in any collection by passing the collection slug and optional ID or where clause.'\n\nexport const findDocumentsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Documents',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'For versioned collections, true returns the latest draft version when available. False reads the main document.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n joins: z\n .union([z.record(z.string(), z.unknown()), z.literal(false)])\n .describe('Optional: configure join field queries, or pass false to disable all join fields.')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents 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., {\"title\": true}',\n )\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted documents when trash is enabled on the collection')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. 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 depth,\n draft,\n fallbackLocale,\n joins,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(pagination !== undefined && { pagination }),\n ...(trash !== undefined && { trash }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (where) {\n findOptions.where = where\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\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 reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","joins","record","unknown","literal","limit","locale","page","pagination","populate","select","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","doc","findByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QA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A;QACtB;QAEA,MAAMmB,SAAS,MAAMf,QAAQgB,IAAI,CAACF;QAElC,IAAIG,eAAe,CAAC,aAAa,EAAE1D,eAAe,UAAU,EAAEwD,OAAOG,SAAS,CAAC,kBAAkB,EAAEH,OAAOzB,IAAI,CAAC,IAAI,EAAEyB,OAAOI,UAAU,CAAC,EAAE,CAAC;QAC1I,KAAK,MAAMhB,OAAOY,OAAOK,IAAI,CAAE;YAC7BH,gBAAgB,CAAC,cAAc,EAAEN,KAAKC,SAAS,CAACT,KAAK,QAAQ,CAAC;QAChE;QAEA,OAAO;YACLK,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMO;gBAAa;aAAE;YAC/Cd,KAAKY;QACP;IACF,EAAE,OAAOM,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DvB,OAAOoB,KAAK,CAAC,CAAC,wCAAwC,EAAE9D,eAAe,EAAE,EAAE+D,cAAc;QACzF,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAEnD,eAAe,KAAK,EAAE+D,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.';
7
6
  export const findVersionByIDTool = defineCollectionTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
@@ -36,8 +35,8 @@ export const findVersionByIDTool = defineCollectionTool({
36
35
  id,
37
36
  collection: collectionSlug,
38
37
  depth,
38
+ overrideAccess: authorizedMCP.overrideAccess,
39
39
  req,
40
- ...localAPIDefaults(authorizedMCP),
41
40
  ...fallbackLocale ? {
42
41
  fallbackLocale
43
42
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.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 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'\n\nexport const findVersionByIDTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the 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 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.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned version document')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted version documents when trash is enabled')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input\n\n logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id,\n collection: collectionSlug,\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 ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from collection \"${collectionSlug}\":\\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} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","collectionSlug","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","trash","handler","authorizedMCP","req","payload","logger","info","result","findVersionByID","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,sBAAsBJ,qBAAqB;IACtDK,QAAQ,CAACC,OACPP,cAAcO,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,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,0EACTM,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,8GAEDM,QAAQ;QACXQ,kBAAkBvC,EACfwC,OAAO,GACPf,QAAQ,CAAC,oEACTM,QAAQ;QACXU,OAAOzC,EACJwC,OAAO,GACPf,QAAQ,CAAC,0EACTM,QAAQ;IACb;AACF,GA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;QAChF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAE/B,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAE+C,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.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 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'\n\nexport const findVersionByIDTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the 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 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.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned version document')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted version documents when trash is enabled')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input\n\n logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id,\n collection: collectionSlug,\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 ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from collection \"${collectionSlug}\":\\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} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","collectionSlug","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","trash","handler","authorizedMCP","req","payload","logger","info","result","findVersionByID","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;AAEv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[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,4CA6I3B,CAAA"}
1
+ {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CA6I3B,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  import { whereSchema } from '../../../utils/whereSchema.js';
7
6
  const DEFAULT_DESCRIPTION = 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.';
8
7
  export const findVersionsTool = defineCollectionTool({
@@ -41,9 +40,9 @@ export const findVersionsTool = defineCollectionTool({
41
40
  collection: collectionSlug,
42
41
  depth,
43
42
  limit,
43
+ overrideAccess: authorizedMCP.overrideAccess,
44
44
  page,
45
45
  req,
46
- ...localAPIDefaults(authorizedMCP),
47
46
  ...fallbackLocale ? {
48
47
  fallbackLocale
49
48
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.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'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find 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 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.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned 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 trash: z\n .boolean()\n .describe('Optional: include versions for soft-deleted documents when trash is enabled')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.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 const {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: collectionSlug,\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 ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${collectionSlug}\":\\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 in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","collectionSlug","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","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findVersions","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;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBL,qBAAqB;IACnDM,QA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,CAACR,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,0BAA0B,EAAElD,eAAe,EAAE,EAAEmD,cAAc;QAC3E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAE9C,eAAe,KAAK,EAAEmD,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.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 { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find 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 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.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned 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 trash: z\n .boolean()\n .describe('Optional: include versions for soft-deleted documents when trash is enabled')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.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 const {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: collectionSlug,\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 ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${collectionSlug}\":\\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 in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","collectionSlug","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","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findVersions","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;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBJ,qBAAqB;IACnDK,QAAQ,CAACC,OACPP,cAAcO,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,OAAOvB,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,uEACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgB/B,EACbgC,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,OAAOjC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import type { MCPToolResponse } from '../../../types.js';
3
3
  export declare const formatCollectionError: ({ action, collectionSlug, error, req, }: {
4
- action: "creating" | "duplicating" | "updating";
4
+ action: 'creating' | 'duplicating' | 'updating';
5
5
  collectionSlug: CollectionSlug;
6
6
  error: unknown;
7
7
  req: PayloadRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,GAAI,yCAKnC;IACD,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
1
+ {"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,4CAK/B;IACD,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,4CAyClC,CAAA"}
1
+ {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,4CAqElC,CAAA"}
@@ -1,10 +1,11 @@
1
+ import { getAccessResults } from 'payload';
1
2
  import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineCollectionTool } from '../../../defineTool.js';
3
4
  import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
4
5
  export const getCollectionSchemaTool = defineCollectionTool({
5
6
  access: (args)=>{
6
7
  const permissions = args.permissions?.collections?.[args.collectionSlug];
7
- return defaultAccess(args) && Boolean(permissions?.create || permissions?.delete || permissions?.read || permissions?.update);
8
+ return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
8
9
  },
9
10
  annotations: {
10
11
  destructiveHint: false,
@@ -14,10 +15,27 @@ export const getCollectionSchemaTool = defineCollectionTool({
14
15
  title: 'Get Collection Schema'
15
16
  },
16
17
  description: 'Get the input schema for creating or updating documents in a collection.'
17
- }).handler(({ collectionSlug, req })=>{
18
+ }).handler(async ({ authorizedMCP, collectionSlug, req })=>{
19
+ const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
+ req
21
+ })).collections?.[collectionSlug];
22
+ if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`
28
+ }
29
+ ],
30
+ isError: true
31
+ };
32
+ }
18
33
  const inputSchema = getCollectionInputSchema({
19
34
  collectionSlug,
20
- req
35
+ req,
36
+ ...permissions ? {
37
+ permissions
38
+ } : {}
21
39
  });
22
40
  if (!inputSchema) {
23
41
  return {
@@ -30,16 +48,37 @@ export const getCollectionSchemaTool = defineCollectionTool({
30
48
  isError: true
31
49
  };
32
50
  }
51
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
52
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
53
+ const upload = uploadConfig ? {
54
+ enabled: true,
55
+ filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
56
+ mimeTypes: uploadConfig.mimeTypes ?? [
57
+ '*/*'
58
+ ],
59
+ sources: [
60
+ ...uploadConfig.pasteURL !== false ? [
61
+ 'url'
62
+ ] : [],
63
+ 'base64'
64
+ ],
65
+ ...typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? {
66
+ maxFileSize
67
+ } : {}
68
+ } : {
69
+ enabled: false
70
+ };
33
71
  return {
34
72
  content: [
35
73
  {
36
74
  type: 'text',
37
- text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``
75
+ text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
38
76
  }
39
77
  ],
40
78
  structuredContent: {
41
79
  collectionSlug,
42
- schema: inputSchema
80
+ schema: inputSchema,
81
+ upload
43
82
  }
44
83
  };
45
84
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\n\n return (\n defaultAccess(args) &&\n Boolean(\n permissions?.create || permissions?.delete || permissions?.read || permissions?.update,\n )\n )\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description: 'Get the input schema for creating or updating documents in a collection.',\n}).handler(({ collectionSlug, req }) => {\n const inputSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n },\n }\n})\n"],"names":["defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","delete","read","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","req","inputSchema","content","type","text","isError","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,cAAc,CAAC;QAExE,OACER,cAAcK,SACdI,QACEH,aAAaI,UAAUJ,aAAaK,UAAUL,aAAaM,QAAQN,aAAaO;IAGtF;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,CAAC,EAAEb,cAAc,EAAEc,GAAG,EAAE;IACjC,MAAMC,cAAcrB,yBAAyB;QAAEM;QAAgBc;IAAI;IAEnE,IAAI,CAACC,aAAa;QAChB,OAAO;YACLC,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAElB,eAAe,WAAW,CAAC;gBAAC;aAAE;YACpFmB,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAElB,eAAe,gBAAgB,EAAEoB,KAAKC,SAAS,CAACN,aAAa,QAAQ,CAAC;YACxG;SACD;QACDO,mBAAmB;YACjBtB;YACAuB,QAAQR;QACV;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\n\n return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description: 'Get the input schema for creating or updating documents in a collection.',\n}).handler(async ({ authorizedMCP, collectionSlug, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[collectionSlug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getCollectionSchema\" is not enabled for collection \"${collectionSlug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[collectionSlug]?.config.upload\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n const upload = uploadConfig\n ? {\n enabled: true,\n filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,\n mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],\n sources: [...(uploadConfig.pasteURL !== false ? ['url'] : []), 'base64'],\n ...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),\n }\n : { enabled: false }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n upload,\n },\n }\n})\n"],"names":["getAccessResults","defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,UAAS;AAE1C,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,cAAc,CAAC;QAExE,OAAOR,cAAcK,SAASI,QAAQH,aAAaI,UAAUJ,aAAaK;IAC5E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEZ,cAAc,EAAEa,GAAG,EAAE;IACtD,MAAMf,cAAcc,cAAcE,cAAc,GAC5C,OACA,AAAC,CAAA,MAAMvB,iBAAiB;QAAEsB;IAAI,EAAC,EAAGd,WAAW,EAAE,CAACC,eAAe;IAEnE,IAAI,CAACY,cAA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":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
1
+ {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
7
6
  export const restoreVersionTool = defineCollectionTool({
8
7
  access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
@@ -37,8 +36,8 @@ export const restoreVersionTool = defineCollectionTool({
37
36
  collection: collectionSlug,
38
37
  depth,
39
38
  draft,
39
+ overrideAccess: authorizedMCP.overrideAccess,
40
40
  req,
41
- ...localAPIDefaults(authorizedMCP),
42
41
  ...fallbackLocale ? {
43
42
  fallbackLocale
44
43
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the version to restore'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in response')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to restore the version as a draft')\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe('Optional: locale code to restore in (e.g., \"en\", \"es\")')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id,\n collection: collectionSlug,\n depth,\n draft,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${collectionSlug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","draft","boolean","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","result","restoreVersion","collection","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBJ,qBAAqB;IACrDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAO1B,EACJ2B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,8DACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAOjC,EACJkC,OAAO,GACPT,QAAQ,CAAC,6CACTM,QAAQ,GACRC,OAAO,CAAC;QACXG,gBAAgBnC,EACbwB,MAAM,GACNC,QAAQ,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C,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,EAAEuB,MAAM,IAAIvB,EAAEsC,OAAO,IAC5Bd,QAAQ,CACP,8FAEDM,QAAQ;QACXS,QAAQvC,EACLqC,MAAM,CAACrC,EAAEuB,MAAM,IAAIvB,EAAEsC,OAAO,IAC5Bd,QAAQ,CACP,sGAEDM,QAAQ;QACXU,kBAAkBxC,EACfiC,OAAO,GACPT,QAAQ,CAAC,qEACTM,QAAQ;IACb;AACF,GAAGW,OAAO,CAAC,OAAO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EhC,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAEgD,cAAc;gBAClG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6L7B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6M7B,CAAA"}
@@ -3,11 +3,11 @@ import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
5
  import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
6
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
7
6
  import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
8
7
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
9
8
  import { whereSchema } from '../../../utils/whereSchema.js';
10
9
  import { validateCollectionData } from '../validateEntityData.js';
10
+ import { fileInputSchema, resolveFileInput } from './fileInput.js';
11
11
  import { formatCollectionError } from './formatCollectionError.js';
12
12
  const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
13
13
  export const updateDocumentTool = defineCollectionTool({
@@ -25,14 +25,15 @@ export const updateDocumentTool = defineCollectionTool({
25
25
  z.string(),
26
26
  z.number()
27
27
  ]).describe('The ID of the document to update').optional(),
28
- data: z.record(z.string(), z.unknown()).describe('The fields to update'),
28
+ data: z.record(z.string(), z.unknown()).describe('The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.'),
29
29
  depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
30
- draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
30
+ draft: z.boolean().describe('Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: "published" overrides true.').optional().default(false),
31
31
  fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
32
- filePath: z.string().describe('File path for file uploads').optional(),
32
+ file: fileInputSchema.optional(),
33
33
  locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
34
34
  overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
35
35
  overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
36
+ publishAllLocales: z.boolean().describe('For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.').optional(),
36
37
  select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
37
38
  where: whereSchema.describe('Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
38
39
  })
@@ -41,7 +42,7 @@ export const updateDocumentTool = defineCollectionTool({
41
42
  const logger = getLogger({
42
43
  payload
43
44
  });
44
- const { id, data, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, select, where } = input;
45
+ const { id, data, depth, draft, fallbackLocale, file: fileInput, locale, overrideLock, overwriteExistingFiles, publishAllLocales, select, where } = input;
45
46
  logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
46
47
  try {
47
48
  if (!id && !where) {
@@ -66,6 +67,11 @@ export const updateDocumentTool = defineCollectionTool({
66
67
  return validationError;
67
68
  }
68
69
  const parsedData = transformPointDataToPayload(inputData);
70
+ const file = await resolveFileInput({
71
+ collectionSlug,
72
+ input: fileInput,
73
+ req
74
+ });
69
75
  const whereClause = where ?? {};
70
76
  if (id) {
71
77
  const result = await payload.update({
@@ -74,15 +80,18 @@ export const updateDocumentTool = defineCollectionTool({
74
80
  data: parsedData,
75
81
  depth,
76
82
  draft,
83
+ overrideAccess: authorizedMCP.overrideAccess,
77
84
  overrideLock,
78
85
  req,
79
- ...localAPIDefaults(authorizedMCP),
80
- ...filePath ? {
81
- filePath
86
+ ...file ? {
87
+ file
82
88
  } : {},
83
89
  ...overwriteExistingFiles ? {
84
90
  overwriteExistingFiles
85
91
  } : {},
92
+ ...publishAllLocales !== undefined ? {
93
+ publishAllLocales
94
+ } : {},
86
95
  ...locale ? {
87
96
  locale
88
97
  } : {},
@@ -108,16 +117,19 @@ export const updateDocumentTool = defineCollectionTool({
108
117
  data: parsedData,
109
118
  depth,
110
119
  draft,
120
+ overrideAccess: authorizedMCP.overrideAccess,
111
121
  overrideLock,
112
122
  req,
113
123
  where: whereClause,
114
- ...localAPIDefaults(authorizedMCP),
115
- ...filePath ? {
116
- filePath
124
+ ...file ? {
125
+ file
117
126
  } : {},
118
127
  ...overwriteExistingFiles ? {
119
128
  overwriteExistingFiles
120
129
  } : {},
130
+ ...publishAllLocales !== undefined ? {
131
+ publishAllLocales
132
+ } : {},
121
133
  ...locale ? {
122
134
  locale
123
135
  } : {},