@payloadcms/plugin-mcp 4.0.0-canary.0 → 4.0.0-internal.183b315

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 (57) hide show
  1. package/dist/@types/assets.d.js +2 -0
  2. package/dist/@types/assets.d.js.map +1 -0
  3. package/dist/collection/index.d.ts.map +1 -1
  4. package/dist/collection/index.js +2 -1
  5. package/dist/collection/index.js.map +1 -1
  6. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  7. package/dist/mcp/buildMcpServer.js +17 -10
  8. package/dist/mcp/buildMcpServer.js.map +1 -1
  9. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  10. package/dist/mcp/builtin/collections/createTool.js +12 -8
  11. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  12. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  13. package/dist/mcp/builtin/collections/updateTool.js +21 -17
  14. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  15. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  16. package/dist/mcp/builtin/globals/updateTool.js +13 -9
  17. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  18. package/dist/utils/schemaConversion/buildToolInput.d.ts +29 -0
  19. package/dist/utils/schemaConversion/buildToolInput.d.ts.map +1 -0
  20. package/dist/utils/schemaConversion/buildToolInput.js +51 -0
  21. package/dist/utils/schemaConversion/buildToolInput.js.map +1 -0
  22. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
  23. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  24. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
  25. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  26. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -0
  27. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  28. package/package.json +5 -5
  29. package/src/@types/assets.d.ts +3 -0
  30. package/src/collection/index.ts +1 -0
  31. package/src/mcp/buildMcpServer.ts +19 -14
  32. package/src/mcp/builtin/collections/createTool.ts +37 -37
  33. package/src/mcp/builtin/collections/updateTool.ts +54 -49
  34. package/src/mcp/builtin/globals/updateTool.ts +35 -33
  35. package/src/utils/schemaConversion/buildToolInput.ts +68 -0
  36. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
  37. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
  38. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
  39. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
  40. package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
  41. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
  42. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  43. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  44. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  45. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  46. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  47. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  48. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
  49. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  50. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  51. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  52. package/dist/utils/schemaConversion/transformPointFields.js +0 -57
  53. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  54. package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
  55. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  56. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
  57. package/src/utils/schemaConversion/transformPointFields.ts +0 -56
@@ -0,0 +1,158 @@
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-mcp",
3
- "version": "4.0.0-canary.0",
3
+ "version": "4.0.0-internal.183b315",
4
4
  "description": "MCP (Model Context Protocol) capabilities with Payload",
5
5
  "keywords": [
6
6
  "plugin",
@@ -62,13 +62,13 @@
62
62
  "@types/react": "19.2.14",
63
63
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
64
64
  "@payloadcms/eslint-config": "3.28.0",
65
- "payload": "4.0.0-canary.0",
66
- "@payloadcms/ui": "4.0.0-canary.0"
65
+ "@payloadcms/ui": "4.0.0-internal.183b315",
66
+ "payload": "4.0.0-internal.183b315"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
70
- "@payloadcms/ui": "4.0.0-canary.0",
71
- "payload": "4.0.0-canary.0"
70
+ "@payloadcms/ui": "4.0.0-internal.183b315",
71
+ "payload": "4.0.0-internal.183b315"
72
72
  },
73
73
  "//deps_notes": {
74
74
  "zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
@@ -0,0 +1,3 @@
1
+ declare module '*.css'
2
+
3
+ declare module '*.scss'
@@ -55,6 +55,7 @@ export const getAPIKeysCollection = ({
55
55
  plural: 'API Keys',
56
56
  singular: 'API Key',
57
57
  },
58
+ versions: false,
58
59
  }
59
60
 
60
61
  return pluginConfig.overrideApiKeyCollection
@@ -1,5 +1,5 @@
1
1
  import { McpServer, type ServerContext } from '@modelcontextprotocol/server'
2
- import { APIError, configToJSONSchema, type PayloadRequest } from 'payload'
2
+ import { APIError, entityToStandaloneJSONSchema, type PayloadRequest } from 'payload'
3
3
 
4
4
  import type {
5
5
  AuthorizedMCP,
@@ -64,13 +64,6 @@ export const buildMcpServer = ({
64
64
  return rest
65
65
  }
66
66
 
67
- const configSchema = configToJSONSchema(
68
- req.payload.config,
69
- req.payload.db.defaultIDType,
70
- req.i18n,
71
- { forceInlineBlocks: true },
72
- ) as JsonSchemaType
73
-
74
67
  try {
75
68
  for (const item of authorizedMCP.items) {
76
69
  switch (item.type) {
@@ -79,15 +72,20 @@ export const buildMcpServer = ({
79
72
  const name = wireName(item.key, item.collectionSlug)
80
73
  let inputSchema = tool.input
81
74
  if (typeof inputSchema === 'function') {
82
- const raw = configSchema.$defs?.[item.collectionSlug]
83
- if (!raw) {
75
+ const collection = req.payload.collections[item.collectionSlug]?.config
76
+ if (!collection) {
84
77
  throw new APIError(
85
78
  `Collection schema not found for slug: ${item.collectionSlug}`,
86
79
  500,
87
80
  )
88
81
  }
89
82
  const collectionSchema = removeVirtualFieldsFromSchema(
90
- JSON.parse(JSON.stringify(raw)) as JsonSchemaType,
83
+ entityToStandaloneJSONSchema({
84
+ config: req.payload.config,
85
+ defaultIDType: req.payload.db.defaultIDType,
86
+ entity: collection,
87
+ i18n: req.i18n,
88
+ }) as unknown as JsonSchemaType,
91
89
  getCollectionVirtualFieldNames(req.payload.config, item.collectionSlug),
92
90
  )
93
91
  inputSchema = inputSchema({ collectionSchema })
@@ -118,12 +116,19 @@ export const buildMcpServer = ({
118
116
  const name = wireName(item.key, item.globalSlug)
119
117
  let inputSchema = tool.input
120
118
  if (typeof inputSchema === 'function') {
121
- const raw = configSchema.$defs?.[item.globalSlug]
122
- if (!raw) {
119
+ const globalEntity = req.payload.config.globals.find(
120
+ (globalConfig) => globalConfig.slug === item.globalSlug,
121
+ )
122
+ if (!globalEntity) {
123
123
  throw new APIError(`Global schema not found for slug: ${item.globalSlug}`, 500)
124
124
  }
125
125
  const globalSchema = removeVirtualFieldsFromSchema(
126
- JSON.parse(JSON.stringify(raw)) as JsonSchemaType,
126
+ entityToStandaloneJSONSchema({
127
+ config: req.payload.config,
128
+ defaultIDType: req.payload.db.defaultIDType,
129
+ entity: globalEntity,
130
+ i18n: req.i18n,
131
+ }) as unknown as JsonSchemaType,
127
132
  getGlobalVirtualFieldNames(req.payload.config, item.globalSlug),
128
133
  )
129
134
 
@@ -9,7 +9,8 @@ import {
9
9
  stripVirtualFields,
10
10
  } from '../../../utils/getVirtualFieldNames.js'
11
11
  import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
12
- import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
12
+ import { buildToolInput } from '../../../utils/schemaConversion/buildToolInput.js'
13
+ import { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js'
13
14
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
14
15
 
15
16
  const DEFAULT_DESCRIPTION = 'Create a document in a collection.'
@@ -17,41 +18,40 @@ const DEFAULT_DESCRIPTION = 'Create a document in a collection.'
17
18
  export const createCollectionTool = defineCollectionTool({
18
19
  description: DEFAULT_DESCRIPTION,
19
20
  input: ({ collectionSchema }) =>
20
- z.object({
21
- data: z
22
- .fromJSONSchema(
23
- prepareCollectionSchema(collectionSchema) as unknown as z.core.JSONSchema.JSONSchema,
24
- )
25
- .describe('The document fields to create'),
26
- depth: z
27
- .number()
28
- .int()
29
- .min(0)
30
- .max(10)
31
- .describe('How many levels deep to populate relationships in response')
32
- .optional()
33
- .default(0),
34
- draft: z
35
- .boolean()
36
- .describe('Whether to create the document as a draft')
37
- .optional()
38
- .default(false),
39
- fallbackLocale: z
40
- .string()
41
- .describe('Optional: fallback locale code to use when requested locale is not available')
42
- .optional(),
43
- locale: z
44
- .string()
45
- .describe(
46
- 'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
47
- )
48
- .optional(),
49
- select: z
50
- .string()
51
- .describe(
52
- 'Optional: define exactly which fields you\'d like to create (JSON), e.g., \'{"title": "My Post"}\'',
53
- )
54
- .optional(),
21
+ buildToolInput({
22
+ controls: {
23
+ depth: z
24
+ .number()
25
+ .int()
26
+ .min(0)
27
+ .max(10)
28
+ .describe('How many levels deep to populate relationships in response')
29
+ .optional()
30
+ .default(0),
31
+ draft: z
32
+ .boolean()
33
+ .describe('Whether to create the document as a draft')
34
+ .optional()
35
+ .default(false),
36
+ fallbackLocale: z
37
+ .string()
38
+ .describe('Optional: fallback locale code to use when requested locale is not available')
39
+ .optional(),
40
+ locale: z
41
+ .string()
42
+ .describe(
43
+ 'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
44
+ )
45
+ .optional(),
46
+ select: z
47
+ .string()
48
+ .describe(
49
+ 'Optional: define exactly which fields you\'d like to create (JSON), e.g., \'{"title": "My Post"}\'',
50
+ )
51
+ .optional(),
52
+ },
53
+ dataDescription: 'The document fields to create',
54
+ dataSchema: sanitizeEntitySchema(collectionSchema),
55
55
  }),
56
56
  }).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
57
57
  const payload = req.payload
@@ -64,7 +64,7 @@ export const createCollectionTool = defineCollectionTool({
64
64
  )
65
65
 
66
66
  try {
67
- let parsedData = transformPointDataToPayload(data as Record<string, unknown>)
67
+ let parsedData = transformPointDataToPayload(data)
68
68
  const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
69
69
  parsedData = stripVirtualFields(parsedData, virtualFieldNames)
70
70
 
@@ -9,7 +9,8 @@ import {
9
9
  stripVirtualFields,
10
10
  } from '../../../utils/getVirtualFieldNames.js'
11
11
  import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
12
- import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
12
+ import { buildToolInput } from '../../../utils/schemaConversion/buildToolInput.js'
13
+ import { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js'
13
14
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
14
15
 
15
16
  const DEFAULT_DESCRIPTION = 'Update documents in a collection by ID or where clause.'
@@ -17,7 +18,7 @@ const DEFAULT_DESCRIPTION = 'Update documents in a collection by ID or where cla
17
18
  export const updateCollectionTool = defineCollectionTool({
18
19
  description: DEFAULT_DESCRIPTION,
19
20
  input: ({ collectionSchema }) => {
20
- const partialSchema = prepareCollectionSchema(collectionSchema)
21
+ const partialSchema = sanitizeEntitySchema(collectionSchema)
21
22
 
22
23
  // Collection updates do not require all required fields to be passed => delete .required.
23
24
  //
@@ -25,52 +26,56 @@ export const updateCollectionTool = defineCollectionTool({
25
26
  // data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>
26
27
  delete partialSchema.required
27
28
 
28
- return z.object({
29
- id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
30
- data: z
31
- .fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)
32
- .describe('The fields to update'),
33
- depth: z
34
- .number()
35
- .describe('How many levels deep to populate relationships')
36
- .optional()
37
- .default(0),
38
- draft: z
39
- .boolean()
40
- .describe('Whether to update the document as a draft')
41
- .optional()
42
- .default(false),
43
- fallbackLocale: z
44
- .string()
45
- .describe('Optional: fallback locale code to use when requested locale is not available')
46
- .optional(),
47
- filePath: z.string().describe('File path for file uploads').optional(),
48
- locale: z
49
- .string()
50
- .describe(
51
- 'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
52
- )
53
- .optional(),
54
- overrideLock: z
55
- .boolean()
56
- .describe('Whether to override document locks')
57
- .optional()
58
- .default(true),
59
- overwriteExistingFiles: z
60
- .boolean()
61
- .describe('Whether to overwrite existing files')
62
- .optional()
63
- .default(false),
64
- select: z
65
- .string()
66
- .describe(
67
- 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
68
- )
69
- .optional(),
70
- where: z
71
- .string()
72
- .describe('JSON string for where clause to update multiple documents')
73
- .optional(),
29
+ return buildToolInput({
30
+ controls: {
31
+ id: z
32
+ .union([z.string(), z.number()])
33
+ .describe('The ID of the document to update')
34
+ .optional(),
35
+ depth: z
36
+ .number()
37
+ .describe('How many levels deep to populate relationships')
38
+ .optional()
39
+ .default(0),
40
+ draft: z
41
+ .boolean()
42
+ .describe('Whether to update the document as a draft')
43
+ .optional()
44
+ .default(false),
45
+ fallbackLocale: z
46
+ .string()
47
+ .describe('Optional: fallback locale code to use when requested locale is not available')
48
+ .optional(),
49
+ filePath: z.string().describe('File path for file uploads').optional(),
50
+ locale: z
51
+ .string()
52
+ .describe(
53
+ 'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
54
+ )
55
+ .optional(),
56
+ overrideLock: z
57
+ .boolean()
58
+ .describe('Whether to override document locks')
59
+ .optional()
60
+ .default(true),
61
+ overwriteExistingFiles: z
62
+ .boolean()
63
+ .describe('Whether to overwrite existing files')
64
+ .optional()
65
+ .default(false),
66
+ select: z
67
+ .string()
68
+ .describe(
69
+ 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
70
+ )
71
+ .optional(),
72
+ where: z
73
+ .string()
74
+ .describe('JSON string for where clause to update multiple documents')
75
+ .optional(),
76
+ },
77
+ dataDescription: 'The fields to update',
78
+ dataSchema: partialSchema,
74
79
  })
75
80
  },
76
81
  }).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
@@ -102,7 +107,7 @@ export const updateCollectionTool = defineCollectionTool({
102
107
  }
103
108
  }
104
109
 
105
- let parsedData = transformPointDataToPayload(data as Record<string, unknown>)
110
+ let parsedData = transformPointDataToPayload(data)
106
111
  const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
107
112
  parsedData = stripVirtualFields(parsedData, virtualFieldNames)
108
113
 
@@ -9,50 +9,52 @@ import {
9
9
  stripVirtualFields,
10
10
  } from '../../../utils/getVirtualFieldNames.js'
11
11
  import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
12
- import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
12
+ import { buildToolInput } from '../../../utils/schemaConversion/buildToolInput.js'
13
+ import { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js'
13
14
 
14
15
  const DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.'
15
16
 
16
17
  export const updateGlobalTool = defineGlobalTool({
17
18
  description: DEFAULT_DESCRIPTION,
18
19
  input: ({ globalSchema }) => {
19
- const partialSchema = prepareCollectionSchema(globalSchema)
20
+ const partialSchema = sanitizeEntitySchema(globalSchema)
20
21
  // Global updates do not require all required fields to be passed => delete .required.
21
22
  //
22
23
  // Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:
23
24
  // data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>
24
25
  delete partialSchema.required
25
26
 
26
- return z.object({
27
- data: z
28
- .fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)
29
- .describe('The fields to update'),
30
- depth: z
31
- .number()
32
- .describe('Optional: Depth of relationships to populate')
33
- .optional()
34
- .default(0),
35
- draft: z
36
- .boolean()
37
- .describe('Optional: Whether to save as draft (default: false)')
38
- .optional()
39
- .default(false),
40
- fallbackLocale: z
41
- .string()
42
- .describe('Optional: fallback locale code to use when requested locale is not available')
43
- .optional(),
44
- locale: z
45
- .string()
46
- .describe(
47
- 'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
48
- )
49
- .optional(),
50
- select: z
51
- .string()
52
- .describe(
53
- 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'',
54
- )
55
- .optional(),
27
+ return buildToolInput({
28
+ controls: {
29
+ depth: z
30
+ .number()
31
+ .describe('Optional: Depth of relationships to populate')
32
+ .optional()
33
+ .default(0),
34
+ draft: z
35
+ .boolean()
36
+ .describe('Optional: Whether to save as draft (default: false)')
37
+ .optional()
38
+ .default(false),
39
+ fallbackLocale: z
40
+ .string()
41
+ .describe('Optional: fallback locale code to use when requested locale is not available')
42
+ .optional(),
43
+ locale: z
44
+ .string()
45
+ .describe(
46
+ 'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
47
+ )
48
+ .optional(),
49
+ select: z
50
+ .string()
51
+ .describe(
52
+ 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'',
53
+ )
54
+ .optional(),
55
+ },
56
+ dataDescription: 'The fields to update',
57
+ dataSchema: partialSchema,
56
58
  })
57
59
  },
58
60
  }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
@@ -67,7 +69,7 @@ export const updateGlobalTool = defineGlobalTool({
67
69
 
68
70
  try {
69
71
  const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
70
- const parsedData = stripVirtualFields(data as Record<string, unknown>, virtualFieldNames)
72
+ const parsedData = stripVirtualFields(data, virtualFieldNames)
71
73
 
72
74
  let selectClause: SelectType | undefined
73
75
  if (select) {