@payloadcms/plugin-mcp 3.86.0-internal.ac46214 → 4.0.0-canary.1
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.
- package/README.md +2 -2
- package/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +60 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +36 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +199 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +250 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +94 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +102 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +144 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +35 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +199 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +49 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +76 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +35 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +94 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +105 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +107 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +188 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +251 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +64 -0
- package/src/components/AccessField/index.client.tsx +347 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +257 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +112 -0
- package/src/mcp/builtin/collections/deleteTool.ts +116 -0
- package/src/mcp/builtin/collections/findTool.ts +177 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +28 -0
- package/src/mcp/builtin/collections/updateTool.ts +211 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +44 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +28 -0
- package/src/mcp/builtin/globals/updateTool.ts +115 -0
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +98 -0
- package/src/mcp/sanitizeMCPConfig.ts +260 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +290 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
- package/src/utils/toStandardSchema.ts +9 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -51
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
- package/src/utils/schemaConversion/transformPointFields.ts +0 -55
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import {
|
|
8
|
+
getCollectionVirtualFieldNames,
|
|
9
|
+
stripVirtualFields,
|
|
10
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
13
|
+
import { validateCollectionData } from '../validateEntityData.js'
|
|
14
|
+
import { formatCollectionError } from './formatCollectionError.js'
|
|
15
|
+
|
|
16
|
+
const DEFAULT_DESCRIPTION =
|
|
17
|
+
'Create a document in any collection by passing the collection slug and data.'
|
|
18
|
+
|
|
19
|
+
export const createDocumentTool = defineCollectionTool({
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: z.object({
|
|
22
|
+
data: z.record(z.string(), z.unknown()).describe('The document fields to create'),
|
|
23
|
+
depth: z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(0)
|
|
27
|
+
.max(10)
|
|
28
|
+
.describe('How many levels deep to populate relationships in response')
|
|
29
|
+
.optional()
|
|
30
|
+
.default(0),
|
|
31
|
+
draft: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.describe('Whether to create the document as a draft')
|
|
34
|
+
.optional()
|
|
35
|
+
.default(false),
|
|
36
|
+
fallbackLocale: z
|
|
37
|
+
.string()
|
|
38
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
39
|
+
.optional(),
|
|
40
|
+
locale: z
|
|
41
|
+
.string()
|
|
42
|
+
.describe(
|
|
43
|
+
'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
44
|
+
)
|
|
45
|
+
.optional(),
|
|
46
|
+
select: z
|
|
47
|
+
.string()
|
|
48
|
+
.describe(
|
|
49
|
+
"Optional: define exactly which fields you'd like to return (JSON), e.g., '{\"title\": true}'",
|
|
50
|
+
)
|
|
51
|
+
.optional(),
|
|
52
|
+
}),
|
|
53
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
54
|
+
const payload = req.payload
|
|
55
|
+
const logger = getLogger({ payload })
|
|
56
|
+
|
|
57
|
+
const { data, depth, draft, fallbackLocale, locale, select } = input
|
|
58
|
+
|
|
59
|
+
logger.info(
|
|
60
|
+
`Creating document in collection: ${collectionSlug}${locale ? ` with locale: ${locale}` : ''}`,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
65
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
66
|
+
const validationError = validateCollectionData({ collectionSlug, data: inputData, req })
|
|
67
|
+
|
|
68
|
+
if (validationError) {
|
|
69
|
+
return validationError
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
73
|
+
|
|
74
|
+
let selectClause: SelectType | undefined
|
|
75
|
+
if (select) {
|
|
76
|
+
try {
|
|
77
|
+
selectClause = JSON.parse(select) as SelectType
|
|
78
|
+
} catch {
|
|
79
|
+
logger.warn(`Invalid select clause JSON: ${select}`)
|
|
80
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const result = await payload.create({
|
|
85
|
+
collection: collectionSlug,
|
|
86
|
+
data: parsedData,
|
|
87
|
+
depth,
|
|
88
|
+
draft,
|
|
89
|
+
req,
|
|
90
|
+
...localAPIDefaults(authorizedMCP),
|
|
91
|
+
...(locale ? { locale } : {}),
|
|
92
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
93
|
+
...(selectClause ? { select: selectClause } : {}),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
logger.info(`Successfully created document in ${collectionSlug} with ID: ${result.id}`)
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
text: `Document created successfully in collection "${collectionSlug}"!\nCreated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
doc: result as Record<string, unknown>,
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
109
|
+
logger.error(`Error creating document in ${collectionSlug}: ${errorMessage}`)
|
|
110
|
+
return formatCollectionError({ action: 'creating', collectionSlug, error, req })
|
|
111
|
+
}
|
|
112
|
+
})
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
5
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
6
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
7
|
+
|
|
8
|
+
const DEFAULT_DESCRIPTION =
|
|
9
|
+
'Delete documents in any collection by passing the collection slug and ID or where clause.'
|
|
10
|
+
|
|
11
|
+
export const deleteDocumentsTool = defineCollectionTool({
|
|
12
|
+
description: DEFAULT_DESCRIPTION,
|
|
13
|
+
input: z.object({
|
|
14
|
+
id: z
|
|
15
|
+
.union([z.string(), z.number()])
|
|
16
|
+
.describe('Optional: specific document ID to delete')
|
|
17
|
+
.optional(),
|
|
18
|
+
depth: z
|
|
19
|
+
.number()
|
|
20
|
+
.int()
|
|
21
|
+
.min(0)
|
|
22
|
+
.max(10)
|
|
23
|
+
.describe('Depth of population for relationships in response')
|
|
24
|
+
.optional()
|
|
25
|
+
.default(0),
|
|
26
|
+
fallbackLocale: z
|
|
27
|
+
.string()
|
|
28
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
29
|
+
.optional(),
|
|
30
|
+
locale: z
|
|
31
|
+
.string()
|
|
32
|
+
.describe(
|
|
33
|
+
'Optional: locale code for the operation (e.g., "en", "es"). Defaults to the default locale',
|
|
34
|
+
)
|
|
35
|
+
.optional(),
|
|
36
|
+
where: whereSchema
|
|
37
|
+
.describe(
|
|
38
|
+
'Optional: where clause to delete multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
39
|
+
)
|
|
40
|
+
.optional(),
|
|
41
|
+
}),
|
|
42
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
43
|
+
const payload = req.payload
|
|
44
|
+
const logger = getLogger({ payload })
|
|
45
|
+
|
|
46
|
+
const { id, depth, fallbackLocale, locale, where } = input
|
|
47
|
+
|
|
48
|
+
logger.info(
|
|
49
|
+
`Deleting document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
if (!id && !where) {
|
|
54
|
+
return {
|
|
55
|
+
content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const deleteOptions: Record<string, unknown> = {
|
|
60
|
+
collection: collectionSlug,
|
|
61
|
+
depth,
|
|
62
|
+
req,
|
|
63
|
+
...localAPIDefaults(authorizedMCP),
|
|
64
|
+
...(locale && { locale }),
|
|
65
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (id) {
|
|
69
|
+
deleteOptions.id = id
|
|
70
|
+
} else {
|
|
71
|
+
deleteOptions.where = where
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])
|
|
75
|
+
|
|
76
|
+
if (id) {
|
|
77
|
+
return {
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: `Document deleted successfully from collection "${collectionSlug}"!\nDeleted document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
doc: result as Record<string, unknown>,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }
|
|
89
|
+
const docs = bulkResult.docs || []
|
|
90
|
+
const errors = bulkResult.errors || []
|
|
91
|
+
|
|
92
|
+
let responseText = `Document deleted successfully from collection "${collectionSlug}"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`
|
|
93
|
+
if (docs.length > 0) {
|
|
94
|
+
responseText += `\n\nDeleted documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``
|
|
95
|
+
}
|
|
96
|
+
if (errors.length > 0) {
|
|
97
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
content: [{ type: 'text', text: responseText }],
|
|
102
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
106
|
+
logger.error(`Error deleting document from ${collectionSlug}: ${errorMessage}`)
|
|
107
|
+
return {
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: `Error deleting document from collection "${collectionSlug}": ${errorMessage}`,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
})
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DESCRIPTION =
|
|
11
|
+
'Find documents in any collection by passing the collection slug and optional ID or where clause.'
|
|
12
|
+
|
|
13
|
+
export const findDocumentsTool = defineCollectionTool({
|
|
14
|
+
description: DEFAULT_DESCRIPTION,
|
|
15
|
+
input: z.object({
|
|
16
|
+
id: z
|
|
17
|
+
.union([z.string(), z.number()])
|
|
18
|
+
.describe(
|
|
19
|
+
'Optional: specific document ID to retrieve. If not provided, returns all documents',
|
|
20
|
+
)
|
|
21
|
+
.optional(),
|
|
22
|
+
depth: z
|
|
23
|
+
.number()
|
|
24
|
+
.int()
|
|
25
|
+
.min(0)
|
|
26
|
+
.max(10)
|
|
27
|
+
.describe('How many levels deep to populate relationships (default: 0)')
|
|
28
|
+
.optional()
|
|
29
|
+
.default(0),
|
|
30
|
+
draft: z
|
|
31
|
+
.boolean()
|
|
32
|
+
.describe(
|
|
33
|
+
'Optional: whether the document should be queried from the versions table/collection or not.',
|
|
34
|
+
)
|
|
35
|
+
.optional(),
|
|
36
|
+
fallbackLocale: z
|
|
37
|
+
.string()
|
|
38
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
39
|
+
.optional(),
|
|
40
|
+
limit: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.min(1)
|
|
44
|
+
.max(100)
|
|
45
|
+
.describe('Maximum number of documents to return (default: 10, max: 100)')
|
|
46
|
+
.optional()
|
|
47
|
+
.default(10),
|
|
48
|
+
locale: z
|
|
49
|
+
.string()
|
|
50
|
+
.describe(
|
|
51
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
52
|
+
)
|
|
53
|
+
.optional(),
|
|
54
|
+
page: z
|
|
55
|
+
.number()
|
|
56
|
+
.int()
|
|
57
|
+
.min(1)
|
|
58
|
+
.describe('Page number for pagination (default: 1)')
|
|
59
|
+
.optional()
|
|
60
|
+
.default(1),
|
|
61
|
+
select: z
|
|
62
|
+
.string()
|
|
63
|
+
.describe(
|
|
64
|
+
"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
|
|
65
|
+
)
|
|
66
|
+
.optional(),
|
|
67
|
+
sort: z
|
|
68
|
+
.string()
|
|
69
|
+
.describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)')
|
|
70
|
+
.optional(),
|
|
71
|
+
where: whereSchema
|
|
72
|
+
.describe(
|
|
73
|
+
'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
74
|
+
)
|
|
75
|
+
.optional(),
|
|
76
|
+
}),
|
|
77
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
78
|
+
const payload = req.payload
|
|
79
|
+
const logger = getLogger({ payload })
|
|
80
|
+
|
|
81
|
+
const { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input
|
|
82
|
+
|
|
83
|
+
logger.info(
|
|
84
|
+
`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
let selectClause: SelectType | undefined
|
|
89
|
+
if (select) {
|
|
90
|
+
try {
|
|
91
|
+
selectClause = JSON.parse(select) as SelectType
|
|
92
|
+
} catch {
|
|
93
|
+
logger.warn(`Invalid select clause JSON: ${select}`)
|
|
94
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (id) {
|
|
99
|
+
try {
|
|
100
|
+
const doc = await payload.findByID({
|
|
101
|
+
id,
|
|
102
|
+
collection: collectionSlug,
|
|
103
|
+
depth,
|
|
104
|
+
req,
|
|
105
|
+
...localAPIDefaults(authorizedMCP),
|
|
106
|
+
...(selectClause && { select: selectClause }),
|
|
107
|
+
...(locale && { locale }),
|
|
108
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
109
|
+
...(draft !== undefined && { draft }),
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: 'text',
|
|
116
|
+
text: `Document from collection "${collectionSlug}":\n${JSON.stringify(doc)}`,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
doc: doc as Record<string, unknown>,
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)
|
|
123
|
+
return {
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
type: 'text',
|
|
127
|
+
text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const findOptions: Parameters<typeof payload.find>[0] = {
|
|
135
|
+
collection: collectionSlug,
|
|
136
|
+
depth,
|
|
137
|
+
limit,
|
|
138
|
+
page,
|
|
139
|
+
req,
|
|
140
|
+
...localAPIDefaults(authorizedMCP),
|
|
141
|
+
...(selectClause && { select: selectClause }),
|
|
142
|
+
...(locale && { locale }),
|
|
143
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
144
|
+
...(draft !== undefined && { draft }),
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (sort) {
|
|
148
|
+
findOptions.sort = sort
|
|
149
|
+
}
|
|
150
|
+
if (where) {
|
|
151
|
+
findOptions.where = where
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const result = await payload.find(findOptions)
|
|
155
|
+
|
|
156
|
+
let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`
|
|
157
|
+
for (const doc of result.docs) {
|
|
158
|
+
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
content: [{ type: 'text', text: responseText }],
|
|
163
|
+
doc: result as unknown as Record<string, unknown>,
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
167
|
+
logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`)
|
|
168
|
+
return {
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
type: 'text',
|
|
172
|
+
text: `❌ **Error reading documents from collection "${collectionSlug}":** ${errorMessage}`,
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { CollectionSlug, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import type { MCPToolResponse } from '../../../types.js'
|
|
4
|
+
|
|
5
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
6
|
+
|
|
7
|
+
const getValidationErrors = (error: unknown): undefined | unknown[] => {
|
|
8
|
+
if (!error || typeof error !== 'object') {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const data = 'data' in error ? error.data : undefined
|
|
13
|
+
if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return data.errors
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isSchemaError = (error: unknown, message: string): boolean => {
|
|
21
|
+
if (getValidationErrors(error)) {
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
name === 'CastError' ||
|
|
29
|
+
name === 'ValidationError' ||
|
|
30
|
+
message.includes('Cast to ') ||
|
|
31
|
+
message.includes('validation failed')
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const formatCollectionError = ({
|
|
36
|
+
action,
|
|
37
|
+
collectionSlug,
|
|
38
|
+
error,
|
|
39
|
+
req,
|
|
40
|
+
}: {
|
|
41
|
+
action: 'creating' | 'updating'
|
|
42
|
+
collectionSlug: CollectionSlug
|
|
43
|
+
error: unknown
|
|
44
|
+
req: PayloadRequest
|
|
45
|
+
}): MCPToolResponse => {
|
|
46
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
47
|
+
const errors = getValidationErrors(error) ?? [{ message: errorMessage }]
|
|
48
|
+
|
|
49
|
+
if (!isSchemaError(error, errorMessage)) {
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const schema = getCollectionInputSchema({ collectionSlug, req })
|
|
62
|
+
const schemaText = schema
|
|
63
|
+
? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
|
|
64
|
+
: ''
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: 'text',
|
|
70
|
+
text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
isError: true,
|
|
74
|
+
...(schema
|
|
75
|
+
? {
|
|
76
|
+
structuredContent: {
|
|
77
|
+
collectionSlug,
|
|
78
|
+
errors,
|
|
79
|
+
schema,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
2
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
3
|
+
|
|
4
|
+
export const getCollectionSchemaTool = defineCollectionTool({
|
|
5
|
+
description: 'Get the input schema for creating or updating documents in a collection.',
|
|
6
|
+
}).handler(({ collectionSlug, req }) => {
|
|
7
|
+
const inputSchema = getCollectionInputSchema({ collectionSlug, req })
|
|
8
|
+
|
|
9
|
+
if (!inputSchema) {
|
|
10
|
+
return {
|
|
11
|
+
content: [{ type: 'text', text: `Error: Collection "${collectionSlug}" not found` }],
|
|
12
|
+
isError: true,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
structuredContent: {
|
|
24
|
+
collectionSlug,
|
|
25
|
+
schema: inputSchema,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
})
|