@payloadcms/plugin-mcp 4.0.0-canary.2 → 4.0.0-canary.20261117
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/LICENSE.md +1 -1
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +29 -6
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +133 -100
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +121 -16
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +37 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +105 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/endpoint/oauthLoginToken.d.ts +27 -0
- package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
- package/dist/endpoint/oauthLoginToken.js +86 -0
- package/dist/endpoint/oauthLoginToken.js.map +1 -0
- package/dist/endpoint/oauthServer.d.ts +28 -0
- package/dist/endpoint/oauthServer.d.ts.map +1 -0
- package/dist/endpoint/oauthServer.js +455 -0
- package/dist/endpoint/oauthServer.js.map +1 -0
- package/dist/exports/client.d.ts +1 -4
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -4
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/exports/rsc.d.ts +2 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -55
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +6 -6
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +70 -34
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +123 -61
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +63 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +109 -66
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +56 -45
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +88 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +58 -56
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +78 -10
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +75 -102
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +30 -10
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +26 -35
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +56 -10
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +38 -54
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +75 -12
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +75 -13
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +76 -27
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -3
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +86 -47
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +224 -95
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/seal.d.ts +17 -0
- package/dist/utils/seal.d.ts.map +1 -0
- package/dist/utils/seal.js +24 -0
- package/dist/utils/seal.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.js.map +1 -1
- package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
- package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
- package/dist/views/Authorize/AllowButtons/index.js +88 -0
- package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
- package/dist/views/Authorize/index.css +19 -0
- package/dist/views/Authorize/index.d.ts +9 -0
- package/dist/views/Authorize/index.d.ts.map +1 -0
- package/dist/views/Authorize/index.js +98 -0
- package/dist/views/Authorize/index.js.map +1 -0
- package/package.json +34 -38
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +149 -109
- package/src/endpoint/index.ts +103 -15
- package/src/endpoint/oauth.ts +108 -0
- package/src/endpoint/oauthLoginToken.ts +100 -0
- package/src/endpoint/oauthServer.ts +472 -0
- package/src/exports/client.ts +2 -4
- package/src/exports/internal.ts +1 -0
- package/src/exports/rsc.ts +1 -0
- package/src/index.ts +53 -63
- package/src/mcp/buildMcpServer.ts +88 -51
- package/src/mcp/builtin/collections/authTools.ts +124 -77
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +113 -82
- package/src/mcp/builtin/collections/deleteTool.ts +49 -66
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +54 -97
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +70 -7
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +72 -110
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +29 -5
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +27 -57
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +52 -7
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +49 -72
- package/src/mcp/builtinTools.ts +81 -18
- package/src/mcp/sanitizeMCPConfig.ts +53 -30
- package/src/stdio.ts +80 -47
- package/src/types.ts +232 -99
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/seal.ts +46 -0
- package/src/utils/toStandardSchema.ts +1 -1
- package/src/views/Authorize/AllowButtons/index.tsx +97 -0
- package/src/views/Authorize/index.css +19 -0
- package/src/views/Authorize/index.tsx +100 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -72
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -105
- package/dist/collection/index.js.map +0 -1
- package/dist/components/APIKeyField/index.client.d.ts +0 -9
- package/dist/components/APIKeyField/index.client.d.ts.map +0 -1
- package/dist/components/APIKeyField/index.client.js +0 -85
- package/dist/components/APIKeyField/index.client.js.map +0 -1
- package/dist/components/APIKeyField/index.css +0 -105
- package/dist/components/APIKeysEmptyState/index.client.d.ts +0 -4
- package/dist/components/APIKeysEmptyState/index.client.d.ts.map +0 -1
- package/dist/components/APIKeysEmptyState/index.client.js +0 -21
- package/dist/components/APIKeysEmptyState/index.client.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -247
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -99
- package/dist/components/SettingsMenu/index.client.d.ts +0 -8
- package/dist/components/SettingsMenu/index.client.d.ts.map +0 -1
- package/dist/components/SettingsMenu/index.client.js +0 -29
- package/dist/components/SettingsMenu/index.client.js.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- package/dist/translations/index.d.ts +0 -11
- package/dist/translations/index.d.ts.map +0 -1
- package/dist/translations/index.js +0 -92
- package/dist/translations/index.js.map +0 -1
- package/dist/translations/languages/ar.d.ts +0 -31
- package/dist/translations/languages/ar.d.ts.map +0 -1
- package/dist/translations/languages/ar.js +0 -34
- package/dist/translations/languages/ar.js.map +0 -1
- package/dist/translations/languages/az.d.ts +0 -31
- package/dist/translations/languages/az.d.ts.map +0 -1
- package/dist/translations/languages/az.js +0 -34
- package/dist/translations/languages/az.js.map +0 -1
- package/dist/translations/languages/bg.d.ts +0 -31
- package/dist/translations/languages/bg.d.ts.map +0 -1
- package/dist/translations/languages/bg.js +0 -34
- package/dist/translations/languages/bg.js.map +0 -1
- package/dist/translations/languages/bnBd.d.ts +0 -31
- package/dist/translations/languages/bnBd.d.ts.map +0 -1
- package/dist/translations/languages/bnBd.js +0 -34
- package/dist/translations/languages/bnBd.js.map +0 -1
- package/dist/translations/languages/bnIn.d.ts +0 -31
- package/dist/translations/languages/bnIn.d.ts.map +0 -1
- package/dist/translations/languages/bnIn.js +0 -34
- package/dist/translations/languages/bnIn.js.map +0 -1
- package/dist/translations/languages/ca.d.ts +0 -31
- package/dist/translations/languages/ca.d.ts.map +0 -1
- package/dist/translations/languages/ca.js +0 -34
- package/dist/translations/languages/ca.js.map +0 -1
- package/dist/translations/languages/cs.d.ts +0 -31
- package/dist/translations/languages/cs.d.ts.map +0 -1
- package/dist/translations/languages/cs.js +0 -34
- package/dist/translations/languages/cs.js.map +0 -1
- package/dist/translations/languages/da.d.ts +0 -31
- package/dist/translations/languages/da.d.ts.map +0 -1
- package/dist/translations/languages/da.js +0 -34
- package/dist/translations/languages/da.js.map +0 -1
- package/dist/translations/languages/de.d.ts +0 -31
- package/dist/translations/languages/de.d.ts.map +0 -1
- package/dist/translations/languages/de.js +0 -34
- package/dist/translations/languages/de.js.map +0 -1
- package/dist/translations/languages/en.d.ts +0 -31
- package/dist/translations/languages/en.d.ts.map +0 -1
- package/dist/translations/languages/en.js +0 -34
- package/dist/translations/languages/en.js.map +0 -1
- package/dist/translations/languages/es.d.ts +0 -31
- package/dist/translations/languages/es.d.ts.map +0 -1
- package/dist/translations/languages/es.js +0 -34
- package/dist/translations/languages/es.js.map +0 -1
- package/dist/translations/languages/et.d.ts +0 -31
- package/dist/translations/languages/et.d.ts.map +0 -1
- package/dist/translations/languages/et.js +0 -34
- package/dist/translations/languages/et.js.map +0 -1
- package/dist/translations/languages/fa.d.ts +0 -31
- package/dist/translations/languages/fa.d.ts.map +0 -1
- package/dist/translations/languages/fa.js +0 -34
- package/dist/translations/languages/fa.js.map +0 -1
- package/dist/translations/languages/fr.d.ts +0 -31
- package/dist/translations/languages/fr.d.ts.map +0 -1
- package/dist/translations/languages/fr.js +0 -34
- package/dist/translations/languages/fr.js.map +0 -1
- package/dist/translations/languages/he.d.ts +0 -31
- package/dist/translations/languages/he.d.ts.map +0 -1
- package/dist/translations/languages/he.js +0 -34
- package/dist/translations/languages/he.js.map +0 -1
- package/dist/translations/languages/hr.d.ts +0 -31
- package/dist/translations/languages/hr.d.ts.map +0 -1
- package/dist/translations/languages/hr.js +0 -34
- package/dist/translations/languages/hr.js.map +0 -1
- package/dist/translations/languages/hu.d.ts +0 -31
- package/dist/translations/languages/hu.d.ts.map +0 -1
- package/dist/translations/languages/hu.js +0 -34
- package/dist/translations/languages/hu.js.map +0 -1
- package/dist/translations/languages/hy.d.ts +0 -31
- package/dist/translations/languages/hy.d.ts.map +0 -1
- package/dist/translations/languages/hy.js +0 -34
- package/dist/translations/languages/hy.js.map +0 -1
- package/dist/translations/languages/id.d.ts +0 -31
- package/dist/translations/languages/id.d.ts.map +0 -1
- package/dist/translations/languages/id.js +0 -34
- package/dist/translations/languages/id.js.map +0 -1
- package/dist/translations/languages/is.d.ts +0 -31
- package/dist/translations/languages/is.d.ts.map +0 -1
- package/dist/translations/languages/is.js +0 -34
- package/dist/translations/languages/is.js.map +0 -1
- package/dist/translations/languages/it.d.ts +0 -31
- package/dist/translations/languages/it.d.ts.map +0 -1
- package/dist/translations/languages/it.js +0 -34
- package/dist/translations/languages/it.js.map +0 -1
- package/dist/translations/languages/ja.d.ts +0 -31
- package/dist/translations/languages/ja.d.ts.map +0 -1
- package/dist/translations/languages/ja.js +0 -34
- package/dist/translations/languages/ja.js.map +0 -1
- package/dist/translations/languages/ko.d.ts +0 -31
- package/dist/translations/languages/ko.d.ts.map +0 -1
- package/dist/translations/languages/ko.js +0 -34
- package/dist/translations/languages/ko.js.map +0 -1
- package/dist/translations/languages/lt.d.ts +0 -31
- package/dist/translations/languages/lt.d.ts.map +0 -1
- package/dist/translations/languages/lt.js +0 -34
- package/dist/translations/languages/lt.js.map +0 -1
- package/dist/translations/languages/lv.d.ts +0 -31
- package/dist/translations/languages/lv.d.ts.map +0 -1
- package/dist/translations/languages/lv.js +0 -34
- package/dist/translations/languages/lv.js.map +0 -1
- package/dist/translations/languages/my.d.ts +0 -31
- package/dist/translations/languages/my.d.ts.map +0 -1
- package/dist/translations/languages/my.js +0 -34
- package/dist/translations/languages/my.js.map +0 -1
- package/dist/translations/languages/nb.d.ts +0 -31
- package/dist/translations/languages/nb.d.ts.map +0 -1
- package/dist/translations/languages/nb.js +0 -34
- package/dist/translations/languages/nb.js.map +0 -1
- package/dist/translations/languages/nl.d.ts +0 -31
- package/dist/translations/languages/nl.d.ts.map +0 -1
- package/dist/translations/languages/nl.js +0 -34
- package/dist/translations/languages/nl.js.map +0 -1
- package/dist/translations/languages/pl.d.ts +0 -31
- package/dist/translations/languages/pl.d.ts.map +0 -1
- package/dist/translations/languages/pl.js +0 -34
- package/dist/translations/languages/pl.js.map +0 -1
- package/dist/translations/languages/pt.d.ts +0 -31
- package/dist/translations/languages/pt.d.ts.map +0 -1
- package/dist/translations/languages/pt.js +0 -34
- package/dist/translations/languages/pt.js.map +0 -1
- package/dist/translations/languages/ro.d.ts +0 -31
- package/dist/translations/languages/ro.d.ts.map +0 -1
- package/dist/translations/languages/ro.js +0 -34
- package/dist/translations/languages/ro.js.map +0 -1
- package/dist/translations/languages/rs.d.ts +0 -31
- package/dist/translations/languages/rs.d.ts.map +0 -1
- package/dist/translations/languages/rs.js +0 -34
- package/dist/translations/languages/rs.js.map +0 -1
- package/dist/translations/languages/rsLatin.d.ts +0 -31
- package/dist/translations/languages/rsLatin.d.ts.map +0 -1
- package/dist/translations/languages/rsLatin.js +0 -34
- package/dist/translations/languages/rsLatin.js.map +0 -1
- package/dist/translations/languages/ru.d.ts +0 -31
- package/dist/translations/languages/ru.d.ts.map +0 -1
- package/dist/translations/languages/ru.js +0 -34
- package/dist/translations/languages/ru.js.map +0 -1
- package/dist/translations/languages/sk.d.ts +0 -31
- package/dist/translations/languages/sk.d.ts.map +0 -1
- package/dist/translations/languages/sk.js +0 -34
- package/dist/translations/languages/sk.js.map +0 -1
- package/dist/translations/languages/sl.d.ts +0 -31
- package/dist/translations/languages/sl.d.ts.map +0 -1
- package/dist/translations/languages/sl.js +0 -34
- package/dist/translations/languages/sl.js.map +0 -1
- package/dist/translations/languages/sv.d.ts +0 -31
- package/dist/translations/languages/sv.d.ts.map +0 -1
- package/dist/translations/languages/sv.js +0 -34
- package/dist/translations/languages/sv.js.map +0 -1
- package/dist/translations/languages/ta.d.ts +0 -31
- package/dist/translations/languages/ta.d.ts.map +0 -1
- package/dist/translations/languages/ta.js +0 -34
- package/dist/translations/languages/ta.js.map +0 -1
- package/dist/translations/languages/th.d.ts +0 -31
- package/dist/translations/languages/th.d.ts.map +0 -1
- package/dist/translations/languages/th.js +0 -34
- package/dist/translations/languages/th.js.map +0 -1
- package/dist/translations/languages/tr.d.ts +0 -31
- package/dist/translations/languages/tr.d.ts.map +0 -1
- package/dist/translations/languages/tr.js +0 -34
- package/dist/translations/languages/tr.js.map +0 -1
- package/dist/translations/languages/uk.d.ts +0 -31
- package/dist/translations/languages/uk.d.ts.map +0 -1
- package/dist/translations/languages/uk.js +0 -34
- package/dist/translations/languages/uk.js.map +0 -1
- package/dist/translations/languages/vi.d.ts +0 -31
- package/dist/translations/languages/vi.d.ts.map +0 -1
- package/dist/translations/languages/vi.js +0 -34
- package/dist/translations/languages/vi.js.map +0 -1
- package/dist/translations/languages/zh.d.ts +0 -31
- package/dist/translations/languages/zh.d.ts.map +0 -1
- package/dist/translations/languages/zh.js +0 -34
- package/dist/translations/languages/zh.js.map +0 -1
- package/dist/translations/languages/zhTw.d.ts +0 -31
- package/dist/translations/languages/zhTw.d.ts.map +0 -1
- package/dist/translations/languages/zhTw.js +0 -34
- package/dist/translations/languages/zhTw.js.map +0 -1
- package/dist/translations/types.d.ts +0 -32
- package/dist/translations/types.d.ts.map +0 -1
- package/dist/translations/types.js +0 -3
- package/dist/translations/types.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/localAPIDefaults.d.ts +0 -20
- package/dist/utils/localAPIDefaults.d.ts.map +0 -1
- package/dist/utils/localAPIDefaults.js +0 -19
- package/dist/utils/localAPIDefaults.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -84
- package/src/collection/index.ts +0 -105
- package/src/components/APIKeyField/index.client.tsx +0 -73
- package/src/components/APIKeyField/index.css +0 -105
- package/src/components/APIKeysEmptyState/index.client.tsx +0 -36
- package/src/components/AccessField/index.client.tsx +0 -299
- package/src/components/AccessField/index.css +0 -99
- package/src/components/SettingsMenu/index.client.tsx +0 -34
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/translations/index.ts +0 -108
- package/src/translations/languages/ar.ts +0 -35
- package/src/translations/languages/az.ts +0 -35
- package/src/translations/languages/bg.ts +0 -35
- package/src/translations/languages/bnBd.ts +0 -35
- package/src/translations/languages/bnIn.ts +0 -35
- package/src/translations/languages/ca.ts +0 -35
- package/src/translations/languages/cs.ts +0 -35
- package/src/translations/languages/da.ts +0 -35
- package/src/translations/languages/de.ts +0 -35
- package/src/translations/languages/en.ts +0 -35
- package/src/translations/languages/es.ts +0 -35
- package/src/translations/languages/et.ts +0 -35
- package/src/translations/languages/fa.ts +0 -35
- package/src/translations/languages/fr.ts +0 -35
- package/src/translations/languages/he.ts +0 -35
- package/src/translations/languages/hr.ts +0 -35
- package/src/translations/languages/hu.ts +0 -35
- package/src/translations/languages/hy.ts +0 -35
- package/src/translations/languages/id.ts +0 -35
- package/src/translations/languages/is.ts +0 -35
- package/src/translations/languages/it.ts +0 -35
- package/src/translations/languages/ja.ts +0 -35
- package/src/translations/languages/ko.ts +0 -35
- package/src/translations/languages/lt.ts +0 -35
- package/src/translations/languages/lv.ts +0 -35
- package/src/translations/languages/my.ts +0 -35
- package/src/translations/languages/nb.ts +0 -35
- package/src/translations/languages/nl.ts +0 -35
- package/src/translations/languages/pl.ts +0 -35
- package/src/translations/languages/pt.ts +0 -35
- package/src/translations/languages/ro.ts +0 -35
- package/src/translations/languages/rs.ts +0 -35
- package/src/translations/languages/rsLatin.ts +0 -35
- package/src/translations/languages/ru.ts +0 -35
- package/src/translations/languages/sk.ts +0 -35
- package/src/translations/languages/sl.ts +0 -35
- package/src/translations/languages/sv.ts +0 -35
- package/src/translations/languages/ta.ts +0 -35
- package/src/translations/languages/th.ts +0 -35
- package/src/translations/languages/tr.ts +0 -35
- package/src/translations/languages/uk.ts +0 -35
- package/src/translations/languages/vi.ts +0 -35
- package/src/translations/languages/zh.ts +0 -35
- package/src/translations/languages/zhTw.ts +0 -35
- package/src/translations/types.ts +0 -34
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload'
|
|
2
|
+
|
|
1
3
|
import { McpServer, type ServerContext } from '@modelcontextprotocol/server'
|
|
2
|
-
import { APIError,
|
|
3
|
-
import { z } from 'zod'
|
|
4
|
+
import { APIError, strictObject, z } from 'payload'
|
|
4
5
|
|
|
5
6
|
import type {
|
|
6
7
|
AuthorizedMCP,
|
|
@@ -17,14 +18,14 @@ import { getLogger } from '../utils/getLogger.js'
|
|
|
17
18
|
import { toStandardSchema } from '../utils/toStandardSchema.js'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
-
* `McpServer` and returns it. The
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
|
|
22
|
+
* `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
|
|
23
|
+
* instances from this builder while they own the transport and protocol-era
|
|
24
|
+
* decision.
|
|
24
25
|
*
|
|
25
26
|
* `req` is the request context handlers see. For HTTP it's the live
|
|
26
27
|
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
27
|
-
* synthesized one built via `
|
|
28
|
+
* synthesized one built via `createPayloadRequest`.
|
|
28
29
|
*/
|
|
29
30
|
export const buildMcpServer = ({
|
|
30
31
|
authorizedMCP,
|
|
@@ -35,6 +36,8 @@ export const buildMcpServer = ({
|
|
|
35
36
|
pluginConfig: SanitizedMCPPluginConfig
|
|
36
37
|
req: PayloadRequest
|
|
37
38
|
}): McpServer => {
|
|
39
|
+
z.config(z.locales.en())
|
|
40
|
+
|
|
38
41
|
const serverOptions = pluginConfig.mcp?.serverOptions || {}
|
|
39
42
|
const server = new McpServer(
|
|
40
43
|
{ name: 'Payload MCP Server', version: '1.0.0', ...serverOptions.serverInfo },
|
|
@@ -47,18 +50,28 @@ export const buildMcpServer = ({
|
|
|
47
50
|
* Wrap a tool handler's response with the tool's `overrideResponse`, then
|
|
48
51
|
* strip the internal `doc` field so it doesn't leak onto the wire.
|
|
49
52
|
*/
|
|
50
|
-
const finalizeToolResponse = (
|
|
51
|
-
|
|
52
|
-
overrideResponse
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const finalizeToolResponse = async ({
|
|
54
|
+
input,
|
|
55
|
+
overrideResponse,
|
|
56
|
+
response,
|
|
57
|
+
toolName,
|
|
58
|
+
}: {
|
|
59
|
+
input: unknown
|
|
60
|
+
overrideResponse?: MCPResponseOverride
|
|
61
|
+
response: MCPToolResponse
|
|
62
|
+
toolName: string
|
|
63
|
+
}): Promise<MCPToolResponse> => {
|
|
64
|
+
let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response
|
|
65
|
+
for (const hook of pluginConfig.hooks?.afterToolCall ?? []) {
|
|
66
|
+
overridden = await hook({ input, req, response: overridden, toolName })
|
|
67
|
+
}
|
|
55
68
|
const { doc: _doc, ...rest } = overridden
|
|
56
69
|
return rest
|
|
57
70
|
}
|
|
58
71
|
|
|
59
72
|
/**
|
|
60
73
|
* Runs a collection/global tool call:
|
|
61
|
-
* - reads `
|
|
74
|
+
* - reads `slug` from the input
|
|
62
75
|
* - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug
|
|
63
76
|
* - runs the tool handler and finalizes its response
|
|
64
77
|
*/
|
|
@@ -72,16 +85,15 @@ export const buildMcpServer = ({
|
|
|
72
85
|
serverContext: ServerContext
|
|
73
86
|
}): Promise<MCPToolResponse> => {
|
|
74
87
|
const entity = item.type === 'collectionTool' ? 'collection' : 'global'
|
|
75
|
-
const slugKey = item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug'
|
|
76
88
|
const toolInput = (input ?? {}) as Record<string, unknown>
|
|
77
|
-
const slug = toolInput
|
|
89
|
+
const slug = toolInput.slug as string | undefined
|
|
78
90
|
|
|
79
91
|
if (!slug) {
|
|
80
92
|
return {
|
|
81
93
|
content: [
|
|
82
94
|
{
|
|
83
95
|
type: 'text',
|
|
84
|
-
text: `Error: "${item.mcpName}" requires
|
|
96
|
+
text: `Error: "${item.mcpName}" requires slug. Use getConfigInfo to inspect ${entity} slugs.`,
|
|
85
97
|
},
|
|
86
98
|
],
|
|
87
99
|
isError: true,
|
|
@@ -109,12 +121,22 @@ export const buildMcpServer = ({
|
|
|
109
121
|
}
|
|
110
122
|
}
|
|
111
123
|
|
|
112
|
-
const handlerArgs = {
|
|
124
|
+
const handlerArgs = {
|
|
125
|
+
authorizedMCP,
|
|
126
|
+
input: toolInput,
|
|
127
|
+
req,
|
|
128
|
+
serverContext,
|
|
129
|
+
}
|
|
113
130
|
const response = await (match.type === 'collectionTool'
|
|
114
|
-
? match.tool.handler({ ...handlerArgs,
|
|
115
|
-
: match.tool.handler({ ...handlerArgs,
|
|
131
|
+
? match.tool.handler({ ...handlerArgs, slug })
|
|
132
|
+
: match.tool.handler({ ...handlerArgs, slug }))
|
|
116
133
|
|
|
117
|
-
return finalizeToolResponse(
|
|
134
|
+
return finalizeToolResponse({
|
|
135
|
+
input: toolInput,
|
|
136
|
+
overrideResponse: match.tool.overrideResponse,
|
|
137
|
+
response,
|
|
138
|
+
toolName: match.mcpName,
|
|
139
|
+
})
|
|
118
140
|
}
|
|
119
141
|
|
|
120
142
|
try {
|
|
@@ -129,14 +151,12 @@ export const buildMcpServer = ({
|
|
|
129
151
|
}
|
|
130
152
|
registeredEntityTools.add(item.mcpName)
|
|
131
153
|
|
|
132
|
-
const inputSchema = withSlugInput({
|
|
133
|
-
name: item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug',
|
|
134
|
-
input: item.tool.input,
|
|
135
|
-
})
|
|
154
|
+
const inputSchema = withSlugInput({ input: item.tool.input })
|
|
136
155
|
|
|
137
156
|
server.registerTool(
|
|
138
157
|
item.mcpName,
|
|
139
158
|
{
|
|
159
|
+
annotations: item.tool.annotations,
|
|
140
160
|
description: item.tool.description,
|
|
141
161
|
inputSchema: toStandardSchema(inputSchema),
|
|
142
162
|
},
|
|
@@ -193,19 +213,25 @@ export const buildMcpServer = ({
|
|
|
193
213
|
server.registerTool(
|
|
194
214
|
item.mcpName,
|
|
195
215
|
{
|
|
216
|
+
annotations: tool.annotations,
|
|
196
217
|
description: tool.description,
|
|
197
218
|
inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,
|
|
198
219
|
},
|
|
199
|
-
async (input: unknown, ctx: ServerContext) =>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
async (input: unknown, ctx: ServerContext) => {
|
|
221
|
+
const toolInput = (input ?? {}) as Record<string, unknown>
|
|
222
|
+
const response = await tool.handler({
|
|
223
|
+
authorizedMCP,
|
|
224
|
+
input: toolInput,
|
|
225
|
+
req,
|
|
226
|
+
serverContext: ctx,
|
|
227
|
+
})
|
|
228
|
+
return finalizeToolResponse({
|
|
229
|
+
input: toolInput,
|
|
230
|
+
overrideResponse: tool.overrideResponse,
|
|
231
|
+
response,
|
|
232
|
+
toolName: item.mcpName,
|
|
233
|
+
})
|
|
234
|
+
},
|
|
209
235
|
)
|
|
210
236
|
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
211
237
|
break
|
|
@@ -219,39 +245,50 @@ export const buildMcpServer = ({
|
|
|
219
245
|
return server
|
|
220
246
|
}
|
|
221
247
|
|
|
222
|
-
const withSlugInput = ({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}: {
|
|
226
|
-
input?: ToolInputSchema
|
|
227
|
-
name: 'collectionSlug' | 'globalSlug'
|
|
228
|
-
}): ToolInputSchema => {
|
|
229
|
-
const description = name === 'collectionSlug' ? 'The collection slug' : 'The global slug'
|
|
230
|
-
const slugSchema = z.string().describe(description)
|
|
248
|
+
const withSlugInput = ({ input }: { input?: ToolInputSchema }): ToolInputSchema => {
|
|
249
|
+
const description = 'The target slug.'
|
|
250
|
+
const slugSchema = z.string().check(z.describe(description))
|
|
231
251
|
|
|
232
252
|
if (!input) {
|
|
233
|
-
return
|
|
253
|
+
return strictObject({ slug: slugSchema })
|
|
234
254
|
}
|
|
235
255
|
|
|
236
|
-
if (input
|
|
237
|
-
|
|
256
|
+
if (typeof input === 'object' && input !== null && '~standard' in input) {
|
|
257
|
+
const schema = input['~standard'].jsonSchema.input({ target: 'draft-2020-12' })
|
|
258
|
+
const properties = schema.properties as Record<string, unknown> | undefined
|
|
259
|
+
|
|
260
|
+
if (properties?.slug) {
|
|
261
|
+
return input
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return addSlugToJSONSchema({ description, schema })
|
|
238
265
|
}
|
|
239
266
|
|
|
240
|
-
|
|
267
|
+
return addSlugToJSONSchema({ description, schema: input })
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const addSlugToJSONSchema = ({
|
|
271
|
+
description,
|
|
272
|
+
schema,
|
|
273
|
+
}: {
|
|
274
|
+
description: string
|
|
275
|
+
schema: JsonSchemaType
|
|
276
|
+
}): JsonSchemaType => {
|
|
277
|
+
const objectSchema = schema as {
|
|
241
278
|
properties?: Record<string, JsonSchemaType>
|
|
242
279
|
required?: string[]
|
|
243
280
|
} & JsonSchemaType
|
|
244
281
|
|
|
245
282
|
return {
|
|
246
|
-
...
|
|
283
|
+
...objectSchema,
|
|
247
284
|
type: 'object',
|
|
248
285
|
properties: {
|
|
249
|
-
...
|
|
250
|
-
|
|
286
|
+
...objectSchema.properties,
|
|
287
|
+
slug: {
|
|
251
288
|
type: 'string',
|
|
252
289
|
description,
|
|
253
290
|
},
|
|
254
291
|
},
|
|
255
|
-
required: Array.from(new Set([
|
|
292
|
+
required: Array.from(new Set(['slug', ...(objectSchema.required ?? [])])),
|
|
256
293
|
}
|
|
257
294
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { z } from '
|
|
1
|
+
import { createPayloadRequest, strictObject, z } from 'payload'
|
|
2
2
|
|
|
3
3
|
import type { MCPToolResponse } from '../../../types.js'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
8
|
|
|
@@ -16,43 +17,65 @@ import { getLogger } from '../../../utils/getLogger.js'
|
|
|
16
17
|
* users collection so all auth-shaped tools live in one place.
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
const emailSchema = z.
|
|
20
|
+
const emailSchema = z.email().check(z.describe('The user email address.'))
|
|
20
21
|
|
|
21
22
|
const wrapError =
|
|
22
23
|
(name: string) =>
|
|
23
|
-
({
|
|
24
|
+
({ slug, message }: { message: string; slug: string }): MCPToolResponse => {
|
|
24
25
|
return {
|
|
25
26
|
content: [
|
|
26
27
|
{
|
|
27
28
|
type: 'text',
|
|
28
|
-
text: `❌ **Error in ${name}** on ${
|
|
29
|
+
text: `❌ **Error in ${name}** on ${slug}: ${message}`,
|
|
29
30
|
},
|
|
30
31
|
],
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export const authCollectionTool = defineCollectionTool({
|
|
36
|
+
annotations: {
|
|
37
|
+
destructiveHint: false,
|
|
38
|
+
idempotentHint: true,
|
|
39
|
+
openWorldHint: false,
|
|
40
|
+
readOnlyHint: true,
|
|
41
|
+
title: 'Check Auth Status',
|
|
42
|
+
},
|
|
35
43
|
description: 'Checks authentication status for the current user.',
|
|
36
|
-
input:
|
|
44
|
+
input: strictObject({
|
|
37
45
|
headers: z
|
|
38
|
-
.string()
|
|
39
|
-
.describe(
|
|
40
|
-
'Optional JSON string containing custom headers to send with the authentication request',
|
|
41
|
-
)
|
|
42
|
-
.optional(),
|
|
46
|
+
.optional(z.record(z.string(), z.string()))
|
|
47
|
+
.check(z.describe('Custom headers to send with the authentication request.')),
|
|
43
48
|
}),
|
|
44
|
-
}).handler(async ({
|
|
49
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
45
50
|
const logger = getLogger({ payload: req.payload })
|
|
46
51
|
try {
|
|
47
52
|
let authHeaders = new Headers()
|
|
48
53
|
if (input.headers) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
authHeaders = new Headers(input.headers)
|
|
55
|
+
}
|
|
56
|
+
const authReq = await createPayloadRequest({
|
|
57
|
+
payload: req.payload,
|
|
58
|
+
req: { headers: authHeaders },
|
|
59
|
+
})
|
|
60
|
+
const result = await req.payload.auth({ headers: authHeaders, req: authReq })
|
|
61
|
+
|
|
62
|
+
if (result.user) {
|
|
63
|
+
const authenticatedUser = result.user
|
|
64
|
+
// Auth strategies read users with trusted Local API access. Re-read the user with the MCP
|
|
65
|
+
// caller's access level before returning it to the client.
|
|
66
|
+
const user = await req.payload.findByID({
|
|
67
|
+
id: authenticatedUser.id,
|
|
68
|
+
collection: authenticatedUser.collection,
|
|
69
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
70
|
+
req: authReq,
|
|
71
|
+
})
|
|
72
|
+
result.user = {
|
|
73
|
+
...user,
|
|
74
|
+
_sid: authenticatedUser._sid,
|
|
75
|
+
_strategy: authenticatedUser._strategy,
|
|
76
|
+
collection: authenticatedUser.collection,
|
|
53
77
|
}
|
|
54
78
|
}
|
|
55
|
-
const result = await req.payload.auth({ headers: authHeaders })
|
|
56
79
|
return {
|
|
57
80
|
content: [
|
|
58
81
|
{
|
|
@@ -64,170 +87,194 @@ export const authCollectionTool = defineCollectionTool({
|
|
|
64
87
|
}
|
|
65
88
|
} catch (error) {
|
|
66
89
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
67
|
-
logger.error(`Error in auth tool on ${
|
|
68
|
-
return wrapError('auth')({
|
|
90
|
+
logger.error(`Error in auth tool on ${slug}: ${errorMessage}`)
|
|
91
|
+
return wrapError('auth')({ slug, message: errorMessage })
|
|
69
92
|
}
|
|
70
93
|
})
|
|
71
94
|
|
|
72
95
|
export const forgotPasswordCollectionTool = defineCollectionTool({
|
|
96
|
+
annotations: {
|
|
97
|
+
destructiveHint: false,
|
|
98
|
+
idempotentHint: false,
|
|
99
|
+
openWorldHint: true,
|
|
100
|
+
readOnlyHint: false,
|
|
101
|
+
title: 'Forgot Password',
|
|
102
|
+
},
|
|
73
103
|
description: 'Sends a password reset email to a user.',
|
|
74
|
-
input:
|
|
75
|
-
disableEmail: z
|
|
76
|
-
.boolean()
|
|
77
|
-
.describe('Whether to disable sending the email (for testing)')
|
|
78
|
-
.optional()
|
|
79
|
-
.default(false),
|
|
104
|
+
input: strictObject({
|
|
80
105
|
email: emailSchema,
|
|
81
106
|
}),
|
|
82
|
-
}).handler(async ({
|
|
107
|
+
}).handler(async ({ slug, input, req }) => {
|
|
83
108
|
const logger = getLogger({ payload: req.payload })
|
|
84
109
|
try {
|
|
85
|
-
|
|
86
|
-
collection:
|
|
110
|
+
await req.payload.forgotPassword({
|
|
111
|
+
collection: slug,
|
|
87
112
|
data: { email: input.email },
|
|
88
|
-
disableEmail:
|
|
113
|
+
disableEmail: false,
|
|
114
|
+
overrideAccess: false,
|
|
115
|
+
req,
|
|
89
116
|
})
|
|
90
117
|
return {
|
|
91
118
|
content: [
|
|
92
119
|
{
|
|
93
120
|
type: 'text',
|
|
94
|
-
text:
|
|
121
|
+
text: 'If an account matches that email, password reset instructions have been sent.',
|
|
95
122
|
},
|
|
96
123
|
],
|
|
97
|
-
doc: { result } as Record<string, unknown>,
|
|
98
124
|
}
|
|
99
125
|
} catch (error) {
|
|
100
126
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
101
|
-
logger.error(`Error in forgotPassword tool on ${
|
|
102
|
-
return wrapError('forgotPassword')({
|
|
127
|
+
logger.error(`Error in forgotPassword tool on ${slug}: ${errorMessage}`)
|
|
128
|
+
return wrapError('forgotPassword')({ slug, message: errorMessage })
|
|
103
129
|
}
|
|
104
130
|
})
|
|
105
131
|
|
|
106
132
|
export const loginCollectionTool = defineCollectionTool({
|
|
133
|
+
annotations: {
|
|
134
|
+
destructiveHint: false,
|
|
135
|
+
idempotentHint: false,
|
|
136
|
+
openWorldHint: false,
|
|
137
|
+
readOnlyHint: false,
|
|
138
|
+
title: 'User Login',
|
|
139
|
+
},
|
|
107
140
|
description: 'Authenticates a user with email and password.',
|
|
108
|
-
input:
|
|
141
|
+
input: strictObject({
|
|
109
142
|
depth: z
|
|
110
|
-
.
|
|
111
|
-
.
|
|
112
|
-
.min(0)
|
|
113
|
-
.max(10)
|
|
114
|
-
.describe('Depth of population for relationships')
|
|
115
|
-
.optional()
|
|
116
|
-
.default(0),
|
|
143
|
+
._default(z.int().check(z.minimum(0), z.maximum(10)), 0)
|
|
144
|
+
.check(z.describe('Depth of population for relationships.')),
|
|
117
145
|
email: emailSchema,
|
|
118
|
-
password: z.string().describe('The user password'),
|
|
119
|
-
showHiddenFields: z
|
|
120
|
-
.boolean()
|
|
121
|
-
.describe('Whether to show hidden fields in the response')
|
|
122
|
-
.optional()
|
|
123
|
-
.default(false),
|
|
146
|
+
password: z.string().check(z.describe('The user password.')),
|
|
124
147
|
}),
|
|
125
|
-
}).handler(async ({
|
|
148
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
126
149
|
const logger = getLogger({ payload: req.payload })
|
|
127
150
|
try {
|
|
128
151
|
const result = await req.payload.login({
|
|
129
|
-
collection:
|
|
152
|
+
collection: slug,
|
|
130
153
|
data: { email: input.email, password: input.password },
|
|
131
154
|
depth: input.depth,
|
|
132
|
-
|
|
155
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
133
156
|
})
|
|
134
157
|
return {
|
|
135
158
|
content: [
|
|
136
159
|
{
|
|
137
160
|
type: 'text',
|
|
138
|
-
text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${
|
|
161
|
+
text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
139
162
|
},
|
|
140
163
|
],
|
|
141
164
|
doc: result as unknown as Record<string, unknown>,
|
|
142
165
|
}
|
|
143
166
|
} catch (error) {
|
|
144
167
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
145
|
-
logger.error(`Error in login tool on ${
|
|
146
|
-
return wrapError('login')({
|
|
168
|
+
logger.error(`Error in login tool on ${slug}: ${errorMessage}`)
|
|
169
|
+
return wrapError('login')({ slug, message: errorMessage })
|
|
147
170
|
}
|
|
148
171
|
})
|
|
149
172
|
|
|
150
173
|
export const resetPasswordCollectionTool = defineCollectionTool({
|
|
174
|
+
annotations: {
|
|
175
|
+
destructiveHint: false,
|
|
176
|
+
idempotentHint: false,
|
|
177
|
+
openWorldHint: false,
|
|
178
|
+
readOnlyHint: false,
|
|
179
|
+
title: 'Reset Password',
|
|
180
|
+
},
|
|
151
181
|
description: 'Resets a user password with a reset token.',
|
|
152
|
-
input:
|
|
153
|
-
password: z.string().describe('The new password for the user'),
|
|
154
|
-
token: z.string().describe('The password reset token sent to the user email'),
|
|
182
|
+
input: strictObject({
|
|
183
|
+
password: z.string().check(z.describe('The new password for the user.')),
|
|
184
|
+
token: z.string().check(z.describe('The password reset token sent to the user email.')),
|
|
155
185
|
}),
|
|
156
|
-
}).handler(async ({
|
|
186
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
157
187
|
const logger = getLogger({ payload: req.payload })
|
|
158
188
|
try {
|
|
159
189
|
const result = await req.payload.resetPassword({
|
|
160
|
-
collection:
|
|
190
|
+
collection: slug,
|
|
161
191
|
data: { password: input.password, token: input.token },
|
|
162
|
-
overrideAccess:
|
|
192
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
163
193
|
})
|
|
164
194
|
return {
|
|
165
195
|
content: [
|
|
166
196
|
{
|
|
167
197
|
type: 'text',
|
|
168
|
-
text: `# Password Reset Successful\n\n**Collection:** ${
|
|
198
|
+
text: `# Password Reset Successful\n\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
169
199
|
},
|
|
170
200
|
],
|
|
171
201
|
doc: result as unknown as Record<string, unknown>,
|
|
172
202
|
}
|
|
173
203
|
} catch (error) {
|
|
174
204
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
175
|
-
logger.error(`Error in resetPassword tool on ${
|
|
176
|
-
return wrapError('resetPassword')({
|
|
205
|
+
logger.error(`Error in resetPassword tool on ${slug}: ${errorMessage}`)
|
|
206
|
+
return wrapError('resetPassword')({ slug, message: errorMessage })
|
|
177
207
|
}
|
|
178
208
|
})
|
|
179
209
|
|
|
180
210
|
export const unlockCollectionTool = defineCollectionTool({
|
|
211
|
+
access: (args) =>
|
|
212
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.unlock),
|
|
213
|
+
annotations: {
|
|
214
|
+
destructiveHint: false,
|
|
215
|
+
idempotentHint: true,
|
|
216
|
+
openWorldHint: false,
|
|
217
|
+
readOnlyHint: false,
|
|
218
|
+
title: 'Unlock Account',
|
|
219
|
+
},
|
|
181
220
|
description: 'Unlocks a user account that has been locked due to failed login attempts.',
|
|
182
|
-
input:
|
|
183
|
-
}).handler(async ({
|
|
221
|
+
input: strictObject({ email: emailSchema }),
|
|
222
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
184
223
|
const logger = getLogger({ payload: req.payload })
|
|
185
224
|
try {
|
|
186
225
|
const result = await req.payload.unlock({
|
|
187
|
-
collection:
|
|
226
|
+
collection: slug,
|
|
188
227
|
data: { email: input.email },
|
|
189
|
-
overrideAccess:
|
|
228
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
229
|
+
req,
|
|
190
230
|
})
|
|
191
231
|
return {
|
|
192
232
|
content: [
|
|
193
233
|
{
|
|
194
234
|
type: 'text',
|
|
195
|
-
text: `# Account Unlocked\n\n**Collection:** ${
|
|
235
|
+
text: `# Account Unlocked\n\n**Collection:** ${slug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
196
236
|
},
|
|
197
237
|
],
|
|
198
|
-
doc: { result }
|
|
238
|
+
doc: { result },
|
|
199
239
|
}
|
|
200
240
|
} catch (error) {
|
|
201
241
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
202
|
-
logger.error(`Error in unlock tool on ${
|
|
203
|
-
return wrapError('unlock')({
|
|
242
|
+
logger.error(`Error in unlock tool on ${slug}: ${errorMessage}`)
|
|
243
|
+
return wrapError('unlock')({ slug, message: errorMessage })
|
|
204
244
|
}
|
|
205
245
|
})
|
|
206
246
|
|
|
207
247
|
export const verifyCollectionTool = defineCollectionTool({
|
|
248
|
+
annotations: {
|
|
249
|
+
destructiveHint: false,
|
|
250
|
+
idempotentHint: false,
|
|
251
|
+
openWorldHint: false,
|
|
252
|
+
readOnlyHint: false,
|
|
253
|
+
title: 'Email Verification',
|
|
254
|
+
},
|
|
208
255
|
description: 'Verifies a user email with a verification token.',
|
|
209
|
-
input:
|
|
210
|
-
token: z.string().describe('The verification token sent to the user email'),
|
|
256
|
+
input: strictObject({
|
|
257
|
+
token: z.string().check(z.describe('The verification token sent to the user email.')),
|
|
211
258
|
}),
|
|
212
|
-
}).handler(async ({
|
|
259
|
+
}).handler(async ({ slug, input, req }) => {
|
|
213
260
|
const logger = getLogger({ payload: req.payload })
|
|
214
261
|
try {
|
|
215
262
|
const result = await req.payload.verifyEmail({
|
|
216
|
-
collection:
|
|
263
|
+
collection: slug,
|
|
217
264
|
token: input.token,
|
|
218
265
|
})
|
|
219
266
|
return {
|
|
220
267
|
content: [
|
|
221
268
|
{
|
|
222
269
|
type: 'text',
|
|
223
|
-
text: `# Email Verification Successful\n\n**Collection:** ${
|
|
270
|
+
text: `# Email Verification Successful\n\n**Collection:** ${slug}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
224
271
|
},
|
|
225
272
|
],
|
|
226
|
-
doc: { result }
|
|
273
|
+
doc: { result },
|
|
227
274
|
}
|
|
228
275
|
} catch (error) {
|
|
229
276
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
230
|
-
logger.error(`Error in verify tool on ${
|
|
231
|
-
return wrapError('verify')({
|
|
277
|
+
logger.error(`Error in verify tool on ${slug}: ${errorMessage}`)
|
|
278
|
+
return wrapError('verify')({ slug, message: errorMessage })
|
|
232
279
|
}
|
|
233
280
|
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { countDocumentsInputSchema } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_DESCRIPTION =
|
|
8
|
+
'Count documents in any collection by passing the collection slug and optional where clause.'
|
|
9
|
+
|
|
10
|
+
export const countDocumentsTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Count Documents',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: countDocumentsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
const { locale, trash, where } = input
|
|
26
|
+
|
|
27
|
+
logger.info(`Counting documents in collection: ${slug}`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.count({
|
|
31
|
+
collection: slug,
|
|
32
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
33
|
+
req,
|
|
34
|
+
...(locale ? { locale } : {}),
|
|
35
|
+
...(trash !== undefined ? { trash } : {}),
|
|
36
|
+
...(where ? { where } : {}),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
text: `Collection "${slug}" contains ${result.totalDocs} matching documents.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
doc: result,
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
50
|
+
logger.error(`Error counting documents in ${slug}: ${errorMessage}`)
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: `❌ **Error counting documents in collection "${slug}":** ${errorMessage}`,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
isError: true,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|