@payloadcms/plugin-mcp 3.70.0 → 3.71.0-canary.3

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 (56) hide show
  1. package/dist/collections/createApiKeysCollection.d.ts +1 -1
  2. package/dist/collections/createApiKeysCollection.d.ts.map +1 -1
  3. package/dist/collections/createApiKeysCollection.js +10 -75
  4. package/dist/collections/createApiKeysCollection.js.map +1 -1
  5. package/dist/endpoints/mcp.d.ts.map +1 -1
  6. package/dist/endpoints/mcp.js +1 -0
  7. package/dist/endpoints/mcp.js.map +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +4 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/mcp/getMcpHandler.d.ts.map +1 -1
  12. package/dist/mcp/getMcpHandler.js +24 -10
  13. package/dist/mcp/getMcpHandler.js.map +1 -1
  14. package/dist/mcp/tools/global/find.d.ts +5 -0
  15. package/dist/mcp/tools/global/find.d.ts.map +1 -0
  16. package/dist/mcp/tools/global/find.js +59 -0
  17. package/dist/mcp/tools/global/find.js.map +1 -0
  18. package/dist/mcp/tools/global/update.d.ts +6 -0
  19. package/dist/mcp/tools/global/update.d.ts.map +1 -0
  20. package/dist/mcp/tools/global/update.js +97 -0
  21. package/dist/mcp/tools/global/update.js.map +1 -0
  22. package/dist/mcp/tools/resource/find.d.ts.map +1 -1
  23. package/dist/mcp/tools/resource/find.js +9 -3
  24. package/dist/mcp/tools/resource/find.js.map +1 -1
  25. package/dist/mcp/tools/schemas.d.ts +58 -17
  26. package/dist/mcp/tools/schemas.d.ts.map +1 -1
  27. package/dist/mcp/tools/schemas.js +19 -0
  28. package/dist/mcp/tools/schemas.js.map +1 -1
  29. package/dist/types.d.ts +40 -1
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/types.js.map +1 -1
  32. package/dist/utils/adminEntitySettings.d.ts +17 -0
  33. package/dist/utils/adminEntitySettings.d.ts.map +1 -0
  34. package/dist/utils/adminEntitySettings.js +41 -0
  35. package/dist/utils/adminEntitySettings.js.map +1 -0
  36. package/dist/utils/createApiKeyFields.d.ts +15 -0
  37. package/dist/utils/createApiKeyFields.d.ts.map +1 -0
  38. package/dist/utils/createApiKeyFields.js +57 -0
  39. package/dist/utils/createApiKeyFields.js.map +1 -0
  40. package/dist/utils/getEnabledSlugs.d.ts +13 -0
  41. package/dist/utils/getEnabledSlugs.d.ts.map +1 -0
  42. package/dist/utils/getEnabledSlugs.js +32 -0
  43. package/dist/utils/getEnabledSlugs.js.map +1 -0
  44. package/package.json +3 -3
  45. package/src/collections/createApiKeysCollection.ts +11 -111
  46. package/src/endpoints/mcp.ts +1 -0
  47. package/src/index.ts +4 -0
  48. package/src/mcp/getMcpHandler.ts +62 -26
  49. package/src/mcp/tools/global/find.ts +104 -0
  50. package/src/mcp/tools/global/update.ts +168 -0
  51. package/src/mcp/tools/resource/find.ts +5 -2
  52. package/src/mcp/tools/schemas.ts +56 -0
  53. package/src/types.ts +59 -1
  54. package/src/utils/adminEntitySettings.ts +40 -0
  55. package/src/utils/createApiKeyFields.ts +72 -0
  56. package/src/utils/getEnabledSlugs.ts +42 -0
@@ -0,0 +1,59 @@
1
+ import { toCamelCase } from '../../../utils/camelCase.js';
2
+ import { toolSchemas } from '../schemas.js';
3
+ export const findGlobalTool = (server, req, user, verboseLogs, globalSlug, globals)=>{
4
+ const tool = async (depth = 0, locale, fallbackLocale)=>{
5
+ const payload = req.payload;
6
+ if (verboseLogs) {
7
+ payload.logger.info(`[payload-mcp] Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`);
8
+ }
9
+ try {
10
+ const findOptions = {
11
+ slug: globalSlug,
12
+ depth,
13
+ user
14
+ };
15
+ // Add locale parameters if provided
16
+ if (locale) {
17
+ findOptions.locale = locale;
18
+ }
19
+ if (fallbackLocale) {
20
+ findOptions.fallbackLocale = fallbackLocale;
21
+ }
22
+ const result = await payload.findGlobal(findOptions);
23
+ if (verboseLogs) {
24
+ payload.logger.info(`[payload-mcp] Found global: ${globalSlug}`);
25
+ }
26
+ const response = {
27
+ content: [
28
+ {
29
+ type: 'text',
30
+ text: `Global "${globalSlug}":
31
+ \`\`\`json
32
+ ${JSON.stringify(result, null, 2)}
33
+ \`\`\``
34
+ }
35
+ ]
36
+ };
37
+ return globals?.[globalSlug]?.overrideResponse?.(response, result, req) || response;
38
+ } catch (error) {
39
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
40
+ payload.logger.error(`[payload-mcp] Error reading global ${globalSlug}: ${errorMessage}`);
41
+ const response = {
42
+ content: [
43
+ {
44
+ type: 'text',
45
+ text: `❌ **Error reading global "${globalSlug}":** ${errorMessage}`
46
+ }
47
+ ]
48
+ };
49
+ return globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response;
50
+ }
51
+ };
52
+ if (globals?.[globalSlug]?.enabled) {
53
+ server.tool(`find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, `${toolSchemas.findGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`, toolSchemas.findGlobal.parameters.shape, async ({ depth, fallbackLocale, locale })=>{
54
+ return await tool(depth, locale, fallbackLocale);
55
+ });
56
+ }
57
+ };
58
+
59
+ //# sourceMappingURL=find.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/tools/global/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n) => {\n const tool = async (\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n user,\n }\n\n // Add locale parameters if provided\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n\n const result = await payload.findGlobal(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\":\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, result, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error reading global ${globalSlug}: ${errorMessage}`)\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (globals?.[globalSlug]?.enabled) {\n server.tool(\n `find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n `${toolSchemas.findGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n toolSchemas.findGlobal.parameters.shape,\n async ({ depth, fallbackLocale, locale }) => {\n return await tool(depth, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findGlobalTool","server","req","user","verboseLogs","globalSlug","globals","tool","depth","locale","fallbackLocale","payload","logger","info","findOptions","slug","result","findGlobal","response","content","type","text","JSON","stringify","overrideResponse","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,iBAAiB,CAC5BC,QACAC,KACAC,MACAC,aACAC,YACAC;IAEA,MAAMC,OAAO,OACXC,QAAgB,CAAC,EACjBC,QACAC;QAOA,MAAMC,UAAUT,IAAIS,OAAO;QAE3B,IAAIP,aAAa;YACfO,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAER,WAAW,SAAS,EAAEG,QAAQC,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAExG;QAEA,IAAI;YACF,MAAMK,cAAwD;gBAC5DC,MAAMV;gBACNG;gBACAL;YACF;YAEA,oCAAoC;YACpC,IAAIM,QAAQ;gBACVK,YAAYL,MAAM,GAAGA;YACvB;YACA,IAAIC,gBAAgB;gBAClBI,YAAYJ,cAAc,GAAGA;YAC/B;YAEA,MAAMM,SAAS,MAAML,QAAQM,UAAU,CAACH;YAExC,IAAIV,aAAa;gBACfO,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,EAAER,YAAY;YACjE;YAEA,MAAMa,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,QAAQ,EAAEhB,WAAW;;AAExC,EAAEiB,KAAKC,SAAS,CAACP,QAAQ,MAAM,GAAG;MAC5B,CAAC;oBACG;iBACD;YACH;YAEA,OAAQV,SAAS,CAACD,WAAW,EAAEmB,mBAAmBN,UAAUF,QAAQd,QAAQgB;QAM9E,EAAE,OAAOO,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9DjB,QAAQC,MAAM,CAACa,KAAK,CAAC,CAAC,mCAAmC,EAAEpB,WAAW,EAAE,EAAEqB,cAAc;YACxF,MAAMR,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,0BAA0B,EAAEhB,WAAW,KAAK,EAAEqB,cAAc;oBACrE;iBACD;YACH;YACA,OAAQpB,SAAS,CAACD,WAAW,EAAEmB,mBAAmBN,UAAU,CAAC,GAAGhB,QAAQgB;QAM1E;IACF;IAEA,IAAIZ,SAAS,CAACD,WAAW,EAAEwB,SAAS;QAClC5B,OAAOM,IAAI,CACT,CAAC,IAAI,EAAEF,WAAWyB,MAAM,CAAC,GAAGC,WAAW,KAAKjC,YAAYO,YAAY2B,KAAK,CAAC,IAAI,EAC9E,GAAGjC,YAAYkB,UAAU,CAACgB,WAAW,CAACC,IAAI,GAAG,IAAI,EAAE5B,SAAS,CAACD,WAAW,EAAE4B,eAAe,IAAI,EAC7FlC,YAAYkB,UAAU,CAACkB,UAAU,CAACC,KAAK,EACvC,OAAO,EAAE5B,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAE;YACtC,OAAO,MAAMF,KAAKC,OAAOC,QAAQC;QACnC;IAEJ;AACF,EAAC"}
@@ -0,0 +1,6 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { JSONSchema4 } from 'json-schema';
3
+ import type { PayloadRequest, TypedUser } from 'payload';
4
+ import type { PluginMCPServerConfig } from '../../../types.js';
5
+ export declare const updateGlobalTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, globalSlug: string, globals: PluginMCPServerConfig["globals"], schema: JSONSchema4) => void;
6
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/global/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAM9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,UACjC,WAAW,SAoJpB,CAAA"}
@@ -0,0 +1,97 @@
1
+ import { z } from 'zod';
2
+ import { toCamelCase } from '../../../utils/camelCase.js';
3
+ import { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js';
4
+ import { toolSchemas } from '../schemas.js';
5
+ export const updateGlobalTool = (server, req, user, verboseLogs, globalSlug, globals, schema)=>{
6
+ const tool = async (data, draft = false, depth = 0, locale, fallbackLocale)=>{
7
+ const payload = req.payload;
8
+ if (verboseLogs) {
9
+ payload.logger.info(`[payload-mcp] Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
10
+ }
11
+ try {
12
+ // Parse the data JSON
13
+ let parsedData;
14
+ try {
15
+ parsedData = JSON.parse(data);
16
+ if (verboseLogs) {
17
+ payload.logger.info(`[payload-mcp] Parsed data for ${globalSlug}: ${JSON.stringify(parsedData)}`);
18
+ }
19
+ } catch (_parseError) {
20
+ payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`);
21
+ const response = {
22
+ content: [
23
+ {
24
+ type: 'text',
25
+ text: 'Error: Invalid JSON data provided'
26
+ }
27
+ ]
28
+ };
29
+ return globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response;
30
+ }
31
+ const updateOptions = {
32
+ slug: globalSlug,
33
+ data: parsedData,
34
+ depth,
35
+ draft,
36
+ user
37
+ };
38
+ // Add locale parameters if provided
39
+ if (locale) {
40
+ updateOptions.locale = locale;
41
+ }
42
+ if (fallbackLocale) {
43
+ updateOptions.fallbackLocale = fallbackLocale;
44
+ }
45
+ const result = await payload.updateGlobal(updateOptions);
46
+ if (verboseLogs) {
47
+ payload.logger.info(`[payload-mcp] Successfully updated global: ${globalSlug}`);
48
+ }
49
+ const response = {
50
+ content: [
51
+ {
52
+ type: 'text',
53
+ text: `Global "${globalSlug}" updated successfully!
54
+ \`\`\`json
55
+ ${JSON.stringify(result, null, 2)}
56
+ \`\`\``
57
+ }
58
+ ]
59
+ };
60
+ return globals?.[globalSlug]?.overrideResponse?.(response, result, req) || response;
61
+ } catch (error) {
62
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
63
+ payload.logger.error(`[payload-mcp] Error updating global ${globalSlug}: ${errorMessage}`);
64
+ const response = {
65
+ content: [
66
+ {
67
+ type: 'text',
68
+ text: `Error updating global "${globalSlug}": ${errorMessage}`
69
+ }
70
+ ]
71
+ };
72
+ return globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response;
73
+ }
74
+ };
75
+ if (globals?.[globalSlug]?.enabled) {
76
+ const convertedFields = convertCollectionSchemaToZod(schema);
77
+ // Make all fields optional for partial updates (PATCH-style)
78
+ const optionalFields = Object.fromEntries(Object.entries(convertedFields.shape).map(([key, value])=>[
79
+ key,
80
+ value.optional()
81
+ ]));
82
+ const updateGlobalSchema = z.object({
83
+ ...optionalFields,
84
+ depth: z.number().optional().describe('Optional: Depth of relationships to populate'),
85
+ draft: z.boolean().optional().describe('Optional: Whether to save as draft (default: false)'),
86
+ fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
87
+ locale: z.string().optional().describe('Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields')
88
+ });
89
+ server.tool(`update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, `${toolSchemas.updateGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`, updateGlobalSchema.shape, async (params)=>{
90
+ const { depth, draft, fallbackLocale, locale, ...rest } = params;
91
+ const data = JSON.stringify(rest);
92
+ return await tool(data, draft, depth, locale, fallbackLocale);
93
+ });
94
+ }
95
+ };
96
+
97
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/tools/global/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n draft: boolean = false,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${globalSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {\n slug: globalSlug,\n data: parsedData,\n depth,\n draft,\n user,\n }\n\n // Add locale parameters if provided\n if (locale) {\n updateOptions.locale = locale\n }\n if (fallbackLocale) {\n updateOptions.fallbackLocale = fallbackLocale\n }\n\n const result = await payload.updateGlobal(updateOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\" updated successfully!\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, result, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error updating global ${globalSlug}: ${errorMessage}`)\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating global \"${globalSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (globals?.[globalSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Make all fields optional for partial updates (PATCH-style)\n const optionalFields = Object.fromEntries(\n Object.entries(convertedFields.shape).map(([key, value]) => [key, (value as any).optional()]),\n )\n\n const updateGlobalSchema = z.object({\n ...optionalFields,\n depth: z.number().optional().describe('Optional: Depth of relationships to populate'),\n draft: z.boolean().optional().describe('Optional: Whether to save as draft (default: false)'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to update data in (e.g., \"en\", \"es\"). Use \"all\" to update all locales for localized fields',\n ),\n })\n\n server.tool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n updateGlobalSchema.shape,\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, ...rest } = params\n const data = JSON.stringify(rest)\n return await tool(\n data,\n draft as boolean,\n depth as number,\n locale as string,\n fallbackLocale as string,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","response","content","type","text","overrideResponse","updateOptions","slug","result","updateGlobal","errorMessage","Error","message","enabled","convertedFields","optionalFields","Object","fromEntries","entries","shape","map","key","value","optional","updateGlobalSchema","object","number","describe","boolean","string","charAt","toUpperCase","slice","description","trim","params","rest"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,YACAC,SACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,QAAiB,KAAK,EACtBC,QAAgB,CAAC,EACjBC,QACAC;QAOA,MAAMC,UAAUZ,IAAIY,OAAO;QAE3B,IAAIV,aAAa;YACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+BAA+B,EAAEX,WAAW,SAAS,EAAEK,QAAQE,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAEzG;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIK;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACV;gBACxB,IAAIL,aAAa;oBACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEX,WAAW,EAAE,EAAEa,KAAKE,SAAS,CAACH,aAAa;gBAEhF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAEb,MAAM;gBACxE,MAAMc,WAAW;oBACfC,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;gBACA,O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,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SA6LlD,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SAgMlD,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { toCamelCase } from '../../../utils/camelCase.js';
2
2
  import { toolSchemas } from '../schemas.js';
3
3
  export const findResourceTool = (server, req, user, verboseLogs, collectionSlug, collections)=>{
4
- const tool = async (id, limit = 10, page = 1, sort, where, locale, fallbackLocale)=>{
4
+ const tool = async (id, limit = 10, page = 1, sort, where, locale, fallbackLocale, draft)=>{
5
5
  const payload = req.payload;
6
6
  if (verboseLogs) {
7
7
  payload.logger.info(`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
@@ -42,6 +42,9 @@ export const findResourceTool = (server, req, user, verboseLogs, collectionSlug,
42
42
  },
43
43
  ...fallbackLocale && {
44
44
  fallbackLocale
45
+ },
46
+ ...draft !== undefined && {
47
+ draft
45
48
  }
46
49
  });
47
50
  if (verboseLogs) {
@@ -83,6 +86,9 @@ ${JSON.stringify(doc, null, 2)}`
83
86
  },
84
87
  ...fallbackLocale && {
85
88
  fallbackLocale
89
+ },
90
+ ...draft !== undefined && {
91
+ draft
86
92
  }
87
93
  };
88
94
  if (sort) {
@@ -126,8 +132,8 @@ Page: ${result.page} of ${result.totalPages}
126
132
  }
127
133
  };
128
134
  if (collections?.[collectionSlug]?.enabled) {
129
- server.tool(`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`, toolSchemas.findResources.parameters.shape, async ({ id, fallbackLocale, limit, locale, page, sort, where })=>{
130
- return await tool(id, limit, page, sort, where, locale, fallbackLocale);
135
+ server.tool(`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`, toolSchemas.findResources.parameters.shape, async ({ id, draft, fallbackLocale, limit, locale, page, sort, where })=>{
136
+ return await tool(id, limit, page, sort, where, locale, fallbackLocale, draft);
131
137
  });
132
138
  }
133
139
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: number | string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, fallbackLocale, limit, locale, page, sort, where }) => {\n return await tool(id, limit, page, sort, where, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","locale","fallbackLocale","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","findResources","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAm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C,MAAMC,MAAMC,OAAOC,QAAQC;QAC1D;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: number | string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n locale?: string,\n fallbackLocale?: string,\n draft?: boolean,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, draft, fallbackLocale, limit, locale, page, sort, where }) => {\n return await tool(id, limit, page, sort, where, locale, fallbackLocale, draft)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","locale","fallbackLocale","draft","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","undefined","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","findResources","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,QAAgB,EAAE,EAClBC,OAAe,CAAC,EAChBC,MACAC,OACAC,QACAC,gBACAC;QAOA,MAAMC,UAAUd,IAAIc,OAAO;QAE3B,IAAIZ,aAAa;YACfY,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEb,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,OAAOG,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE3K;QAEA,IAAI;YACF,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aAAa,CAACD,eAAe,EAAEuB,mBAAmBJ,UAAUgB,QAAQtC,QAC1EsB;QAMJ,EAAE,OAAOsB,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9DjC,QAAQC,MAAM,CAAC6B,KAAK,CAClB,CAAC,sDAAsD,EAAEzC,eAAe,EAAE,EAAE0C,cAAc;YAE5F,MAAMvB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,6CAA6C,EAAEtB,eAAe,KAAK,EAAE0C,cAAc;oBAC5F;iBACD;YACH;YACA,OAAQzC,aAAa,CAACD,eAAe,EAAEuB,mBAAmBJ,UAAU,CAAC,GAAGtB,QAAQsB;QAMlF;IACF;IAEA,IAAIlB,aAAa,CAACD,eAAe,EAAE6C,SAAS;QAC1CjD,OAAOM,IAAI,CACT,CAAC,IAAI,EAAEF,eAAe8C,MAAM,CAAC,GAAGC,WAAW,KAAKtD,YAAYO,gBAAgBgD,KAAK,CAAC,IAAI,EACtF,GAAG/C,aAAa,CAACD,eAAe,EAAEiD,eAAevD,YAAYwD,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI,EAC/FzD,YAAYwD,aAAa,CAACE,UAAU,CAACC,KAAK,EAC1C,OAAO,EAAElD,EAAE,EAAEO,KAAK,EAAED,cAAc,EAAEL,KAAK,EAAEI,MAAM,EAAEH,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;YACpE,OAAO,MAAML,KAAKC,IAAIC,OAAOC,MAAMC,MAAMC,OAAOC,QAAQC,gBAAgBC;QAC1E;IAEJ;AACF,EAAC"}
@@ -1,9 +1,26 @@
1
1
  import { z } from 'zod';
2
2
  export declare const toolSchemas: {
3
+ findGlobal: {
4
+ description: string;
5
+ parameters: z.ZodObject<{
6
+ depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
7
+ fallbackLocale: z.ZodOptional<z.ZodString>;
8
+ locale: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ depth: number;
11
+ locale?: string | undefined;
12
+ fallbackLocale?: string | undefined;
13
+ }, {
14
+ depth?: number | undefined;
15
+ locale?: string | undefined;
16
+ fallbackLocale?: string | undefined;
17
+ }>;
18
+ };
3
19
  findResources: {
4
20
  description: string;
5
21
  parameters: z.ZodObject<{
6
22
  id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
23
+ draft: z.ZodOptional<z.ZodBoolean>;
7
24
  fallbackLocale: z.ZodOptional<z.ZodString>;
8
25
  limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
9
26
  locale: z.ZodOptional<z.ZodString>;
@@ -13,19 +30,21 @@ export declare const toolSchemas: {
13
30
  }, "strip", z.ZodTypeAny, {
14
31
  limit: number;
15
32
  page: number;
16
- sort?: string | undefined;
17
33
  locale?: string | undefined;
34
+ sort?: string | undefined;
35
+ draft?: boolean | undefined;
36
+ where?: string | undefined;
18
37
  id?: string | number | undefined;
19
38
  fallbackLocale?: string | undefined;
20
- where?: string | undefined;
21
39
  }, {
22
- sort?: string | undefined;
23
40
  locale?: string | undefined;
41
+ sort?: string | undefined;
42
+ draft?: boolean | undefined;
43
+ where?: string | undefined;
24
44
  id?: string | number | undefined;
25
45
  fallbackLocale?: string | undefined;
26
46
  limit?: number | undefined;
27
47
  page?: number | undefined;
28
- where?: string | undefined;
29
48
  }>;
30
49
  };
31
50
  createResource: {
@@ -67,18 +86,18 @@ export declare const toolSchemas: {
67
86
  overrideLock: boolean;
68
87
  overwriteExistingFiles: boolean;
69
88
  locale?: string | undefined;
89
+ where?: string | undefined;
70
90
  id?: string | number | undefined;
71
91
  fallbackLocale?: string | undefined;
72
- where?: string | undefined;
73
92
  filePath?: string | undefined;
74
93
  }, {
75
94
  data: string;
76
95
  depth?: number | undefined;
77
96
  locale?: string | undefined;
78
97
  draft?: boolean | undefined;
98
+ where?: string | undefined;
79
99
  id?: string | number | undefined;
80
100
  fallbackLocale?: string | undefined;
81
- where?: string | undefined;
82
101
  filePath?: string | undefined;
83
102
  overrideLock?: boolean | undefined;
84
103
  overwriteExistingFiles?: boolean | undefined;
@@ -95,15 +114,37 @@ export declare const toolSchemas: {
95
114
  }, "strip", z.ZodTypeAny, {
96
115
  depth: number;
97
116
  locale?: string | undefined;
117
+ where?: string | undefined;
98
118
  id?: string | number | undefined;
99
119
  fallbackLocale?: string | undefined;
100
- where?: string | undefined;
101
120
  }, {
102
121
  depth?: number | undefined;
103
122
  locale?: string | undefined;
123
+ where?: string | undefined;
104
124
  id?: string | number | undefined;
105
125
  fallbackLocale?: string | undefined;
106
- where?: string | undefined;
126
+ }>;
127
+ };
128
+ updateGlobal: {
129
+ description: string;
130
+ parameters: z.ZodObject<{
131
+ data: z.ZodString;
132
+ depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
133
+ draft: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
134
+ fallbackLocale: z.ZodOptional<z.ZodString>;
135
+ locale: z.ZodOptional<z.ZodString>;
136
+ }, "strip", z.ZodTypeAny, {
137
+ depth: number;
138
+ draft: boolean;
139
+ data: string;
140
+ locale?: string | undefined;
141
+ fallbackLocale?: string | undefined;
142
+ }, {
143
+ data: string;
144
+ depth?: number | undefined;
145
+ locale?: string | undefined;
146
+ draft?: boolean | undefined;
147
+ fallbackLocale?: string | undefined;
107
148
  }>;
108
149
  };
109
150
  createCollection: {
@@ -243,16 +284,16 @@ export declare const toolSchemas: {
243
284
  password: z.ZodString;
244
285
  showHiddenFields: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
245
286
  }, "strip", z.ZodTypeAny, {
246
- email: string;
287
+ collection: string;
247
288
  depth: number;
289
+ email: string;
248
290
  password: string;
249
- collection: string;
250
291
  overrideAccess: boolean;
251
292
  showHiddenFields: boolean;
252
293
  }, {
294
+ collection: string;
253
295
  email: string;
254
296
  password: string;
255
- collection: string;
256
297
  depth?: number | undefined;
257
298
  overrideAccess?: boolean | undefined;
258
299
  showHiddenFields?: boolean | undefined;
@@ -278,12 +319,12 @@ export declare const toolSchemas: {
278
319
  password: z.ZodString;
279
320
  token: z.ZodString;
280
321
  }, "strip", z.ZodTypeAny, {
281
- password: string;
282
322
  collection: string;
323
+ password: string;
283
324
  token: string;
284
325
  }, {
285
- password: string;
286
326
  collection: string;
327
+ password: string;
287
328
  token: string;
288
329
  }>;
289
330
  };
@@ -294,12 +335,12 @@ export declare const toolSchemas: {
294
335
  disableEmail: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
295
336
  email: z.ZodString;
296
337
  }, "strip", z.ZodTypeAny, {
297
- email: string;
298
338
  collection: string;
339
+ email: string;
299
340
  disableEmail: boolean;
300
341
  }, {
301
- email: string;
302
342
  collection: string;
343
+ email: string;
303
344
  disableEmail?: boolean | undefined;
304
345
  }>;
305
346
  };
@@ -309,11 +350,11 @@ export declare const toolSchemas: {
309
350
  collection: z.ZodString;
310
351
  email: z.ZodString;
311
352
  }, "strip", z.ZodTypeAny, {
312
- email: string;
313
353
  collection: string;
314
- }, {
315
354
  email: string;
355
+ }, {
316
356
  collection: string;
357
+ email: string;
317
358
  }>;
318
359
  };
319
360
  createJob: {
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgavB,CAAA"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwdvB,CAAA"}
@@ -1,5 +1,13 @@
1
1
  import { z } from 'zod';
2
2
  export const toolSchemas = {
3
+ findGlobal: {
4
+ description: 'Find a Payload global singleton configuration.',
5
+ parameters: z.object({
6
+ depth: z.number().int().min(0).max(10).optional().default(0).describe('Depth of population for relationships'),
7
+ fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
8
+ locale: z.string().optional().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields')
9
+ })
10
+ },
3
11
  findResources: {
4
12
  description: 'Find documents in a collection by ID or where clause using Find or FindByID.',
5
13
  parameters: z.object({
@@ -7,6 +15,7 @@ export const toolSchemas = {
7
15
  z.string(),
8
16
  z.number()
9
17
  ]).optional().describe('Optional: specific document ID to retrieve. If not provided, returns all documents'),
18
+ draft: z.boolean().optional().describe('Optional: Whether the document should be queried from the versions table/collection or not.'),
10
19
  fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
11
20
  limit: z.number().int().min(1, 'Limit must be at least 1').max(100, 'Limit cannot exceed 100').optional().default(10).describe('Maximum number of documents to return (default: 10, max: 100)'),
12
21
  locale: z.string().optional().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields'),
@@ -55,6 +64,16 @@ export const toolSchemas = {
55
64
  where: z.string().optional().describe('Optional: JSON string for where clause to delete multiple documents')
56
65
  })
57
66
  },
67
+ updateGlobal: {
68
+ description: 'Update a Payload global singleton configuration.',
69
+ parameters: z.object({
70
+ data: z.string().describe('JSON string containing the data to update'),
71
+ depth: z.number().int().min(0).max(10).optional().default(0).describe('Depth of population for relationships'),
72
+ draft: z.boolean().optional().default(false).describe('Whether to update as a draft'),
73
+ fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
74
+ locale: z.string().optional().describe('Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields')
75
+ })
76
+ },
58
77
  // Experimental Below This Line
59
78
  createCollection: {
60
79
  description: 'Creates a new collection with specified fields and configuration.',