@payloadcms/plugin-mcp 3.83.0-internal.06ac84e → 3.83.0-internal.86b7bfb

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 (70) hide show
  1. package/dist/collections/createApiKeysCollection.d.ts +3 -3
  2. package/dist/collections/createApiKeysCollection.d.ts.map +1 -1
  3. package/dist/collections/createApiKeysCollection.js.map +1 -1
  4. package/dist/endpoints/mcp.d.ts +2 -2
  5. package/dist/endpoints/mcp.d.ts.map +1 -1
  6. package/dist/endpoints/mcp.js.map +1 -1
  7. package/dist/index.d.ts +6 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +7 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/mcp/getMcpHandler.d.ts +2 -2
  12. package/dist/mcp/getMcpHandler.d.ts.map +1 -1
  13. package/dist/mcp/getMcpHandler.js.map +1 -1
  14. package/dist/mcp/tools/auth/auth.js +1 -1
  15. package/dist/mcp/tools/auth/auth.js.map +1 -1
  16. package/dist/mcp/tools/auth/forgotPassword.js +1 -1
  17. package/dist/mcp/tools/auth/forgotPassword.js.map +1 -1
  18. package/dist/mcp/tools/auth/login.js +1 -1
  19. package/dist/mcp/tools/auth/login.js.map +1 -1
  20. package/dist/mcp/tools/auth/resetPassword.js +1 -1
  21. package/dist/mcp/tools/auth/resetPassword.js.map +1 -1
  22. package/dist/mcp/tools/auth/unlock.js +1 -1
  23. package/dist/mcp/tools/auth/unlock.js.map +1 -1
  24. package/dist/mcp/tools/global/find.d.ts +2 -2
  25. package/dist/mcp/tools/global/find.d.ts.map +1 -1
  26. package/dist/mcp/tools/global/find.js +1 -1
  27. package/dist/mcp/tools/global/find.js.map +1 -1
  28. package/dist/mcp/tools/global/update.d.ts +2 -2
  29. package/dist/mcp/tools/global/update.d.ts.map +1 -1
  30. package/dist/mcp/tools/global/update.js +1 -1
  31. package/dist/mcp/tools/global/update.js.map +1 -1
  32. package/dist/mcp/tools/job/run.js +2 -2
  33. package/dist/mcp/tools/job/run.js.map +1 -1
  34. package/dist/mcp/tools/resource/create.d.ts +2 -2
  35. package/dist/mcp/tools/resource/create.d.ts.map +1 -1
  36. package/dist/mcp/tools/resource/create.js +1 -1
  37. package/dist/mcp/tools/resource/create.js.map +1 -1
  38. package/dist/mcp/tools/resource/delete.d.ts +2 -2
  39. package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
  40. package/dist/mcp/tools/resource/delete.js +3 -3
  41. package/dist/mcp/tools/resource/delete.js.map +1 -1
  42. package/dist/mcp/tools/resource/find.d.ts +2 -2
  43. package/dist/mcp/tools/resource/find.d.ts.map +1 -1
  44. package/dist/mcp/tools/resource/find.js +2 -2
  45. package/dist/mcp/tools/resource/find.js.map +1 -1
  46. package/dist/mcp/tools/resource/update.d.ts +2 -2
  47. package/dist/mcp/tools/resource/update.d.ts.map +1 -1
  48. package/dist/mcp/tools/resource/update.js +3 -3
  49. package/dist/mcp/tools/resource/update.js.map +1 -1
  50. package/dist/types.d.ts +2 -2
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/types.js.map +1 -1
  53. package/package.json +3 -3
  54. package/src/collections/createApiKeysCollection.ts +5 -5
  55. package/src/endpoints/mcp.ts +2 -2
  56. package/src/index.ts +13 -7
  57. package/src/mcp/getMcpHandler.ts +6 -6
  58. package/src/mcp/tools/auth/auth.ts +1 -1
  59. package/src/mcp/tools/auth/forgotPassword.ts +1 -1
  60. package/src/mcp/tools/auth/login.ts +1 -1
  61. package/src/mcp/tools/auth/resetPassword.ts +1 -1
  62. package/src/mcp/tools/auth/unlock.ts +1 -1
  63. package/src/mcp/tools/global/find.ts +3 -3
  64. package/src/mcp/tools/global/update.ts +3 -3
  65. package/src/mcp/tools/job/run.ts +2 -2
  66. package/src/mcp/tools/resource/create.ts +3 -3
  67. package/src/mcp/tools/resource/delete.ts +5 -5
  68. package/src/mcp/tools/resource/find.ts +4 -4
  69. package/src/mcp/tools/resource/update.ts +5 -5
  70. package/src/types.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { PayloadRequest, TypedUser } from 'payload';
3
- import type { PluginMCPServerConfig } from '../../../types.js';
4
- export declare const findGlobalTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, globalSlug: string, globals: PluginMCPServerConfig["globals"]) => void;
3
+ import type { MCPPluginConfig } from '../../../types.js';
4
+ export declare const findGlobalTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, globalSlug: string, globals: MCPPluginConfig["globals"]) => void;
5
5
  //# sourceMappingURL=find.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/global/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAEpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,cAAc,WACjB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,SAiH1C,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/global/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAEpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKxD,eAAO,MAAM,cAAc,WACjB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,eAAe,CAAC,SAAS,CAAC,SAiHpC,CAAA"}
@@ -49,7 +49,7 @@ export const findGlobalTool = (server, req, user, verboseLogs, globalSlug, globa
49
49
  type: 'text',
50
50
  text: `Global "${globalSlug}":
51
51
  \`\`\`json
52
- ${JSON.stringify(result, null, 2)}
52
+ ${JSON.stringify(result)}
53
53
  \`\`\``
54
54
  }
55
55
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/global/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, SelectType, 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 select?: 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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\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 // Add locale parameters if provided\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\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.registerTool(\n `find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.findGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: toolSchemas.findGlobal.parameters.shape,\n },\n async ({ depth, fallbackLocale, locale, select }) => {\n return await tool(depth, locale, fallbackLocale, select)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findGlobalTool","server","req","user","verboseLogs","globalSlug","globals","tool","depth","locale","fallbackLocale","select","payload","logger","info","findOptions","slug","selectClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","result","findGlobal","stringify","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","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,gBACAC;QAOA,MAAMC,UAAU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AAQF,MAAMG,OAAO,GAAG;YAC9DrB,QAAQC,MAAM,CAACiB,KAAK,CAAC,CAAC,mCAAmC,EAAEzB,WAAW,EAAE,EAAE0B,cAAc;YACxF,MAAMT,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,0BAA0B,EAAEpB,WAAW,KAAK,EAAE0B,cAAc;oBACrE;iBACD;YACH;YACA,OAAQzB,SAAS,CAACD,WAAW,EAAEqB,mBAAmBJ,UAAU,CAAC,GAAGpB,QAAQoB;QAM1E;IACF;IAEA,IAAIhB,SAAS,CAACD,WAAW,EAAE6B,SAAS;QAClCjC,OAAOkC,YAAY,CACjB,CAAC,IAAI,EAAE9B,WAAW+B,MAAM,CAAC,GAAGC,WAAW,KAAKvC,YAAYO,YAAYiC,KAAK,CAAC,IAAI,EAC9E;YACEC,aAAa,GAAGxC,YAAY6B,UAAU,CAACW,WAAW,CAACC,IAAI,GAAG,IAAI,EAAElC,SAAS,CAACD,WAAW,EAAEkC,eAAe,IAAI;YAC1GE,aAAa1C,YAAY6B,UAAU,CAACc,UAAU,CAACC,KAAK;QACtD,GACA,OAAO,EAAEnC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE;YAC9C,OAAO,MAAMJ,KAAKC,OAAOC,QAAQC,gBAAgBC;QACnD;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/global/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, SelectType, TypedUser } from 'payload'\n\nimport type { MCPPluginConfig } 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: MCPPluginConfig['globals'],\n) => {\n const tool = async (\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n select?: 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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\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 // Add locale parameters if provided\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\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)}\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.registerTool(\n `find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.findGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: toolSchemas.findGlobal.parameters.shape,\n },\n async ({ depth, fallbackLocale, locale, select }) => {\n return await tool(depth, locale, fallbackLocale, select)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findGlobalTool","server","req","user","verboseLogs","globalSlug","globals","tool","depth","locale","fallbackLocale","select","payload","logger","info","findOptions","slug","selectClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","result","findGlobal","stringify","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","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,gBACAC;QAOA,MAAMC,UAAUV,IAAIU,OAAO;QAE3B,IAAIR,aAAa;YACfQ,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAET,WAAW,SAAS,EAAEG,QAAQC,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAExG;QAEA,IAAI;YACF,MAAMM,cAAwD;gBAC5DC,MAAMX;gBACNG;gBACAL;YACF;YAEA,IAAIc;YACJ,IAAIN,QAAQ;gBACV,IAAI;oBACFM,eAAeC,KAAKC,KAAK,CAACR;gBAC5B,EAAE,OAAOS,aAAa;oBACpBR,QAAQC,MAAM,CAACQ,IAAI,CAAC,CAAC,qDAAqD,EAAEV,QAAQ;oBACpF,MAAMW,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAuC;yBAAE;oBACpF;oBACA,OAAQnB,SAAS,CAACD,WAAW,EAAEqB,mBAAmBJ,UAAU,CAA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IAAI,EAAElC,SAAS,CAACD,WAAW,EAAEkC,eAAe,IAAI;YAC1GE,aAAa1C,YAAY6B,UAAU,CAACc,UAAU,CAACC,KAAK;QACtD,GACA,OAAO,EAAEnC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE;YAC9C,OAAO,MAAMJ,KAAKC,OAAOC,QAAQC,gBAAgBC;QACnD;IAEJ;AACF,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { JSONSchema4 } from 'json-schema';
3
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;
4
+ import type { MCPPluginConfig } from '../../../types.js';
5
+ export declare const updateGlobalTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, globalSlug: string, globals: MCPPluginConfig["globals"], schema: JSONSchema4) => void;
6
6
  //# sourceMappingURL=update.d.ts.map
@@ -1 +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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAU9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,UACjC,WAAW,SAuLpB,CAAA"}
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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAUxD,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,eAAe,CAAC,SAAS,CAAC,UAC3B,WAAW,SAuLpB,CAAA"}
@@ -75,7 +75,7 @@ export const updateGlobalTool = (server, req, user, verboseLogs, globalSlug, glo
75
75
  type: 'text',
76
76
  text: `Global "${globalSlug}" updated successfully!
77
77
  \`\`\`json
78
- ${JSON.stringify(result, null, 2)}
78
+ ${JSON.stringify(result)}
79
79
  \`\`\``
80
80
  }
81
81
  ]
@@ -1 +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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/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 select?: 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\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\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 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 if (selectClause) {\n updateOptions.select = selectClause\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n ),\n })\n\n server.registerTool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: updateGlobalSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...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 select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getGlobalVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","selectClause","warn","updateOptions","slug","result","updateGlobal","errorMessage","Error","message","enabled","convertedFields","optionalFields","Object","fromEntries","entries","shape","map","key","value","optional","updateGlobalSchema","object","number","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","params","rest"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,0BAA0B,EAC1BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,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,gBACAC;QAOA,MAAMC,UAAUb,IAAIa,OAAO;QAE3B,IAAIX,aAAa;YACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+BAA+B,EAAEZ,WAAW,SAAS,EAAEK,QAAQE,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAEzG;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACX;gBAExB,MAAMY,oBAAoBzB,2BAA2BmB,QAAQO,MAAM,EAAEjB;gBACrEa,aAAarB,mBAAmBqB,YAAYG;gBAE5C,IAAIjB,aAAa;oBACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEZ,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qD,MAAM,CAAC,GAAGC,WAAW,KAAKhE,YAAYU,YAAYuD,KAAK,CAAC,IAAI,EAChF;YACEC,aAAa,GAAG9D,YAAYqC,YAAY,CAACyB,WAAW,CAACC,IAAI,GAAG,IAAI,EAAExD,SAAS,CAACD,WAAW,EAAEwD,eAAe,IAAI;YAC5GE,aAAaZ,mBAAmBL,KAAK;QACvC,GACA,OAAOkB;YACL,MAAM,EAAErD,KAAK,EAAED,KAAK,EAAEG,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAGmD,MAAM,GAAGD;YAClE,MAAMvD,OAAOU,KAAKI,SAAS,CAAC0C;YAC5B,OAAO,MAAMzD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { MCPPluginConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/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: MCPPluginConfig['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 select?: 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\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\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 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 if (selectClause) {\n updateOptions.select = selectClause\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)}\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n ),\n })\n\n server.registerTool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: updateGlobalSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...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 select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getGlobalVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","selectClause","warn","updateOptions","slug","result","updateGlobal","errorMessage","Error","message","enabled","convertedFields","optionalFields","Object","fromEntries","entries","shape","map","key","value","optional","updateGlobalSchema","object","number","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","params","rest"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,0BAA0B,EAC1BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,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,gBACAC;QAOA,MAAMC,UAAUb,IAAIa,OAAO;QAE3B,IAAIX,aAAa;YACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+BAA+B,EAAEZ,WAAW,SAAS,EAAEK,QAAQE,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAEzG;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACX;gBAExB,MAAMY,oBAAoBzB,2BAA2BmB,QAAQO,MAAM,EAAEjB;gBACrEa,aAAarB,mBAAmBqB,YAAYG;gBAE5C,IAAIjB,aAAa;oBACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEZ,WAAW,EAAE,EAAEc,KAAKI,SAAS,CAACL,aAAa;gBAEhF;YACF,EAAE,OAAOM,aAAa;gBACpBT,QAAQC,MAAM,CAACS,KAAK,CAAC,CAAC,0CAA0C,EAAEhB,MAAM;gBACxE,MAAMiB,WAAW;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D,eAAe,IAAI;YAC5GE,aAAaZ,mBAAmBL,KAAK;QACvC,GACA,OAAOkB;YACL,MAAM,EAAErD,KAAK,EAAED,KAAK,EAAEG,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAGmD,MAAM,GAAGD;YAClE,MAAMvD,OAAOU,KAAKI,SAAS,CAAC0C;YAC5B,OAAO,MAAMzD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
@@ -53,7 +53,7 @@ export const runJob = async (req, verboseLogs, jobSlug, input, queue, priority,
53
53
 
54
54
  ## Input Data
55
55
  \`\`\`json
56
- ${JSON.stringify(input, null, 2)}
56
+ ${JSON.stringify(input)}
57
57
  \`\`\`
58
58
 
59
59
  ## Job Status
@@ -94,7 +94,7 @@ console.log('Job result:', result)
94
94
 
95
95
  ## Input Data Provided:
96
96
  \`\`\`json
97
- ${JSON.stringify(input, null, 2)}
97
+ ${JSON.stringify(input)}
98
98
  \`\`\`
99
99
 
100
100
  ## Next Steps:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/job/run.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Reusable function for running jobs\nexport const runJob = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n jobSlug: string,\n input: Record<string, unknown>,\n queue?: string,\n priority?: number,\n delay?: number,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Running job: ${jobSlug}`)\n }\n\n try {\n // Actually run the job using Payload's job queue\n const jobQueueOptions: Record<string, unknown> = {\n input,\n task: jobSlug,\n }\n\n if (queue && queue !== 'default') {\n jobQueueOptions.queue = queue\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom queue: ${queue}`)\n }\n }\n\n if (priority && priority > 0) {\n jobQueueOptions.priority = priority\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job priority: ${priority}`)\n }\n }\n\n if (delay && delay > 0) {\n jobQueueOptions.waitUntil = new Date(Date.now() + delay)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job delay: ${delay}ms`)\n }\n }\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Queuing job with options: ${JSON.stringify(jobQueueOptions)}`,\n )\n }\n\n const job = await payload.jobs.queue(\n jobQueueOptions as Parameters<typeof payload.jobs.queue>[0],\n )\n\n const jobId = (job as { id?: string })?.id || 'unknown'\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Job created successfully: ${jobId}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Job Queued Successfully: ${jobSlug}\n\n## Job Details\n- **Job ID**: ${jobId}\n- **Job Slug**: ${jobSlug}\n- **Queue**: ${queue || 'default'}\n- **Priority**: ${priority || 'default'}\n- **Delay**: ${delay ? `${delay}ms` : 'none'}\n- **Status**: Queued and Running\n\n## Input Data\n\\`\\`\\`json\n${JSON.stringify(input, null, 2)}\n\\`\\`\\`\n\n## Job Status\nThe job has been successfully queued and will be processed according to the queue settings.\n\n## Monitoring the Job\nYou can monitor the job status using:\n\n\\`\\`\\`typescript\n// Check job status\nconst jobStatus = await payload.jobs.status('${jobId}')\nconsole.log('Job status:', jobStatus)\n\n// Wait for completion\nconst result = await payload.jobs.wait('${jobId}')\nconsole.log('Job result:', result)\n\\`\\`\\`\n\n✅ Job successfully queued with ID: ${jobId}`,\n },\n ],\n }\n } catch (error) {\n const errorMsg = (error as Error).message\n payload.logger.error(`[payload-mcp] Error running job \"${jobSlug}\": ${errorMsg}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ Error running job \"${jobSlug}\": ${errorMsg}\n\n## Common Issues:\n1. **Job not found**: The job \"${jobSlug}\" may not be registered in your Payload configuration\n2. **Invalid input format**: Ensure the input matches the job's input schema\n3. **Queue not configured**: The queue \"${queue || 'default'}\" may not be properly set up\n4. **Permission issues**: Ensure proper access rights for job execution\n5. **Job handler error**: The job implementation may have errors\n\n## Input Data Provided:\n\\`\\`\\`json\n${JSON.stringify(input, null, 2)}\n\\`\\`\\`\n\n## Next Steps:\n1. **Verify job exists**: Check that the job \"${jobSlug}\" is properly registered\n2. **Check input format**: Ensure the input data matches the expected schema\n3. **Review job configuration**: Verify the job is properly configured in your Payload setup\n4. **Check permissions**: Ensure you have the necessary permissions to run jobs\n5. **Review error logs**: Check the server logs for more detailed error information\n\n## Troubleshooting:\n- **Job not found**: Verify the job slug and check your jobs configuration\n- **Schema mismatch**: Ensure input data matches the job's input schema\n- **Queue issues**: Check that the specified queue is properly configured\n- **Permission errors**: Verify user permissions for job execution`,\n },\n ],\n }\n }\n}\n\nexport const runJobTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n server.registerTool(\n 'runJob',\n {\n description: 'Runs a Payload job with specified input data and queue options',\n inputSchema: toolSchemas.runJob.parameters.shape,\n },\n async ({ delay, input, jobSlug, priority, queue }) => {\n if (verboseLogs) {\n req.payload.logger.info(`[payload-mcp] Run Job Tool called with: ${jobSlug}`)\n }\n return runJob(\n req,\n verboseLogs,\n jobSlug,\n input as Record<string, unknown>,\n queue,\n priority,\n delay,\n )\n },\n )\n}\n"],"names":["toolSchemas","runJob","req","verboseLogs","jobSlug","input","queue","priority","delay","payload","logger","info","jobQueueOptions","task","waitUntil","Date","now","JSON","stringify","job","jobs","jobId","id","content","type","text","error","errorMsg","message","runJobTool","server","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,qCAAqC;AACrC,OAAO,MAAMC,SAAS,OACpBC,KACAC,aACAC,SACAC,OACAC,OACAC,UACAC;IAEA,MAAMC,UAAUP,IAAIO,OAAO;IAE3B,IAAIN,aAAa;QACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEP,SAAS;IAC7D;IAEA,IAAI;QACF,iDAAiD;QACj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;;;mCAIb,EAAEA,OAAO;gBACpC;aACD;QACH;IACF,EAAE,OAAOK,OAAO;QACd,MAAMC,WAAW,AAACD,MAAgBE,OAAO;QACzCnB,QAAQC,MAAM,CAACgB,KAAK,CAAC,CAAC,iCAAiC,EAAEtB,QAAQ,GAAG,EAAEuB,UAAU;QAEhF,OAAO;YACLJ,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,qBAAqB,EAAErB,QAAQ,GAAG,EAAEuB,SAAS;;;+BAG/B,EAAEvB,QAAQ;;wCAED,EAAEE,SAAS,UAAU;;;;;;AAM7D,EAAEW,KAAKC,SAAS,CAACb,OAAO,MAAM,GAAG;;;;8CAIa,EAAED,QAAQ;;;;;;;;;;kEAUU,CAAC;gBAC3D;aACD;QACH;IACF;AACF,EAAC;AAED,OAAO,MAAMyB,aAAa,CAACC,QAAmB5B,KAAqBC;IACjE2B,OAAOC,YAAY,CACjB,UACA;QACEC,aAAa;QACbC,aAAajC,YAAYC,MAAM,CAACiC,UAAU,CAACC,KAAK;IAClD,GACA,OAAO,EAAE3B,KAAK,EAAEH,KAAK,EAAED,OAAO,EAAEG,QAAQ,EAAED,KAAK,EAAE;QAC/C,IAAIH,aAAa;YACfD,IAAIO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,wCAAwC,EAAEP,SAAS;QAC9E;QACA,OAAOH,OACLC,KACAC,aACAC,SACAC,OACAC,OACAC,UACAC;IAEJ;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/job/run.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Reusable function for running jobs\nexport const runJob = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n jobSlug: string,\n input: Record<string, unknown>,\n queue?: string,\n priority?: number,\n delay?: number,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Running job: ${jobSlug}`)\n }\n\n try {\n // Actually run the job using Payload's job queue\n const jobQueueOptions: Record<string, unknown> = {\n input,\n task: jobSlug,\n }\n\n if (queue && queue !== 'default') {\n jobQueueOptions.queue = queue\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom queue: ${queue}`)\n }\n }\n\n if (priority && priority > 0) {\n jobQueueOptions.priority = priority\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job priority: ${priority}`)\n }\n }\n\n if (delay && delay > 0) {\n jobQueueOptions.waitUntil = new Date(Date.now() + delay)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job delay: ${delay}ms`)\n }\n }\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Queuing job with options: ${JSON.stringify(jobQueueOptions)}`,\n )\n }\n\n const job = await payload.jobs.queue(\n jobQueueOptions as Parameters<typeof payload.jobs.queue>[0],\n )\n\n const jobId = (job as { id?: string })?.id || 'unknown'\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Job created successfully: ${jobId}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Job Queued Successfully: ${jobSlug}\n\n## Job Details\n- **Job ID**: ${jobId}\n- **Job Slug**: ${jobSlug}\n- **Queue**: ${queue || 'default'}\n- **Priority**: ${priority || 'default'}\n- **Delay**: ${delay ? `${delay}ms` : 'none'}\n- **Status**: Queued and Running\n\n## Input Data\n\\`\\`\\`json\n${JSON.stringify(input)}\n\\`\\`\\`\n\n## Job Status\nThe job has been successfully queued and will be processed according to the queue settings.\n\n## Monitoring the Job\nYou can monitor the job status using:\n\n\\`\\`\\`typescript\n// Check job status\nconst jobStatus = await payload.jobs.status('${jobId}')\nconsole.log('Job status:', jobStatus)\n\n// Wait for completion\nconst result = await payload.jobs.wait('${jobId}')\nconsole.log('Job result:', result)\n\\`\\`\\`\n\n✅ Job successfully queued with ID: ${jobId}`,\n },\n ],\n }\n } catch (error) {\n const errorMsg = (error as Error).message\n payload.logger.error(`[payload-mcp] Error running job \"${jobSlug}\": ${errorMsg}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ Error running job \"${jobSlug}\": ${errorMsg}\n\n## Common Issues:\n1. **Job not found**: The job \"${jobSlug}\" may not be registered in your Payload configuration\n2. **Invalid input format**: Ensure the input matches the job's input schema\n3. **Queue not configured**: The queue \"${queue || 'default'}\" may not be properly set up\n4. **Permission issues**: Ensure proper access rights for job execution\n5. **Job handler error**: The job implementation may have errors\n\n## Input Data Provided:\n\\`\\`\\`json\n${JSON.stringify(input)}\n\\`\\`\\`\n\n## Next Steps:\n1. **Verify job exists**: Check that the job \"${jobSlug}\" is properly registered\n2. **Check input format**: Ensure the input data matches the expected schema\n3. **Review job configuration**: Verify the job is properly configured in your Payload setup\n4. **Check permissions**: Ensure you have the necessary permissions to run jobs\n5. **Review error logs**: Check the server logs for more detailed error information\n\n## Troubleshooting:\n- **Job not found**: Verify the job slug and check your jobs configuration\n- **Schema mismatch**: Ensure input data matches the job's input schema\n- **Queue issues**: Check that the specified queue is properly configured\n- **Permission errors**: Verify user permissions for job execution`,\n },\n ],\n }\n }\n}\n\nexport const runJobTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n server.registerTool(\n 'runJob',\n {\n description: 'Runs a Payload job with specified input data and queue options',\n inputSchema: toolSchemas.runJob.parameters.shape,\n },\n async ({ delay, input, jobSlug, priority, queue }) => {\n if (verboseLogs) {\n req.payload.logger.info(`[payload-mcp] Run Job Tool called with: ${jobSlug}`)\n }\n return runJob(\n req,\n verboseLogs,\n jobSlug,\n input as Record<string, unknown>,\n queue,\n priority,\n delay,\n )\n },\n )\n}\n"],"names":["toolSchemas","runJob","req","verboseLogs","jobSlug","input","queue","priority","delay","payload","logger","info","jobQueueOptions","task","waitUntil","Date","now","JSON","stringify","job","jobs","jobId","id","content","type","text","error","errorMsg","message","runJobTool","server","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,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M;gBACN,EAAEjB,QAAQ;aACb,EAAEE,SAAS,UAAU;gBAClB,EAAEC,YAAY,UAAU;aAC3B,EAAEC,QAAQ,GAAGA,MAAM,EAAE,CAAC,GAAG,OAAO;;;;;AAK7C,EAAES,KAAKC,SAAS,CAACb,OAAO;;;;;;;;;;;6CAWqB,EAAEgB,MAAM;;;;wCAIb,EAAEA,MAAM;;;;mCAIb,EAAEA,OAAO;gBACpC;aACD;QACH;IACF,EAAE,OAAOK,OAAO;QACd,MAAMC,WAAW,AAACD,MAAgBE,OAAO;QACzCnB,QAAQC,MAAM,CAACgB,KAAK,CAAC,CAAC,iCAAiC,EAAEtB,QAAQ,GAAG,EAAEuB,UAAU;QAEhF,OAAO;YACLJ,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,qBAAqB,EAAErB,QAAQ,GAAG,EAAEuB,SAAS;;;+BAG/B,EAAEvB,QAAQ;;wCAED,EAAEE,SAAS,UAAU;;;;;;AAM7D,EAAEW,KAAKC,SAAS,CAACb,OAAO;;;;8CAIsB,EAAED,QAAQ;;;;;;;;;;kEAUU,CAAC;gBAC3D;aACD;QACH;IACF;AACF,EAAC;AAED,OAAO,MAAMyB,aAAa,CAACC,QAAmB5B,KAAqBC;IACjE2B,OAAOC,YAAY,CACjB,UACA;QACEC,aAAa;QACbC,aAAajC,YAAYC,MAAM,CAACiC,UAAU,CAACC,KAAK;IAClD,GACA,OAAO,EAAE3B,KAAK,EAAEH,KAAK,EAAED,OAAO,EAAEG,QAAQ,EAAED,KAAK,EAAE;QAC/C,IAAIH,aAAa;YACfD,IAAIO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,wCAAwC,EAAEP,SAAS;QAC9E;QACA,OAAOH,OACLC,KACAC,aACAC,SACAC,OACAC,OACAC,UACAC;IAEJ;AAEJ,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { JSONSchema4 } from 'json-schema';
3
3
  import type { PayloadRequest, TypedUser } from 'payload';
4
- import type { PluginMCPServerConfig } from '../../../types.js';
5
- export declare const createResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: PluginMCPServerConfig["collections"], schema: JSONSchema4) => void;
4
+ import type { MCPPluginConfig } from '../../../types.js';
5
+ export declare const createResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: MCPPluginConfig["collections"], schema: JSONSchema4) => void;
6
6
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAU9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,SA2LpB,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAUxD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,eAAe,CAAC,aAAa,CAAC,UACnC,WAAW,SA2LpB,CAAA"}
@@ -79,7 +79,7 @@ export const createResourceTool = (server, req, user, verboseLogs, collectionSlu
79
79
  text: `Resource created successfully in collection "${collectionSlug}"!
80
80
  Created resource:
81
81
  \`\`\`json
82
- ${JSON.stringify(result, null, 2)}
82
+ ${JSON.stringify(result)}
83
83
  \`\`\``
84
84
  }
85
85
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n depth: number = 0,\n draft: boolean,\n locale?: string,\n fallbackLocale?: string,\n select?: 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] Creating resource in collection: ${collectionSlug}${locale ? ` with 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(selectClause && { select: selectClause }),\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\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 creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\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 const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Create a new schema that combines the converted fields with create-specific parameters\n const createResourceSchema = z.object({\n ...convertedFields.shape,\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships in response'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to create the document as a draft'),\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 create the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to create (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n })\n\n server.registerTool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n inputSchema: createResourceSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...fieldData } = params\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n depth as number,\n draft as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","depth","draft","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","content","type","text","selectClause","warn","response","overrideResponse","result","create","collection","overrideAccess","id","errorMessage","Error","message","enabled","convertedFields","createResourceSchema","object","shape","number","int","min","max","optional","default","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","createResource","trim","inputS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aAAa,CAACD,eAAe,EAAE2B,mBAAmBD,UAAU,CAAC,GAAG7B,QAAQ6B;QAMlF;IACF;IAEA,IAAIzB,aAAa,CAACD,eAAe,EAAEoC,SAAS;QAC1C,MAAMC,kBAAkB7C,6BAA6BU;QAErD,yFAAyF;QACzF,MAAMoC,uBAAuBlD,EAAEmD,MAAM,CAAC;YACpC,GAAGF,gBAAgBG,KAAK;YACxBnC,OAAOjB,EACJqD,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,GACRC,OAAO,CAAC,GACRC,QAAQ,CAAC;YACZzC,OAAOlB,EACJ4D,OAAO,GACPH,QAAQ,GACRC,OAAO,CAAC,OACRC,QAAQ,CAAC;YACZvC,gBAAgBpB,EACb6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CAAC;YACZxC,QAAQnB,EACL6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CACP;YAEJtC,QAAQrB,EACL6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CACP;QAEN;QAEAnD,OAAOsD,YAAY,CACjB,CAAC,MAAM,EAAElD,eAAemD,MAAM,CAAC,GAAGC,WAAW,KAAK/D,YAAYW,gBAAgBqD,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGrD,aAAa,CAACD,eAAe,EAAEsD,eAAe5D,YAAY6D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAanB,qBAAqBE,KAAK;QACzC,GACA,OAAOkB;YACL,MAAM,EAAErD,KAAK,EAAEC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAGkD,WAAW,GAAGD;YACvE,MAAMtD,OAAOU,KAAKI,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { MCPPluginConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: MCPPluginConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n depth: number = 0,\n draft: boolean,\n locale?: string,\n fallbackLocale?: string,\n select?: 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] Creating resource in collection: ${collectionSlug}${locale ? ` with 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(selectClause && { select: selectClause }),\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result)}\n\\`\\`\\``,\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 creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\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 const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Create a new schema that combines the converted fields with create-specific parameters\n const createResourceSchema = z.object({\n ...convertedFields.shape,\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships in response'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to create the document as a draft'),\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 create the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to create (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n })\n\n server.registerTool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n inputSchema: createResourceSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...fieldData } = params\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n depth as number,\n draft as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","depth","draft","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","content","type","text","selectClause","warn","response","overrideResponse","result","create","collection","overrideAccess","id","errorMessage","Error","message","enabled","convertedFields","createResourceSchema","object","shape","number","int","min","max","optional","default","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","createResource","trim","inputSchema","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,QAAgB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,CAAC;YACZzC,OAAOlB,EACJ4D,OAAO,GACPH,QAAQ,GACRC,OAAO,CAAC,OACRC,QAAQ,CAAC;YACZvC,gBAAgBpB,EACb6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CAAC;YACZxC,QAAQnB,EACL6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CACP;YAEJtC,QAAQrB,EACL6D,MAAM,GACNJ,QAAQ,GACRE,QAAQ,CACP;QAEN;QAEAnD,OAAOsD,YAAY,CACjB,CAAC,MAAM,EAAElD,eAAemD,MAAM,CAAC,GAAGC,WAAW,KAAK/D,YAAYW,gBAAgBqD,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGrD,aAAa,CAACD,eAAe,EAAEsD,eAAe5D,YAAY6D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAanB,qBAAqBE,KAAK;QACzC,GACA,OAAOkB;YACL,MAAM,EAAErD,KAAK,EAAEC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAGkD,WAAW,GAAGD;YACvE,MAAMtD,OAAOU,KAAKI,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { PayloadRequest, TypedUser } from 'payload';
3
- import type { PluginMCPServerConfig } from '../../../types.js';
4
- export declare const deleteResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: PluginMCPServerConfig["collections"]) => void;
3
+ import type { MCPPluginConfig } from '../../../types.js';
4
+ export declare const deleteResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: MCPPluginConfig["collections"]) => void;
5
5
  //# sourceMappingURL=delete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/delete.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,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SA2MlD,CAAA"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/delete.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,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKxD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,eAAe,CAAC,aAAa,CAAC,SA2M5C,CAAA"}
@@ -81,7 +81,7 @@ export const deleteResourceTool = (server, req, user, verboseLogs, collectionSlu
81
81
  text: `Document deleted successfully from collection "${collectionSlug}"!
82
82
  Deleted document:
83
83
  \`\`\`json
84
- ${JSON.stringify(result, null, 2)}
84
+ ${JSON.stringify(result)}
85
85
  \`\`\``
86
86
  }
87
87
  ]
@@ -102,13 +102,13 @@ Errors: ${errors.length}
102
102
  if (docs.length > 0) {
103
103
  responseText += `\n\nDeleted documents:
104
104
  \`\`\`json
105
- ${JSON.stringify(docs, null, 2)}
105
+ ${JSON.stringify(docs)}
106
106
  \`\`\``;
107
107
  }
108
108
  if (errors.length > 0) {
109
109
  responseText += `\n\nErrors:
110
110
  \`\`\`json
111
- ${JSON.stringify(errors, null, 2)}
111
+ ${JSON.stringify(errors)}
112
112
  \`\`\``;
113
113
  }
114
114
  const response = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/resource/delete.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 deleteResourceTool = (\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 where?: string,\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] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\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 // 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 // Build delete options\n const deleteOptions: Record<string, unknown> = {\n collection: collectionSlug,\n depth,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n // Delete by ID or where clause\n if (id) {\n deleteOptions.id = id\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting single document with ID: ${id}`)\n }\n } else {\n deleteOptions.where = whereClause\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting multiple documents with where clause`)\n }\n }\n\n const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])\n\n // Handle different result types\n if (id) {\n // Single document deletion\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully deleted document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted document:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\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 } else {\n // Multiple documents deletion\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nDeleted documents:\n\\`\\`\\`json\n${JSON.stringify(docs, null, 2)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors, 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?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting resource from ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting resource from collection \"${collectionSlug}\": ${errorMessage}`,\n },\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.registerTool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n inputSchema: toolSchemas.deleteResource.parameters.shape,\n },\n async ({ id, depth, fallbackLocale, locale, where }) => {\n return await tool(id, where, depth, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","locale","fallbackLocale","payload","logger","info","error","response","content","type","text","overrideResponse","whereClause","JSON","parse","_parseError","warn","deleteOptions","collection","overrideAccess","result","delete","stringify","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","deleteResource","trim","inputSchema","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,OACAC,QAAgB,CAAC,EACjBC,QACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,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EA,MAAMlB,WAAW;oBACfC,SAAS;wBACP;4BACEC,MAAM;4BACNC,MAAMiB;wBACR;qBACD;gBACH;gBAEA,OAAQ/B,aAAa,CAACD,eAAe,EAAEgB,mBACrCJ,UACA;oBAAEiB;oBAAMC;gBAAO,GACfjC,QACGe;YAMP;QACF,EAAE,OAAOD,OAAO;YACd,MAAMsB,eAAetB,iBAAiBuB,QAAQvB,MAAMwB,OAAO,GAAG;YAC9D3B,QAAQC,MAAM,CAACE,KAAK,CAClB,CAAC,2CAA2C,EAAEX,eAAe,EAAE,EAAEiC,cAAc;YAGjF,MAAMrB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,yCAAyC,EAAEf,eAAe,GAAG,EAAEiC,cAAc;oBACtF;iBACD;YACH;YAEA,OAAQhC,aAAa,CAACD,eAAe,EAAEgB,mBAAmBJ,UAAU,CAAC,GAAGf,QAAQe;QAMlF;IACF;IAEA,IAAIX,aAAa,CAACD,eAAe,EAAEoC,SAAS;QAC1CxC,OAAOyC,YAAY,CACjB,CAAC,MAAM,EAAErC,eAAesC,MAAM,CAAC,GAAGC,WAAW,KAAK9C,YAAYO,gBAAgBwC,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGxC,aAAa,CAACD,eAAe,EAAEyC,eAAe/C,YAAYgD,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalD,YAAYgD,cAAc,CAACG,UAAU,CAACC,KAAK;QAC1D,GACA,OAAO,EAAE3C,EAAE,EAAEE,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEF,KAAK,EAAE;YACjD,OAAO,MAAMF,KAAKC,IAAIC,OAAOC,OAAOC,QAAQC;QAC9C;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/resource/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { MCPPluginConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const deleteResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: MCPPluginConfig['collections'],\n) => {\n const tool = async (\n id?: number | string,\n where?: string,\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] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\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 // 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 // Build delete options\n const deleteOptions: Record<string, unknown> = {\n collection: collectionSlug,\n depth,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n // Delete by ID or where clause\n if (id) {\n deleteOptions.id = id\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting single document with ID: ${id}`)\n }\n } else {\n deleteOptions.where = whereClause\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting multiple documents with where clause`)\n }\n }\n\n const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])\n\n // Handle different result types\n if (id) {\n // Single document deletion\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully deleted document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted document:\n\\`\\`\\`json\n${JSON.stringify(result)}\n\\`\\`\\``,\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 } else {\n // Multiple documents deletion\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nDeleted documents:\n\\`\\`\\`json\n${JSON.stringify(docs)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors)}\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?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting resource from ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting resource from collection \"${collectionSlug}\": ${errorMessage}`,\n },\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.registerTool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n inputSchema: toolSchemas.deleteResource.parameters.shape,\n },\n async ({ id, depth, fallbackLocale, locale, where }) => {\n return await tool(id, where, depth, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","locale","fallbackLocale","payload","logger","info","error","response","content","type","text","overrideResponse","whereClause","JSON","parse","_parseError","warn","deleteOptions","collection","overrideAccess","result","delete","stringify","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","deleteResource","trim","inputSchema","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,OACAC,QAAgB,CAAC,EACjBC,QACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,uBAAuBG,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE9J;QAEA,IAAI;YACF,+CAA+C;YAC/C,IAAI,CAACH,MAAM,CAACC,OAAO;gBACjBI,QAAQC,MAAM,CAACE,KAAK,CAAC;gBACrB,MAAMC,WAAW;oBACfC,SAAS;wBACP;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoD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,MAAM,CAACE,KAAK,CAClB,CAAC,2CAA2C,EAAEX,eAAe,EAAE,EAAEiC,cAAc;YAGjF,MAAMrB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,yCAAyC,EAAEf,eAAe,GAAG,EAAEiC,cAAc;oBACtF;iBACD;YACH;YAEA,OAAQhC,aAAa,CAACD,eAAe,EAAEgB,mBAAmBJ,UAAU,CAAC,GAAGf,QAAQe;QAMlF;IACF;IAEA,IAAIX,aAAa,CAACD,eAAe,EAAEoC,SAAS;QAC1CxC,OAAOyC,YAAY,CACjB,CAAC,MAAM,EAAErC,eAAesC,MAAM,CAAC,GAAGC,WAAW,KAAK9C,YAAYO,gBAAgBwC,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGxC,aAAa,CAACD,eAAe,EAAEyC,eAAe/C,YAAYgD,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalD,YAAYgD,cAAc,CAACG,UAAU,CAACC,KAAK;QAC1D,GACA,OAAO,EAAE3C,EAAE,EAAEE,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEF,KAAK,EAAE;YACjD,OAAO,MAAMF,KAAKC,IAAIC,OAAOC,OAAOC,QAAQC;QAC9C;IAEJ;AACF,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { PayloadRequest, TypedUser } from 'payload';
3
- import type { PluginMCPServerConfig } from '../../../types.js';
4
- export declare const findResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: PluginMCPServerConfig["collections"]) => void;
3
+ import type { MCPPluginConfig } from '../../../types.js';
4
+ export declare const findResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: MCPPluginConfig["collections"]) => void;
5
5
  //# sourceMappingURL=find.d.ts.map
@@ -1 +1 @@
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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAEpE,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,SAuOlD,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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAEpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKxD,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,eAAe,CAAC,aAAa,CAAC,SAuO5C,CAAA"}
@@ -77,7 +77,7 @@ export const findResourceTool = (server, req, user, verboseLogs, collectionSlug,
77
77
  {
78
78
  type: 'text',
79
79
  text: `Resource from collection "${collectionSlug}":
80
- ${JSON.stringify(doc, null, 2)}`
80
+ ${JSON.stringify(doc)}`
81
81
  }
82
82
  ]
83
83
  };
@@ -132,7 +132,7 @@ Total: ${result.totalDocs} documents
132
132
  Page: ${result.page} of ${result.totalPages}
133
133
  `;
134
134
  for (const doc of result.docs){
135
- responseText += `\n\`\`\`json\n${JSON.stringify(doc, null, 2)}\n\`\`\``;
135
+ responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
136
136
  }
137
137
  const response = {
138
138
  content: [
@@ -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, SelectType, 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 select?: string,\n depth: number = 0,\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 // Parse select clause if provided\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 depth,\n ...(selectClause && { select: selectClause }),\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 depth,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(selectClause && { select: selectClause }),\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.registerTool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n inputSchema: toolSchemas.findResources.parameters.shape,\n },\n async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {\n return await tool(\n id,\n limit,\n page,\n sort,\n where,\n select,\n depth,\n locale,\n fallbackLocale,\n draft,\n )\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","select","depth","locale","fallbackLocale","draft","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","selectClause","doc","findByID","collection","overrideAccess","undefined","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","findResources","trim","inputSchema","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,gBACAC;I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B,eAAe,KAAK,EAAE6C,cAAc;oBAC5F;iBACD;YACH;YACA,OAAQ5C,aAAa,CAACD,eAAe,EAAEyB,mBAAmBJ,UAAU,CAAC,GAAGxB,QAAQwB;QAMlF;IACF;IAEA,IAAIpB,aAAa,CAACD,eAAe,EAAEgD,SAAS;QAC1CpD,OAAOqD,YAAY,CACjB,CAAC,IAAI,EAAEjD,eAAekD,MAAM,CAAC,GAAGC,WAAW,KAAK1D,YAAYO,gBAAgBoD,KAAK,CAAC,IAAI,EACtF;YACEC,aAAa,GAAGpD,aAAa,CAACD,eAAe,EAAEqD,eAAe3D,YAAY4D,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI;YAC5GC,aAAa9D,YAAY4D,aAAa,CAACG,UAAU,CAACC,KAAK;QACzD,GACA,OAAO,EAAEvD,EAAE,EAAEM,KAAK,EAAEG,KAAK,EAAED,cAAc,EAAEP,KAAK,EAAEM,MAAM,EAAEL,IAAI,EAAEG,MAAM,EAAEF,IAAI,EAAEC,KAAK,EAAE;YACnF,OAAO,MAAML,KACXC,IACAC,OACAC,MACAC,MACAC,OACAC,QACAC,OACAC,QACAC,gBACAC;QAEJ;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, SelectType, TypedUser } from 'payload'\n\nimport type { MCPPluginConfig } 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: MCPPluginConfig['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 select?: string,\n depth: number = 0,\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 // Parse select clause if provided\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 depth,\n ...(selectClause && { select: selectClause }),\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)}`,\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 depth,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(selectClause && { select: selectClause }),\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)}\\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.registerTool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n inputSchema: toolSchemas.findResources.parameters.shape,\n },\n async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {\n return await tool(\n id,\n limit,\n page,\n sort,\n where,\n select,\n depth,\n locale,\n fallbackLocale,\n draft,\n )\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","select","depth","locale","fallbackLocale","draft","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","selectClause","doc","findByID","collection","overrideAccess","undefined","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","findResources","trim","inputSchema","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,QAAgB,CAAC,EACjBC,QACAC,gBACAC;QAOA,MAAMC,UAAUhB,IAAIgB,OAAO;QAE3B,IAAId,aAAa;YACfc,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEf,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,OAAOK,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE3K;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIM,cAAc,CAAC;YACnB,IAAIT,OAAO;gBACT,IAAI;oBACFS,cAAcC,KAAKC,KAAK,C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AK,EAAEG,KAAK,EAAED,cAAc,EAAEP,KAAK,EAAEM,MAAM,EAAEL,IAAI,EAAEG,MAAM,EAAEF,IAAI,EAAEC,KAAK,EAAE;YACnF,OAAO,MAAML,KACXC,IACAC,OACAC,MACAC,MACAC,OACAC,QACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { JSONSchema4 } from 'json-schema';
3
3
  import type { PayloadRequest, TypedUser } from 'payload';
4
- import type { PluginMCPServerConfig } from '../../../types.js';
5
- export declare const updateResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: PluginMCPServerConfig["collections"], schema: JSONSchema4) => void;
4
+ import type { MCPPluginConfig } from '../../../types.js';
5
+ export declare const updateResourceTool: (server: McpServer, req: PayloadRequest, user: TypedUser, verboseLogs: boolean, collectionSlug: string, collections: MCPPluginConfig["collections"], schema: JSONSchema4) => void;
6
6
  //# sourceMappingURL=update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAU9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,SAuWpB,CAAA"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/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,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAUxD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,eAAe,CAAC,aAAa,CAAC,UACnC,WAAW,SAuWpB,CAAA"}
@@ -131,7 +131,7 @@ export const updateResourceTool = (server, req, user, verboseLogs, collectionSlu
131
131
  text: `Document updated successfully in collection "${collectionSlug}"!
132
132
  Updated document:
133
133
  \`\`\`json
134
- ${JSON.stringify(result, null, 2)}
134
+ ${JSON.stringify(result)}
135
135
  \`\`\``
136
136
  }
137
137
  ]
@@ -185,13 +185,13 @@ Errors: ${errors.length}
185
185
  if (docs.length > 0) {
186
186
  responseText += `\n\nUpdated documents:
187
187
  \`\`\`json
188
- ${JSON.stringify(docs, null, 2)}
188
+ ${JSON.stringify(docs)}
189
189
  \`\`\``;
190
190
  }
191
191
  if (errors.length > 0) {
192
192
  responseText += `\n\nErrors:
193
193
  \`\`\`json
194
- ${JSON.stringify(errors, null, 2)}
194
+ ${JSON.stringify(errors)}
195
195
  \`\`\``;
196
196
  }
197
197
  const response = {