@payloadcms/plugin-mcp 4.0.0-internal.4cbdd50 → 4.0.0-internal.4e1f822

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 (202) 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 +6 -13
  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 +5 -5
  19. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  20. package/dist/mcp/buildMcpServer.js +67 -33
  21. package/dist/mcp/buildMcpServer.js.map +1 -1
  22. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  23. package/dist/mcp/builtin/collections/authTools.js +79 -56
  24. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  25. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  26. package/dist/mcp/builtin/collections/countTool.js +10 -16
  27. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  28. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  29. package/dist/mcp/builtin/collections/countVersionsTool.js +10 -15
  30. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  31. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  32. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  33. package/dist/mcp/builtin/collections/createTool.js +104 -54
  34. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  35. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  36. package/dist/mcp/builtin/collections/deleteTool.js +41 -45
  37. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  38. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  39. package/dist/mcp/builtin/collections/duplicateTool.js +27 -38
  40. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  41. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  42. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  43. package/dist/mcp/builtin/collections/fileInput.js +123 -0
  44. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  45. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  46. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  47. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/findDistinctTool.js +12 -28
  49. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  51. package/dist/mcp/builtin/collections/findTool.js +23 -46
  52. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  53. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  54. package/dist/mcp/builtin/collections/findVersionByIDTool.js +18 -28
  55. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  56. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/findVersionsTool.js +17 -32
  58. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  59. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  60. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +51 -11
  61. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  62. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  63. package/dist/mcp/builtin/collections/restoreVersionTool.js +15 -28
  64. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  65. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  66. package/dist/mcp/builtin/collections/updateTool.js +62 -86
  67. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  68. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  69. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  70. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  71. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  72. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  73. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  74. package/dist/mcp/builtin/formatEntityError.js +55 -0
  75. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  76. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/getConfigInfoTool.js +5 -7
  78. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/countVersionsTool.js +10 -15
  81. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  82. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  83. package/dist/mcp/builtin/globals/findTool.js +12 -18
  84. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  85. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  86. package/dist/mcp/builtin/globals/findVersionByIDTool.js +14 -26
  87. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  88. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  89. package/dist/mcp/builtin/globals/findVersionsTool.js +14 -31
  90. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  91. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +28 -10
  93. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  94. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  95. package/dist/mcp/builtin/globals/restoreVersionTool.js +16 -24
  96. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  97. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  98. package/dist/mcp/builtin/globals/updateTool.js +28 -37
  99. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  100. package/dist/mcp/builtinTools.d.ts +6 -0
  101. package/dist/mcp/builtinTools.d.ts.map +1 -1
  102. package/dist/mcp/builtinTools.js +9 -3
  103. package/dist/mcp/builtinTools.js.map +1 -1
  104. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  105. package/dist/mcp/sanitizeMCPConfig.js +5 -1
  106. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  107. package/dist/stdio.d.ts +3 -4
  108. package/dist/stdio.d.ts.map +1 -1
  109. package/dist/stdio.js +61 -42
  110. package/dist/stdio.js.map +1 -1
  111. package/dist/types.d.ts +61 -13
  112. package/dist/types.d.ts.map +1 -1
  113. package/dist/types.js +2 -4
  114. package/dist/types.js.map +1 -1
  115. package/dist/utils/camelCase.d.ts.map +1 -1
  116. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  117. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  118. package/package.json +8 -12
  119. package/src/endpoint/access.ts +5 -13
  120. package/src/endpoint/index.ts +45 -16
  121. package/src/index.ts +4 -4
  122. package/src/mcp/buildMcpServer.ts +79 -49
  123. package/src/mcp/builtin/collections/authTools.ts +77 -69
  124. package/src/mcp/builtin/collections/countTool.ts +10 -23
  125. package/src/mcp/builtin/collections/countVersionsTool.ts +10 -20
  126. package/src/mcp/builtin/collections/createTool.ts +110 -77
  127. package/src/mcp/builtin/collections/deleteTool.ts +36 -65
  128. package/src/mcp/builtin/collections/duplicateTool.ts +34 -86
  129. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  130. package/src/mcp/builtin/collections/fileInput.ts +169 -0
  131. package/src/mcp/builtin/collections/findDistinctTool.ts +12 -65
  132. package/src/mcp/builtin/collections/findTool.ts +23 -106
  133. package/src/mcp/builtin/collections/findVersionByIDTool.ts +16 -60
  134. package/src/mcp/builtin/collections/findVersionsTool.ts +15 -87
  135. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +48 -14
  136. package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -58
  137. package/src/mcp/builtin/collections/updateTool.ts +61 -100
  138. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  139. package/src/mcp/builtin/formatEntityError.ts +77 -0
  140. package/src/mcp/builtin/getConfigInfoTool.ts +4 -5
  141. package/src/mcp/builtin/globals/countVersionsTool.ts +10 -19
  142. package/src/mcp/builtin/globals/findTool.ts +14 -53
  143. package/src/mcp/builtin/globals/findVersionByIDTool.ts +14 -54
  144. package/src/mcp/builtin/globals/findVersionsTool.ts +15 -94
  145. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +30 -8
  146. package/src/mcp/builtin/globals/restoreVersionTool.ts +15 -47
  147. package/src/mcp/builtin/globals/updateTool.ts +39 -62
  148. package/src/mcp/builtinTools.ts +9 -2
  149. package/src/mcp/sanitizeMCPConfig.ts +5 -1
  150. package/src/stdio.ts +61 -43
  151. package/src/types.ts +61 -13
  152. package/dist/@types/assets.d.js +0 -2
  153. package/dist/@types/assets.d.js.map +0 -1
  154. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  155. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  156. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  157. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  158. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  159. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  160. package/dist/mcp/builtin/validateEntityData.js +0 -82
  161. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  162. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  163. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  164. package/dist/utils/getVirtualFieldNames.js +0 -35
  165. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  166. package/dist/utils/localAPIDefaults.d.ts +0 -20
  167. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  168. package/dist/utils/localAPIDefaults.js +0 -19
  169. package/dist/utils/localAPIDefaults.js.map +0 -1
  170. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
  171. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  172. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
  173. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  174. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  175. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  176. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  177. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  178. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
  179. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  180. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
  181. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  182. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
  183. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  184. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  185. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  186. package/dist/utils/transformPointDataToPayload.js +0 -28
  187. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  188. package/dist/utils/whereSchema.d.ts +0 -9
  189. package/dist/utils/whereSchema.d.ts.map +0 -1
  190. package/dist/utils/whereSchema.js +0 -13
  191. package/dist/utils/whereSchema.js.map +0 -1
  192. package/src/@types/assets.d.ts +0 -3
  193. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  194. package/src/mcp/builtin/validateEntityData.ts +0 -132
  195. package/src/utils/getVirtualFieldNames.ts +0 -53
  196. package/src/utils/localAPIDefaults.ts +0 -22
  197. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
  198. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  199. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
  200. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
  201. package/src/utils/transformPointDataToPayload.ts +0 -40
  202. package/src/utils/whereSchema.ts +0 -24
@@ -1,158 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { sanitizeEntitySchema } from './sanitizeEntitySchema.js';
3
- describe('sanitizeEntitySchema', ()=>{
4
- it('keeps a Lexical node union strict (oneOf) while simplifying relationship values to IDs', ()=>{
5
- // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field:
6
- // a `$defs` node union (a `oneOf` of node shapes) where a relationship node's `value` is either
7
- // an ID or a `$ref` to the populated related collection.
8
- const standalone = {
9
- type: 'object',
10
- $defs: {
11
- LexicalNodes_ABCDEF12: {
12
- oneOf: [
13
- {
14
- type: 'object',
15
- additionalProperties: false,
16
- properties: {
17
- type: {
18
- const: 'paragraph'
19
- }
20
- },
21
- required: [
22
- 'type'
23
- ]
24
- },
25
- {
26
- type: 'object',
27
- additionalProperties: false,
28
- properties: {
29
- type: {
30
- const: 'relationship'
31
- },
32
- value: {
33
- oneOf: [
34
- {
35
- type: 'string'
36
- },
37
- {
38
- $ref: '#/$defs/posts'
39
- }
40
- ]
41
- }
42
- },
43
- required: [
44
- 'type'
45
- ]
46
- }
47
- ]
48
- },
49
- posts: {
50
- type: 'object',
51
- additionalProperties: false,
52
- properties: {
53
- id: {
54
- type: 'string'
55
- },
56
- title: {
57
- type: 'string'
58
- }
59
- }
60
- }
61
- },
62
- properties: {
63
- id: {
64
- type: 'string'
65
- },
66
- content: {
67
- type: 'object',
68
- properties: {
69
- root: {
70
- type: 'object',
71
- properties: {
72
- children: {
73
- type: 'array',
74
- items: {
75
- $ref: '#/$defs/LexicalNodes_ABCDEF12'
76
- }
77
- }
78
- }
79
- }
80
- }
81
- }
82
- }
83
- };
84
- expect(sanitizeEntitySchema(standalone)).toStrictEqual({
85
- type: 'object',
86
- $defs: {
87
- // The node union is renamed to a short, readable `node`, and stays a strict discriminated
88
- // `oneOf` - not loosened to `anyOf`...
89
- node: {
90
- oneOf: [
91
- {
92
- type: 'object',
93
- additionalProperties: false,
94
- properties: {
95
- type: {
96
- const: 'paragraph'
97
- }
98
- },
99
- required: [
100
- 'type'
101
- ]
102
- },
103
- {
104
- type: 'object',
105
- additionalProperties: false,
106
- properties: {
107
- type: {
108
- const: 'relationship'
109
- },
110
- // ...while the relationship `value` is simplified to a bare ID (the populated-doc `$ref` is dropped).
111
- value: {
112
- type: 'string',
113
- description: 'The ID of the related "posts" document.'
114
- }
115
- },
116
- required: [
117
- 'type'
118
- ]
119
- }
120
- ]
121
- },
122
- posts: {
123
- type: 'object',
124
- additionalProperties: false,
125
- properties: {
126
- id: {
127
- type: 'string'
128
- },
129
- title: {
130
- type: 'string'
131
- }
132
- }
133
- }
134
- },
135
- properties: {
136
- // `id` is dropped - it's a Payload-managed field MCP clients never set.
137
- content: {
138
- type: 'object',
139
- properties: {
140
- root: {
141
- type: 'object',
142
- properties: {
143
- children: {
144
- type: 'array',
145
- items: {
146
- $ref: '#/$defs/node'
147
- }
148
- }
149
- }
150
- }
151
- }
152
- }
153
- }
154
- });
155
- });
156
- });
157
-
158
- //# sourceMappingURL=sanitizeEntitySchema.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\ndescribe('sanitizeEntitySchema', () => {\n it('keeps a Lexical node union strict (oneOf) while simplifying relationship values to IDs', () => {\n // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field:\n // a `$defs` node union (a `oneOf` of node shapes) where a relationship node's `value` is either\n // an ID or a `$ref` to the populated related collection.\n const standalone: JsonSchemaType = {\n type: 'object',\n $defs: {\n LexicalNodes_ABCDEF12: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n value: { oneOf: [{ type: 'string' }, { $ref: '#/$defs/posts' }] },\n },\n required: ['type'],\n },\n ],\n },\n posts: {\n type: 'object',\n additionalProperties: false,\n properties: { id: { type: 'string' }, title: { type: 'string' } },\n },\n },\n properties: {\n id: { type: 'string' },\n content: {\n type: 'object',\n properties: {\n root: {\n type: 'object',\n properties: {\n children: { type: 'array', items: { $ref: '#/$defs/LexicalNodes_ABCDEF12' } },\n },\n },\n },\n },\n },\n }\n\n expect(sanitizeEntitySchema(standalone)).toStrictEqual({\n type: 'object',\n $defs: {\n // The node union is renamed to a short, readable `node`, and stays a strict discriminated\n // `oneOf` - not loosened to `anyOf`...\n node: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n // ...while the relationship `value` is simplified to a bare ID (the populated-doc `$ref` is dropped).\n value: { type: 'string', description: 'The ID of the related \"posts\" document.' },\n },\n required: ['type'],\n },\n ],\n },\n posts: {\n type: 'object',\n additionalProperties: false,\n properties: { id: { type: 'string' }, title: { type: 'string' } },\n },\n },\n properties: {\n // `id` is dropped - it's a Payload-managed field MCP clients never set.\n content: {\n type: 'object',\n properties: {\n root: {\n type: 'object',\n properties: {\n children: { type: 'array', items: { $ref: '#/$defs/node' } },\n },\n },\n },\n },\n },\n })\n })\n})\n"],"names":["describe","expect","it","sanitizeEntitySchema","standalone","type","$defs","LexicalNodes_ABCDEF12","oneOf","additionalProperties","properties","const","required","value","$ref","posts","id","title","content","root","children","items","toStrictEqual","node","description"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAI7C,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhEH,SAAS,wBAAwB;IAC/BE,GAAG,0FAA0F;QAC3F,iGAAiG;QACjG,gGAAgG;QAChG,yDAAyD;QACzD,MAAME,aAA6B;YACjCC,MAAM;YACNC,OAAO;gBACLC,uBAAuB;oBACrBC,OAAO;wBACL;4BACEH,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCAAEL,MAAM;oCAAEM,OAAO;gCAAY;4BAAE;4BAC3CC,UAAU;gCAAC;6BAAO;wBACpB;wBACA;4BACEP,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCACVL,MAAM;oCAAEM,OAAO;gCAAe;gCAC9BE,OAAO;oCAAEL,OAAO;wCAAC;4CAAEH,MAAM;wCAAS;wCAAG;4CAAES,MAAM;wCAAgB;qCAAE;gCAAC;4BAClE;4BACAF,UAAU;gCAAC;6BAAO;wBACpB;qBACD;gBACH;gBACAG,OAAO;oBACLV,MAAM;oBACNI,sBAAsB;oBACtBC,YAAY;wBAAEM,IAAI;4BAAEX,MAAM;wBAAS;wBAAGY,OAAO;4BAAEZ,MAAM;wBAAS;oBAAE;gBAClE;YACF;YACAK,YAAY;gBACVM,IAAI;oBAAEX,MAAM;gBAAS;gBACrBa,SAAS;oBACPb,MAAM;oBACNK,YAAY;wBACVS,MAAM;4BACJd,MAAM;4BACNK,YAAY;gCACVU,UAAU;oCAAEf,MAAM;oCAASgB,OAAO;wCAAEP,MAAM;oCAAgC;gCAAE;4BAC9E;wBACF;oBACF;gBACF;YACF;QACF;QAEAb,OAAOE,qBAAqBC,aAAakB,aAAa,CAAC;YACrDjB,MAAM;YACNC,OAAO;gBACL,0FAA0F;gBAC1F,uCAAuC;gBACvCiB,MAAM;oBACJf,OAAO;wBACL;4BACEH,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCAAEL,MAAM;oCAAEM,OAAO;gCAAY;4BAAE;4BAC3CC,UAAU;gCAAC;6BAAO;wBACpB;wBACA;4BACEP,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCACVL,MAAM;oCAAEM,OAAO;gCAAe;gCAC9B,sGAAsG;gCACtGE,OAAO;oCAAER,MAAM;oCAAUmB,aAAa;gCAA0C;4BAClF;4BACAZ,UAAU;gCAAC;6BAAO;wBACpB;qBACD;gBACH;gBACAG,OAAO;oBACLV,MAAM;oBACNI,sBAAsB;oBACtBC,YAAY;wBAAEM,IAAI;4BAAEX,MAAM;wBAAS;wBAAGY,OAAO;4BAAEZ,MAAM;wBAAS;oBAAE;gBAClE;YACF;YACAK,YAAY;gBACV,wEAAwE;gBACxEQ,SAAS;oBACPb,MAAM;oBACNK,YAAY;wBACVS,MAAM;4BACJd,MAAM;4BACNK,YAAY;gCACVU,UAAU;oCAAEf,MAAM;oCAASgB,OAAO;wCAAEP,MAAM;oCAAe;gCAAE;4BAC7D;wBACF;oBACF;gBACF;YACF;QACF;IACF;AACF"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Transforms incoming MCP tool data from object format to tuple array format.
3
- * Converts { longitude: number, latitude: number } back to [longitude, latitude]
4
- * for Payload's internal point field representation.
5
- */
6
- export declare function transformPointDataToPayload(data: Record<string, unknown>): Record<string, unknown>;
7
- //# sourceMappingURL=transformPointDataToPayload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformPointDataToPayload.d.ts","sourceRoot":"","sources":["../../src/utils/transformPointDataToPayload.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgCzB"}
@@ -1,28 +0,0 @@
1
- /**
2
- * Transforms incoming MCP tool data from object format to tuple array format.
3
- * Converts { longitude: number, latitude: number } back to [longitude, latitude]
4
- * for Payload's internal point field representation.
5
- */ export function transformPointDataToPayload(data) {
6
- if (!data || typeof data !== 'object') {
7
- return data;
8
- }
9
- const transformed = {};
10
- for (const [key, value] of Object.entries(data)){
11
- if (value && typeof value === 'object' && 'longitude' in value && 'latitude' in value && typeof value.longitude === 'number' && typeof value.latitude === 'number') {
12
- // Transform to tuple array [longitude, latitude]
13
- transformed[key] = [
14
- value.longitude,
15
- value.latitude
16
- ];
17
- } else if (Array.isArray(value)) {
18
- transformed[key] = value.map((item)=>typeof item === 'object' ? transformPointDataToPayload(item) : item);
19
- } else if (value && typeof value === 'object') {
20
- transformed[key] = transformPointDataToPayload(value);
21
- } else {
22
- transformed[key] = value;
23
- }
24
- }
25
- return transformed;
26
- }
27
-
28
- //# sourceMappingURL=transformPointDataToPayload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/transformPointDataToPayload.ts"],"sourcesContent":["/**\n * Transforms incoming MCP tool data from object format to tuple array format.\n * Converts { longitude: number, latitude: number } back to [longitude, latitude]\n * for Payload's internal point field representation.\n */\nexport function transformPointDataToPayload(\n data: Record<string, unknown>,\n): Record<string, unknown> {\n if (!data || typeof data !== 'object') {\n return data\n }\n\n const transformed: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(data)) {\n if (\n value &&\n typeof value === 'object' &&\n 'longitude' in value &&\n 'latitude' in value &&\n typeof value.longitude === 'number' &&\n typeof value.latitude === 'number'\n ) {\n // Transform to tuple array [longitude, latitude]\n transformed[key] = [value.longitude, value.latitude]\n } else if (Array.isArray(value)) {\n transformed[key] = value.map((item) =>\n typeof item === 'object'\n ? transformPointDataToPayload(item as Record<string, unknown>)\n : item,\n )\n } else if (value && typeof value === 'object') {\n transformed[key] = transformPointDataToPayload(value as Record<string, unknown>)\n } else {\n transformed[key] = value\n }\n }\n\n return transformed\n}\n"],"names":["transformPointDataToPayload","data","transformed","key","value","Object","entries","longitude","latitude","Array","isArray","map","item"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,4BACdC,IAA6B;IAE7B,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;QACrC,OAAOA;IACT;IAEA,MAAMC,cAAuC,CAAC;IAE9C,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,MAAO;QAC/C,IACEG,SACA,OAAOA,UAAU,YACjB,eAAeA,SACf,cAAcA,SACd,OAAOA,MAAMG,SAAS,KAAK,YAC3B,OAAOH,MAAMI,QAAQ,KAAK,UAC1B;YACA,iDAAiD;YACjDN,WAAW,CAACC,IAAI,GAAG;gBAACC,MAAMG,SAAS;gBAAEH,MAAMI,QAAQ;aAAC;QACtD,OAAO,IAAIC,MAAMC,OAAO,CAACN,QAAQ;YAC/BF,WAAW,CAACC,IAAI,GAAGC,MAAMO,GAAG,CAAC,CAACC,OAC5B,OAAOA,SAAS,WACZZ,4BAA4BY,QAC5BA;QAER,OAAO,IAAIR,SAAS,OAAOA,UAAU,UAAU;YAC7CF,WAAW,CAACC,IAAI,GAAGH,4BAA4BI;QACjD,OAAO;YACLF,WAAW,CAACC,IAAI,GAAGC;QACrB;IACF;IAEA,OAAOF;AACT"}
@@ -1,9 +0,0 @@
1
- import type { Where } from 'payload';
2
- import { z } from 'zod';
3
- /**
4
- * - Validates the `where` input of collection tools against Payload's `Where` shape
5
- * - Field keys map to operator objects restricted to `validOperators`
6
- * - `and` / `or` nest recursively
7
- */
8
- export declare const whereSchema: z.ZodType<Where>;
9
- //# sourceMappingURL=whereSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"whereSchema.d.ts","sourceRoot":"","sources":["../../src/utils/whereSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CASqD,CAAA"}
@@ -1,13 +0,0 @@
1
- import { validOperators } from 'payload/shared';
2
- import { z } from 'zod';
3
- const whereFieldSchema = z.partialRecord(z.enum(validOperators), z.unknown()).describe('Field query operators');
4
- /**
5
- * - Validates the `where` input of collection tools against Payload's `Where` shape
6
- * - Field keys map to operator objects restricted to `validOperators`
7
- * - `and` / `or` nest recursively
8
- */ export const whereSchema = z.lazy(()=>z.object({
9
- and: z.array(whereSchema).optional(),
10
- or: z.array(whereSchema).optional()
11
- }).catchall(whereFieldSchema)).describe('Where clause using field names with Payload query operators, plus and/or groups');
12
-
13
- //# sourceMappingURL=whereSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/whereSchema.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nimport { validOperators } from 'payload/shared'\nimport { z } from 'zod'\n\nconst whereFieldSchema = z\n .partialRecord(z.enum(validOperators), z.unknown())\n .describe('Field query operators')\n\n/**\n * - Validates the `where` input of collection tools against Payload's `Where` shape\n * - Field keys map to operator objects restricted to `validOperators`\n * - `and` / `or` nest recursively\n */\nexport const whereSchema: z.ZodType<Where> = z\n .lazy(() =>\n z\n .object({\n and: z.array(whereSchema).optional(),\n or: z.array(whereSchema).optional(),\n })\n .catchall(whereFieldSchema),\n )\n .describe('Where clause using field names with Payload query operators, plus and/or groups')\n"],"names":["validOperators","z","whereFieldSchema","partialRecord","enum","unknown","describe","whereSchema","lazy","object","and","array","optional","or","catchall"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAC/C,SAASC,CAAC,QAAQ,MAAK;AAEvB,MAAMC,mBAAmBD,EACtBE,aAAa,CAACF,EAAEG,IAAI,CAACJ,iBAAiBC,EAAEI,OAAO,IAC/CC,QAAQ,CAAC;AAEZ;;;;CAIC,GACD,OAAO,MAAMC,cAAgCN,EAC1CO,IAAI,CAAC,IACJP,EACGQ,MAAM,CAAC;QACNC,KAAKT,EAAEU,KAAK,CAACJ,aAAaK,QAAQ;QAClCC,IAAIZ,EAAEU,KAAK,CAACJ,aAAaK,QAAQ;IACnC,GACCE,QAAQ,CAACZ,mBAEbI,QAAQ,CAAC,mFAAkF"}
@@ -1,3 +0,0 @@
1
- declare module '*.css'
2
-
3
- declare module '*.scss'
@@ -1,84 +0,0 @@
1
- import type { CollectionSlug, PayloadRequest } from 'payload'
2
-
3
- import type { MCPToolResponse } from '../../../types.js'
4
-
5
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
6
-
7
- const getValidationErrors = (error: unknown): undefined | unknown[] => {
8
- if (!error || typeof error !== 'object') {
9
- return undefined
10
- }
11
-
12
- const data = 'data' in error ? error.data : undefined
13
- if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
14
- return undefined
15
- }
16
-
17
- return data.errors
18
- }
19
-
20
- const isSchemaError = (error: unknown, message: string): boolean => {
21
- if (getValidationErrors(error)) {
22
- return true
23
- }
24
-
25
- const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined
26
-
27
- return (
28
- name === 'CastError' ||
29
- name === 'ValidationError' ||
30
- message.includes('Cast to ') ||
31
- message.includes('validation failed')
32
- )
33
- }
34
-
35
- export const formatCollectionError = ({
36
- action,
37
- collectionSlug,
38
- error,
39
- req,
40
- }: {
41
- action: 'creating' | 'duplicating' | 'updating'
42
- collectionSlug: CollectionSlug
43
- error: unknown
44
- req: PayloadRequest
45
- }): MCPToolResponse => {
46
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
47
- const errors = getValidationErrors(error) ?? [{ message: errorMessage }]
48
-
49
- if (!isSchemaError(error, errorMessage)) {
50
- return {
51
- content: [
52
- {
53
- type: 'text',
54
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`,
55
- },
56
- ],
57
- isError: true,
58
- }
59
- }
60
-
61
- const schema = getCollectionInputSchema({ collectionSlug, req })
62
- const schemaText = schema
63
- ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
64
- : ''
65
-
66
- return {
67
- content: [
68
- {
69
- type: 'text',
70
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`,
71
- },
72
- ],
73
- isError: true,
74
- ...(schema
75
- ? {
76
- structuredContent: {
77
- collectionSlug,
78
- errors,
79
- schema,
80
- },
81
- }
82
- : {}),
83
- }
84
- }
@@ -1,132 +0,0 @@
1
- import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
2
-
3
- import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'
4
-
5
- import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
6
-
7
- import {
8
- getCollectionInputSchema,
9
- getGlobalInputSchema,
10
- } from '../../utils/schemaConversion/getEntityInputSchema.js'
11
-
12
- /**
13
- * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
14
- */
15
- const validator = new CfWorkerJsonSchemaValidator({ shortcircuit: true })
16
-
17
- type EntityValidator = {
18
- schema: JsonSchemaType
19
- validate: ReturnType<(typeof validator)['getValidator']>
20
- }
21
-
22
- /**
23
- * - Caches each entity's schema and validator, so both are only built on the first request.
24
- * - Keyed by payload config, then by entity type, slug, partial and language.
25
- */
26
- const validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()
27
-
28
- export const validateCollectionData = ({
29
- collectionSlug,
30
- data,
31
- partial,
32
- req,
33
- }: {
34
- collectionSlug: CollectionSlug
35
- data: Record<string, unknown>
36
- partial?: boolean
37
- req: PayloadRequest
38
- }): MCPToolResponse | null =>
39
- validateData({
40
- slug: collectionSlug,
41
- buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
42
- data,
43
- entity: 'collection',
44
- partial,
45
- req,
46
- })
47
-
48
- export const validateGlobalData = ({
49
- data,
50
- globalSlug,
51
- req,
52
- }: {
53
- data: Record<string, unknown>
54
- globalSlug: GlobalSlug
55
- req: PayloadRequest
56
- }): MCPToolResponse | null =>
57
- validateData({
58
- slug: globalSlug,
59
- buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
60
- data,
61
- entity: 'global',
62
- partial: true,
63
- req,
64
- })
65
-
66
- const validateData = ({
67
- slug,
68
- buildSchema,
69
- data,
70
- entity,
71
- partial,
72
- req,
73
- }: {
74
- buildSchema: () => JsonSchemaType | null
75
- data: Record<string, unknown>
76
- entity: 'collection' | 'global'
77
- partial?: boolean
78
- req: PayloadRequest
79
- slug: string
80
- }): MCPToolResponse | null => {
81
- let cache = validatorCache.get(req.payload.config)
82
- if (!cache) {
83
- cache = new Map()
84
- validatorCache.set(req.payload.config, cache)
85
- }
86
-
87
- const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`
88
- let entityValidator = cache.get(cacheKey)
89
-
90
- if (!entityValidator) {
91
- const schema = buildSchema()
92
-
93
- if (!schema) {
94
- return null
95
- }
96
-
97
- entityValidator = {
98
- schema,
99
- validate: validator.getValidator(partial ? withoutRequired(schema) : schema),
100
- }
101
- cache.set(cacheKey, entityValidator)
102
- }
103
-
104
- const result = entityValidator.validate(data)
105
-
106
- if (result.valid) {
107
- return null
108
- }
109
-
110
- const { schema } = entityValidator
111
-
112
- return {
113
- content: [
114
- {
115
- type: 'text',
116
- text: `Invalid data for ${entity} "${slug}": ${result.errorMessage}\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``,
117
- },
118
- ],
119
- isError: true,
120
- structuredContent: {
121
- [`${entity}Slug`]: slug,
122
- errors: [{ message: result.errorMessage }],
123
- schema,
124
- },
125
- }
126
- }
127
-
128
- /** Updates are partial — drop the schema's top-level `required` before validating. */
129
- const withoutRequired = (schema: JsonSchemaType): JsonSchemaType => {
130
- const { required: _required, ...rest } = schema
131
- return rest
132
- }
@@ -1,53 +0,0 @@
1
- import type { SanitizedConfig } from 'payload'
2
-
3
- import { fieldIsVirtual } from 'payload/shared'
4
-
5
- /**
6
- * Returns the names of all top-level virtual fields for a given collection slug.
7
- */
8
- export function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {
9
- const collection = config.collections.find((c) => c.slug === slug)
10
-
11
- if (!collection) {
12
- return []
13
- }
14
-
15
- return collection.flattenedFields
16
- .filter((field) => 'name' in field && fieldIsVirtual(field))
17
- .map((field) => (field as { name: string }).name)
18
- }
19
-
20
- /**
21
- * Returns the names of all top-level virtual fields for a given global slug.
22
- */
23
- export function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {
24
- const global = config.globals.find((g) => g.slug === slug)
25
-
26
- if (!global) {
27
- return []
28
- }
29
-
30
- return global.flattenedFields
31
- .filter((field) => 'name' in field && fieldIsVirtual(field))
32
- .map((field) => (field as { name: string }).name)
33
- }
34
-
35
- /**
36
- * Strips virtual field values from a data object given a list of virtual field names.
37
- */
38
- export function stripVirtualFields(
39
- data: Record<string, unknown>,
40
- virtualFieldNames: string[],
41
- ): Record<string, unknown> {
42
- if (virtualFieldNames.length === 0) {
43
- return data
44
- }
45
-
46
- const stripped = { ...data }
47
-
48
- for (const name of virtualFieldNames) {
49
- delete stripped[name]
50
- }
51
-
52
- return stripped
53
- }
@@ -1,22 +0,0 @@
1
- import type { AuthorizedMCP } from '../types.js'
2
-
3
- /**
4
- * Returns the `user` and `overrideAccess` arguments every Payload local API call
5
- * should receive when initiated from an MCP request. Spread the result into the
6
- * call's arg object so the two pieces of caller state can't drift apart.
7
- *
8
- * @example
9
- * ```ts
10
- * await req.payload.create({
11
- * collection: 'posts',
12
- * data,
13
- * ...localAPIDefaults(authorizedMCP),
14
- * })
15
- * ```
16
- */
17
- export const localAPIDefaults = (
18
- authorizedMCP: AuthorizedMCP,
19
- ): { overrideAccess: boolean; user: AuthorizedMCP['user'] } => ({
20
- overrideAccess: authorizedMCP.overrideAccess,
21
- user: authorizedMCP.user,
22
- })
@@ -1,78 +0,0 @@
1
- import {
2
- type CollectionSlug,
3
- entityToStandaloneJSONSchema,
4
- type GlobalSlug,
5
- type PayloadRequest,
6
- type SanitizedCollectionConfig,
7
- type SanitizedGlobalConfig,
8
- } from 'payload'
9
-
10
- import type { JsonSchemaType } from '../../types.js'
11
-
12
- import {
13
- getCollectionVirtualFieldNames,
14
- getGlobalVirtualFieldNames,
15
- } from '../getVirtualFieldNames.js'
16
- import { removeVirtualFieldsFromSchema } from './removeVirtualFieldsFromSchema.js'
17
- import { sanitizeEntitySchema } from './sanitizeEntitySchema.js'
18
-
19
- export const getCollectionInputSchema = ({
20
- collectionSlug,
21
- req,
22
- }: {
23
- collectionSlug: CollectionSlug
24
- req: PayloadRequest
25
- }): JsonSchemaType | null => {
26
- const collection = req.payload.collections[collectionSlug]?.config
27
-
28
- if (!collection) {
29
- return null
30
- }
31
-
32
- return buildEntityInputSchema({
33
- entity: collection,
34
- req,
35
- virtualFieldNames: getCollectionVirtualFieldNames(req.payload.config, collectionSlug),
36
- })
37
- }
38
-
39
- export const getGlobalInputSchema = ({
40
- globalSlug,
41
- req,
42
- }: {
43
- globalSlug: GlobalSlug
44
- req: PayloadRequest
45
- }): JsonSchemaType | null => {
46
- const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)
47
-
48
- if (!global) {
49
- return null
50
- }
51
-
52
- return buildEntityInputSchema({
53
- entity: global,
54
- req,
55
- virtualFieldNames: getGlobalVirtualFieldNames(req.payload.config, globalSlug),
56
- })
57
- }
58
-
59
- const buildEntityInputSchema = ({
60
- entity,
61
- req,
62
- virtualFieldNames,
63
- }: {
64
- entity: SanitizedCollectionConfig | SanitizedGlobalConfig
65
- req: PayloadRequest
66
- virtualFieldNames: string[]
67
- }): JsonSchemaType =>
68
- sanitizeEntitySchema(
69
- removeVirtualFieldsFromSchema(
70
- entityToStandaloneJSONSchema({
71
- config: req.payload.config,
72
- defaultIDType: req.payload.db.defaultIDType,
73
- entity,
74
- i18n: req.i18n,
75
- }) as unknown as JsonSchemaType,
76
- virtualFieldNames,
77
- ),
78
- )
@@ -1,27 +0,0 @@
1
- import type { JsonSchemaType } from '../../types.js'
2
-
3
- /**
4
- * Removes virtual fields from a JSON Schema by name so they don't appear
5
- * in the generated MCP tool input schema.
6
- */
7
- export function removeVirtualFieldsFromSchema(
8
- schema: JsonSchemaType,
9
- virtualFieldNames: string[],
10
- ): JsonSchemaType {
11
- if (virtualFieldNames.length === 0) {
12
- return schema
13
- }
14
-
15
- for (const name of virtualFieldNames) {
16
- delete schema?.properties?.[name]
17
- }
18
-
19
- if (Array.isArray(schema.required)) {
20
- schema.required = schema.required.filter((field) => !virtualFieldNames.includes(field))
21
- if (schema.required.length === 0) {
22
- delete schema.required
23
- }
24
- }
25
-
26
- return schema
27
- }