@payloadcms/plugin-mcp 3.77.0-internal.8cf758f → 3.77.0-internal.fd50432

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 (119) hide show
  1. package/dist/mcp/getMcpHandler.d.ts.map +1 -1
  2. package/dist/mcp/getMcpHandler.js +8 -4
  3. package/dist/mcp/getMcpHandler.js.map +1 -1
  4. package/dist/mcp/tools/auth/auth.d.ts.map +1 -1
  5. package/dist/mcp/tools/auth/auth.js +4 -1
  6. package/dist/mcp/tools/auth/auth.js.map +1 -1
  7. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +1 -1
  8. package/dist/mcp/tools/auth/forgotPassword.js +4 -1
  9. package/dist/mcp/tools/auth/forgotPassword.js.map +1 -1
  10. package/dist/mcp/tools/auth/login.d.ts.map +1 -1
  11. package/dist/mcp/tools/auth/login.js +4 -1
  12. package/dist/mcp/tools/auth/login.js.map +1 -1
  13. package/dist/mcp/tools/auth/resetPassword.d.ts.map +1 -1
  14. package/dist/mcp/tools/auth/resetPassword.js +4 -1
  15. package/dist/mcp/tools/auth/resetPassword.js.map +1 -1
  16. package/dist/mcp/tools/auth/unlock.d.ts.map +1 -1
  17. package/dist/mcp/tools/auth/unlock.js +4 -1
  18. package/dist/mcp/tools/auth/unlock.js.map +1 -1
  19. package/dist/mcp/tools/auth/verify.d.ts.map +1 -1
  20. package/dist/mcp/tools/auth/verify.js +4 -1
  21. package/dist/mcp/tools/auth/verify.js.map +1 -1
  22. package/dist/mcp/tools/collection/create.d.ts.map +1 -1
  23. package/dist/mcp/tools/collection/create.js +4 -1
  24. package/dist/mcp/tools/collection/create.js.map +1 -1
  25. package/dist/mcp/tools/collection/delete.d.ts.map +1 -1
  26. package/dist/mcp/tools/collection/delete.js +4 -1
  27. package/dist/mcp/tools/collection/delete.js.map +1 -1
  28. package/dist/mcp/tools/collection/find.d.ts.map +1 -1
  29. package/dist/mcp/tools/collection/find.js +4 -1
  30. package/dist/mcp/tools/collection/find.js.map +1 -1
  31. package/dist/mcp/tools/collection/update.d.ts.map +1 -1
  32. package/dist/mcp/tools/collection/update.js +4 -1
  33. package/dist/mcp/tools/collection/update.js.map +1 -1
  34. package/dist/mcp/tools/config/find.d.ts.map +1 -1
  35. package/dist/mcp/tools/config/find.js +4 -1
  36. package/dist/mcp/tools/config/find.js.map +1 -1
  37. package/dist/mcp/tools/config/update.d.ts.map +1 -1
  38. package/dist/mcp/tools/config/update.js +4 -1
  39. package/dist/mcp/tools/config/update.js.map +1 -1
  40. package/dist/mcp/tools/global/find.d.ts.map +1 -1
  41. package/dist/mcp/tools/global/find.js +4 -1
  42. package/dist/mcp/tools/global/find.js.map +1 -1
  43. package/dist/mcp/tools/global/update.d.ts.map +1 -1
  44. package/dist/mcp/tools/global/update.js +5 -2
  45. package/dist/mcp/tools/global/update.js.map +1 -1
  46. package/dist/mcp/tools/job/create.d.ts.map +1 -1
  47. package/dist/mcp/tools/job/create.js +4 -1
  48. package/dist/mcp/tools/job/create.js.map +1 -1
  49. package/dist/mcp/tools/job/run.d.ts.map +1 -1
  50. package/dist/mcp/tools/job/run.js +4 -1
  51. package/dist/mcp/tools/job/run.js.map +1 -1
  52. package/dist/mcp/tools/job/update.d.ts.map +1 -1
  53. package/dist/mcp/tools/job/update.js +4 -1
  54. package/dist/mcp/tools/job/update.js.map +1 -1
  55. package/dist/mcp/tools/resource/create.d.ts.map +1 -1
  56. package/dist/mcp/tools/resource/create.js +5 -2
  57. package/dist/mcp/tools/resource/create.js.map +1 -1
  58. package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
  59. package/dist/mcp/tools/resource/delete.js +4 -1
  60. package/dist/mcp/tools/resource/delete.js.map +1 -1
  61. package/dist/mcp/tools/resource/find.d.ts.map +1 -1
  62. package/dist/mcp/tools/resource/find.js +4 -1
  63. package/dist/mcp/tools/resource/find.js.map +1 -1
  64. package/dist/mcp/tools/resource/update.d.ts.map +1 -1
  65. package/dist/mcp/tools/resource/update.js +5 -2
  66. package/dist/mcp/tools/resource/update.js.map +1 -1
  67. package/dist/types.d.ts +11 -1
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js.map +1 -1
  70. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +1 -0
  71. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +34 -0
  72. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +1 -0
  73. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +8 -0
  74. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -0
  75. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +18 -0
  76. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -0
  77. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +20 -0
  78. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -0
  79. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +53 -0
  80. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -0
  81. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -0
  82. package/dist/utils/schemaConversion/transformPointFields.js.map +1 -0
  83. package/package.json +5 -5
  84. package/src/mcp/getMcpHandler.ts +9 -6
  85. package/src/mcp/tools/auth/auth.ts +5 -3
  86. package/src/mcp/tools/auth/forgotPassword.ts +5 -3
  87. package/src/mcp/tools/auth/login.ts +5 -3
  88. package/src/mcp/tools/auth/resetPassword.ts +5 -3
  89. package/src/mcp/tools/auth/unlock.ts +5 -3
  90. package/src/mcp/tools/auth/verify.ts +5 -3
  91. package/src/mcp/tools/collection/create.ts +5 -3
  92. package/src/mcp/tools/collection/delete.ts +5 -3
  93. package/src/mcp/tools/collection/find.ts +5 -3
  94. package/src/mcp/tools/collection/update.ts +5 -3
  95. package/src/mcp/tools/config/find.ts +5 -3
  96. package/src/mcp/tools/config/update.ts +5 -3
  97. package/src/mcp/tools/global/find.ts +5 -3
  98. package/src/mcp/tools/global/update.ts +6 -4
  99. package/src/mcp/tools/job/create.ts +5 -3
  100. package/src/mcp/tools/job/run.ts +5 -3
  101. package/src/mcp/tools/job/update.ts +6 -3
  102. package/src/mcp/tools/resource/create.ts +6 -4
  103. package/src/mcp/tools/resource/delete.ts +5 -3
  104. package/src/mcp/tools/resource/find.ts +5 -3
  105. package/src/mcp/tools/resource/update.ts +6 -4
  106. package/src/types.ts +11 -2
  107. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +41 -0
  108. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +21 -0
  109. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +65 -0
  110. package/dist/utils/convertCollectionSchemaToZod.d.ts.map +0 -1
  111. package/dist/utils/convertCollectionSchemaToZod.js +0 -80
  112. package/dist/utils/convertCollectionSchemaToZod.js.map +0 -1
  113. package/dist/utils/transformPointFields.d.ts.map +0 -1
  114. package/dist/utils/transformPointFields.js.map +0 -1
  115. package/src/utils/convertCollectionSchemaToZod.ts +0 -95
  116. /package/dist/utils/{convertCollectionSchemaToZod.d.ts → schemaConversion/convertCollectionSchemaToZod.d.ts} +0 -0
  117. /package/dist/utils/{transformPointFields.d.ts → schemaConversion/transformPointFields.d.ts} +0 -0
  118. /package/dist/utils/{transformPointFields.js → schemaConversion/transformPointFields.js} +0 -0
  119. /package/src/utils/{transformPointFields.ts → schemaConversion/transformPointFields.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/collection/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, unlinkSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Helper function for removing collection from config\nconst removeCollectionFromConfig = (configContent: string, collectionName: string): string => {\n // Simple implementation - find and remove the collection import and reference\n let updatedContent = configContent\n\n // Remove import statement\n const importRegex = new RegExp(\n `import\\\\s*{\\\\s*${collectionName}\\\\s*}\\\\s*from\\\\s*['\"]\\\\./collections/${collectionName}['\"];?\\\\s*\\\\n?`,\n 'g',\n )\n updatedContent = updatedContent.replace(importRegex, '')\n\n // Remove from collections array\n const collectionsRegex = new RegExp(`\\\\s*${collectionName},?\\\\s*`, 'g')\n updatedContent = updatedContent.replace(collectionsRegex, '')\n\n return updatedContent\n}\n\nexport const deleteCollection = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Attempting to delete collection: ${collectionName}`)\n }\n\n if (!confirmDeletion) {\n payload.logger.warn(`[payload-mcp] Deletion cancelled for collection: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Deletion cancelled**. Set confirmDeletion to true to proceed with deleting collection \"${collectionName}\".`,\n },\n ],\n }\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const collectionFilePath = join(collectionsDirPath, `${capitalizedName}.ts`)\n\n // Security check: ensure we're working with the collections directory\n if (!collectionFilePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${collectionFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid collection path',\n },\n ],\n }\n }\n\n try {\n // Check if collection file exists\n let fileExists = false\n try {\n readFileSync(collectionFilePath, 'utf8')\n fileExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Collection file does not exist: ${collectionFilePath}`)\n }\n\n // Read current config if we need to update it\n let configContent = ''\n let configExists = false\n if (updateConfig) {\n try {\n configContent = readFileSync(configFilePath, 'utf8')\n configExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Config file does not exist: ${configFilePath}`)\n }\n }\n\n let responseText = ''\n let operationsPerformed = 0\n\n // Delete the collection file\n if (fileExists) {\n try {\n unlinkSync(collectionFilePath)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted collection file: ${collectionFilePath}`,\n )\n }\n responseText += `✅ Deleted collection file: \\`${capitalizedName}.ts\\`\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error deleting collection file: ${errorMessage}`)\n responseText += `❌ Error deleting collection file: ${errorMessage}\\n`\n }\n } else {\n responseText += `⚠️ Collection file not found: \\`${capitalizedName}.ts\\`\\n`\n }\n\n // Update the config file if requested and it exists\n if (updateConfig && configExists) {\n try {\n const updatedConfigContent = removeCollectionFromConfig(configContent, capitalizedName)\n writeFileSync(configFilePath, updatedConfigContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n responseText += `✅ Updated payload.config.ts to remove collection reference\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating config file: ${errorMessage}`)\n responseText += `❌ Error updating config file: ${errorMessage}\\n`\n }\n } else if (updateConfig && !configExists) {\n responseText += `⚠️ Config file not found: payload.config.ts\\n`\n }\n\n // Summary\n if (operationsPerformed > 0) {\n responseText += `\\n✅ **Collection deletion completed!**`\n } else {\n responseText += `\\n⚠️ **No operations performed**\n\nThe collection file may not have existed or there were errors during deletion.`\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error during collection deletion: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error during collection deletion**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const deleteCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = (\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Deleting collection: ${collectionName}, confirmDeletion: ${confirmDeletion}, updateConfig: ${updateConfig}`,\n )\n }\n\n try {\n const result = deleteCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n confirmDeletion,\n updateConfig,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection deletion completed for: ${collectionName}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'deleteCollection',\n toolSchemas.deleteCollection.description,\n toolSchemas.deleteCollection.parameters.shape,\n ({ collectionName, confirmDeletion, updateConfig }) => {\n return tool(collectionName, confirmDeletion, updateConfig)\n },\n )\n}\n"],"names":["readFileSync","unlinkSync","writeFileSync","join","toolSchemas","removeCollectionFromConfig","configContent","collectionName","updatedContent","importRegex","RegExp","replace","collectionsRegex","deleteCollection","req","verboseLogs","collectionsDirPath","configFilePath","confirmDeletion","updateConfig","payload","logger","info","warn","content","type","text","capitalizedName","charAt","toUpperCase","slice","collectionFilePath","startsWith","error","fileExists","configExists","responseText","operationsPerformed","errorMessage","message","updatedConfigContent","deleteCollectionTool","server","tool","result","Error","description","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,KAAI;AAC5D,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,WAAW,QAAQ,gBAAe;AAE3C,sDAAsD;AACtD,MAAMC,6BAA6B,CAACC,eAAuBC;IACzD,8EAA8E;IAC9E,IAAIC,iBAAiBF;IAErB,0BAA0B;IAC1B,MAAMG,cAAc,IAAIC,OACtB,CAAC,eAAe,EAAEH,eAAe,qCAAqC,EAAE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AAM,CAAC,2BAA2B,EAAEnB,eAAe,GAAG,EAAE+B,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAI,OAAOC,IAAI,CACT,oBACAvC,YAAYS,gBAAgB,CAACiC,WAAW,EACxC1C,YAAYS,gBAAgB,CAACkC,UAAU,CAACC,KAAK,EAC7C,CAAC,EAAEzC,cAAc,EAAEW,eAAe,EAAEC,YAAY,EAAE;QAChD,OAAOwB,KAAKpC,gBAAgBW,iBAAiBC;IAC/C;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/collection/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, unlinkSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Helper function for removing collection from config\nconst removeCollectionFromConfig = (configContent: string, collectionName: string): string => {\n // Simple implementation - find and remove the collection import and reference\n let updatedContent = configContent\n\n // Remove import statement\n const importRegex = new RegExp(\n `import\\\\s*{\\\\s*${collectionName}\\\\s*}\\\\s*from\\\\s*['\"]\\\\./collections/${collectionName}['\"];?\\\\s*\\\\n?`,\n 'g',\n )\n updatedContent = updatedContent.replace(importRegex, '')\n\n // Remove from collections array\n const collectionsRegex = new RegExp(`\\\\s*${collectionName},?\\\\s*`, 'g')\n updatedContent = updatedContent.replace(collectionsRegex, '')\n\n return updatedContent\n}\n\nexport const deleteCollection = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Attempting to delete collection: ${collectionName}`)\n }\n\n if (!confirmDeletion) {\n payload.logger.warn(`[payload-mcp] Deletion cancelled for collection: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Deletion cancelled**. Set confirmDeletion to true to proceed with deleting collection \"${collectionName}\".`,\n },\n ],\n }\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const collectionFilePath = join(collectionsDirPath, `${capitalizedName}.ts`)\n\n // Security check: ensure we're working with the collections directory\n if (!collectionFilePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${collectionFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid collection path',\n },\n ],\n }\n }\n\n try {\n // Check if collection file exists\n let fileExists = false\n try {\n readFileSync(collectionFilePath, 'utf8')\n fileExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Collection file does not exist: ${collectionFilePath}`)\n }\n\n // Read current config if we need to update it\n let configContent = ''\n let configExists = false\n if (updateConfig) {\n try {\n configContent = readFileSync(configFilePath, 'utf8')\n configExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Config file does not exist: ${configFilePath}`)\n }\n }\n\n let responseText = ''\n let operationsPerformed = 0\n\n // Delete the collection file\n if (fileExists) {\n try {\n unlinkSync(collectionFilePath)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted collection file: ${collectionFilePath}`,\n )\n }\n responseText += `✅ Deleted collection file: \\`${capitalizedName}.ts\\`\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error deleting collection file: ${errorMessage}`)\n responseText += `❌ Error deleting collection file: ${errorMessage}\\n`\n }\n } else {\n responseText += `⚠️ Collection file not found: \\`${capitalizedName}.ts\\`\\n`\n }\n\n // Update the config file if requested and it exists\n if (updateConfig && configExists) {\n try {\n const updatedConfigContent = removeCollectionFromConfig(configContent, capitalizedName)\n writeFileSync(configFilePath, updatedConfigContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n responseText += `✅ Updated payload.config.ts to remove collection reference\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating config file: ${errorMessage}`)\n responseText += `❌ Error updating config file: ${errorMessage}\\n`\n }\n } else if (updateConfig && !configExists) {\n responseText += `⚠️ Config file not found: payload.config.ts\\n`\n }\n\n // Summary\n if (operationsPerformed > 0) {\n responseText += `\\n✅ **Collection deletion completed!**`\n } else {\n responseText += `\\n⚠️ **No operations performed**\n\nThe collection file may not have existed or there were errors during deletion.`\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error during collection deletion: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error during collection deletion**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const deleteCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = (\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Deleting collection: ${collectionName}, confirmDeletion: ${confirmDeletion}, updateConfig: ${updateConfig}`,\n )\n }\n\n try {\n const result = deleteCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n confirmDeletion,\n updateConfig,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection deletion completed for: ${collectionName}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'deleteCollection',\n {\n description: toolSchemas.deleteCollection.description,\n inputSchema: toolSchemas.deleteCollection.parameters.shape,\n },\n ({ collectionName, confirmDeletion, updateConfig }) => {\n return tool(collectionName, confirmDeletion, updateConfig)\n },\n )\n}\n"],"names":["readFileSync","unlinkSync","writeFileSync","join","toolSchemas","removeCollectionFromConfig","configContent","collectionName","updatedContent","importRegex","RegExp","replace","collectionsRegex","deleteCollection","req","verboseLogs","collectionsDirPath","configFilePath","confirmDeletion","updateConfig","payload","logger","info","warn","content","type","text","capitalizedName","charAt","toUpperCase","slice","collectionFilePath","startsWith","error","fileExists","configExists","responseText","operationsPerformed","errorMessage","message","updatedConfigContent","deleteCollectionTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,KAAI;AAC5D,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,WAAW,QAAQ,gBAAe;AAE3C,sDAAsD;AACtD,MAAMC,6BAA6B,CAACC,eAAuBC;IACzD,8EAA8E;IAC9E,IAAIC,iBAAiBF;IAErB,0BAA0B;IAC1B,MAAMG,cAAc,IAAIC,OACtB,CAAC,eAAe,EAAEH,eAAe,qCAAqC,EAAEA,eAAe,cAAc,CAAC,EACtG;IAEFC,iBAAiBA,eAAeG,OAAO,CAACF,aAAa;IAErD,gCAAgC;IAChC,MAAMG,mBAAmB,IAAIF,OAAO,CAAC,IAAI,EAAEH,eAAe,MAAM,CAAC,EAAE;IACnEC,iBAAiBA,eAAeG,OAAO,CAACC,kBAAkB;IAE1D,OAAOJ;AACT;AAEA,OAAO,MAAMK,mBAAmB,CAC9BC,KACAC,aACAC,oBACAC,gBACAV,gBACAW,iBACAC;IAEA,MAAMC,UAAUN,IAAIM,OAAO;IAE3B,IAAIL,aAAa;QACfK,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAEf,gBAAgB;IACxF;IAEA,IAAI,CAACW,iBAAiB;QACpBE,QAAQC,MAAM,CAACE,IAAI,CAAC,CAAC,iDAAiD,EAAEhB,gBAAgB;QACxF,OA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,MAAMG,uBAAuB,CAClCC,QACA5B,KACAC,aACAC,oBACAC;IAEA,MAAM0B,OAAO,CACXpC,gBACAW,iBACAC,eAAwB,KAAK;QAE7B,MAAMC,UAAUN,IAAIM,OAAO;QAE3B,IAAIL,aAAa;YACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,mCAAmC,EAAEf,eAAe,mBAAmB,EAAEW,gBAAgB,gBAAgB,EAAEC,cAAc;QAE9H;QAEA,IAAI;YACF,MAAMyB,SAAS/B,iBACbC,KACAC,aACAC,oBACAC,gBACAV,gBACAW,iBACAC;YAGF,IAAIJ,aAAa;gBACfK,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,iDAAiD,EAAEf,gBAAgB;YAC1F;YAEA,OAAOqC;QACT,EAAE,OAAOX,OAAO;YACd,MAAMK,eAAeL,iBAAiBY,QAAQZ,MAAMM,OAAO,GAAG;YAC9DnB,QAAQC,MAAM,CAACY,KAAK,CAClB,CAAC,wCAAwC,EAAE1B,eAAe,EAAE,EAAE+B,cAAc;YAG9E,OAAO;gBACLd,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEnB,eAAe,GAAG,EAAE+B,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAI,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAa3C,YAAYS,gBAAgB,CAACkC,WAAW;QACrDC,aAAa5C,YAAYS,gBAAgB,CAACoC,UAAU,CAACC,KAAK;IAC5D,GACA,CAAC,EAAE3C,cAAc,EAAEW,eAAe,EAAEC,YAAY,EAAE;QAChD,OAAOwB,KAAKpC,gBAAgBW,iBAAiBC;IAC/C;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,eAAe,QACrB,cAAc,eACN,OAAO,sBACA,MAAM,mBACT,MAAM,mBACP,OAAO,iBACT,OAAO;;;;;CAmJtB,CAAA;AAGD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,SAqD3B,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,eAAe,QACrB,cAAc,eACN,OAAO,sBACA,MAAM,mBACT,MAAM,mBACP,OAAO,iBACT,OAAO;;;;;CAmJtB,CAAA;AAGD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,SAuD3B,CAAA"}
@@ -154,7 +154,10 @@ export const findCollectionTool = (server, req, verboseLogs, collectionsDirPath)
154
154
  };
155
155
  }
156
156
  };
157
- server.tool('findCollections', toolSchemas.findCollections.description, toolSchemas.findCollections.parameters.shape, ({ collectionName, includeContent, includeCount })=>{
157
+ server.registerTool('findCollections', {
158
+ description: toolSchemas.findCollections.description,
159
+ inputSchema: toolSchemas.findCollections.parameters.shape
160
+ }, ({ collectionName, includeContent, includeCount })=>{
158
161
  return tool(collectionName, includeContent, includeCount);
159
162
  });
160
163
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/collection/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readdirSync, readFileSync, statSync } from 'fs'\nimport { extname, join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readCollections = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n // Read specific Collection (optional)\n if (collectionName) {\n const fileName = `${collectionName.charAt(0).toUpperCase() + collectionName.slice(1)}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection name attempted: ${collectionName}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid collection name' }],\n }\n }\n\n try {\n const content = readFileSync(filePath, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read collection: ${collectionName}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Collection: ${collectionName}\nFile: ${fileName}\n---\n${content}`,\n },\n ],\n }\n } catch (_error) {\n payload.logger.warn(`[payload-mcp] Collection not found: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error: Collection '${collectionName}' not found`,\n },\n ],\n }\n }\n }\n\n // Read all Collections\n const files = readdirSync(collectionsDirPath)\n .filter((file) => extname(file) === '.ts')\n .sort()\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found ${files.length} collection files in directory`)\n }\n\n if (files.length === 0) {\n payload.logger.warn('[payload-mcp] No collection files found in src/collections directory')\n return {\n content: [\n {\n type: 'text' as const,\n text: 'No collection files found in src/collections directory',\n },\n ],\n }\n }\n\n const results = []\n\n // Build complete table as a single markdown string\n let tableContent = `Found ${files.length} collection file(s):\\n\\n`\n\n // Build table header\n let tableHeader = '| Collection | File | Size | Modified'\n let tableSeparator = '|------------|------|------|----------'\n\n if (includeCount) {\n tableHeader += ' | Documents'\n tableSeparator += ' |----------'\n }\n tableHeader += ' |'\n tableSeparator += ' |'\n\n tableContent += tableHeader + '\\n'\n tableContent += tableSeparator + '\\n'\n\n for (const file of files) {\n const filePath = join(collectionsDirPath, file)\n const stats = statSync(filePath)\n const fileSize = stats.size\n const lastModified = stats.mtime\n\n const collectionName = file.replace('.ts', '')\n\n // Build table row\n let tableRow = `| **${collectionName}** | ${file} | ${fileSize.toLocaleString()} bytes | ${lastModified.toISOString()}`\n\n // Add document count if requested\n if (includeCount) {\n try {\n // For now, we'll skip document counting since we don't have access to payload instance\n tableRow += ' | -'\n } catch (error) {\n tableRow += ` | Error: ${(error as Error).message}`\n }\n }\n tableRow += ' |'\n\n tableContent += tableRow + '\\n'\n\n if (includeContent) {\n try {\n const content = readFileSync(filePath, 'utf8')\n tableContent += `\\n**${collectionName} Content:**\\n\\`\\`\\`typescript\\n${content}\\n\\`\\`\\`\\n\\n`\n } catch (error) {\n tableContent += `\\nError reading content: ${(error as Error).message}\\n\\n`\n }\n }\n }\n\n results.push({\n type: 'text' as const,\n text: tableContent,\n })\n\n return {\n content: results,\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading collections: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading collections**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n) => {\n const tool = (\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Finding collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n const result = readCollections(\n req,\n verboseLogs,\n collectionsDirPath,\n collectionName,\n includeContent,\n includeCount,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding collections: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding collections: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'findCollections',\n toolSchemas.findCollections.description,\n toolSchemas.findCollections.parameters.shape,\n ({ collectionName, includeContent, includeCount }) => {\n return tool(collectionName, includeContent, includeCount)\n },\n )\n}\n"],"names":["readdirSync","readFileSync","statSync","extname","join","toolSchemas","readCollections","req","verboseLogs","collectionsDirPath","collectionName","includeContent","includeCount","payload","logger","info","fileName","charAt","toUpperCase","slice","filePath","startsWith","error","content","type","text","_error","warn","files","filter","file","sort","length","results","tableContent","tableHeader","tableSeparator","stats","fileSize","size","lastModified","mtime","replace","tableRow","toLocaleString","toISOString","message","push","errorMessage","findCollectionTool","server","tool","result","Error","findCollections","description","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AACxD,SAASC,OAAO,EAAEC,IAAI,QAAQ,OAAM;AAEpC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,kBAAkB,CAC7BC,KACAC,aACAC,oBACAC,gBACAC,iBAA0B,KAAK,EAC/BC,eAAwB,KAAK;IAE7B,MAAMC,UAAUN,IAAIM,OAAO;IAE3B,IAAIL,aAAa;QACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEL,iBAAiB,CAAC,MAAM,EAAEA,gBAAgB,GAAG,GAAG,kBAAkB,EAAEC,eAAe,gBAAgB,EAAEC,cAAc;IAE3J;IAEA,IAAI;QACF,sCAAsC;QACtC,IAAIF,gBAAgB;YAClB,MAAMM,WAAW,GAAGN,eAAeO,MAAM,CAAC,GAAGC,WAAW,KAAKR,eAAeS,KAAK,CAAC,GAAG,GAAG,CAAC;YACzF,MAAMC,WAAWhB,KAAKK,oBAAoBO;YAE1C,IAAI,CAACI,SAASC,UAAU,CAACZ,qBAAqB;gBAC5CI,QAAQC,MAAM,CAACQ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AAM;oBACNC,MAAM,CAAC,iCAAiC,EAAEuB,cAAc;gBAC1D;aACD;QACH;IACF;AACF,EAAC;AAED,+BAA+B;AAC/B,OAAO,MAAMC,qBAAqB,CAChCC,QACA3C,KACAC,aACAC;IAEA,MAAM0C,OAAO,CACXzC,gBACAC,iBAA0B,KAAK,EAC/BC,eAAwB,KAAK;QAE7B,MAAMC,UAAUN,IAAIM,OAAO;QAE3B,IAAIL,aAAa;YACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEL,iBAAiB,CAAC,MAAM,EAAEA,gBAAgB,GAAG,GAAG,kBAAkB,EAAEC,eAAe,gBAAgB,EAAEC,cAAc;QAE3J;QAEA,IAAI;YACF,MAAMwC,SAAS9C,gBACbC,KACAC,aACAC,oBACAC,gBACAC,gBACAC;YAGF,IAAIJ,aAAa;gBACfK,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,yCAAyC,CAAC;YACjE;YAEA,OAAOqC;QACT,EAAE,OAAO9B,OAAO;YACd,MAAM0B,eAAe1B,iBAAiB+B,QAAQ/B,MAAMwB,OAAO,GAAG;YAC9DjC,QAAQC,MAAM,CAACQ,KAAK,CAAC,CAAC,yCAAyC,EAAE0B,cAAc;YAE/E,OAAO;gBACLzB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEuB,cAAc;oBACpD;iBACD;YACH;QACF;IACF;IAEAE,OAAOC,IAAI,CACT,mBACA9C,YAAYiD,eAAe,CAACC,WAAW,EACvClD,YAAYiD,eAAe,CAACE,UAAU,CAACC,KAAK,EAC5C,CAAC,EAAE/C,cAAc,EAAEC,cAAc,EAAEC,YAAY,EAAE;QAC/C,OAAOuC,KAAKzC,gBAAgBC,gBAAgBC;IAC9C;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/collection/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readdirSync, readFileSync, statSync } from 'fs'\nimport { extname, join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readCollections = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n // Read specific Collection (optional)\n if (collectionName) {\n const fileName = `${collectionName.charAt(0).toUpperCase() + collectionName.slice(1)}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection name attempted: ${collectionName}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid collection name' }],\n }\n }\n\n try {\n const content = readFileSync(filePath, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read collection: ${collectionName}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Collection: ${collectionName}\nFile: ${fileName}\n---\n${content}`,\n },\n ],\n }\n } catch (_error) {\n payload.logger.warn(`[payload-mcp] Collection not found: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error: Collection '${collectionName}' not found`,\n },\n ],\n }\n }\n }\n\n // Read all Collections\n const files = readdirSync(collectionsDirPath)\n .filter((file) => extname(file) === '.ts')\n .sort()\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found ${files.length} collection files in directory`)\n }\n\n if (files.length === 0) {\n payload.logger.warn('[payload-mcp] No collection files found in src/collections directory')\n return {\n content: [\n {\n type: 'text' as const,\n text: 'No collection files found in src/collections directory',\n },\n ],\n }\n }\n\n const results = []\n\n // Build complete table as a single markdown string\n let tableContent = `Found ${files.length} collection file(s):\\n\\n`\n\n // Build table header\n let tableHeader = '| Collection | File | Size | Modified'\n let tableSeparator = '|------------|------|------|----------'\n\n if (includeCount) {\n tableHeader += ' | Documents'\n tableSeparator += ' |----------'\n }\n tableHeader += ' |'\n tableSeparator += ' |'\n\n tableContent += tableHeader + '\\n'\n tableContent += tableSeparator + '\\n'\n\n for (const file of files) {\n const filePath = join(collectionsDirPath, file)\n const stats = statSync(filePath)\n const fileSize = stats.size\n const lastModified = stats.mtime\n\n const collectionName = file.replace('.ts', '')\n\n // Build table row\n let tableRow = `| **${collectionName}** | ${file} | ${fileSize.toLocaleString()} bytes | ${lastModified.toISOString()}`\n\n // Add document count if requested\n if (includeCount) {\n try {\n // For now, we'll skip document counting since we don't have access to payload instance\n tableRow += ' | -'\n } catch (error) {\n tableRow += ` | Error: ${(error as Error).message}`\n }\n }\n tableRow += ' |'\n\n tableContent += tableRow + '\\n'\n\n if (includeContent) {\n try {\n const content = readFileSync(filePath, 'utf8')\n tableContent += `\\n**${collectionName} Content:**\\n\\`\\`\\`typescript\\n${content}\\n\\`\\`\\`\\n\\n`\n } catch (error) {\n tableContent += `\\nError reading content: ${(error as Error).message}\\n\\n`\n }\n }\n }\n\n results.push({\n type: 'text' as const,\n text: tableContent,\n })\n\n return {\n content: results,\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading collections: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading collections**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n) => {\n const tool = (\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Finding collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n const result = readCollections(\n req,\n verboseLogs,\n collectionsDirPath,\n collectionName,\n includeContent,\n includeCount,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding collections: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding collections: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'findCollections',\n {\n description: toolSchemas.findCollections.description,\n inputSchema: toolSchemas.findCollections.parameters.shape,\n },\n ({ collectionName, includeContent, includeCount }) => {\n return tool(collectionName, includeContent, includeCount)\n },\n )\n}\n"],"names":["readdirSync","readFileSync","statSync","extname","join","toolSchemas","readCollections","req","verboseLogs","collectionsDirPath","collectionName","includeContent","includeCount","payload","logger","info","fileName","charAt","toUpperCase","slice","filePath","startsWith","error","content","type","text","_error","warn","files","filter","file","sort","length","results","tableContent","tableHeader","tableSeparator","stats","fileSize","size","lastModified","mtime","replace","tableRow","toLocaleString","toISOString","message","push","errorMessage","findCollectionTool","server","tool","result","Error","registerTool","description","findCollections","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AACxD,SAASC,OAAO,EAAEC,IAAI,QAAQ,OAAM;AAEpC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,kBAAkB,CAC7BC,KACAC,aACAC,oBACAC,gBACAC,iBAA0B,KAAK,EAC/BC,eAAwB,KAAK;IAE7B,MAAMC,UAAUN,IAAIM,OAAO;IAE3B,IAAIL,aAAa;QACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEL,iBAAiB,CAAC,MAAM,EAAEA,gBAAgB,GAAG,GAAG,kBAAkB,EAAEC,eAAe,gBAAgB,EAAEC,cAAc;IAE3J;IAEA,IAAI;QACF,sCAAsC;QACtC,IAAIF,gBAAgB;YAClB,MAAMM,WAAW,GAAGN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EAAEC,cAAc,EAAEC,YAAY,EAAE;QAC/C,OAAOuC,KAAKzC,gBAAgBC,gBAAgBC;IAC9C;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,gBAAgB,QACtB,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,kBACN,MAAM,cACV,MAAM,cACN,GAAG,EAAE,uBACI,MAAM,EAAE,uBACR,GAAG,EAAE,kBACV,GAAG,eACN,MAAM;;;;;EAuLpB,CAAA;AAED,eAAO,MAAM,oBAAoB,WACvB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,SAwEvB,CAAA"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,gBAAgB,QACtB,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,kBACN,MAAM,cACV,MAAM,cACN,GAAG,EAAE,uBACI,MAAM,EAAE,uBACR,GAAG,EAAE,kBACV,GAAG,eACN,MAAM;;;;;EAuLpB,CAAA;AAED,eAAO,MAAM,oBAAoB,WACvB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,SA0EvB,CAAA"}
@@ -198,7 +198,10 @@ export const updateCollectionTool = (server, req, verboseLogs, collectionsDirPat
198
198
  };
199
199
  }
200
200
  };
201
- server.tool('updateCollection', toolSchemas.updateCollection.description, toolSchemas.updateCollection.parameters.shape, async (args)=>{
201
+ server.registerTool('updateCollection', {
202
+ description: toolSchemas.updateCollection.description,
203
+ inputSchema: toolSchemas.updateCollection.parameters.shape
204
+ }, async (args)=>{
202
205
  return await tool(args);
203
206
  });
204
207
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/collection/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport {\n addFieldsToCollection,\n modifyFieldsInCollection,\n removeFieldsFromCollection,\n} from '../../helpers/fields.js'\nimport { validateCollectionFile } from '../../helpers/fileValidation.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateCollection = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n updateType: string,\n newFields?: any[],\n fieldNamesToRemove?: string[],\n fieldModifications?: any[],\n configUpdates?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const fileName = `${capitalizedName}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n // Security check: ensure we're working with the collections directory\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid collection path',\n },\n ],\n }\n }\n\n try {\n // Check if collection file exists\n let currentContent: string\n try {\n currentContent = readFileSync(filePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Collection file not found: ${fileName}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_field':\n if (!newFields || newFields.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No fields provided for add_field update type',\n },\n ],\n }\n }\n updatedContent = addFieldsToCollection(currentContent, newFields)\n updateSummary = newFields.map((field: any) => `Added field: ${field.name} (${field.type})`)\n break\n\n case 'modify_field':\n if (!fieldModifications || fieldModifications.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field modifications provided for modify_field update type',\n },\n ],\n }\n }\n updatedContent = modifyFieldsInCollection(currentContent, fieldModifications)\n updateSummary = fieldModifications.map((mod: any) => `Modified field: ${mod.fieldName}`)\n break\n\n case 'remove_field':\n if (!fieldNamesToRemove || fieldNamesToRemove.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field names provided for remove_field update type',\n },\n ],\n }\n }\n updatedContent = removeFieldsFromCollection(currentContent, fieldNamesToRemove)\n updateSummary = fieldNamesToRemove.map((fieldName: string) => `Removed field: ${fieldName}`)\n break\n\n case 'replace_content':\n if (!newContent) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No new content provided for replace_content update type',\n },\n ],\n }\n }\n updatedContent = newContent\n updateSummary = ['Replaced entire collection content']\n break\n\n case 'update_config':\n if (!configUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No config updates provided for update_config update type',\n },\n ],\n }\n }\n // For now, we'll use a simple approach since the config helper might not have this functionality\n updatedContent = currentContent\n updateSummary = Object.keys(configUpdates).map((key) => `Updated config: ${key}`)\n break\n\n default:\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Unknown update type: ${updateType}`,\n },\n ],\n }\n }\n\n // Write the updated content back to the file\n writeFileSync(filePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated collection file: ${filePath}`)\n }\n\n // Validate the updated file\n const validationResult = await validateCollectionFile(fileName)\n if (validationResult.error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Updated collection has validation issues:\\n\\n${validationResult.error}`,\n },\n ],\n }\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Collection updated successfully!**\n\n**File**: \\`${fileName}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Collection Code:**\n\\`\\`\\`typescript\n${updatedContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating collection: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating collection**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = async ({\n collectionName,\n configUpdates,\n fieldModifications,\n fieldNamesToRemove,\n newContent,\n newFields,\n updateType,\n }: {\n collectionName: string\n configUpdates?: any\n fieldModifications?: any[]\n fieldNamesToRemove?: string[]\n newContent?: string\n newFields?: any[]\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n try {\n const result = await updateCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n updateType,\n newFields,\n fieldNamesToRemove,\n fieldModifications,\n configUpdates,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection update completed for: ${collectionName}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error updating collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'updateCollection',\n toolSchemas.updateCollection.description,\n toolSchemas.updateCollection.parameters.shape,\n async (args) => {\n return await tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","join","addFieldsToCollection","modifyFieldsInCollection","removeFieldsFromCollection","validateCollectionFile","toolSchemas","updateCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","updateType","newFields","fieldNamesToRemove","fieldModifications","configUpdates","newContent","payload","logger","info","capitalizedName","charAt","toUpperCase","slice","fileName","filePath","startsWith","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","length","map","field","name","mod","fieldName","Object","keys","key","validationResult","summary","errorMessage","message","updateCollectionTool","server","tool","result","Error","description","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,SAASC,IAAI,QAAQ,OAAM;AAE3B,SACEC,qBAAqB,EACrBC,wBAAwB,EACxBC,0BAA0B,QACrB,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,kCAAiC;AACxE,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,OAC9BC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBACAC,eACAC;IAEA,MAAMC,UAAUX,IAAIW,OAAO;IAC3B,IAAIV,aAAa;QACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,mCAAmC,EAAET,eAAe,cAAc,EAAEC,YAAY;IAErF;IAEA,MAAMS,kBAAkBV,eAAeW,MAAM,CAAC,GAAGC,WAAW,KAAKZ,eAAea,KAAK,CAAC;IACtF,MAAMC,WAAW,GAAGJ,gBAAgB,GAAG,CAAC;IACxC,MAAMK,WAAW1B,KAAKS,oBAAoBgB;IAE1C,sEAAsE;IACtE,IAAI,CAACC,SAASC,UAAU,CAAClB,qBAAqB;QAC5CS,QAAQC,MAAM,CAACS,KAAK,CAAC,CAAC,iDAAiD,EAAEF,UAAU;QACnF,OAAO;YACLG,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;IACF;IAEA,IAAI;QAC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AyC,EAAEmB,cAAc;QAC/E,OAAO;YACLlB,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,iCAAiC,EAAEgB,cAAc;gBAC1D;aACD;QACH;IACF;AACF,EAAC;AAED,OAAO,MAAME,uBAAuB,CAClCC,QACA3C,KACAC,aACAC,oBACAC;IAEA,MAAMyC,OAAO,OAAO,EAClBxC,cAAc,EACdK,aAAa,EACbD,kBAAkB,EAClBD,kBAAkB,EAClBG,UAAU,EACVJ,SAAS,EACTD,UAAU,EASX;QACC,MAAMM,UAAUX,IAAIW,OAAO;QAE3B,IAAIV,aAAa;YACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,mCAAmC,EAAET,eAAe,cAAc,EAAEC,YAAY;QAErF;QAEA,IAAI;YACF,MAAMwC,SAAS,MAAM9C,iBACnBC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBACAC,eACAC;YAGF,IAAIT,aAAa;gBACfU,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAET,gBAAgB;YACxF;YAEA,OAAOyC;QACT,EAAE,OAAOxB,OAAO;YACd,MAAMmB,eAAenB,iBAAiByB,QAAQzB,MAAMoB,OAAO,GAAG;YAC9D9B,QAAQC,MAAM,CAACS,KAAK,CAClB,CAAC,wCAAwC,EAAEjB,eAAe,EAAE,EAAEoC,cAAc;YAG9E,OAAO;gBACLlB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEpB,eAAe,GAAG,EAAEoC,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAG,OAAOC,IAAI,CACT,oBACA9C,YAAYC,gBAAgB,CAACgD,WAAW,EACxCjD,YAAYC,gBAAgB,CAACiD,UAAU,CAACC,KAAK,EAC7C,OAAOC;QACL,OAAO,MAAMN,KAAKM;IACpB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/collection/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport {\n addFieldsToCollection,\n modifyFieldsInCollection,\n removeFieldsFromCollection,\n} from '../../helpers/fields.js'\nimport { validateCollectionFile } from '../../helpers/fileValidation.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateCollection = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n updateType: string,\n newFields?: any[],\n fieldNamesToRemove?: string[],\n fieldModifications?: any[],\n configUpdates?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const fileName = `${capitalizedName}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n // Security check: ensure we're working with the collections directory\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid collection path',\n },\n ],\n }\n }\n\n try {\n // Check if collection file exists\n let currentContent: string\n try {\n currentContent = readFileSync(filePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Collection file not found: ${fileName}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_field':\n if (!newFields || newFields.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No fields provided for add_field update type',\n },\n ],\n }\n }\n updatedContent = addFieldsToCollection(currentContent, newFields)\n updateSummary = newFields.map((field: any) => `Added field: ${field.name} (${field.type})`)\n break\n\n case 'modify_field':\n if (!fieldModifications || fieldModifications.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field modifications provided for modify_field update type',\n },\n ],\n }\n }\n updatedContent = modifyFieldsInCollection(currentContent, fieldModifications)\n updateSummary = fieldModifications.map((mod: any) => `Modified field: ${mod.fieldName}`)\n break\n\n case 'remove_field':\n if (!fieldNamesToRemove || fieldNamesToRemove.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field names provided for remove_field update type',\n },\n ],\n }\n }\n updatedContent = removeFieldsFromCollection(currentContent, fieldNamesToRemove)\n updateSummary = fieldNamesToRemove.map((fieldName: string) => `Removed field: ${fieldName}`)\n break\n\n case 'replace_content':\n if (!newContent) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No new content provided for replace_content update type',\n },\n ],\n }\n }\n updatedContent = newContent\n updateSummary = ['Replaced entire collection content']\n break\n\n case 'update_config':\n if (!configUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No config updates provided for update_config update type',\n },\n ],\n }\n }\n // For now, we'll use a simple approach since the config helper might not have this functionality\n updatedContent = currentContent\n updateSummary = Object.keys(configUpdates).map((key) => `Updated config: ${key}`)\n break\n\n default:\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Unknown update type: ${updateType}`,\n },\n ],\n }\n }\n\n // Write the updated content back to the file\n writeFileSync(filePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated collection file: ${filePath}`)\n }\n\n // Validate the updated file\n const validationResult = await validateCollectionFile(fileName)\n if (validationResult.error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Updated collection has validation issues:\\n\\n${validationResult.error}`,\n },\n ],\n }\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Collection updated successfully!**\n\n**File**: \\`${fileName}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Collection Code:**\n\\`\\`\\`typescript\n${updatedContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating collection: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating collection**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = async ({\n collectionName,\n configUpdates,\n fieldModifications,\n fieldNamesToRemove,\n newContent,\n newFields,\n updateType,\n }: {\n collectionName: string\n configUpdates?: any\n fieldModifications?: any[]\n fieldNamesToRemove?: string[]\n newContent?: string\n newFields?: any[]\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n try {\n const result = await updateCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n updateType,\n newFields,\n fieldNamesToRemove,\n fieldModifications,\n configUpdates,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection update completed for: ${collectionName}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error updating collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'updateCollection',\n {\n description: toolSchemas.updateCollection.description,\n inputSchema: toolSchemas.updateCollection.parameters.shape,\n },\n async (args) => {\n return await tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","join","addFieldsToCollection","modifyFieldsInCollection","removeFieldsFromCollection","validateCollectionFile","toolSchemas","updateCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","updateType","newFields","fieldNamesToRemove","fieldModifications","configUpdates","newContent","payload","logger","info","capitalizedName","charAt","toUpperCase","slice","fileName","filePath","startsWith","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","length","map","field","name","mod","fieldName","Object","keys","key","validationResult","summary","errorMessage","message","updateCollectionTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,SAASC,IAAI,QAAQ,OAAM;AAE3B,SACEC,qBAAqB,EACrBC,wBAAwB,EACxBC,0BAA0B,QACrB,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,kCAAiC;AACxE,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,OAC9BC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBACAC,eACAC;IAEA,MAAMC,UAAUX,IAAIW,OAAO;IAC3B,IAAIV,aAAa;QACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,mCAAmC,EAAET,eAAe,cAAc,EAAEC,YAAY;IAErF;IAEA,MAAMS,kBAAkBV,eAAeW,MAAM,CAAC,GAAGC,WAAW,KAAKZ,eAAea,KAAK,CAAC;IACtF,MAAMC,WAAW,GAAGJ,gBAAgB,GAAG,CAAC;IACxC,MAAMK,WAAW1B,KAAKS,oBAAoBgB;IAE1C,sEAAsE;IACtE,IAAI,CAACC,SAASC,UAAU,CAAClB,qBAAqB;QAC5CS,QAAQC,MAAM,CAACS,KAAK,CAAC,CAAC,iDAAiD,EAAEF,UAAU;QACnF,OAAO;YACLG,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;IACF;IAEA,IAAI;QACF,kCAAkC;QAClC,IAAIC;QACJ,IAAI;YACFA,iBAAiBlC,aAAa4B,UAAU;QAC1C,EAAE,OAAOO,SAAS;YAChB,OAAO;gBACLJ,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,wCAAwC,EAAEN,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ACA3C,KACAC,aACAC,oBACAC;IAEA,MAAMyC,OAAO,OAAO,EAClBxC,cAAc,EACdK,aAAa,EACbD,kBAAkB,EAClBD,kBAAkB,EAClBG,UAAU,EACVJ,SAAS,EACTD,UAAU,EASX;QACC,MAAMM,UAAUX,IAAIW,OAAO;QAE3B,IAAIV,aAAa;YACfU,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,mCAAmC,EAAET,eAAe,cAAc,EAAEC,YAAY;QAErF;QAEA,IAAI;YACF,MAAMwC,SAAS,MAAM9C,iBACnBC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBACAC,eACAC;YAGF,IAAIT,aAAa;gBACfU,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAET,gBAAgB;YACxF;YAEA,OAAOyC;QACT,EAAE,OAAOxB,OAAO;YACd,MAAMmB,eAAenB,iBAAiByB,QAAQzB,MAAMoB,OAAO,GAAG;YAC9D9B,QAAQC,MAAM,CAACS,KAAK,CAClB,CAAC,wCAAwC,EAAEjB,eAAe,EAAE,EAAEoC,cAAc;YAG9E,OAAO;gBACLlB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEpB,eAAe,GAAG,EAAEoC,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAalD,YAAYC,gBAAgB,CAACiD,WAAW;QACrDC,aAAanD,YAAYC,gBAAgB,CAACmD,UAAU,CAACC,KAAK;IAC5D,GACA,OAAOC;QACL,OAAO,MAAMR,KAAKQ;IACpB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,QACpB,cAAc,eACN,OAAO,kBACJ,MAAM,oBACL,OAAO;;;;;CAmEzB,CAAA;AAGD,eAAO,MAAM,cAAc,WACjB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SAwCvB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,QACpB,cAAc,eACN,OAAO,kBACJ,MAAM,oBACL,OAAO;;;;;CAmEzB,CAAA;AAGD,eAAO,MAAM,cAAc,WACjB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SA0CvB,CAAA"}
@@ -86,7 +86,10 @@ export const findConfigTool = (server, req, verboseLogs, configFilePath)=>{
86
86
  };
87
87
  }
88
88
  };
89
- server.tool('findConfig', toolSchemas.findConfig.description, toolSchemas.findConfig.parameters.shape, ({ includeMetadata })=>{
89
+ server.registerTool('findConfig', {
90
+ description: toolSchemas.findConfig.description,
91
+ inputSchema: toolSchemas.findConfig.parameters.shape
92
+ }, ({ includeMetadata })=>{
90
93
  return tool(includeMetadata);
91
94
  });
92
95
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/config/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, statSync } from 'fs'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readConfigFile = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n includeMetadata: boolean = false,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Reading config file, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n // Security check: ensure we're working with the specified config file\n if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {\n payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid config path',\n },\n ],\n }\n }\n\n const content = readFileSync(configFilePath, 'utf8')\n const stats = statSync(configFilePath)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read config file. Size: ${stats.size} bytes`)\n }\n\n let responseText = `# Payload Configuration\n\n**File**: \\`${configFilePath}\\``\n\n if (includeMetadata) {\n responseText += `\n**Size**: ${stats.size.toLocaleString()} bytes\n**Modified**: ${stats.mtime.toISOString()}\n**Created**: ${stats.birthtime.toISOString()}`\n }\n\n responseText += `\n---\n\n**Configuration Content:**\n\\`\\`\\`typescript\n${content}\n\\`\\`\\``\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading config file: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading config file**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = (includeMetadata: boolean = false) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Finding config, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n const result = readConfigFile(req, verboseLogs, configFilePath, includeMetadata)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'findConfig',\n toolSchemas.findConfig.description,\n toolSchemas.findConfig.parameters.shape,\n ({ includeMetadata }) => {\n return tool(includeMetadata)\n },\n )\n}\n"],"names":["readFileSync","statSync","toolSchemas","readConfigFile","req","verboseLogs","configFilePath","includeMetadata","payload","logger","info","startsWith","process","cwd","error","content","type","text","stats","size","responseText","toLocaleString","mtime","toISOString","birthtime","errorMessage","message","findConfigTool","server","tool","result","Error","findConfig","description","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AAE3C,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,iBAAiB,CAC5BC,KACAC,aACAC,gBACAC,kBAA2B,KAAK;IAEhC,MAAMC,UAAUJ,IAAII,OAAO;IAC3B,IAAIH,aAAa;QACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,oDAAoD,EAAEH,iBAAiB;IAC9F;IAEA,IAAI;QACF,sEAAsE;QACtE,IAAI,CAACD,eAAeK,UAAU,CAACC,QAAQC,GAAG,OAAO,CAACP,eAAeK,UAAU,CAAC,MAAM;YAChFH,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,6CAA6C,EAAER,gBAAgB;YACrF,OAAO;gBACLS,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM;oBACR;iBACD;YACH;QACF;QAEA,MAAMF,UAAUf,aAAaM,gBAAgB;QAC7C,MAAMY,QAAQjB,SAASK;QAEvB,IAAID,aAAa;YACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,mDAAmD,EAAEQ,MAAMC,IAAI,CAAC,MAAM,CAAC;QAC9F;QAEA,IAAIC,eAAe,CAAC;;YAEZ,EAAEd,eAAe,EAAE,CAAC;QAE5B,IAAIC,iBAAiB;YACnBa,gBAAgB,CAAC;UACb,EAAEF,MAAMC,IAAI,CAACE,cAAc,GAAG;cAC1B,EAAEH,MAAMI,KAAK,CAACC,WAAW,GAAG;aAC7B,EAAEL,MAAMM,SAAS,CAACD,WAAW,IAAI;QAC1C;QAEAH,gBAA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{"version":3,"sources":["../../../../src/mcp/tools/config/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, statSync } from 'fs'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readConfigFile = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n includeMetadata: boolean = false,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Reading config file, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n // Security check: ensure we're working with the specified config file\n if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {\n payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid config path',\n },\n ],\n }\n }\n\n const content = readFileSync(configFilePath, 'utf8')\n const stats = statSync(configFilePath)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read config file. Size: ${stats.size} bytes`)\n }\n\n let responseText = `# Payload Configuration\n\n**File**: \\`${configFilePath}\\``\n\n if (includeMetadata) {\n responseText += `\n**Size**: ${stats.size.toLocaleString()} bytes\n**Modified**: ${stats.mtime.toISOString()}\n**Created**: ${stats.birthtime.toISOString()}`\n }\n\n responseText += `\n---\n\n**Configuration Content:**\n\\`\\`\\`typescript\n${content}\n\\`\\`\\``\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading config file: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading config file**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = (includeMetadata: boolean = false) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Finding config, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n const result = readConfigFile(req, verboseLogs, configFilePath, includeMetadata)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'findConfig',\n {\n description: toolSchemas.findConfig.description,\n inputSchema: toolSchemas.findConfig.parameters.shape,\n },\n ({ includeMetadata }) => {\n return tool(includeMetadata)\n },\n )\n}\n"],"names":["readFileSync","statSync","toolSchemas","readConfigFile","req","verboseLogs","configFilePath","includeMetadata","payload","logger","info","startsWith","process","cwd","error","content","type","text","stats","size","responseText","toLocaleString","mtime","toISOString","birthtime","errorMessage","message","findConfigTool","server","tool","result","Error","registerTool","description","findConfig","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AAE3C,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,iBAAiB,CAC5BC,KACAC,aACAC,gBACAC,kBAA2B,KAAK;IAEhC,MAAMC,UAAUJ,IAAII,OAAO;IAC3B,IAAIH,aAAa;QACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,oDAAoD,EAAEH,iBAAiB;IAC9F;IAEA,IAAI;QACF,sEAAsE;QACtE,IAAI,CAACD,eAAeK,UAAU,CAACC,QAAQC,GAAG,OAAO,CAACP,eAAeK,UAAU,CAAC,MAAM;YAChFH,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,6CAA6C,EAAER,gBAAgB;YACrF,OAAO;gBACLS,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM;oBACR;iBACD;YACH;QACF;QAEA,MAAMF,UAAUf,aAAaM,gBAAgB;QAC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,QAAQjB,MAAMY,OAAO,GAAG;YAC9DlB,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,oCAAoC,EAAEW,cAAc;YAE1E,OAAO;gBACLV,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,sBAAsB,EAAEQ,cAAc;oBAC/C;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,cACA;QACEC,aAAa/B,YAAYgC,UAAU,CAACD,WAAW;QAC/CE,aAAajC,YAAYgC,UAAU,CAACE,UAAU,CAACC,KAAK;IACtD,GACA,CAAC,EAAE9B,eAAe,EAAE;QAClB,OAAOsB,KAAKtB;IACd;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,YAAY,QAClB,cAAc,eACN,OAAO,kBACJ,MAAM,cACV,MAAM,mBACD,MAAM,gBACT,GAAG,mBACA,GAAG,kBACJ,GAAG,kBACH,GAAG,eACN,MAAM;;;;;CAwLpB,CAAA;AAED,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SAmEvB,CAAA"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,YAAY,QAClB,cAAc,eACN,OAAO,kBACJ,MAAM,cACV,MAAM,mBACD,MAAM,gBACT,GAAG,mBACA,GAAG,kBACJ,GAAG,kBACH,GAAG,eACN,MAAM;;;;;CAwLpB,CAAA;AAED,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SAqEvB,CAAA"}
@@ -204,7 +204,10 @@ export const updateConfigTool = (server, req, verboseLogs, configFilePath)=>{
204
204
  };
205
205
  }
206
206
  };
207
- server.tool('updateConfig', toolSchemas.updateConfig.description, toolSchemas.updateConfig.parameters.shape, (args)=>{
207
+ server.registerTool('updateConfig', {
208
+ description: toolSchemas.updateConfig.description,
209
+ inputSchema: toolSchemas.updateConfig.parameters.shape
210
+ }, (args)=>{
208
211
  return tool(args);
209
212
  });
210
213
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/config/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\n\nimport {\n addCollectionToConfig,\n removeCollectionFromConfig,\n updateAdminConfig,\n updateDatabaseConfig,\n updatePluginsConfig,\n} from '../../helpers/config.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateConfig = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n updateType: string,\n collectionName?: string,\n adminConfig?: any,\n databaseConfig?: any,\n pluginUpdates?: any,\n generalConfig?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config with update type: ${updateType}`)\n }\n\n // Security check: ensure we're working with the specified config file\n if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {\n payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid config path',\n },\n ],\n }\n }\n\n try {\n // Read current config\n let currentContent: string\n try {\n currentContent = readFileSync(configFilePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Config file not found: ${configFilePath}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for add_collection update type',\n },\n ],\n }\n }\n updatedContent = addCollectionToConfig(currentContent, collectionName)\n updateSummary = [`Added collection: ${collectionName}`]\n break\n\n case 'remove_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for remove_collection update type',\n },\n ],\n }\n }\n updatedContent = removeCollectionFromConfig(currentContent, collectionName)\n updateSummary = [`Removed collection: ${collectionName}`]\n break\n\n case 'replace_content':\n if (!newContent) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No new content provided for replace_content update type',\n },\n ],\n }\n }\n updatedContent = newContent\n updateSummary = ['Replaced entire config content']\n break\n\n case 'update_admin':\n if (!adminConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No admin config provided for update_admin update type',\n },\n ],\n }\n }\n updatedContent = updateAdminConfig(currentContent, adminConfig)\n updateSummary = Object.keys(adminConfig).map((key) => `Updated admin config: ${key}`)\n break\n\n case 'update_database':\n if (!databaseConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No database config provided for update_database update type',\n },\n ],\n }\n }\n updatedContent = updateDatabaseConfig(currentContent, databaseConfig)\n updateSummary = Object.keys(databaseConfig).map((key) => `Updated database config: ${key}`)\n break\n\n case 'update_plugins':\n if (!pluginUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No plugin updates provided for update_plugins update type',\n },\n ],\n }\n }\n updatedContent = updatePluginsConfig(currentContent, pluginUpdates)\n updateSummary = []\n if (pluginUpdates.add) {\n updateSummary.push(`Added plugins: ${pluginUpdates.add.join(', ')}`)\n }\n if (pluginUpdates.remove) {\n updateSummary.push(`Removed plugins: ${pluginUpdates.remove.join(', ')}`)\n }\n break\n\n default:\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Unknown update type: ${updateType}`,\n },\n ],\n }\n }\n\n // Write the updated content back to the file\n writeFileSync(configFilePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Config updated successfully!**\n\n**File**: \\`${configFilePath}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Config Content:**\n\\`\\`\\`typescript\n${updatedContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating config: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating config**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = ({\n adminConfig,\n collectionName,\n databaseConfig,\n generalConfig,\n newContent,\n pluginUpdates,\n updateType,\n }: {\n adminConfig?: any\n collectionName?: string\n databaseConfig?: any\n generalConfig?: any\n newContent?: string\n pluginUpdates?: any\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config: ${updateType}`)\n }\n\n try {\n const result = updateConfig(\n req,\n verboseLogs,\n configFilePath,\n updateType,\n collectionName,\n adminConfig,\n databaseConfig,\n pluginUpdates,\n generalConfig,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config update completed for: ${updateType}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error updating config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'updateConfig',\n toolSchemas.updateConfig.description,\n toolSchemas.updateConfig.parameters.shape,\n (args) => {\n return tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","addCollectionToConfig","removeCollectionFromConfig","updateAdminConfig","updateDatabaseConfig","updatePluginsConfig","toolSchemas","updateConfig","req","verboseLogs","configFilePath","updateType","collectionName","adminConfig","databaseConfig","pluginUpdates","generalConfig","newContent","payload","logger","info","startsWith","process","cwd","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","Object","keys","map","key","add","push","join","remove","summary","errorMessage","message","updateConfigTool","server","tool","result","Error","description","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAEhD,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,iBAAiB,EACjBC,oBAAoB,EACpBC,mBAAmB,QACd,0BAAyB;AAChC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,eAAe,CAC1BC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC,eACAC;IAEA,MAAMC,UAAUV,IAAIU,OAAO;IAC3B,IAAIT,aAAa;QACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,gDAAgD,EAAET,YAAY;IACrF;IAEA,sEAAsE;IACtE,IAAI,CAACD,eAAeW,UAAU,CAACC,QAAQC,GAAG,OAAO,CAACb,eAAeW,UAAU,CAAC,MAAM;QAChFH,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,6CAA6C,EAAEd,gBAAgB;QACrF,OAAO;YACLe,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;IACF;IAEA,IAAI;QACF,sBAAsB;QACtB,IAAIC;QACJ,IAAI;YACFA,iBAAiB7B,aAAaW,gBAAgB;QAChD,EAAE,OAAOmB,SAAS;YAChB,OAAO;gBACLJ,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,oCAAoC,EAAEjB,gBAAgB;oBAC/D;iBACD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AAC;AAED,OAAO,MAAME,mBAAmB,CAC9BC,QACApC,KACAC,aACAC;IAEA,MAAMmC,OAAO,CAAC,EACZhC,WAAW,EACXD,cAAc,EACdE,cAAc,EACdE,aAAa,EACbC,UAAU,EACVF,aAAa,EACbJ,UAAU,EASX;QACC,MAAMO,UAAUV,IAAIU,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+BAA+B,EAAET,YAAY;QACpE;QAEA,IAAI;YACF,MAAMmC,SAASvC,aACbC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC,eACAC;YAGF,IAAIR,aAAa;gBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,2CAA2C,EAAET,YAAY;YAChF;YAEA,OAAOmC;QACT,EAAE,OAAOtB,OAAO;YACd,MAAMiB,eAAejB,iBAAiBuB,QAAQvB,MAAMkB,OAAO,GAAG;YAC9DxB,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,qCAAqC,EAAEiB,cAAc;YAE3E,OAAO;gBACLhB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,uBAAuB,EAAEc,cAAc;oBAChD;iBACD;YACH;QACF;IACF;IAEAG,OAAOC,IAAI,CACT,gBACAvC,YAAYC,YAAY,CAACyC,WAAW,EACpC1C,YAAYC,YAAY,CAAC0C,UAAU,CAACC,KAAK,EACzC,CAACC;QACC,OAAON,KAAKM;IACd;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/mcp/tools/config/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\n\nimport {\n addCollectionToConfig,\n removeCollectionFromConfig,\n updateAdminConfig,\n updateDatabaseConfig,\n updatePluginsConfig,\n} from '../../helpers/config.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateConfig = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n updateType: string,\n collectionName?: string,\n adminConfig?: any,\n databaseConfig?: any,\n pluginUpdates?: any,\n generalConfig?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config with update type: ${updateType}`)\n }\n\n // Security check: ensure we're working with the specified config file\n if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {\n payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid config path',\n },\n ],\n }\n }\n\n try {\n // Read current config\n let currentContent: string\n try {\n currentContent = readFileSync(configFilePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Config file not found: ${configFilePath}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for add_collection update type',\n },\n ],\n }\n }\n updatedContent = addCollectionToConfig(currentContent, collectionName)\n updateSummary = [`Added collection: ${collectionName}`]\n break\n\n case 'remove_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for remove_collection update type',\n },\n ],\n }\n }\n updatedContent = removeCollectionFromConfig(currentContent, collectionName)\n updateSummary = [`Removed collection: ${collectionName}`]\n break\n\n case 'replace_content':\n if (!newContent) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No new content provided for replace_content update type',\n },\n ],\n }\n }\n updatedContent = newContent\n updateSummary = ['Replaced entire config content']\n break\n\n case 'update_admin':\n if (!adminConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No admin config provided for update_admin update type',\n },\n ],\n }\n }\n updatedContent = updateAdminConfig(currentContent, adminConfig)\n updateSummary = Object.keys(adminConfig).map((key) => `Updated admin config: ${key}`)\n break\n\n case 'update_database':\n if (!databaseConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No database config provided for update_database update type',\n },\n ],\n }\n }\n updatedContent = updateDatabaseConfig(currentContent, databaseConfig)\n updateSummary = Object.keys(databaseConfig).map((key) => `Updated database config: ${key}`)\n break\n\n case 'update_plugins':\n if (!pluginUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No plugin updates provided for update_plugins update type',\n },\n ],\n }\n }\n updatedContent = updatePluginsConfig(currentContent, pluginUpdates)\n updateSummary = []\n if (pluginUpdates.add) {\n updateSummary.push(`Added plugins: ${pluginUpdates.add.join(', ')}`)\n }\n if (pluginUpdates.remove) {\n updateSummary.push(`Removed plugins: ${pluginUpdates.remove.join(', ')}`)\n }\n break\n\n default:\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Unknown update type: ${updateType}`,\n },\n ],\n }\n }\n\n // Write the updated content back to the file\n writeFileSync(configFilePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Config updated successfully!**\n\n**File**: \\`${configFilePath}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Config Content:**\n\\`\\`\\`typescript\n${updatedContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating config: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating config**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = ({\n adminConfig,\n collectionName,\n databaseConfig,\n generalConfig,\n newContent,\n pluginUpdates,\n updateType,\n }: {\n adminConfig?: any\n collectionName?: string\n databaseConfig?: any\n generalConfig?: any\n newContent?: string\n pluginUpdates?: any\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config: ${updateType}`)\n }\n\n try {\n const result = updateConfig(\n req,\n verboseLogs,\n configFilePath,\n updateType,\n collectionName,\n adminConfig,\n databaseConfig,\n pluginUpdates,\n generalConfig,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config update completed for: ${updateType}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error updating config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'updateConfig',\n {\n description: toolSchemas.updateConfig.description,\n inputSchema: toolSchemas.updateConfig.parameters.shape,\n },\n (args) => {\n return tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","addCollectionToConfig","removeCollectionFromConfig","updateAdminConfig","updateDatabaseConfig","updatePluginsConfig","toolSchemas","updateConfig","req","verboseLogs","configFilePath","updateType","collectionName","adminConfig","databaseConfig","pluginUpdates","generalConfig","newContent","payload","logger","info","startsWith","process","cwd","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","Object","keys","map","key","add","push","join","remove","summary","errorMessage","message","updateConfigTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAEhD,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,iBAAiB,EACjBC,oBAAoB,EACpBC,mBAAmB,QACd,0BAAyB;AAChC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,eAAe,CAC1BC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC,eACAC;IAEA,MAAM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E,OAAO;gBACLhB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,uBAAuB,EAAEc,cAAc;oBAChD;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,gBACA;QACEC,aAAa3C,YAAYC,YAAY,CAAC0C,WAAW;QACjDC,aAAa5C,YAAYC,YAAY,CAAC4C,UAAU,CAACC,KAAK;IACxD,GACA,CAACC;QACC,OAAOR,KAAKQ;IACd;AAEJ,EAAC"}
@@ -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,SA+G1C,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,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"}
@@ -70,7 +70,10 @@ ${JSON.stringify(result, null, 2)}
70
70
  }
71
71
  };
72
72
  if (globals?.[globalSlug]?.enabled) {
73
- server.tool(`find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, `${toolSchemas.findGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`, toolSchemas.findGlobal.parameters.shape, async ({ depth, fallbackLocale, locale, select })=>{
73
+ server.registerTool(`find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, {
74
+ description: `${toolSchemas.findGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`,
75
+ inputSchema: toolSchemas.findGlobal.parameters.shape
76
+ }, async ({ depth, fallbackLocale, locale, select })=>{
74
77
  return await tool(depth, locale, fallbackLocale, select);
75
78
  });
76
79
  }
@@ -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.tool(\n `find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n `${toolSchemas.findGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n toolSchemas.findGlobal.parameters.shape,\n async ({ depth, fallbackLocale, locale, 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","charAt","toUpperCase","slice","description","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8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,QAAQ,MAAM,GAAG;MAC5B,CAAC;oBACG;iBACD;YACH;YAEA,OAAQrB,SAAS,CAACD,WAAW,EAAEqB,mBAAmBJ,UAAUK,QAAQzB,QAAQoB;QAM9E,EAAE,OAAOQ,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,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,OAAOM,IAAI,CACT,CAAC,IAAI,EAAEF,WAAW8B,MAAM,CAAC,GAAGC,WAAW,KAAKtC,YAAYO,YAAYgC,KAAK,CAAC,IAAI,EAC9E,GAAGtC,YAAY6B,UAAU,CAACU,WAAW,CAACC,IAAI,GAAG,IAAI,EAAEjC,SAAS,CAACD,WAAW,EAAEiC,eAAe,IAAI,EAC7FvC,YAAY6B,UAAU,CAACY,UAAU,CAACC,KAAK,EACvC,OAAO,EAAEjC,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 { 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,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,E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,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 +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;AAM9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,UACjC,WAAW,SAiLpB,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,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAM9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,UACjC,WAAW,SAmLpB,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { toCamelCase } from '../../../utils/camelCase.js';
3
- import { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js';
3
+ import { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js';
4
4
  import { toolSchemas } from '../schemas.js';
5
5
  export const updateGlobalTool = (server, req, user, verboseLogs, globalSlug, globals, schema)=>{
6
6
  const tool = async (data, draft = false, depth = 0, locale, fallbackLocale, select)=>{
@@ -107,7 +107,10 @@ ${JSON.stringify(result, null, 2)}
107
107
  locale: z.string().optional().describe('Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields'),
108
108
  select: z.string().optional().describe('Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'')
109
109
  });
110
- server.tool(`update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, `${toolSchemas.updateGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`, updateGlobalSchema.shape, async (params)=>{
110
+ server.registerTool(`update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`, {
111
+ description: `${toolSchemas.updateGlobal.description.trim()}\n\n${globals?.[globalSlug]?.description || ''}`,
112
+ inputSchema: updateGlobalSchema.shape
113
+ }, async (params)=>{
111
114
  const { depth, draft, fallbackLocale, locale, select, ...rest } = params;
112
115
  const data = JSON.stringify(rest);
113
116
  return await tool(data, draft, depth, locale, fallbackLocale, select);
@@ -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 { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n draft: boolean = false,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n 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 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.tool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n updateGlobalSchema.shape,\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, 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","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","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","charAt","toUpperCase","slice","description","trim","params","rest"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,YACAC,SACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,QAAiB,KAAK,EACtBC,QAAgB,CAAC,EACjBC,QACAC,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,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,QAAQ,GACRI,QAAQ,CACP;QAEN;QAEAnD,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,WAAWkD,MAAM,CAAC,GAAGC,WAAW,KAAK3D,YAAYQ,YAAYoD,KAAK,CAAC,IAAI,EAChF,GAAG1D,YAAYmC,YAAY,CAACwB,WAAW,CAACC,IAAI,GAAG,IAAI,EAAErD,SAAS,CAACD,WAAW,EAAEqD,eAAe,IAAI,EAC/FT,mBAAmBL,KAAK,EACxB,OAAOgB;YACL,MAAM,EAAEjD,KAAK,EAAED,KAAK,EAAEG,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAG+C,MAAM,GAAGD;YAClE,MAAMnD,OAAOU,KAAKE,SAAS,CAACwC;YAC5B,OAAO,MAAMrD,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 { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.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 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","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","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,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;gBACxB,IAAIL,aAAa;oBACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEZ,WAAW,EAAE,EAAEc,KAAKE,SAAS,CAACH,aAAa;gBAEhF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAEd,MAAM;gBACxE,MAAMe,WAAW;oBACfC,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;gBACA,OAAQrB,SAAS,CAACD,WAAW,EAAEuB,mBAAmBJ,UAAU,CAAC,GAAGtB,QAAQsB;YAM1E;YAEA,IAAIK;YACJ,IAAIf,QAAQ;gBACV,IAAI;oBACFe,eAAeV,KAAKC,KAAK,CAACN;gBAC5B,EAAE,OAAOQ,aAAa;oBACpB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BACAC;QAEJ;IAEJ;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/job/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAsH7C,eAAO,MAAM,SAAS,QACf,cAAc,eACN,OAAO,WACX,MAAM,WACN,MAAM,WACN,MAAM,GAAG,UAAU,WACnB,MAAM,eACF,MAAM,eACN,GAAG,gBACF,GAAG,WACR,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;EA4I7B,CAAA;AA+ED,eAAO,MAAM,aAAa,WAChB,SAAS,OACZ,cAAc,eACN,OAAO,WACX,MAAM,SAmEhB,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/job/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAsH7C,eAAO,MAAM,SAAS,QACf,cAAc,eACN,OAAO,WACX,MAAM,WACN,MAAM,WACN,MAAM,GAAG,UAAU,WACnB,MAAM,eACF,MAAM,eACN,GAAG,gBACF,GAAG,WACR,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;EA4I7B,CAAA;AA+ED,eAAO,MAAM,aAAa,WAChB,SAAS,OACZ,cAAc,eACN,OAAO,WACX,MAAM,SAqEhB,CAAA"}
@@ -285,7 +285,10 @@ export const createJobTool = (server, req, verboseLogs, jobsDir)=>{
285
285
  };
286
286
  }
287
287
  };
288
- server.tool('createJob', 'Creates a new Payload job (task or workflow) with specified configuration', toolSchemas.createJob.parameters.shape, async (args)=>{
288
+ server.registerTool('createJob', {
289
+ description: 'Creates a new Payload job (task or workflow) with specified configuration',
290
+ inputSchema: toolSchemas.createJob.parameters.shape
291
+ }, async (args)=>{
289
292
  return tool(args.jobName, args.jobType, args.jobSlug, args.description, args.inputSchema, args.outputSchema, args.jobData);
290
293
  });
291
294
  };