@payloadcms/plugin-mcp 3.73.0-internal.783bc97 → 3.73.0-internal.dd5902a

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.
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import type { JSONSchema4 } from 'json-schema'
3
- import type { PayloadRequest, TypedUser } from 'payload'
3
+ import type { PayloadRequest, SelectType, TypedUser } from 'payload'
4
4
 
5
5
  import { z } from 'zod'
6
6
 
@@ -25,6 +25,7 @@ export const updateGlobalTool = (
25
25
  depth: number = 0,
26
26
  locale?: string,
27
27
  fallbackLocale?: string,
28
+ select?: string,
28
29
  ): Promise<{
29
30
  content: Array<{
30
31
  text: string
@@ -62,6 +63,24 @@ export const updateGlobalTool = (
62
63
  }
63
64
  }
64
65
 
66
+ let selectClause: SelectType | undefined
67
+ if (select) {
68
+ try {
69
+ selectClause = JSON.parse(select) as SelectType
70
+ } catch (_parseError) {
71
+ payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)
72
+ const response = {
73
+ content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
74
+ }
75
+ return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {
76
+ content: Array<{
77
+ text: string
78
+ type: 'text'
79
+ }>
80
+ }
81
+ }
82
+ }
83
+
65
84
  const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
66
85
  slug: globalSlug,
67
86
  data: parsedData,
@@ -77,6 +96,9 @@ export const updateGlobalTool = (
77
96
  if (fallbackLocale) {
78
97
  updateOptions.fallbackLocale = fallbackLocale
79
98
  }
99
+ if (selectClause) {
100
+ updateOptions.select = selectClause
101
+ }
80
102
 
81
103
  const result = await payload.updateGlobal(updateOptions)
82
104
 
@@ -146,6 +168,12 @@ ${JSON.stringify(result, null, 2)}
146
168
  .describe(
147
169
  'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
148
170
  ),
171
+ select: z
172
+ .string()
173
+ .optional()
174
+ .describe(
175
+ 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'',
176
+ ),
149
177
  })
150
178
 
151
179
  server.tool(
@@ -153,7 +181,7 @@ ${JSON.stringify(result, null, 2)}
153
181
  `${toolSchemas.updateGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`,
154
182
  updateGlobalSchema.shape,
155
183
  async (params: Record<string, unknown>) => {
156
- const { depth, draft, fallbackLocale, locale, ...rest } = params
184
+ const { depth, draft, fallbackLocale, locale, select, ...rest } = params
157
185
  const data = JSON.stringify(rest)
158
186
  return await tool(
159
187
  data,
@@ -161,6 +189,7 @@ ${JSON.stringify(result, null, 2)}
161
189
  depth as number,
162
190
  locale as string,
163
191
  fallbackLocale as string,
192
+ select as string | undefined,
164
193
  )
165
194
  },
166
195
  )
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import type { JSONSchema4 } from 'json-schema'
3
- import type { PayloadRequest, TypedUser } from 'payload'
3
+ import type { PayloadRequest, SelectType, TypedUser } from 'payload'
4
4
 
5
5
  import { z } from 'zod'
6
6
 
@@ -24,6 +24,7 @@ export const createResourceTool = (
24
24
  draft: boolean,
25
25
  locale?: string,
26
26
  fallbackLocale?: string,
27
+ select?: string,
27
28
  ): Promise<{
28
29
  content: Array<{
29
30
  text: string
@@ -55,6 +56,25 @@ export const createResourceTool = (
55
56
  }
56
57
  }
57
58
 
59
+ let selectClause: SelectType | undefined
60
+ if (select) {
61
+ try {
62
+ selectClause = JSON.parse(select) as SelectType
63
+ } catch (_parseError) {
64
+ payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)
65
+ const response = {
66
+ content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
67
+ }
68
+ return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
69
+ response) as {
70
+ content: Array<{
71
+ text: string
72
+ type: 'text'
73
+ }>
74
+ }
75
+ }
76
+ }
77
+
58
78
  // Create the resource
59
79
  const result = await payload.create({
60
80
  collection: collectionSlug,
@@ -66,6 +86,7 @@ export const createResourceTool = (
66
86
  user,
67
87
  ...(locale && { locale }),
68
88
  ...(fallbackLocale && { fallbackLocale }),
89
+ ...(selectClause && { select: selectClause }),
69
90
  })
70
91
 
71
92
  if (verboseLogs) {
@@ -147,6 +168,12 @@ ${JSON.stringify(result, null, 2)}
147
168
  .describe(
148
169
  'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
149
170
  ),
171
+ select: z
172
+ .string()
173
+ .optional()
174
+ .describe(
175
+ 'Optional: define exactly which fields you\'d like to create (JSON), e.g., \'{"title": "My Post"}\'',
176
+ ),
150
177
  })
151
178
 
152
179
  server.tool(
@@ -154,7 +181,7 @@ ${JSON.stringify(result, null, 2)}
154
181
  `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,
155
182
  createResourceSchema.shape,
156
183
  async (params: Record<string, unknown>) => {
157
- const { depth, draft, fallbackLocale, locale, ...fieldData } = params
184
+ const { depth, draft, fallbackLocale, locale, select, ...fieldData } = params
158
185
  const data = JSON.stringify(fieldData)
159
186
  return await tool(
160
187
  data,
@@ -162,6 +189,7 @@ ${JSON.stringify(result, null, 2)}
162
189
  draft as boolean,
163
190
  locale as string | undefined,
164
191
  fallbackLocale as string | undefined,
192
+ select as string | undefined,
165
193
  )
166
194
  },
167
195
  )
@@ -1,5 +1,5 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import type { PayloadRequest, TypedUser } from 'payload'
2
+ import type { PayloadRequest, SelectType, TypedUser } from 'payload'
3
3
 
4
4
  import type { PluginMCPServerConfig } from '../../../types.js'
5
5
 
@@ -20,6 +20,7 @@ export const findResourceTool = (
20
20
  page: number = 1,
21
21
  sort?: string,
22
22
  where?: string,
23
+ select?: string,
23
24
  depth: number = 0,
24
25
  locale?: string,
25
26
  fallbackLocale?: string,
@@ -62,6 +63,26 @@ export const findResourceTool = (
62
63
  }
63
64
  }
64
65
 
66
+ // Parse select clause if provided
67
+ let selectClause: SelectType | undefined
68
+ if (select) {
69
+ try {
70
+ selectClause = JSON.parse(select) as SelectType
71
+ } catch (_parseError) {
72
+ payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)
73
+ const response = {
74
+ content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
75
+ }
76
+ return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
77
+ response) as {
78
+ content: Array<{
79
+ text: string
80
+ type: 'text'
81
+ }>
82
+ }
83
+ }
84
+ }
85
+
65
86
  // If ID is provided, use findByID
66
87
  if (id) {
67
88
  try {
@@ -69,6 +90,7 @@ export const findResourceTool = (
69
90
  id,
70
91
  collection: collectionSlug,
71
92
  depth,
93
+ ...(selectClause && { select: selectClause }),
72
94
  overrideAccess: false,
73
95
  req,
74
96
  user,
@@ -129,6 +151,7 @@ ${JSON.stringify(doc, null, 2)}`,
129
151
  page,
130
152
  req,
131
153
  user,
154
+ ...(selectClause && { select: selectClause }),
132
155
  ...(locale && { locale }),
133
156
  ...(fallbackLocale && { fallbackLocale }),
134
157
  ...(draft !== undefined && { draft }),
@@ -202,8 +225,19 @@ Page: ${result.page} of ${result.totalPages}
202
225
  `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
203
226
  `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,
204
227
  toolSchemas.findResources.parameters.shape,
205
- async ({ id, depth, draft, fallbackLocale, limit, locale, page, sort, where }) => {
206
- return await tool(id, limit, page, sort, where, depth, locale, fallbackLocale, draft)
228
+ async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {
229
+ return await tool(
230
+ id,
231
+ limit,
232
+ page,
233
+ sort,
234
+ where,
235
+ select,
236
+ depth,
237
+ locale,
238
+ fallbackLocale,
239
+ draft,
240
+ )
207
241
  },
208
242
  )
209
243
  }
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import type { JSONSchema4 } from 'json-schema'
3
- import type { PayloadRequest, TypedUser } from 'payload'
3
+ import type { PayloadRequest, SelectType, TypedUser } from 'payload'
4
4
 
5
5
  import { z } from 'zod'
6
6
 
@@ -29,6 +29,7 @@ export const updateResourceTool = (
29
29
  overwriteExistingFiles: boolean = false,
30
30
  locale?: string,
31
31
  fallbackLocale?: string,
32
+ select?: string,
32
33
  ): Promise<{
33
34
  content: Array<{
34
35
  text: string
@@ -107,6 +108,25 @@ export const updateResourceTool = (
107
108
  }
108
109
  }
109
110
 
111
+ let selectClause: SelectType | undefined
112
+ if (select) {
113
+ try {
114
+ selectClause = JSON.parse(select) as SelectType
115
+ } catch (_parseError) {
116
+ payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)
117
+ const response = {
118
+ content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
119
+ }
120
+ return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
121
+ response) as {
122
+ content: Array<{
123
+ text: string
124
+ type: 'text'
125
+ }>
126
+ }
127
+ }
128
+ }
129
+
110
130
  // Update by ID or where clause
111
131
  if (id) {
112
132
  // Single document update
@@ -124,6 +144,7 @@ export const updateResourceTool = (
124
144
  ...(overwriteExistingFiles && { overwriteExistingFiles }),
125
145
  ...(locale && { locale }),
126
146
  ...(fallbackLocale && { fallbackLocale }),
147
+ ...(selectClause && { select: selectClause }),
127
148
  }
128
149
 
129
150
  if (verboseLogs) {
@@ -174,6 +195,7 @@ ${JSON.stringify(result, null, 2)}
174
195
  ...(overwriteExistingFiles && { overwriteExistingFiles }),
175
196
  ...(locale && { locale }),
176
197
  ...(fallbackLocale && { fallbackLocale }),
198
+ ...(selectClause && { select: selectClause }),
177
199
  }
178
200
 
179
201
  if (verboseLogs) {
@@ -296,6 +318,12 @@ ${JSON.stringify(errors, null, 2)}
296
318
  .optional()
297
319
  .default(false)
298
320
  .describe('Whether to overwrite existing files'),
321
+ select: z
322
+ .string()
323
+ .optional()
324
+ .describe(
325
+ 'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
326
+ ),
299
327
  where: z
300
328
  .string()
301
329
  .optional()
@@ -316,6 +344,7 @@ ${JSON.stringify(errors, null, 2)}
316
344
  locale,
317
345
  overrideLock,
318
346
  overwriteExistingFiles,
347
+ select,
319
348
  where,
320
349
  ...fieldData
321
350
  } = params
@@ -332,6 +361,7 @@ ${JSON.stringify(errors, null, 2)}
332
361
  overwriteExistingFiles as boolean,
333
362
  locale as string | undefined,
334
363
  fallbackLocale as string | undefined,
364
+ select as string | undefined,
335
365
  )
336
366
  },
337
367
  )
@@ -22,6 +22,12 @@ export const toolSchemas = {
22
22
  .describe(
23
23
  'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
24
24
  ),
25
+ select: z
26
+ .string()
27
+ .optional()
28
+ .describe(
29
+ "Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
30
+ ),
25
31
  }),
26
32
  },
27
33
 
@@ -73,6 +79,12 @@ export const toolSchemas = {
73
79
  .optional()
74
80
  .default(1)
75
81
  .describe('Page number for pagination (default: 1)'),
82
+ select: z
83
+ .string()
84
+ .optional()
85
+ .describe(
86
+ "Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
87
+ ),
76
88
  sort: z
77
89
  .string()
78
90
  .optional()
@@ -113,6 +125,12 @@ export const toolSchemas = {
113
125
  .describe(
114
126
  'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
115
127
  ),
128
+ select: z
129
+ .string()
130
+ .optional()
131
+ .describe(
132
+ "Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
133
+ ),
116
134
  }),
117
135
  },
118
136
 
@@ -154,6 +172,12 @@ export const toolSchemas = {
154
172
  .optional()
155
173
  .default(false)
156
174
  .describe('Whether to overwrite existing files'),
175
+ select: z
176
+ .string()
177
+ .optional()
178
+ .describe(
179
+ "Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
180
+ ),
157
181
  where: z
158
182
  .string()
159
183
  .optional()
@@ -216,6 +240,12 @@ export const toolSchemas = {
216
240
  .describe(
217
241
  'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
218
242
  ),
243
+ select: z
244
+ .string()
245
+ .optional()
246
+ .describe(
247
+ "Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"siteName\": true}'",
248
+ ),
219
249
  }),
220
250
  },
221
251