@payloadcms/plugin-mcp 4.0.0-canary.3 → 4.0.0-canary.31
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/bin.js +7 -0
- 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 +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +74 -103
- 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 +68 -17
- package/dist/endpoint/index.js.map +1 -1
- 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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -56
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +5 -5
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +67 -33
- 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 +79 -56
- 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 +105 -53
- 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 +46 -44
- 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 +123 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
- package/dist/mcp/builtin/collections/fileInput.spec.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 +30 -47
- 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 +54 -9
- 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 +68 -86
- 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 +23 -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 +13 -17
- 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 +31 -8
- 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 +29 -36
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +73 -2
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +73 -3
- 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 +48 -17
- 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 +84 -46
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +95 -89
- 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/toStandardSchema.d.ts.map +1 -1
- package/package.json +10 -18
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +79 -112
- package/src/endpoint/index.ts +58 -16
- package/src/exports/client.ts +2 -4
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +5 -62
- package/src/mcp/buildMcpServer.ts +85 -50
- package/src/mcp/builtin/collections/authTools.ts +77 -69
- 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 +112 -76
- package/src/mcp/builtin/collections/deleteTool.ts +38 -64
- 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 +169 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +27 -107
- 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 +51 -6
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +65 -100
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +22 -5
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +15 -51
- 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 +34 -6
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +40 -60
- package/src/mcp/builtinTools.ts +72 -6
- package/src/mcp/sanitizeMCPConfig.ts +36 -19
- package/src/stdio.ts +79 -46
- package/src/types.ts +103 -93
- package/src/utils/getPluginConfig.ts +1 -1
- 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 -24
- 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 -68
- package/src/components/APIKeyField/index.css +0 -105
- package/src/components/APIKeysEmptyState/index.client.tsx +0 -33
- package/src/components/AccessField/index.client.tsx +0 -296
- package/src/components/AccessField/index.css +0 -99
- package/src/components/SettingsMenu/index.client.tsx +0 -30
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/translations/index.ts +0 -105
- package/src/translations/languages/ar.ts +0 -38
- package/src/translations/languages/az.ts +0 -38
- package/src/translations/languages/bg.ts +0 -39
- package/src/translations/languages/bnBd.ts +0 -39
- package/src/translations/languages/bnIn.ts +0 -39
- package/src/translations/languages/ca.ts +0 -39
- package/src/translations/languages/cs.ts +0 -39
- package/src/translations/languages/da.ts +0 -38
- package/src/translations/languages/de.ts +0 -39
- package/src/translations/languages/en.ts +0 -39
- package/src/translations/languages/es.ts +0 -39
- package/src/translations/languages/et.ts +0 -38
- package/src/translations/languages/fa.ts +0 -39
- package/src/translations/languages/fr.ts +0 -39
- package/src/translations/languages/he.ts +0 -37
- package/src/translations/languages/hr.ts +0 -39
- package/src/translations/languages/hu.ts +0 -39
- package/src/translations/languages/hy.ts +0 -39
- package/src/translations/languages/id.ts +0 -39
- package/src/translations/languages/is.ts +0 -39
- package/src/translations/languages/it.ts +0 -39
- package/src/translations/languages/ja.ts +0 -39
- package/src/translations/languages/ko.ts +0 -39
- package/src/translations/languages/lt.ts +0 -39
- package/src/translations/languages/lv.ts +0 -38
- package/src/translations/languages/my.ts +0 -39
- package/src/translations/languages/nb.ts +0 -39
- package/src/translations/languages/nl.ts +0 -39
- package/src/translations/languages/pl.ts +0 -38
- package/src/translations/languages/pt.ts +0 -39
- package/src/translations/languages/ro.ts +0 -39
- package/src/translations/languages/rs.ts +0 -38
- package/src/translations/languages/rsLatin.ts +0 -38
- package/src/translations/languages/ru.ts +0 -39
- package/src/translations/languages/sk.ts +0 -39
- package/src/translations/languages/sl.ts +0 -38
- package/src/translations/languages/sv.ts +0 -39
- package/src/translations/languages/ta.ts +0 -39
- package/src/translations/languages/th.ts +0 -38
- package/src/translations/languages/tr.ts +0 -38
- package/src/translations/languages/uk.ts +0 -39
- package/src/translations/languages/vi.ts +0 -39
- package/src/translations/languages/zh.ts +0 -36
- package/src/translations/languages/zhTw.ts +0 -36
- 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
package/src/endpoint/access.ts
CHANGED
|
@@ -1,144 +1,111 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequest, SanitizedPermissions } from 'payload'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { UnauthorizedError } from 'payload'
|
|
3
|
+
import { getAccessResults, UnauthorizedError } from 'payload'
|
|
5
4
|
|
|
6
|
-
import type { AuthorizedMCP,
|
|
5
|
+
import type { AuthorizedMCP, MCPItem } from '../types.js'
|
|
7
6
|
|
|
8
|
-
import { getLogger } from '../utils/getLogger.js'
|
|
9
7
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
10
8
|
|
|
9
|
+
export type GetAuthorizedMCPArgs = {
|
|
10
|
+
overrideAccess: boolean
|
|
11
|
+
req: PayloadRequest
|
|
12
|
+
}
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
15
|
+
* Authenticates an MCP request and removes items the user cannot access.
|
|
16
|
+
* `overrideAccess` skips Payload and MCP item access checks.
|
|
14
17
|
*/
|
|
15
|
-
export const getAuthorizedMCP: (args:
|
|
18
|
+
export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
|
|
19
|
+
overrideAccess,
|
|
16
20
|
req,
|
|
17
21
|
}) => {
|
|
18
|
-
const logger = getLogger({ payload: req.payload })
|
|
19
22
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const buildAuthorized = (apiKeyDoc: MCPAPIKeysDoc): AuthorizedMCP => ({
|
|
25
|
-
items: pluginConfig.items.filter((item) => {
|
|
26
|
-
switch (item.type) {
|
|
27
|
-
case 'collectionTool':
|
|
28
|
-
return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.configKey] !== false
|
|
29
|
-
case 'globalTool':
|
|
30
|
-
return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.configKey] !== false
|
|
31
|
-
case 'prompt':
|
|
32
|
-
return apiKeyDoc.access.prompts?.[item.configKey] !== false
|
|
33
|
-
case 'resource':
|
|
34
|
-
return apiKeyDoc.access.resources?.[item.configKey] !== false
|
|
35
|
-
case 'tool':
|
|
36
|
-
return apiKeyDoc.access.tools?.[item.configKey] !== false
|
|
37
|
-
}
|
|
38
|
-
}),
|
|
39
|
-
overrideAccess:
|
|
40
|
-
typeof apiKeyDoc.overrideAccess === 'boolean' ? apiKeyDoc.overrideAccess : false,
|
|
41
|
-
user: apiKeyDoc.user,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
if (pluginConfig.overrideAuth) {
|
|
45
|
-
return await pluginConfig.overrideAuth({
|
|
46
|
-
getAPIKeyDoc: (overrideApiKey) => getAPIKeyDoc({ logger, overrideApiKey, pluginConfig, req }),
|
|
47
|
-
getAuthorizedMCP: ({ apiKeyDoc }) => buildAuthorized(apiKeyDoc),
|
|
24
|
+
if (pluginConfig.overrideGetAuthorizedMCP) {
|
|
25
|
+
return await pluginConfig.overrideGetAuthorizedMCP({
|
|
26
|
+
overrideAccess,
|
|
48
27
|
pluginConfig,
|
|
49
28
|
req,
|
|
50
29
|
})
|
|
51
30
|
}
|
|
52
31
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
32
|
+
if (req.headers) {
|
|
33
|
+
const headers = new Headers(req.headers)
|
|
34
|
+
const hasAuthorization = headers.has('Authorization')
|
|
35
|
+
|
|
36
|
+
headers.set('DisableAutologin', 'true')
|
|
37
|
+
req.user = (await req.payload.auth({ headers, req })).user
|
|
38
|
+
|
|
39
|
+
if (hasAuthorization && !req.user) {
|
|
40
|
+
throw new UnauthorizedError(req.t)
|
|
41
|
+
}
|
|
61
42
|
}
|
|
62
43
|
|
|
63
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
items: await filterMCPItems({
|
|
46
|
+
items: pluginConfig.items,
|
|
47
|
+
overrideAccess,
|
|
48
|
+
req,
|
|
49
|
+
}),
|
|
50
|
+
overrideAccess,
|
|
51
|
+
}
|
|
64
52
|
}
|
|
65
53
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
pluginConfig,
|
|
54
|
+
export const filterMCPItems = async ({
|
|
55
|
+
items,
|
|
56
|
+
overrideAccess,
|
|
70
57
|
req,
|
|
71
58
|
}: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pluginConfig: ReturnType<typeof getPluginConfig>
|
|
59
|
+
items: MCPItem[]
|
|
60
|
+
overrideAccess: boolean
|
|
75
61
|
req: PayloadRequest
|
|
76
|
-
}): Promise<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const apiKey =
|
|
81
|
-
overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null)
|
|
82
|
-
|
|
83
|
-
if (!apiKey) {
|
|
84
|
-
throw new UnauthorizedError()
|
|
62
|
+
}): Promise<MCPItem[]> => {
|
|
63
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
64
|
+
if (overrideAccess) {
|
|
65
|
+
return items
|
|
85
66
|
}
|
|
86
67
|
|
|
87
|
-
const
|
|
88
|
-
.createHmac('sha256', req.payload.secret)
|
|
89
|
-
.update(apiKey)
|
|
90
|
-
.digest('hex')
|
|
91
|
-
|
|
92
|
-
const doc = await req.payload.db.findOne<MCPAPIKeysDoc>({
|
|
93
|
-
collection: 'payload-mcp-api-keys',
|
|
94
|
-
req,
|
|
95
|
-
where: {
|
|
96
|
-
apiKeyIndex: { equals: sha256APIKeyIndex },
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
if (!doc || !doc.user) {
|
|
101
|
-
throw new UnauthorizedError()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
logger.info('API Key is valid')
|
|
68
|
+
const authorizedItems: MCPItem[] = []
|
|
105
69
|
|
|
106
|
-
const
|
|
107
|
-
const userID =
|
|
108
|
-
typeof userRef === 'object' && userRef !== null && 'id' in userRef
|
|
109
|
-
? userRef.id
|
|
110
|
-
: (userRef as unknown as DefaultDocumentIDType)
|
|
70
|
+
const permissions = await getAccessResults({ req })
|
|
111
71
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
req,
|
|
118
|
-
})) as null | TypedUser
|
|
119
|
-
|
|
120
|
-
if (!user) {
|
|
121
|
-
throw new UnauthorizedError()
|
|
72
|
+
for (const item of items) {
|
|
73
|
+
if (!(await checkItemAccess({ item, permissions, req }))) {
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
authorizedItems.push(item)
|
|
122
77
|
}
|
|
123
78
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
id: doc.id,
|
|
127
|
-
collection: 'payload-mcp-api-keys',
|
|
128
|
-
data: { lastUsed: new Date().toISOString() },
|
|
129
|
-
req,
|
|
130
|
-
returning: false,
|
|
131
|
-
})
|
|
132
|
-
} catch (err) {
|
|
133
|
-
logger.warn({ err, msg: 'Failed to update MCP API key last-used timestamp' })
|
|
134
|
-
}
|
|
79
|
+
return authorizedItems
|
|
80
|
+
}
|
|
135
81
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Runs MCP item access callbacks
|
|
84
|
+
*/
|
|
85
|
+
const checkItemAccess = async ({
|
|
86
|
+
item,
|
|
87
|
+
permissions,
|
|
88
|
+
req,
|
|
89
|
+
}: {
|
|
90
|
+
item: MCPItem
|
|
91
|
+
permissions?: SanitizedPermissions
|
|
92
|
+
req: PayloadRequest
|
|
93
|
+
}): Promise<boolean> => {
|
|
94
|
+
switch (item.type) {
|
|
95
|
+
case 'collectionTool':
|
|
96
|
+
return (
|
|
97
|
+
!item.tool.access ||
|
|
98
|
+
(await item.tool.access({ slug: item.collectionSlug, permissions, req }))
|
|
99
|
+
)
|
|
100
|
+
case 'globalTool':
|
|
101
|
+
return (
|
|
102
|
+
!item.tool.access || (await item.tool.access({ slug: item.globalSlug, permissions, req }))
|
|
103
|
+
)
|
|
104
|
+
case 'prompt':
|
|
105
|
+
return !item.prompt.access || (await item.prompt.access({ permissions, req }))
|
|
106
|
+
case 'resource':
|
|
107
|
+
return !item.resource.access || (await item.resource.access({ permissions, req }))
|
|
108
|
+
case 'tool':
|
|
109
|
+
return !item.tool.access || (await item.tool.access({ permissions, req }))
|
|
143
110
|
}
|
|
144
111
|
}
|
package/src/endpoint/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { PayloadHandler, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createMcpHandler,
|
|
5
|
+
isLegacyRequest,
|
|
6
|
+
WebStandardStreamableHTTPServerTransport,
|
|
7
|
+
} from '@modelcontextprotocol/server'
|
|
8
|
+
import { APIError } from 'payload'
|
|
3
9
|
|
|
4
10
|
import { buildMcpServer } from '../mcp/buildMcpServer.js'
|
|
5
11
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
@@ -13,23 +19,59 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
13
19
|
req.payloadAPI = 'MCP' as const
|
|
14
20
|
|
|
15
21
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
16
|
-
const
|
|
22
|
+
const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {
|
|
25
|
+
throw new APIError('MCP overrideAccess is only available in development.', 400)
|
|
26
|
+
}
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
28
|
+
let overrideAccess = false
|
|
29
|
+
if (overrideAccessParam === 'true') {
|
|
30
|
+
overrideAccess = true
|
|
31
|
+
} else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {
|
|
32
|
+
throw new APIError('MCP overrideAccess must be "true" or "false".', 400)
|
|
33
|
+
}
|
|
24
34
|
|
|
25
|
-
await
|
|
35
|
+
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
36
|
+
// Payload augments the original web-standard Request in place.
|
|
37
|
+
const mcpRequest = req as PayloadRequest & Request
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
40
|
+
if (await isLegacyRequest(mcpRequest)) {
|
|
41
|
+
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
42
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
43
|
+
enableJsonResponse: true,
|
|
44
|
+
sessionIdGenerator: undefined, // stateless mode
|
|
45
|
+
})
|
|
46
|
+
transport.onerror = (err) => {
|
|
47
|
+
req.payload.logger.error({ err, msg: 'Error serving legacy MCP request' })
|
|
48
|
+
}
|
|
33
49
|
|
|
34
|
-
|
|
50
|
+
try {
|
|
51
|
+
await server.connect(transport)
|
|
52
|
+
return await transport.handleRequest(mcpRequest)
|
|
53
|
+
} finally {
|
|
54
|
+
await server.close().catch((err) => {
|
|
55
|
+
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
61
|
+
legacy: 'reject',
|
|
62
|
+
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
63
|
+
maxSubscriptions: 0,
|
|
64
|
+
onerror: (err) => {
|
|
65
|
+
req.payload.logger.error({ err, msg: 'Error serving modern MCP request' })
|
|
66
|
+
},
|
|
67
|
+
responseMode: 'json',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
return await handler.fetch(mcpRequest)
|
|
72
|
+
} finally {
|
|
73
|
+
await handler.close().catch((err) => {
|
|
74
|
+
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
75
|
+
})
|
|
76
|
+
}
|
|
35
77
|
}
|
package/src/exports/client.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { APIKeysEmptyState } from '../components/APIKeysEmptyState/index.client.js'
|
|
5
|
-
export { MCPSettingsMenu } from '../components/SettingsMenu/index.client.js'
|
|
2
|
+
|
|
3
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { filterMCPItems, getAuthorizedMCP } from '../endpoint/access.js'
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { definePlugin } from 'payload'
|
|
2
2
|
|
|
3
|
-
import { defaultUserCollection, definePlugin } from 'payload'
|
|
4
|
-
|
|
5
|
-
import type { PluginDefaultTranslationsObject } from './translations/types.js'
|
|
6
3
|
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
7
4
|
|
|
8
|
-
import { getAPIKeysCollection } from './collection/index.js'
|
|
9
5
|
import { mcpEndpoint } from './endpoint/index.js'
|
|
10
6
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
11
|
-
import { translations } from './translations/index.js'
|
|
12
7
|
|
|
13
8
|
declare module 'payload' {
|
|
14
|
-
export interface
|
|
15
|
-
|
|
9
|
+
export interface PayloadRequestAPI {
|
|
10
|
+
MCP: true
|
|
16
11
|
}
|
|
17
12
|
interface RegisteredPlugins {
|
|
18
13
|
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
@@ -27,17 +22,8 @@ export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from
|
|
|
27
22
|
export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
28
23
|
slug: '@payloadcms/plugin-mcp',
|
|
29
24
|
order: 10,
|
|
30
|
-
plugin: ({ config,
|
|
31
|
-
|
|
32
|
-
// so the relationship target and default `userCollection` exist.
|
|
33
|
-
if (!config.admin?.user) {
|
|
34
|
-
const firstCollectionWithAuth = (config.collections ?? []).find(({ auth }) => Boolean(auth))
|
|
35
|
-
if (!firstCollectionWithAuth) {
|
|
36
|
-
;(config.collections ??= []).push(defaultUserCollection)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: rawConfig })
|
|
25
|
+
plugin: ({ config, options, plugins }) => {
|
|
26
|
+
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: options })
|
|
41
27
|
|
|
42
28
|
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
43
29
|
const registered = plugins['@payloadcms/plugin-mcp']
|
|
@@ -46,55 +32,12 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
46
32
|
registered.sanitizedOptions = pluginConfig as unknown as typeof registered.options
|
|
47
33
|
}
|
|
48
34
|
|
|
49
|
-
;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))
|
|
50
|
-
|
|
51
|
-
if (!config.i18n) {
|
|
52
|
-
config.i18n = {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!config.i18n.translations) {
|
|
56
|
-
config.i18n.translations = {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const supportedLanguageKeys = config.i18n.supportedLanguages
|
|
60
|
-
? Object.keys(config.i18n.supportedLanguages)
|
|
61
|
-
: ['en']
|
|
62
|
-
|
|
63
|
-
for (const lang of supportedLanguageKeys) {
|
|
64
|
-
const pluginEntry = translations[lang as keyof typeof translations]
|
|
65
|
-
if (!pluginEntry) {
|
|
66
|
-
continue
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const typedLocale = lang as AcceptedLanguages
|
|
70
|
-
const existing = (config.i18n.translations[typedLocale] ?? {}) as Record<string, unknown>
|
|
71
|
-
config.i18n.translations[typedLocale] = {
|
|
72
|
-
...existing,
|
|
73
|
-
'plugin-mcp': pluginEntry.translations['plugin-mcp'],
|
|
74
|
-
} as PluginDefaultTranslationsObject
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Keep the API-keys collection registered even when disabled, so DB schema
|
|
78
|
-
// and generated types don't drift between enabled/disabled environments.
|
|
79
35
|
if (pluginConfig.disabled) {
|
|
80
36
|
return config
|
|
81
37
|
}
|
|
82
38
|
|
|
83
39
|
return {
|
|
84
40
|
...config,
|
|
85
|
-
admin: {
|
|
86
|
-
...config.admin,
|
|
87
|
-
components: {
|
|
88
|
-
...config.admin?.components,
|
|
89
|
-
userMenuSettingsItems: [
|
|
90
|
-
...(config.admin?.components?.userMenuSettingsItems ?? []),
|
|
91
|
-
{
|
|
92
|
-
group: 'MCP',
|
|
93
|
-
items: ['@payloadcms/plugin-mcp/client#MCPSettingsMenu'],
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
41
|
endpoints: [
|
|
99
42
|
...(config.endpoints ?? []),
|
|
100
43
|
// Payload prefixes /api, so the full path is /api/mcp.
|
|
@@ -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,10 +18,10 @@ 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
|
|
@@ -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,10 +151,7 @@ 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,
|
|
@@ -198,16 +217,21 @@ export const buildMcpServer = ({
|
|
|
198
217
|
description: tool.description,
|
|
199
218
|
inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,
|
|
200
219
|
},
|
|
201
|
-
async (input: unknown, ctx: ServerContext) =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
},
|
|
211
235
|
)
|
|
212
236
|
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
213
237
|
break
|
|
@@ -221,39 +245,50 @@ export const buildMcpServer = ({
|
|
|
221
245
|
return server
|
|
222
246
|
}
|
|
223
247
|
|
|
224
|
-
const withSlugInput = ({
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}: {
|
|
228
|
-
input?: ToolInputSchema
|
|
229
|
-
name: 'collectionSlug' | 'globalSlug'
|
|
230
|
-
}): ToolInputSchema => {
|
|
231
|
-
const description = name === 'collectionSlug' ? 'The collection slug' : 'The global slug'
|
|
232
|
-
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))
|
|
233
251
|
|
|
234
252
|
if (!input) {
|
|
235
|
-
return
|
|
253
|
+
return strictObject({ slug: slugSchema }) as unknown as ToolInputSchema
|
|
236
254
|
}
|
|
237
255
|
|
|
238
|
-
if (input
|
|
239
|
-
|
|
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: schema as JsonSchemaType })
|
|
240
265
|
}
|
|
241
266
|
|
|
242
|
-
|
|
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 {
|
|
243
278
|
properties?: Record<string, JsonSchemaType>
|
|
244
279
|
required?: string[]
|
|
245
280
|
} & JsonSchemaType
|
|
246
281
|
|
|
247
282
|
return {
|
|
248
|
-
...
|
|
283
|
+
...objectSchema,
|
|
249
284
|
type: 'object',
|
|
250
285
|
properties: {
|
|
251
|
-
...
|
|
252
|
-
|
|
286
|
+
...objectSchema.properties,
|
|
287
|
+
slug: {
|
|
253
288
|
type: 'string',
|
|
254
289
|
description,
|
|
255
290
|
},
|
|
256
291
|
},
|
|
257
|
-
required: Array.from(new Set([
|
|
292
|
+
required: Array.from(new Set(['slug', ...(objectSchema.required ?? [])])),
|
|
258
293
|
}
|
|
259
294
|
}
|