@payloadcms/plugin-mcp 4.0.0-internal.567a487 → 4.0.0-internal.5a4aa81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/endpoint/access.js +2 -2
  2. package/dist/endpoint/access.js.map +1 -1
  3. package/dist/mcp/buildMcpServer.d.ts +1 -1
  4. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  5. package/dist/mcp/buildMcpServer.js +35 -23
  6. package/dist/mcp/buildMcpServer.js.map +1 -1
  7. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  8. package/dist/mcp/builtin/collections/authTools.js +79 -56
  9. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  10. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  11. package/dist/mcp/builtin/collections/countTool.js +9 -14
  12. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  13. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  14. package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
  15. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  16. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  17. package/dist/mcp/builtin/collections/createTool.js +48 -49
  18. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  19. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  20. package/dist/mcp/builtin/collections/deleteTool.js +40 -43
  21. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  22. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  23. package/dist/mcp/builtin/collections/duplicateTool.js +26 -36
  24. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  25. package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
  26. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
  27. package/dist/mcp/builtin/collections/fileInput.js +19 -20
  28. package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
  29. package/dist/mcp/builtin/collections/fileInput.spec.js +2 -2
  30. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
  31. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  32. package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
  33. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  34. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  35. package/dist/mcp/builtin/collections/findTool.js +21 -43
  36. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  37. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  38. package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
  39. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  40. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  41. package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
  42. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  43. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  44. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +12 -12
  45. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  46. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  47. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  48. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  49. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/updateTool.js +50 -86
  51. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
  53. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
  54. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  55. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  56. package/dist/mcp/builtin/formatEntityError.js +55 -0
  57. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  58. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  59. package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
  60. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  61. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  62. package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
  63. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  64. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  65. package/dist/mcp/builtin/globals/findTool.js +10 -16
  66. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  67. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  68. package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
  69. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  70. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  71. package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
  72. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  73. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
  75. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
  78. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/updateTool.js +27 -36
  81. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  82. package/dist/types.d.ts +4 -4
  83. package/dist/types.d.ts.map +1 -1
  84. package/dist/types.js.map +1 -1
  85. package/package.json +4 -6
  86. package/src/endpoint/access.ts +2 -3
  87. package/src/mcp/buildMcpServer.ts +39 -29
  88. package/src/mcp/builtin/collections/authTools.ts +77 -69
  89. package/src/mcp/builtin/collections/countTool.ts +9 -21
  90. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  91. package/src/mcp/builtin/collections/createTool.ts +73 -96
  92. package/src/mcp/builtin/collections/deleteTool.ts +36 -64
  93. package/src/mcp/builtin/collections/duplicateTool.ts +33 -84
  94. package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
  95. package/src/mcp/builtin/collections/fileInput.ts +30 -25
  96. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  97. package/src/mcp/builtin/collections/findTool.ts +21 -103
  98. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  99. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  100. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +11 -11
  101. package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
  102. package/src/mcp/builtin/collections/updateTool.ts +53 -108
  103. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
  104. package/src/mcp/builtin/formatEntityError.ts +77 -0
  105. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  106. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  107. package/src/mcp/builtin/globals/findTool.ts +12 -51
  108. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  109. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  110. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
  111. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  112. package/src/mcp/builtin/globals/updateTool.ts +37 -60
  113. package/src/types.ts +4 -4
  114. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  115. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  116. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  117. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  118. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  119. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  120. package/dist/mcp/builtin/validateEntityData.js +0 -82
  121. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  122. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  123. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  124. package/dist/utils/getVirtualFieldNames.js +0 -35
  125. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  126. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  127. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  128. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  129. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  130. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  131. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  132. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  133. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  134. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  135. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  136. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  137. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  138. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  139. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  140. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  141. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  142. package/dist/utils/transformPointDataToPayload.js +0 -28
  143. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  144. package/dist/utils/whereSchema.d.ts +0 -9
  145. package/dist/utils/whereSchema.d.ts.map +0 -1
  146. package/dist/utils/whereSchema.js +0 -13
  147. package/dist/utils/whereSchema.js.map +0 -1
  148. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  149. package/src/mcp/builtin/validateEntityData.ts +0 -132
  150. package/src/utils/getVirtualFieldNames.ts +0 -53
  151. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  152. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  153. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  154. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  155. package/src/utils/transformPointDataToPayload.ts +0 -40
  156. package/src/utils/whereSchema.ts +0 -24
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findDistinctInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { whereSchema } from '../../../utils/whereSchema.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find distinct values for a field in any collection by passing the collection slug and field path.';
7
6
  export const findDistinctTool = defineCollectionTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,28 +13,17 @@ export const findDistinctTool = defineCollectionTool({
14
13
  title: 'Find Distinct'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in distinct values').optional().default(0),
19
- field: z.string().describe('The field path to get distinct values for'),
20
- limit: z.number().int().min(1).max(100).describe('Maximum number of distinct values to return (max: 100)').optional(),
21
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
- page: z.number().int().min(1).describe('Page number for pagination').optional(),
23
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
24
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in the distinct query').optional(),
25
- sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
26
- trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
27
- where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
28
- })
29
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findDistinctInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
30
18
  const payload = req.payload;
31
19
  const logger = getLogger({
32
20
  payload
33
21
  });
34
- const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } = input;
35
- logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`);
22
+ const { depth, field, limit, locale, page, populate, sort, trash, where } = input;
23
+ logger.info(`Finding distinct values in collection: ${slug}, field: ${field}`);
36
24
  try {
37
25
  const result = await payload.findDistinct({
38
- collection: collectionSlug,
26
+ collection: slug,
39
27
  depth,
40
28
  field,
41
29
  overrideAccess: authorizedMCP.overrideAccess,
@@ -50,10 +38,7 @@ export const findDistinctTool = defineCollectionTool({
50
38
  page
51
39
  } : {},
52
40
  ...populate ? {
53
- populate: populate
54
- } : {},
55
- ...showHiddenFields !== undefined ? {
56
- showHiddenFields
41
+ populate
57
42
  } : {},
58
43
  ...sort ? {
59
44
  sort
@@ -69,19 +54,19 @@ export const findDistinctTool = defineCollectionTool({
69
54
  content: [
70
55
  {
71
56
  type: 'text',
72
- text: `Distinct values for "${field}" in collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
57
+ text: `Distinct values for "${field}" in collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
73
58
  }
74
59
  ],
75
60
  doc: result
76
61
  };
77
62
  } catch (error) {
78
63
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
79
- logger.error(`Error finding distinct values in ${collectionSlug}: ${errorMessage}`);
64
+ logger.error(`Error finding distinct values in ${slug}: ${errorMessage}`);
80
65
  return {
81
66
  content: [
82
67
  {
83
68
  type: 'text',
84
- text: `❌ **Error finding distinct values in collection "${collectionSlug}":** ${errorMessage}`
69
+ text: `❌ **Error finding distinct values in collection "${slug}":** ${errorMessage}`
85
70
  }
86
71
  ],
87
72
  isError: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"sourcesContent":["import type { PopulateType } 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 distinct values for a field in any collection by passing the collection slug and field path.'\n\nexport const findDistinctTool = 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 Distinct',\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 distinct values')\n .optional()\n .default(0),\n field: z.string().describe('The field path to get distinct values for'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of distinct values to return (max: 100)')\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 page: z.number().int().min(1).describe('Page number for pagination').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 distinct query')\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 const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } =\n input\n\n logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`)\n\n try {\n const result = await payload.findDistinct({\n collection: collectionSlug,\n depth,\n field,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(limit ? { limit } : {}),\n ...(locale ? { locale } : {}),\n ...(page ? { page } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\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: `Distinct values for \"${field}\" in 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 distinct values in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding distinct values in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDistinctTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","field","string","limit","locale","page","populate","record","unknown","showHiddenFields","boolean","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findDistinct","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,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,OAAOvB,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,qEACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAO/B,EAAEgC,MAAM,GAAGJ,QAAQ,CAAC;QAC3BK,OAAOjC,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,KACJC,QAAQ,CAAC,0DACTC,QAAQ;QACXK,QAAQlC,EACLgC,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXM,MAAMnC,EAAEwB,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGE,QAAQ,CAAC,8BAA8BC,QAAQ;QAC7EO,UAAUpC,EACPqC,MAAM,CAACrC,EAAEgC,MAAM,IAAIhC,EAAEsC,OAAO,IAC5BV,QAAQ,CACP,8FAEDC,QAAQ;QACXU,kBAAkBvC,EACfwC,OAAO,GACPZ,QAAQ,CAAC,yDACTC,QAAQ;QACXY,MAAMzC,EACHgC,MAAM,GACNJ,QAAQ,CAAC,qEACTC,QA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AE8C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC1H;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,iCAAiC,EAAEjD,eAAe,EAAE,EAAEkD,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,iDAAiD,EAAE7C,eAAe,KAAK,EAAEkD,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"sourcesContent":["import { findDistinctInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find distinct values for a field in any collection by passing the collection slug and field path.'\n\nexport const findDistinctTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Distinct',\n },\n description: DEFAULT_DESCRIPTION,\n input: findDistinctInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { depth, field, limit, locale, page, populate, sort, trash, where } = input\n\n logger.info(`Finding distinct values in collection: ${slug}, field: ${field}`)\n\n try {\n const result = await payload.findDistinct({\n collection: slug,\n depth,\n field,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(limit ? { limit } : {}),\n ...(locale ? { locale } : {}),\n ...(page ? { page } : {}),\n ...(populate ? { populate } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Distinct values for \"${field}\" in collection \"${slug}\":\\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 distinct values in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding distinct values in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findDistinctInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findDistinctTool","access","args","Boolean","permissions","collections","slug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","depth","field","limit","locale","page","populate","sort","trash","where","info","result","findDistinct","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,UAAS;AAEjD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBH,qBAAqB;IACnDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IACnC,MAAM,EAAEE,KAAK,EAAEC,KAAK,EAAEC,KAAK,EA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sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CA2M5B,CAAA"}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,iBAAiB,4CA4H5B,CAAA"}
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findDocumentsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { whereSchema } from '../../../utils/whereSchema.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
7
6
  export const findDocumentsTool = defineCollectionTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,57 +13,36 @@ export const findDocumentsTool = defineCollectionTool({
14
13
  title: 'Find Documents'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- id: z.union([
19
- z.string(),
20
- z.number()
21
- ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
22
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
23
- draft: z.boolean().describe('For versioned collections, true returns the latest draft version when available. False reads the main document.').optional(),
24
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
25
- joins: z.union([
26
- z.record(z.string(), z.unknown()),
27
- z.literal(false)
28
- ]).describe('Optional: configure join field queries, or pass false to disable all join fields.').optional(),
29
- limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
30
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
31
- page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
32
- pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
33
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
34
- 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(),
35
- sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
36
- trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
37
- where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
38
- })
39
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findDocumentsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
40
18
  const payload = req.payload;
41
19
  const logger = getLogger({
42
20
  payload
43
21
  });
44
22
  const { id, depth, draft, fallbackLocale, joins, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
45
- logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
23
+ logger.info(`Reading document from collection: ${slug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
46
24
  try {
47
25
  if (id) {
48
26
  try {
49
27
  const doc = await payload.findByID({
50
28
  id,
51
- collection: collectionSlug,
29
+ collection: slug,
52
30
  depth,
53
31
  overrideAccess: authorizedMCP.overrideAccess,
54
32
  req,
55
33
  ...select && {
56
- select: select
34
+ select
57
35
  },
58
36
  ...populate && {
59
- populate: populate
37
+ populate
60
38
  },
61
39
  ...joins !== undefined && {
62
- joins: joins
40
+ joins
63
41
  },
64
42
  ...locale && {
65
43
  locale
66
44
  },
67
- ...fallbackLocale && {
45
+ ...fallbackLocale !== undefined && {
68
46
  fallbackLocale
69
47
  },
70
48
  ...draft !== undefined && {
@@ -78,43 +56,43 @@ export const findDocumentsTool = defineCollectionTool({
78
56
  content: [
79
57
  {
80
58
  type: 'text',
81
- text: `Document from collection "${collectionSlug}":\n${JSON.stringify(doc)}`
59
+ text: `Document from collection "${slug}":\n${JSON.stringify(doc)}`
82
60
  }
83
61
  ],
84
62
  doc: doc
85
63
  };
86
64
  } catch {
87
- logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`);
65
+ logger.warn(`Document not found with ID: ${id} in collection: ${slug}`);
88
66
  return {
89
67
  content: [
90
68
  {
91
69
  type: 'text',
92
- text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`
70
+ text: `Error: Document with ID "${id}" not found in collection "${slug}"`
93
71
  }
94
72
  ]
95
73
  };
96
74
  }
97
75
  }
98
76
  const findOptions = {
99
- collection: collectionSlug,
77
+ collection: slug,
100
78
  depth,
101
79
  limit,
102
80
  overrideAccess: authorizedMCP.overrideAccess,
103
81
  page,
104
82
  req,
105
83
  ...select && {
106
- select: select
84
+ select
107
85
  },
108
86
  ...populate && {
109
- populate: populate
87
+ populate
110
88
  },
111
89
  ...joins !== undefined && {
112
- joins: joins
90
+ joins
113
91
  },
114
92
  ...locale && {
115
93
  locale
116
94
  },
117
- ...fallbackLocale && {
95
+ ...fallbackLocale !== undefined && {
118
96
  fallbackLocale
119
97
  },
120
98
  ...draft !== undefined && {
@@ -134,7 +112,7 @@ export const findDocumentsTool = defineCollectionTool({
134
112
  findOptions.where = where;
135
113
  }
136
114
  const result = await payload.find(findOptions);
137
- let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
115
+ let responseText = `Collection: "${slug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
138
116
  for (const doc of result.docs){
139
117
  responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
140
118
  }
@@ -149,12 +127,12 @@ export const findDocumentsTool = defineCollectionTool({
149
127
  };
150
128
  } catch (error) {
151
129
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
152
- logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`);
130
+ logger.error(`Error reading documents from collection ${slug}: ${errorMessage}`);
153
131
  return {
154
132
  content: [
155
133
  {
156
134
  type: 'text',
157
- text: `❌ **Error reading documents from collection "${collectionSlug}":** ${errorMessage}`
135
+ text: `❌ **Error reading documents from collection "${slug}":** ${errorMessage}`
158
136
  }
159
137
  ]
160
138
  };
@@ -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 { 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,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBJ,qBAAqB;IACpDK,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,EACDwB,KAAK,CAAC;YAACxB,EAAEyB,MAAM;YAAIzB,EAAE0B,MAAM;SAAG,EAC9BC,QAAQ,CACP,sFAEDC,QAAQ;QACXC,OAAO7B,EACJ0B,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,+DACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOlC,EACJmC,OAAO,GACPR,QAAQ,CACP,mHAEDC,QAAQ;QACXQ,gBAAgBpC,EACbyB,MAAM,GACNE,QAAQ,CAAC,gFACTC,QAAQ;QACXS,OAAOrC,EACJwB,KAAK,CAAC;YAACxB,EAAEsC,MAAM,CAACtC,EAAEyB,MAAM,IAAIzB,EAAEuC,OAAO;YAAKvC,EAAEwC,OAAO,CAAC;SAAO,EA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UA;YAAyB,CAAC;YACtD,GAAIR,UAAUuB,aAAa;gBAAEvB,OAAOA;YAAmB,CAAC;YACxD,GAAIK,UAAU;gBAAEA;YAAO,CAAC;YACxB,GAAIN,kBAAkB;gBAAEA;YAAe,CAAC;YACxC,GAAIF,UAAU0B,aAAa;gBAAE1B;YAAM,CAAC;YACpC,GAAIU,eAAegB,aAAa;gBAAEhB;YAAW,CAAC;YAC9C,GAAII,UAAUY,aAAa;gBAAEZ;YAAM,CAAC;QACtC;QAEA,IAAID,MAAM;YACRoB,YAAYpB,IAAI,GAAGA;QACrB;QACA,IAAIE,OAAO;YACTkB,YAAYlB,KAAK,GAAGA;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
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import { findDocumentsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.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.slug]?.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: findDocumentsInputSchema,\n}).handler(async ({ slug, authorizedMCP, 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: ${slug}${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: slug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(select && { select }),\n ...(populate && { populate }),\n ...(joins !== undefined && { joins }),\n ...(locale && { locale }),\n ...(fallbackLocale !== undefined && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${slug}\":\\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: ${slug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${slug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(select && { select }),\n ...(populate && { populate }),\n ...(joins !== undefined && { joins }),\n ...(locale && { locale }),\n ...(fallbackLocale !== undefined && { 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: \"${slug}\"\\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 ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["findDocumentsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","slug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","joins","limit","locale","page","pagination","populate","select","sort","trash","where","info","doc","findByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,UAAS;AAElD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBH,qBAAqB;IACpDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI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AACT,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;QAC9DrC,OAAOkC,KAAK,CAAC,CAAC,wCAAwC,EAAEhD,KAAK,EAAE,EAAEiD,cAAc;QAC/E,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAErC,KAAK,KAAK,EAAEiD,cAAc;gBAClF;aACD;QACH;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,mBAAmB,4CAwD9B,CAAA"}
@@ -1,10 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findVersionByIDInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
5
  const DEFAULT_DESCRIPTION = 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.';
6
6
  export const findVersionByIDTool = defineCollectionTool({
7
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  idempotentHint: true,
@@ -13,44 +13,35 @@ export const findVersionByIDTool = defineCollectionTool({
13
13
  title: 'Find Version By ID'
14
14
  },
15
15
  description: DEFAULT_DESCRIPTION,
16
- input: z.object({
17
- id: z.string().describe('The ID of the version to retrieve'),
18
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in the version document').optional().default(0),
19
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
21
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
22
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
23
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in the returned version document').optional(),
24
- trash: z.boolean().describe('Optional: include soft-deleted version documents when trash is enabled').optional()
25
- })
26
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findVersionByIDInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
27
18
  const payload = req.payload;
28
19
  const logger = getLogger({
29
20
  payload
30
21
  });
31
- const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input;
32
- logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`);
22
+ const { id, depth, draft, fallbackLocale, locale, populate, select, trash } = input;
23
+ logger.info(`Finding version in collection: ${slug} with ID: ${id}`);
33
24
  try {
34
25
  const result = await payload.findVersionByID({
35
- id,
36
- collection: collectionSlug,
26
+ id: String(id),
27
+ collection: slug,
37
28
  depth,
38
29
  overrideAccess: authorizedMCP.overrideAccess,
39
30
  req,
40
- ...fallbackLocale ? {
31
+ ...draft !== undefined ? {
32
+ draft
33
+ } : {},
34
+ ...fallbackLocale !== undefined ? {
41
35
  fallbackLocale
42
36
  } : {},
43
37
  ...locale ? {
44
38
  locale
45
39
  } : {},
46
40
  ...populate ? {
47
- populate: populate
41
+ populate
48
42
  } : {},
49
43
  ...select ? {
50
- select: select
51
- } : {},
52
- ...showHiddenFields !== undefined ? {
53
- showHiddenFields
44
+ select
54
45
  } : {},
55
46
  ...trash !== undefined ? {
56
47
  trash
@@ -60,19 +51,19 @@ export const findVersionByIDTool = defineCollectionTool({
60
51
  content: [
61
52
  {
62
53
  type: 'text',
63
- text: `Version "${id}" from collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
54
+ text: `Version "${id}" from collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
55
  }
65
56
  ],
66
57
  doc: result
67
58
  };
68
59
  } catch (error) {
69
60
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
70
- logger.error(`Error finding version ${id} in ${collectionSlug}: ${errorMessage}`);
61
+ logger.error(`Error finding version ${id} in ${slug}: ${errorMessage}`);
71
62
  return {
72
63
  content: [
73
64
  {
74
65
  type: 'text',
75
- text: `❌ **Error finding version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
66
+ text: `❌ **Error finding version "${id}" in collection "${slug}":** ${errorMessage}`
76
67
  }
77
68
  ],
78
69
  isError: true
@@ -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'\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;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBH,qBAAqB;IACtDI,QAAQ,CAACC,OACPN,cAAcM,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,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,0EACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgBhC,EACbuB,MAAM,GACNC,QAAQ,CAAC,gFACTM,QAAQ;QACXG,QAAQjC,EACLuB,MAAM,GACNC,QAAQ,CACP,wHAEDM,QAAQ;QACXI,UAAUlC,EACPmC,MAAM,CAACnC,EAAEuB,MAAM,IAAIvB,EAAEoC,OAAO,IAC5BZ,QAAQ,CACP,8FAEDM,QAAQ;QACXO,QAAQrC,EACLmC,M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AAQ,QAAQ,CAAC;gBAC7G;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,sBAAsB,EAAEpC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAEgD,cAAc;QAChF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAEhC,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAEgD,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"sourcesContent":["import { findVersionByIDInputSchema } from 'payload'\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) && Boolean(args.permissions?.collections?.[args.slug]?.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: findVersionByIDInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, trash } = input\n\n logger.info(`Finding version in collection: ${slug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id: String(id),\n collection: slug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from collection \"${slug}\":\\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 ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionByIDInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","locale","populate","select","trash","info","result","findVersionByID","String","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,UAAS;AAEpD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBH,qBAAqB;IACtDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEq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ACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CA6I3B,CAAA"}
1
+ {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,4CAyE3B,CAAA"}
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findVersionsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { whereSchema } from '../../../utils/whereSchema.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.';
7
6
  export const findVersionsTool = defineCollectionTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,36 +13,26 @@ export const findVersionsTool = defineCollectionTool({
14
13
  title: 'Find Versions'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in version documents').optional().default(0),
19
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
- limit: z.number().int().min(1).max(100).describe('Maximum number of versions to return (default: 10, max: 100)').optional().default(10),
21
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
- page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
23
- pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
24
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
25
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
26
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in returned version documents').optional(),
27
- sort: z.string().describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)').optional(),
28
- trash: z.boolean().describe('Optional: include versions for soft-deleted documents when trash is enabled').optional(),
29
- where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}').optional()
30
- })
31
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findVersionsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
32
18
  const payload = req.payload;
33
19
  const logger = getLogger({
34
20
  payload
35
21
  });
36
- const { depth, fallbackLocale, limit, locale, page, pagination, populate, select, showHiddenFields, sort, trash, where } = input;
37
- logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`);
22
+ const { depth, draft, fallbackLocale, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
23
+ logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`);
38
24
  try {
39
25
  const result = await payload.findVersions({
40
- collection: collectionSlug,
26
+ collection: slug,
41
27
  depth,
42
28
  limit,
43
29
  overrideAccess: authorizedMCP.overrideAccess,
44
30
  page,
45
31
  req,
46
- ...fallbackLocale ? {
32
+ ...draft !== undefined ? {
33
+ draft
34
+ } : {},
35
+ ...fallbackLocale !== undefined ? {
47
36
  fallbackLocale
48
37
  } : {},
49
38
  ...locale ? {
@@ -53,13 +42,10 @@ export const findVersionsTool = defineCollectionTool({
53
42
  pagination
54
43
  } : {},
55
44
  ...populate ? {
56
- populate: populate
45
+ populate
57
46
  } : {},
58
47
  ...select ? {
59
- select: select
60
- } : {},
61
- ...showHiddenFields !== undefined ? {
62
- showHiddenFields
48
+ select
63
49
  } : {},
64
50
  ...sort ? {
65
51
  sort
@@ -75,19 +61,19 @@ export const findVersionsTool = defineCollectionTool({
75
61
  content: [
76
62
  {
77
63
  type: 'text',
78
- text: `Versions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
+ text: `Versions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
79
65
  }
80
66
  ],
81
67
  doc: result
82
68
  };
83
69
  } catch (error) {
84
70
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
85
- logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`);
71
+ logger.error(`Error finding versions in ${slug}: ${errorMessage}`);
86
72
  return {
87
73
  content: [
88
74
  {
89
75
  type: 'text',
90
- text: `❌ **Error finding versions in collection "${collectionSlug}":** ${errorMessage}`
76
+ text: `❌ **Error finding versions in collection "${slug}":** ${errorMessage}`
91
77
  }
92
78
  ],
93
79
  isError: true
@@ -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 { 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;I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Ae,EAAE,EAAEoD,cAAc;QAC3E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAE/C,eAAe,KAAK,EAAEoD,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import { findVersionsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.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) && Boolean(args.permissions?.collections?.[args.slug]?.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: findVersionsInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n draft,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\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 \"${slug}\":\\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 ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","depth","draft","fallbackLocale","limit","locale","page","pagination","populate","select","sort","trash","where","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,UAAS;AAEjD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBH,qBAAqB;IACnDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IACnC,MAAM,EACJE,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,QAAQ,EACRC,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