@payloadcms/plugin-mcp 3.64.0-internal.fc1e451 → 3.64.0

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 (41) hide show
  1. package/dist/collections/createApiKeysCollection.d.ts.map +1 -1
  2. package/dist/collections/createApiKeysCollection.js +6 -0
  3. package/dist/collections/createApiKeysCollection.js.map +1 -1
  4. package/dist/endpoints/mcp.d.ts.map +1 -1
  5. package/dist/endpoints/mcp.js +30 -24
  6. package/dist/endpoints/mcp.js.map +1 -1
  7. package/dist/index.d.ts +7 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/mcp/createRequest.d.ts.map +1 -1
  11. package/dist/mcp/createRequest.js +2 -2
  12. package/dist/mcp/createRequest.js.map +1 -1
  13. package/dist/mcp/getMcpHandler.d.ts.map +1 -1
  14. package/dist/mcp/getMcpHandler.js +10 -8
  15. package/dist/mcp/getMcpHandler.js.map +1 -1
  16. package/dist/mcp/tools/resource/create.d.ts.map +1 -1
  17. package/dist/mcp/tools/resource/create.js +1 -0
  18. package/dist/mcp/tools/resource/create.js.map +1 -1
  19. package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
  20. package/dist/mcp/tools/resource/delete.js +1 -0
  21. package/dist/mcp/tools/resource/delete.js.map +1 -1
  22. package/dist/mcp/tools/resource/find.d.ts.map +1 -1
  23. package/dist/mcp/tools/resource/find.js +2 -0
  24. package/dist/mcp/tools/resource/find.js.map +1 -1
  25. package/dist/mcp/tools/resource/update.d.ts.map +1 -1
  26. package/dist/mcp/tools/resource/update.js +2 -0
  27. package/dist/mcp/tools/resource/update.js.map +1 -1
  28. package/dist/types.d.ts +13 -0
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/types.js.map +1 -1
  31. package/package.json +3 -3
  32. package/src/collections/createApiKeysCollection.ts +7 -0
  33. package/src/endpoints/mcp.ts +42 -30
  34. package/src/index.ts +8 -1
  35. package/src/mcp/createRequest.ts +2 -2
  36. package/src/mcp/getMcpHandler.ts +10 -7
  37. package/src/mcp/tools/resource/create.ts +1 -0
  38. package/src/mcp/tools/resource/delete.ts +1 -0
  39. package/src/mcp/tools/resource/find.ts +2 -0
  40. package/src/mcp/tools/resource/update.ts +2 -0
  41. package/src/types.ts +18 -0
@@ -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,SAoMlD,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,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SAqMlD,CAAA"}
@@ -46,6 +46,7 @@ export const deleteResourceTool = (server, req, user, verboseLogs, collectionSlu
46
46
  collection: collectionSlug,
47
47
  depth,
48
48
  overrideAccess: false,
49
+ req,
49
50
  user
50
51
  };
51
52
  // Delete by ID or where clause
@@ -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?: string,\n where?: string,\n depth: number = 0,\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'}`,\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 user,\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.tool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n toolSchemas.deleteResource.parameters.shape,\n async ({ id, depth, where }) => {\n return await tool(id, where, depth)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","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","charAt","toUpperCase","slice","description","deleteResource","trim","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;QAOjB,MAAMC,UAAUT,IAAIS,OAAO;QAE3B,IAAIP,aAAa;YACfO,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAER,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,sBAAsB;QAExH;QAEA,IAAI;YACF,+CAA+C;YAC/C,IAAI,CAACA,MAAM,CAACC,OAAO;gBACjBE,QAAQC,MAAM,CAACE,KAAK,CAAC;gBACrB,MAAMC,WAAW;oBACfC,SAAS;wBACP;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoD;qBACpF;gBACH;gBACA,OAAQZ,aAAa,CAACD,eAAe,EAAEc,mBAAmBJ,UAAU,CAAC,GAAGb,QACtEa;YAMJ;YAEA,iCAAiC;YACjC,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,cAAc;oBACtF;iBACD;YACH;YAEA,OAAQ9B,aAAa,CAACD,eAAe,EAAEc,mBAAmBJ,UAAU,CAAC,GAAGb,QAAQa;QAMlF;IACF;IAEA,IAAIT,aAAa,CAACD,eAAe,EAAEkC,SAAS;QAC1CtC,OAAOM,IAAI,CACT,CAAC,MAAM,EAAEF,eAAemC,MAAM,CAAC,GAAGC,WAAW,KAAK3C,YAAYO,gBAAgBqC,KAAK,CAAC,IAAI,EACxF,GAAGpC,aAAa,CAACD,eAAe,EAAEsC,eAAe5C,YAAY6C,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChG9C,YAAY6C,cAAc,CAACE,UAAU,CAACC,KAAK,EAC3C,OAAO,EAAEvC,EAAE,EAAEE,KAAK,EAAED,KAAK,EAAE;YACzB,OAAO,MAAMF,KAAKC,IAAIC,OAAOC;QAC/B;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 { 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?: string,\n where?: string,\n depth: number = 0,\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'}`,\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 }\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.tool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n toolSchemas.deleteResource.parameters.shape,\n async ({ id, depth, where }) => {\n return await tool(id, where, depth)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","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","charAt","toUpperCase","slice","description","deleteResource","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,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/mcp/tools/resource/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SAqLlD,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SAuLlD,CAAA"}
@@ -35,6 +35,7 @@ export const findResourceTool = (server, req, user, verboseLogs, collectionSlug,
35
35
  id,
36
36
  collection: collectionSlug,
37
37
  overrideAccess: false,
38
+ req,
38
39
  user
39
40
  });
40
41
  if (verboseLogs) {
@@ -69,6 +70,7 @@ ${JSON.stringify(doc, null, 2)}`
69
70
  limit,
70
71
  overrideAccess: false,
71
72
  page,
73
+ req,
72
74
  user
73
75
  };
74
76
  if (sort) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n user,\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, limit, page, sort, where }) => {\n return await tool(id, limit, page, sort, where)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","findResources","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,QAAgB,EAAE,EAClBC,OAAe,CAAC,EAChBC,MACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,MAAM;QAErI;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIM,cAAc,CAAC;YACnB,IAAIJ,OAAO;gBACT,IAAI;oBACFI,cAAcC,KAAKC,KAAK,CAACN;oBACzB,IAAIR,aAAa;wBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEH,OAAO;oBAClE;gBACF,EAAE,OAAOO,aAAa;oBACpBN,QAAQC,MAAM,CAACM,IAAI,CAAC,CAAC,yCAAyC,EAAER,OAAO;oBACvE,MAAMS,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAsC;yBAAE;oBACnF;oBACA,OAAQlB,aAAa,CAACD,eAAe,EAAEoB,mBAAmBJ,UAAU,CAAC,GAAGnB,QACtEmB;gBAMJ;YACF;YAEA,kCAAkC;YAClC,IAAIb,IAAI;gBACN,IAAI;oBACF,MAAMkB,MAAM,MAAMb,QAAQc,QAAQ,CAAC;wBACjCnB;wBACAoB,Y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AML,KAAKC,IAAIC,OAAOC,MAAMC,MAAMC;QAC3C;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n req,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, limit, page, sort, where }) => {\n return await tool(id, limit, page, sort, where)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","findResources","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,QAAgB,EAAE,EAClBC,OAAe,CAAC,EAChBC,MACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,MAAM;QAErI;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIM,cAAc,CAAC;YACnB,IAAIJ,OAAO;gBACT,IAAI;oBACFI,cAAcC,KAAKC,KAAK,CAACN;oBACzB,IAAIR,aAAa;wBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEH,OAAO;oBAClE;gBACF,EAAE,OAAOO,aAAa;oBACpBN,QAAQC,MAAM,CAACM,IAAI,CAAC,CAAC,yCAAyC,EAAER,OAAO;oBACvE,MAAMS,WAAW;wB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WAAW,KAAKlD,YAAYO,gBAAgB4C,KAAK,CAAC,IAAI,EACtF,GAAG3C,aAAa,CAACD,eAAe,EAAE6C,eAAenD,YAAYoD,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI,EAC/FrD,YAAYoD,aAAa,CAACE,UAAU,CAACC,KAAK,EAC1C,OAAO,EAAE9C,EAAE,EAAEC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;YACrC,OAAO,MAAML,KAAKC,IAAIC,OAAOC,MAAMC,MAAMC;QAC3C;IAEJ;AACF,EAAC"}
@@ -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,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,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,UACzC,WAAW,SAySpB,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,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,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,UACzC,WAAW,SA2SpB,CAAA"}
@@ -73,6 +73,7 @@ export const updateResourceTool = (server, req, user, verboseLogs, collectionSlu
73
73
  draft,
74
74
  overrideAccess: false,
75
75
  overrideLock,
76
+ req,
76
77
  user,
77
78
  ...filePath && {
78
79
  filePath
@@ -113,6 +114,7 @@ ${JSON.stringify(result, null, 2)}
113
114
  draft,
114
115
  overrideAccess: false,
115
116
  overrideLock,
117
+ req,
116
118
  user,
117
119
  where: whereClause,
118
120
  ...filePath && {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/resource/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const updateResourceTool = (\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 id?: string,\n where?: string,\n draft: boolean = false,\n depth: number = 0,\n overrideLock: boolean = true,\n filePath?: string,\n overwriteExistingFiles: boolean = false,\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 resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${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 (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\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.error(`[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 // Update by ID or where clause\n if (id) {\n // Single document update\n const updateOptions = {\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n user,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating single document with ID: ${id}`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n } as any)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document updated successfully in collection \"${collectionSlug}\"!\nUpdated 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 update\n const updateOptions = {\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n user,\n where: whereClause,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating multiple documents with where clause`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n } as any)\n\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 updated ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated 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 updating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating 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 update-specific parameters\n const updateResourceSchema = z.object({\n ...convertedFields.shape,\n id: z.string().optional().describe('The ID of the document to update'),\n depth: z\n .number()\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update the document as a draft'),\n filePath: z.string().optional().describe('File path for file uploads'),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.tool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n updateResourceSchema.shape,\n async (params: Record<string, unknown>) => {\n const {\n id,\n depth,\n draft,\n filePath,\n overrideLock,\n overwriteExistingFiles,\n where,\n ...fieldData\n } = params\n // Convert field data back to JSON string format expected by the tool\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n id as string | undefined,\n where as string | undefined,\n draft as boolean,\n depth as number,\n overrideLock as boolean,\n filePath as string | undefined,\n overwriteExistingFiles as boolean,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","updateOptions","collection","overrideAccess","result","update","override","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","convertedFields","updateResourceSchema","object","shape","string","optional","describe","number","default","boolean","charAt","toU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,CAAC,MACRF,QAAQ,CAAC;YACZrC,wBAAwBpB,EACrB4D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,OACRF,QAAQ,CAAC;YACZ1C,OAAOf,EACJuD,MAAM,GACNC,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEApD,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,eAAeoD,MAAM,CAAC,GAAGC,WAAW,KAAK7D,YAAYQ,gBAAgBsD,KAAK,CAAC,IAAI,EACxF,GAAGrD,aAAa,CAACD,eAAe,EAAEuD,eAAe7D,YAAY8D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGd,qBAAqBE,KAAK,EAC1B,OAAOa;YACL,MAAM,EACJrD,EAAE,EACFG,KAAK,EACLD,KAAK,EACLG,QAAQ,EACRD,YAAY,EACZE,sBAAsB,EACtBL,KAAK,EACL,GAAGqD,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMtD,OAAOY,KAAKE,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC;QAEJ;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/resource/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const updateResourceTool = (\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 id?: string,\n where?: string,\n draft: boolean = false,\n depth: number = 0,\n overrideLock: boolean = true,\n filePath?: string,\n overwriteExistingFiles: boolean = false,\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 resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${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 (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\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.error(`[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 // Update by ID or where clause\n if (id) {\n // Single document update\n const updateOptions = {\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating single document with ID: ${id}`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n } as any)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document updated successfully in collection \"${collectionSlug}\"!\nUpdated 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 update\n const updateOptions = {\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n where: whereClause,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating multiple documents with where clause`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n } as any)\n\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 updated ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated 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 updating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating 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 update-specific parameters\n const updateResourceSchema = z.object({\n ...convertedFields.shape,\n id: z.string().optional().describe('The ID of the document to update'),\n depth: z\n .number()\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update the document as a draft'),\n filePath: z.string().optional().describe('File path for file uploads'),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.tool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n updateResourceSchema.shape,\n async (params: Record<string, unknown>) => {\n const {\n id,\n depth,\n draft,\n filePath,\n overrideLock,\n overwriteExistingFiles,\n where,\n ...fieldData\n } = params\n // Convert field data back to JSON string format expected by the tool\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n id as string | undefined,\n where as string | undefined,\n draft as boolean,\n depth as number,\n overrideLock as boolean,\n filePath as string | undefined,\n overwriteExistingFiles as boolean,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","updateOptions","collection","overrideAccess","result","update","override","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","convertedFields","updateResourceSchema","object","shape","string","optional","describe","number","default","boolean","charAt","toUpperCase","slice","description","updateResource","trim","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,IACAC,OACAC,QAAiB,KAAK,EACtBC,QAAgB,CAAC,EACjBC,eAAwB,IAAI,EAC5BC,UACAC,yBAAkC,KAAK;QAOvC,MAAMC,UAAUf,IAAIe,OAAO;QAE3B,IAAIb,aAAa;YACfa,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEd,iBAAiBK,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,qBAAqB,SAAS,EAAEE,OAAO;QAEvI;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIQ;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACb;gBACxB,IAAIL,aAAa;oBACfa,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEd,eAAe,EAAE,EAAEgB,KAAKE,SAAS,CAACH,aAAa;gBAEpF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAA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;YACpC,GAAGF,gBAAgBG,KAAK;YACxBxC,IAAId,EAAEuD,MAAM,GAAGC,QAAQ,GAAGC,QAAQ,CAAC;YACnCxC,OAAOjB,EACJ0D,MAAM,GACNF,QAAQ,GACRG,OAAO,CAAC,GACRF,QAAQ,CAAC;YACZzC,OAAOhB,EACJ4D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,OACRF,QAAQ,CAAC;YACZtC,UAAUnB,EAAEuD,MAAM,GAAGC,QAAQ,GAAGC,QAAQ,CAAC;YACzCvC,cAAclB,EACX4D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,MACRF,QAAQ,CAAC;YACZrC,wBAAwBpB,EACrB4D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,OACRF,QAAQ,CAAC;YACZ1C,OAAOf,EACJuD,MAAM,GACNC,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEApD,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,eAAeoD,MAAM,CAAC,GAAGC,WAAW,KAAK7D,YAAYQ,gBAAgBsD,KAAK,CAAC,IAAI,EACxF,GAAGrD,aAAa,CAACD,eAAe,EAAEuD,eAAe7D,YAAY8D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGd,qBAAqBE,KAAK,EAC1B,OAAOa;YACL,MAAM,EACJrD,EAAE,EACFG,KAAK,EACLD,KAAK,EACLG,QAAQ,EACRD,YAAY,EACZE,sBAAsB,EACtBL,KAAK,EACL,GAAGqD,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMtD,OAAOY,KAAKE,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC;QAEJ;IAEJ;AACF,EAAC"}
package/dist/types.d.ts CHANGED
@@ -197,7 +197,20 @@ export type PluginMCPServerConfig = {
197
197
  parameters: z.ZodRawShape;
198
198
  }[];
199
199
  };
200
+ /**
201
+ * Override the API key collection.
202
+ * This allows you to add fields to the API key collection or modify the collection in any way you want.
203
+ * @param collection - The API key collection.
204
+ * @returns The modified API key collection.
205
+ */
200
206
  overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig;
207
+ /**
208
+ * Override the authentication method.
209
+ * This allows you to use a custom authentication method instead of the default API key authentication.
210
+ * @param req - The request object.
211
+ * @returns The MCP access settings.
212
+ */
213
+ overrideAuth?: (req: PayloadRequest, getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>) => MCPAccessSettings | Promise<MCPAccessSettings>;
201
214
  /**
202
215
  * Set the users collection that API keys should be associated with.
203
216
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAE/E,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CACnB,MAAM,CACJ,cAAc,EACd;QACE;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB;;WAEG;QACH,OAAO,EACH;YACE,MAAM,CAAC,EAAE,OAAO,CAAA;YAChB,MAAM,CAAC,EAAE,OAAO,CAAA;YAChB,IAAI,CAAC,EAAE,OAAO,CAAA;YACd,MAAM,CAAC,EAAE,OAAO,CAAA;SACjB,GACD,OAAO,CAAA;QACX;;WAEG;QACH,QAAQ,CAAC,EAAE,CACT,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,GAAG,EAAE,cAAc,KAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAE5B;;WAEG;QACH,gBAAgB,CAAC,EAAE,CACjB,QAAQ,EAAE;YACR,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type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload'\nimport type { z } from 'zod'\n\nimport { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'\n\nexport type PluginMCPServerConfig = {\n /**\n * Set the collections that should be available as resources via MCP.\n */\n collections?: Partial<\n Record<\n CollectionSlug,\n {\n /**\n * Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.\n */\n description?: string\n /**\n * Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.\n */\n enabled:\n | {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n | boolean\n /**\n * Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n override?: (\n original: Record<string, unknown>,\n req: PayloadRequest,\n ) => Record<string, unknown>\n\n /**\n * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n overrideResponse?: (\n response: {\n content: Array<{\n text: string\n type: string\n }>\n },\n doc: Record<string, unknown>,\n req: PayloadRequest,\n ) => {\n content: Array<{\n text: string\n type: string\n }>\n }\n }\n >\n >\n /**\n * Disable the MCP plugin.\n */\n disabled?: boolean\n /**\n * Experimental features\n * **These features are for experimental purposes -- They are Disabled in Production by Default**\n */\n experimental?: {\n /**\n * These are MCP tools that can be used by a client to modify Payload.\n */\n tools: {\n /**\n * **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.\n */\n auth?: {\n /**\n * Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.\n */\n collections?: {\n /**\n * Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.\n */\n collectionsDirPath: string\n /**\n * Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.\n */\n config?: {\n /**\n * Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.\n */\n configFilePath: string\n /**\n * Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.\n */\n jobs?: {\n /**\n * Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.\n * @default false\n */\n enabled: boolean\n /**\n * Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.\n */\n jobsDirPath: string\n }\n }\n }\n /**\n * MCP Server options.\n */\n mcp?: {\n handlerOptions?: MCPHandlerOptions\n /**\n * Add custom MCP Prompts.\n */\n prompts?: {\n /**\n * Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.\n */\n argsSchema: z.ZodRawShape\n /**\n * Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.\n */\n description: string\n /**\n * Set the handler of the prompt. This is the function that will be called when the prompt is used.\n */\n handler: (...args: any) => any\n /**\n * Set the function name of the prompt.\n */\n name: string\n /**\n * Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.\n */\n title: string\n }[]\n\n /**\n * Add custom MCP Resource.\n */\n resources?: {\n /**\n * Set the description of the resource. This is used by MCP clients to determine when to use the resource.\n * example: 'Data is a resource that contains special data.'\n */\n description: string\n /**\n * Set the handler of the resource. This is the function that will be called when the resource is used.\n */\n handler: (...args: any) => any\n /**\n * Set the mime type of the resource.\n * example: 'text/plain'\n */\n mimeType: string\n /**\n * Set the function name of the resource.\n * example: 'data'\n */\n name: string\n /**\n * Set the title of the resource. LLMs will interperate the title to determine when to use the resource.\n * example: 'Data'\n */\n title: string\n /**\n * Set the uri of the resource.\n * example: 'data://app'\n */\n uri: ResourceTemplate | string\n }[]\n serverOptions?: MCPServerOptions\n /**\n * Add custom MCP Tools.\n */\n tools?: {\n /**\n * Set the description of the tool. This is used by MCP clients to determine when to use the tool.\n */\n description: string\n /**\n * Set the handler of the tool. This is the function that will be called when the tool is used.\n */\n handler: (args: Record<string, unknown>) => Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }>\n /**\n * Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.\n */\n name: string\n /**\n * Set the parameters of the tool. This is the parameters that will be passed to the tool.\n */\n parameters: z.ZodRawShape\n }[]\n }\n overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig\n\n /**\n * Set the users collection that API keys should be associated with.\n */\n userCollection?: CollectionConfig | string\n}\n\n/**\n * MCP Handler options.\n */\nexport type MCPHandlerOptions = {\n /**\n * Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.\n * @default /api\n */\n basePath?: string\n /**\n * Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.\n * @default 60\n */\n maxDuration?: number\n /**\n * Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.\n * @default process.env.REDIS_URL\n * INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n */\n // redisUrl?: string\n /**\n * Set verbose logging.\n * @default false\n */\n verboseLogs?: boolean\n}\n\n/**\n * MCP Server options.\n */\nexport type MCPServerOptions = {\n /**\n * Set the server info of the MCP server.\n */\n serverInfo?: {\n /**\n * Set the name of the MCP server.\n * @default 'Payload MCP Server'\n */\n name: string\n /**\n * Set the version of the MCP server.\n * @default '1.0.0'\n */\n version: string\n }\n}\n\nexport type MCPAccessSettings = {\n auth?: {\n auth?: boolean\n forgotPassword?: boolean\n login?: boolean\n resetPassword?: boolean\n unlock?: boolean\n verify?: boolean\n }\n collections?: {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n config?: {\n find?: boolean\n update?: boolean\n }\n jobs?: {\n create?: boolean\n run?: boolean\n update?: boolean\n }\n 'payload-mcp-prompt'?: Record<string, boolean>\n 'payload-mcp-resource'?: Record<string, boolean>\n 'payload-mcp-tool'?: Record<string, boolean>\n} & Record<string, unknown>\n\nexport type FieldDefinition = {\n description?: string\n name: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type: string\n}\n\nexport type FieldModification = {\n changes: {\n description?: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type?: string\n }\n fieldName: string\n}\n\nexport type CollectionConfigUpdates = {\n access?: {\n create?: string\n delete?: string\n read?: string\n update?: string\n }\n description?: string\n slug?: string\n timestamps?: boolean\n versioning?: boolean\n}\n\nexport type AdminConfig = {\n avatar?: string\n css?: string\n dateFormat?: string\n inactivityRoute?: string\n livePreview?: {\n breakpoints?: Array<{\n height: number\n label: string\n name: string\n width: number\n }>\n }\n logoutRoute?: string\n meta?: {\n favicon?: string\n ogImage?: string\n titleSuffix?: string\n }\n user?: string\n}\n\nexport type DatabaseConfig = {\n connectOptions?: string\n type?: 'mongodb' | 'postgres'\n url?: string\n}\n\nexport type PluginUpdates = {\n add?: string[]\n remove?: string[]\n}\n\nexport type GeneralConfig = {\n cookiePrefix?: string\n cors?: string\n csrf?: string\n graphQL?: {\n disable?: boolean\n schemaOutputFile?: string\n }\n rateLimit?: {\n max?: number\n skip?: string\n window?: number\n }\n secret?: string\n serverURL?: string\n typescript?: {\n declare?: boolean\n outputFile?: string\n }\n}\n\nexport interface SchemaField {\n description?: string\n name: string\n options?: string[]\n required?: boolean\n type: string\n}\n\nexport interface TaskSequenceItem {\n description?: string\n retries?: number\n taskId: string\n taskSlug: string\n timeout?: number\n}\n\nexport interface JobConfigUpdate {\n description?: string\n queue?: string\n retries?: number\n timeout?: number\n}\n"],"names":[],"mappings":"AAqZA,WAKC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload'\nimport type { z } from 'zod'\n\nimport { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'\n\nexport type PluginMCPServerConfig = {\n /**\n * Set the collections that should be available as resources via MCP.\n */\n collections?: Partial<\n Record<\n CollectionSlug,\n {\n /**\n * Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.\n */\n description?: string\n /**\n * Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.\n */\n enabled:\n | {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n | boolean\n /**\n * Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n override?: (\n original: Record<string, unknown>,\n req: PayloadRequest,\n ) => Record<string, unknown>\n\n /**\n * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n overrideResponse?: (\n response: {\n content: Array<{\n text: string\n type: string\n }>\n },\n doc: Record<string, unknown>,\n req: PayloadRequest,\n ) => {\n content: Array<{\n text: string\n type: string\n }>\n }\n }\n >\n >\n /**\n * Disable the MCP plugin.\n */\n disabled?: boolean\n /**\n * Experimental features\n * **These features are for experimental purposes -- They are Disabled in Production by Default**\n */\n experimental?: {\n /**\n * These are MCP tools that can be used by a client to modify Payload.\n */\n tools: {\n /**\n * **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.\n */\n auth?: {\n /**\n * Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.\n */\n collections?: {\n /**\n * Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.\n */\n collectionsDirPath: string\n /**\n * Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.\n */\n config?: {\n /**\n * Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.\n */\n configFilePath: string\n /**\n * Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.\n */\n jobs?: {\n /**\n * Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.\n * @default false\n */\n enabled: boolean\n /**\n * Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.\n */\n jobsDirPath: string\n }\n }\n }\n /**\n * MCP Server options.\n */\n mcp?: {\n handlerOptions?: MCPHandlerOptions\n /**\n * Add custom MCP Prompts.\n */\n prompts?: {\n /**\n * Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.\n */\n argsSchema: z.ZodRawShape\n /**\n * Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.\n */\n description: string\n /**\n * Set the handler of the prompt. This is the function that will be called when the prompt is used.\n */\n handler: (...args: any) => any\n /**\n * Set the function name of the prompt.\n */\n name: string\n /**\n * Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.\n */\n title: string\n }[]\n\n /**\n * Add custom MCP Resource.\n */\n resources?: {\n /**\n * Set the description of the resource. This is used by MCP clients to determine when to use the resource.\n * example: 'Data is a resource that contains special data.'\n */\n description: string\n /**\n * Set the handler of the resource. This is the function that will be called when the resource is used.\n */\n handler: (...args: any) => any\n /**\n * Set the mime type of the resource.\n * example: 'text/plain'\n */\n mimeType: string\n /**\n * Set the function name of the resource.\n * example: 'data'\n */\n name: string\n /**\n * Set the title of the resource. LLMs will interperate the title to determine when to use the resource.\n * example: 'Data'\n */\n title: string\n /**\n * Set the uri of the resource.\n * example: 'data://app'\n */\n uri: ResourceTemplate | string\n }[]\n serverOptions?: MCPServerOptions\n /**\n * Add custom MCP Tools.\n */\n tools?: {\n /**\n * Set the description of the tool. This is used by MCP clients to determine when to use the tool.\n */\n description: string\n /**\n * Set the handler of the tool. This is the function that will be called when the tool is used.\n */\n handler: (args: Record<string, unknown>) => Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }>\n /**\n * Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.\n */\n name: string\n /**\n * Set the parameters of the tool. This is the parameters that will be passed to the tool.\n */\n parameters: z.ZodRawShape\n }[]\n }\n\n /**\n * Override the API key collection.\n * This allows you to add fields to the API key collection or modify the collection in any way you want.\n * @param collection - The API key collection.\n * @returns The modified API key collection.\n */\n overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig\n\n /**\n * Override the authentication method.\n * This allows you to use a custom authentication method instead of the default API key authentication.\n * @param req - The request object.\n * @returns The MCP access settings.\n */\n overrideAuth?: (\n req: PayloadRequest,\n getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>,\n ) => MCPAccessSettings | Promise<MCPAccessSettings>\n\n /**\n * Set the users collection that API keys should be associated with.\n */\n userCollection?: CollectionConfig | string\n}\n\n/**\n * MCP Handler options.\n */\nexport type MCPHandlerOptions = {\n /**\n * Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.\n * @default /api\n */\n basePath?: string\n /**\n * Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.\n * @default 60\n */\n maxDuration?: number\n /**\n * Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.\n * @default process.env.REDIS_URL\n * INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n */\n // redisUrl?: string\n /**\n * Set verbose logging.\n * @default false\n */\n verboseLogs?: boolean\n}\n\n/**\n * MCP Server options.\n */\nexport type MCPServerOptions = {\n /**\n * Set the server info of the MCP server.\n */\n serverInfo?: {\n /**\n * Set the name of the MCP server.\n * @default 'Payload MCP Server'\n */\n name: string\n /**\n * Set the version of the MCP server.\n * @default '1.0.0'\n */\n version: string\n }\n}\n\nexport type MCPAccessSettings = {\n auth?: {\n auth?: boolean\n forgotPassword?: boolean\n login?: boolean\n resetPassword?: boolean\n unlock?: boolean\n verify?: boolean\n }\n collections?: {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n config?: {\n find?: boolean\n update?: boolean\n }\n jobs?: {\n create?: boolean\n run?: boolean\n update?: boolean\n }\n 'payload-mcp-prompt'?: Record<string, boolean>\n 'payload-mcp-resource'?: Record<string, boolean>\n 'payload-mcp-tool'?: Record<string, boolean>\n} & Record<string, unknown>\n\nexport type FieldDefinition = {\n description?: string\n name: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type: string\n}\n\nexport type FieldModification = {\n changes: {\n description?: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type?: string\n }\n fieldName: string\n}\n\nexport type CollectionConfigUpdates = {\n access?: {\n create?: string\n delete?: string\n read?: string\n update?: string\n }\n description?: string\n slug?: string\n timestamps?: boolean\n versioning?: boolean\n}\n\nexport type AdminConfig = {\n avatar?: string\n css?: string\n dateFormat?: string\n inactivityRoute?: string\n livePreview?: {\n breakpoints?: Array<{\n height: number\n label: string\n name: string\n width: number\n }>\n }\n logoutRoute?: string\n meta?: {\n favicon?: string\n ogImage?: string\n titleSuffix?: string\n }\n user?: string\n}\n\nexport type DatabaseConfig = {\n connectOptions?: string\n type?: 'mongodb' | 'postgres'\n url?: string\n}\n\nexport type PluginUpdates = {\n add?: string[]\n remove?: string[]\n}\n\nexport type GeneralConfig = {\n cookiePrefix?: string\n cors?: string\n csrf?: string\n graphQL?: {\n disable?: boolean\n schemaOutputFile?: string\n }\n rateLimit?: {\n max?: number\n skip?: string\n window?: number\n }\n secret?: string\n serverURL?: string\n typescript?: {\n declare?: boolean\n outputFile?: string\n }\n}\n\nexport interface SchemaField {\n description?: string\n name: string\n options?: string[]\n required?: boolean\n type: string\n}\n\nexport interface TaskSequenceItem {\n description?: string\n retries?: number\n taskId: string\n taskSlug: string\n timeout?: number\n}\n\nexport interface JobConfigUpdate {\n description?: string\n queue?: string\n retries?: number\n timeout?: number\n}\n"],"names":[],"mappings":"AAuaA,WAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-mcp",
3
- "version": "3.64.0-internal.fc1e451",
3
+ "version": "3.64.0",
4
4
  "description": "MCP (Model Context Protocol) capabilities with Payload",
5
5
  "keywords": [
6
6
  "plugin",
@@ -45,10 +45,10 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@payloadcms/eslint-config": "3.28.0",
48
- "payload": "3.64.0-internal.fc1e451"
48
+ "payload": "3.64.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "payload": "3.64.0-internal.fc1e451"
51
+ "payload": "3.64.0"
52
52
  },
53
53
  "homepage:": "https://payloadcms.com",
54
54
  "scripts": {
@@ -31,6 +31,7 @@ const addEnabledCollectionTools = (collections: PluginMCPServerConfig['collectio
31
31
  return enabledCollectionSlugs.map((enabledCollectionSlug) => ({
32
32
  type: 'collapsible' as const,
33
33
  admin: {
34
+ description: `Manage client access to ${enabledCollectionSlug}`,
34
35
  position: 'sidebar' as const,
35
36
  },
36
37
  fields: [
@@ -169,6 +170,8 @@ export const createAPIKeysCollection = (
169
170
  return {
170
171
  slug: 'payload-mcp-api-keys',
171
172
  admin: {
173
+ description:
174
+ 'API keys control which collections, resources, tools, and prompts MCP clients can access',
172
175
  group: 'MCP',
173
176
  useAsTitle: 'label',
174
177
  },
@@ -208,6 +211,7 @@ export const createAPIKeysCollection = (
208
211
  {
209
212
  type: 'collapsible' as const,
210
213
  admin: {
214
+ description: 'Manage client access to tools',
211
215
  position: 'sidebar' as const,
212
216
  },
213
217
  fields: [
@@ -228,6 +232,7 @@ export const createAPIKeysCollection = (
228
232
  {
229
233
  type: 'collapsible' as const,
230
234
  admin: {
235
+ description: 'Manage client access to resources',
231
236
  position: 'sidebar' as const,
232
237
  },
233
238
  fields: [
@@ -248,6 +253,7 @@ export const createAPIKeysCollection = (
248
253
  {
249
254
  type: 'collapsible' as const,
250
255
  admin: {
256
+ description: 'Manage client access to prompts',
251
257
  position: 'sidebar' as const,
252
258
  },
253
259
  fields: [
@@ -273,6 +279,7 @@ export const createAPIKeysCollection = (
273
279
  {
274
280
  type: 'collapsible' as const,
275
281
  admin: {
282
+ description: 'Manage client access to experimental tools',
276
283
  position: 'sidebar' as const,
277
284
  },
278
285
  fields: [
@@ -1,5 +1,5 @@
1
1
  import crypto from 'crypto'
2
- import { APIError, type PayloadHandler, type Where } from 'payload'
2
+ import { type PayloadHandler, UnauthorizedError, type Where } from 'payload'
3
3
 
4
4
  import type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'
5
5
 
@@ -13,45 +13,57 @@ export const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {
13
13
  const MCPHandlerOptions = MCPOptions.handlerOptions || {}
14
14
  const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false
15
15
 
16
- const apiKey = req.headers.get('Authorization')?.startsWith('Bearer ')
17
- ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()
18
- : null
16
+ req.payloadAPI = 'MCP' as const
19
17
 
20
- if (apiKey === null) {
21
- throw new APIError('API Key is required', 401)
22
- }
18
+ const getDefaultMcpAccessSettings = async (overrideApiKey?: null | string) => {
19
+ const apiKey =
20
+ (overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer '))
21
+ ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()
22
+ : null
23
+
24
+ if (apiKey === null) {
25
+ throw new UnauthorizedError()
26
+ }
23
27
 
24
- const sha256APIKeyIndex = crypto
25
- .createHmac('sha256', payload.secret)
26
- .update(apiKey || '')
27
- .digest('hex')
28
+ const sha256APIKeyIndex = crypto
29
+ .createHmac('sha256', payload.secret)
30
+ .update(apiKey || '')
31
+ .digest('hex')
28
32
 
29
- const apiKeyConstraints = [
30
- {
31
- apiKeyIndex: {
32
- equals: sha256APIKeyIndex,
33
+ const apiKeyConstraints = [
34
+ {
35
+ apiKeyIndex: {
36
+ equals: sha256APIKeyIndex,
37
+ },
33
38
  },
34
- },
35
- ]
36
- const where: Where = {
37
- or: apiKeyConstraints,
38
- }
39
+ ]
39
40
 
40
- const { docs } = await payload.find({
41
- collection: 'payload-mcp-api-keys',
42
- where,
43
- })
41
+ const where: Where = {
42
+ or: apiKeyConstraints,
43
+ }
44
44
 
45
- if (docs.length === 0) {
46
- throw new APIError('API Key is invalid', 401)
47
- }
45
+ const { docs } = await payload.find({
46
+ collection: 'payload-mcp-api-keys',
47
+ limit: 1,
48
+ pagination: false,
49
+ where,
50
+ })
51
+
52
+ if (docs.length === 0) {
53
+ throw new UnauthorizedError()
54
+ }
48
55
 
49
- const mcpAccessSettings = docs[0] as MCPAccessSettings
56
+ if (useVerboseLogs) {
57
+ payload.logger.info('[payload-mcp] API Key is valid')
58
+ }
50
59
 
51
- if (useVerboseLogs) {
52
- payload.logger.info('[payload-mcp] API Key is valid')
60
+ return docs[0] as MCPAccessSettings
53
61
  }
54
62
 
63
+ const mcpAccessSettings = pluginOptions.overrideAuth
64
+ ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings)
65
+ : await getDefaultMcpAccessSettings()
66
+
55
67
  const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req)
56
68
  const request = createRequestFromPayloadRequest(req)
57
69
  return await handler(request)
package/src/index.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import type { Config } from 'payload'
2
2
 
3
- import type { PluginMCPServerConfig } from './types.js'
3
+ import type { MCPAccessSettings, PluginMCPServerConfig } from './types.js'
4
4
 
5
5
  import { createAPIKeysCollection } from './collections/createApiKeysCollection.js'
6
6
  import { initializeMCPHandler } from './endpoints/mcp.js'
7
7
 
8
+ declare module 'payload' {
9
+ export interface PayloadRequest {
10
+ payloadAPI: 'GraphQL' | 'local' | 'MCP' | 'REST'
11
+ }
12
+ }
13
+
14
+ export type { MCPAccessSettings }
8
15
  /**
9
16
  * The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
10
17
  *
@@ -1,8 +1,8 @@
1
- import { APIError, type PayloadRequest } from 'payload'
1
+ import { AuthenticationError, type PayloadRequest } from 'payload'
2
2
 
3
3
  export const createRequestFromPayloadRequest = (req: PayloadRequest) => {
4
4
  if (!req.url) {
5
- throw new APIError('Request URL is required', 500)
5
+ throw new AuthenticationError()
6
6
  }
7
7
  return new Request(req.url, {
8
8
  body: req.body,
@@ -16,6 +16,9 @@ import { findResourceTool } from './tools/resource/find.js'
16
16
  import { updateResourceTool } from './tools/resource/update.js'
17
17
 
18
18
  // Experimental Tools
19
+ /**
20
+ * @experimental This tools are experimental and may change or be removed in the future.
21
+ */
19
22
  import { authTool } from './tools/auth/auth.js'
20
23
  import { forgotPasswordTool } from './tools/auth/forgotPassword.js'
21
24
  import { loginTool } from './tools/auth/login.js'
@@ -108,10 +111,10 @@ export const getMCPHandler = (
108
111
  const toolCapabilities = mcpAccessSettings?.[
109
112
  `${toCamelCase(enabledCollectionSlug)}`
110
113
  ] as Record<string, unknown>
111
- const allowCreate: boolean | undefined = toolCapabilities['create'] as boolean
112
- const allowUpdate: boolean | undefined = toolCapabilities['update'] as boolean
113
- const allowFind: boolean | undefined = toolCapabilities['find'] as boolean
114
- const allowDelete: boolean | undefined = toolCapabilities['delete'] as boolean
114
+ const allowCreate: boolean | undefined = toolCapabilities?.create as boolean
115
+ const allowUpdate: boolean | undefined = toolCapabilities?.update as boolean
116
+ const allowFind: boolean | undefined = toolCapabilities?.find as boolean
117
+ const allowDelete: boolean | undefined = toolCapabilities?.delete as boolean
115
118
 
116
119
  if (allowCreate) {
117
120
  registerTool(
@@ -194,7 +197,7 @@ export const getMCPHandler = (
194
197
  // Custom tools
195
198
  customMCPTools.forEach((tool) => {
196
199
  const camelCasedToolName = toCamelCase(tool.name)
197
- const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? true
200
+ const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? false
198
201
 
199
202
  registerTool(
200
203
  isToolEnabled,
@@ -209,7 +212,7 @@ export const getMCPHandler = (
209
212
  customMCPPrompts.forEach((prompt) => {
210
213
  const camelCasedPromptName = toCamelCase(prompt.name)
211
214
  const isPromptEnabled =
212
- mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? true
215
+ mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? false
213
216
 
214
217
  if (isPromptEnabled) {
215
218
  server.registerPrompt(
@@ -233,7 +236,7 @@ export const getMCPHandler = (
233
236
  customMCPResources.forEach((resource) => {
234
237
  const camelCasedResourceName = toCamelCase(resource.name)
235
238
  const isResourceEnabled =
236
- mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? true
239
+ mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? false
237
240
 
238
241
  if (isResourceEnabled) {
239
242
  server.registerResource(