@payloadcms/plugin-mcp 4.0.0-internal.011fd46 → 4.0.0-internal.0731f09
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 +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +86 -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 +109 -16
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +39 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +92 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/endpoint/oauthServer.d.ts +11 -0
- package/dist/endpoint/oauthServer.d.ts.map +1 -0
- package/dist/endpoint/oauthServer.js +351 -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/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -58
- 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 +68 -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 +80 -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 +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 +31 -48
- 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 +71 -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 +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 +49 -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 +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 +51 -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 +86 -47
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +170 -92
- 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/dist/utils/toStandardSchema.js.map +1 -1
- package/package.json +27 -38
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +88 -112
- package/src/endpoint/index.ts +95 -15
- package/src/endpoint/oauth.ts +91 -0
- package/src/endpoint/oauthServer.ts +386 -0
- package/src/exports/client.ts +2 -4
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +43 -67
- package/src/mcp/buildMcpServer.ts +86 -51
- package/src/mcp/builtin/collections/authTools.ts +82 -71
- 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 +110 -76
- package/src/mcp/builtin/collections/deleteTool.ts +39 -65
- 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 +28 -108
- 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 +63 -7
- 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 +16 -52
- 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 +45 -7
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +41 -61
- package/src/mcp/builtinTools.ts +72 -6
- package/src/mcp/sanitizeMCPConfig.ts +37 -19
- package/src/stdio.ts +80 -47
- package/src/types.ts +177 -95
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/toStandardSchema.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/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.0731f09",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"plugin",
|
|
7
6
|
"mcp",
|
|
8
|
-
"model context protocol"
|
|
7
|
+
"model context protocol",
|
|
8
|
+
"plugin"
|
|
9
9
|
],
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
13
|
-
"directory": "packages/plugin-mcp"
|
|
14
|
-
},
|
|
15
10
|
"license": "MIT",
|
|
16
11
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
17
12
|
"maintainers": [
|
|
@@ -21,10 +16,22 @@
|
|
|
21
16
|
"url": "https://payloadcms.com"
|
|
22
17
|
}
|
|
23
18
|
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
22
|
+
"directory": "packages/plugin-mcp"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"payload-mcp": "./bin.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src",
|
|
29
|
+
"dist",
|
|
30
|
+
"bin.js"
|
|
26
31
|
],
|
|
27
32
|
"type": "module",
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
28
35
|
"exports": {
|
|
29
36
|
".": {
|
|
30
37
|
"import": "./dist/index.js",
|
|
@@ -40,40 +47,24 @@
|
|
|
40
47
|
"import": "./dist/stdio.js",
|
|
41
48
|
"types": "./dist/stdio.d.ts",
|
|
42
49
|
"default": "./dist/stdio.js"
|
|
50
|
+
},
|
|
51
|
+
"./internal": {
|
|
52
|
+
"import": "./dist/exports/internal.js",
|
|
53
|
+
"types": "./dist/exports/internal.d.ts",
|
|
54
|
+
"default": "./dist/exports/internal.js"
|
|
43
55
|
}
|
|
44
56
|
},
|
|
45
|
-
"main": "./dist/index.js",
|
|
46
|
-
"types": "./dist/index.d.ts",
|
|
47
|
-
"bin": {
|
|
48
|
-
"payload-mcp": "./bin.js"
|
|
49
|
-
},
|
|
50
|
-
"files": [
|
|
51
|
-
"src",
|
|
52
|
-
"dist",
|
|
53
|
-
"bin.js"
|
|
54
|
-
],
|
|
55
57
|
"dependencies": {
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"tsx": "4.22.4",
|
|
59
|
-
"zod": "^4.0.0",
|
|
60
|
-
"@payloadcms/translations": "4.0.0-internal.011fd46"
|
|
58
|
+
"@modelcontextprotocol/server": "2.3.1",
|
|
59
|
+
"tsx": "4.23.15"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
|
-
"
|
|
64
|
-
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
65
|
-
"@payloadcms/ui": "4.0.0-internal.011fd46",
|
|
66
|
-
"payload": "4.0.0-internal.011fd46",
|
|
67
|
-
"@payloadcms/eslint-config": "3.28.0"
|
|
62
|
+
"payload": "4.0.0-internal.0731f09"
|
|
68
63
|
},
|
|
69
64
|
"peerDependencies": {
|
|
70
|
-
"
|
|
71
|
-
"@payloadcms/ui": "4.0.0-internal.011fd46",
|
|
72
|
-
"payload": "4.0.0-internal.011fd46"
|
|
65
|
+
"payload": "4.0.0-internal.0731f09"
|
|
73
66
|
},
|
|
74
67
|
"//deps_notes": {
|
|
75
|
-
"zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
|
|
76
|
-
"@cfworker/json-schema": "Should be able to remove in next @modelcontextprotocol/server alpha release. Marked as an optional peer of @modelcontextprotocol/server, but its bundle does an eager top-level `import { Validator } from '@cfworker/json-schema'`, so it must be installed even when only zod-registered tools are used. Drop once upstream lazy-loads the validator. See: https://github.com/modelcontextprotocol/typescript-sdk",
|
|
77
68
|
"tsx": "Required by the `bin.js` stdio mcp. Keep the version pinned to whatever `payload` ships to avoid duplicate installs."
|
|
78
69
|
},
|
|
79
70
|
"homepage:": "https://payloadcms.com",
|
|
@@ -83,9 +74,7 @@
|
|
|
83
74
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
84
75
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
85
76
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
86
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
87
|
-
"lint": "eslint .",
|
|
88
|
-
"lint:fix": "eslint . --fix",
|
|
77
|
+
"copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
89
78
|
"pack:plugin": "pnpm build && pnpm pack"
|
|
90
79
|
}
|
|
91
80
|
}
|
package/src/endpoint/access.ts
CHANGED
|
@@ -1,144 +1,120 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequest, SanitizedPermissions } from 'payload'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { UnauthorizedError } from 'payload'
|
|
3
|
+
import { executeAuthStrategies, 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
|
+
// Not `payload.auth()`, which also computes permissions that filterMCPItems computes anyway
|
|
38
|
+
req.user = (await executeAuthStrategies({ headers, payload: req.payload, req })).user
|
|
39
|
+
|
|
40
|
+
// Only bearer tokens that no auth strategy accepted reach the hook, e.g. an OAuth access token.
|
|
41
|
+
// API keys use the `<collection> API-Key <key>` scheme instead of `Bearer`, so they never do.
|
|
42
|
+
const bearerToken = headers.get('Authorization')?.match(/^Bearer (.+)$/)?.[1]
|
|
43
|
+
if (!req.user && bearerToken && pluginConfig.oauth?.authenticate) {
|
|
44
|
+
req.user = await pluginConfig.oauth.authenticate({ req, token: bearerToken })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// With OAuth, the endpoint answers with a challenge that starts the client's sign-in
|
|
48
|
+
if (hasAuthorization && !req.user && !pluginConfig.oauth) {
|
|
49
|
+
throw new UnauthorizedError(req.t)
|
|
50
|
+
}
|
|
61
51
|
}
|
|
62
52
|
|
|
63
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
items: await filterMCPItems({
|
|
55
|
+
items: pluginConfig.items,
|
|
56
|
+
overrideAccess,
|
|
57
|
+
req,
|
|
58
|
+
}),
|
|
59
|
+
overrideAccess,
|
|
60
|
+
}
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
pluginConfig,
|
|
63
|
+
export const filterMCPItems = async ({
|
|
64
|
+
items,
|
|
65
|
+
overrideAccess,
|
|
70
66
|
req,
|
|
71
67
|
}: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pluginConfig: ReturnType<typeof getPluginConfig>
|
|
68
|
+
items: MCPItem[]
|
|
69
|
+
overrideAccess: boolean
|
|
75
70
|
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()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const sha256APIKeyIndex = crypto
|
|
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()
|
|
71
|
+
}): Promise<MCPItem[]> => {
|
|
72
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
73
|
+
if (overrideAccess) {
|
|
74
|
+
return items
|
|
102
75
|
}
|
|
103
76
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const userRef = doc.user
|
|
107
|
-
const userID =
|
|
108
|
-
typeof userRef === 'object' && userRef !== null && 'id' in userRef
|
|
109
|
-
? userRef.id
|
|
110
|
-
: (userRef as unknown as DefaultDocumentIDType)
|
|
77
|
+
const authorizedItems: MCPItem[] = []
|
|
111
78
|
|
|
112
|
-
const
|
|
113
|
-
id: userID,
|
|
114
|
-
collection: pluginConfig.userCollection,
|
|
115
|
-
depth: 0,
|
|
116
|
-
disableErrors: true,
|
|
117
|
-
req,
|
|
118
|
-
})) as null | TypedUser
|
|
79
|
+
const permissions = await getAccessResults({ req })
|
|
119
80
|
|
|
120
|
-
|
|
121
|
-
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
if (!(await checkItemAccess({ item, permissions, req }))) {
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
authorizedItems.push(item)
|
|
122
86
|
}
|
|
123
87
|
|
|
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
|
-
}
|
|
88
|
+
return authorizedItems
|
|
89
|
+
}
|
|
135
90
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Runs MCP item access callbacks
|
|
93
|
+
*/
|
|
94
|
+
const checkItemAccess = async ({
|
|
95
|
+
item,
|
|
96
|
+
permissions,
|
|
97
|
+
req,
|
|
98
|
+
}: {
|
|
99
|
+
item: MCPItem
|
|
100
|
+
permissions?: SanitizedPermissions
|
|
101
|
+
req: PayloadRequest
|
|
102
|
+
}): Promise<boolean> => {
|
|
103
|
+
switch (item.type) {
|
|
104
|
+
case 'collectionTool':
|
|
105
|
+
return (
|
|
106
|
+
!item.tool.access ||
|
|
107
|
+
(await item.tool.access({ slug: item.collectionSlug, permissions, req }))
|
|
108
|
+
)
|
|
109
|
+
case 'globalTool':
|
|
110
|
+
return (
|
|
111
|
+
!item.tool.access || (await item.tool.access({ slug: item.globalSlug, permissions, req }))
|
|
112
|
+
)
|
|
113
|
+
case 'prompt':
|
|
114
|
+
return !item.prompt.access || (await item.prompt.access({ permissions, req }))
|
|
115
|
+
case 'resource':
|
|
116
|
+
return !item.resource.access || (await item.resource.access({ permissions, req }))
|
|
117
|
+
case 'tool':
|
|
118
|
+
return !item.tool.access || (await item.tool.access({ permissions, req }))
|
|
143
119
|
}
|
|
144
120
|
}
|
package/src/endpoint/index.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { PayloadHandler, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createMcpHandler,
|
|
5
|
+
isLegacyRequest,
|
|
6
|
+
readRequestBody,
|
|
7
|
+
WebStandardStreamableHTTPServerTransport,
|
|
8
|
+
} from '@modelcontextprotocol/server'
|
|
9
|
+
import { APIError } from 'payload'
|
|
3
10
|
|
|
4
11
|
import { buildMcpServer } from '../mcp/buildMcpServer.js'
|
|
5
12
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
6
13
|
import { getAuthorizedMCP } from './access.js'
|
|
14
|
+
import { getMCPResource, oauthChallenge } from './oauth.js'
|
|
7
15
|
|
|
8
16
|
export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
9
17
|
if (!req.url) {
|
|
@@ -11,25 +19,97 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
req.payloadAPI = 'MCP' as const
|
|
22
|
+
// Lets auth strategies check that an OAuth access token was issued for this MCP server
|
|
23
|
+
req.context.mcp = { resource: getMCPResource({ config: req.payload.config, url: req.url }) }
|
|
14
24
|
|
|
15
25
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
16
|
-
const
|
|
26
|
+
const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
|
|
27
|
+
|
|
28
|
+
if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {
|
|
29
|
+
throw new APIError('MCP overrideAccess is only available in development.', 400)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let overrideAccess = false
|
|
33
|
+
if (overrideAccessParam === 'true') {
|
|
34
|
+
overrideAccess = true
|
|
35
|
+
} else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {
|
|
36
|
+
throw new APIError('MCP overrideAccess must be "true" or "false".', 400)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
40
|
+
|
|
41
|
+
if (pluginConfig.oauth && !req.user) {
|
|
42
|
+
return oauthChallenge({ req })
|
|
43
|
+
}
|
|
17
44
|
|
|
18
|
-
const
|
|
45
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
|
|
46
|
+
// Payload augments the original web-standard Request in place.
|
|
47
|
+
const mcpRequest = req as PayloadRequest & Request
|
|
48
|
+
const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })
|
|
19
49
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
50
|
+
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
51
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {
|
|
52
|
+
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
53
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
54
|
+
enableJsonResponse: true,
|
|
55
|
+
maxRequestBodySize,
|
|
56
|
+
sessionIdGenerator: undefined, // stateless mode
|
|
57
|
+
})
|
|
58
|
+
transport.onerror = (err) => {
|
|
59
|
+
req.payload.logger.error({ err, msg: 'Error serving legacy MCP request' })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await server.connect(transport)
|
|
64
|
+
return await transport.handleRequest(mcpRequest, { parsedBody })
|
|
65
|
+
} finally {
|
|
66
|
+
await server.close().catch((err) => {
|
|
67
|
+
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
73
|
+
legacy: 'reject',
|
|
74
|
+
maxRequestBodySize,
|
|
75
|
+
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
76
|
+
maxSubscriptions: 0,
|
|
77
|
+
onerror: (err) => {
|
|
78
|
+
req.payload.logger.error({ err, msg: 'Error serving modern MCP request' })
|
|
79
|
+
},
|
|
80
|
+
responseMode: 'json',
|
|
23
81
|
})
|
|
24
82
|
|
|
25
|
-
|
|
83
|
+
try {
|
|
84
|
+
return await handler.fetch(mcpRequest, { parsedBody })
|
|
85
|
+
} finally {
|
|
86
|
+
await handler.close().catch((err) => {
|
|
87
|
+
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
26
91
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
94
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
95
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
96
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
97
|
+
*/
|
|
98
|
+
const parseRequestBody = async ({
|
|
99
|
+
maxRequestBodySize,
|
|
100
|
+
request,
|
|
101
|
+
}: {
|
|
102
|
+
maxRequestBodySize?: number
|
|
103
|
+
request: Request
|
|
104
|
+
}): Promise<unknown> => {
|
|
105
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
33
108
|
|
|
34
|
-
|
|
109
|
+
try {
|
|
110
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize)
|
|
111
|
+
return body.tooLarge ? undefined : JSON.parse(body.text)
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
35
115
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { OAuthProtectedResourceMetadata } from '@modelcontextprotocol/server'
|
|
2
|
+
import type { PayloadHandler, PayloadRequest, SanitizedConfig } from 'payload'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
bearerAuthChallengeResponse,
|
|
6
|
+
OAuthError,
|
|
7
|
+
OAuthErrorCode,
|
|
8
|
+
} from '@modelcontextprotocol/server'
|
|
9
|
+
import { createPayloadRequest, getPayload } from 'payload'
|
|
10
|
+
|
|
11
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
15
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
16
|
+
*/
|
|
17
|
+
export const oauthProtectedResourceEndpoint: PayloadHandler = (req) => getMetadataResponse({ req })
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
21
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
22
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import config from '@payload-config'
|
|
26
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
27
|
+
*
|
|
28
|
+
* export const GET = oauthProtectedResourceHandler(config)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const oauthProtectedResourceHandler =
|
|
32
|
+
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
|
33
|
+
async (request: Request): Promise<Response> =>
|
|
34
|
+
getMetadataResponse({
|
|
35
|
+
req: await createPayloadRequest({ payload: await getPayload({ config }), req: request }),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
40
|
+
* metadata, which starts the client's OAuth flow.
|
|
41
|
+
*/
|
|
42
|
+
export const oauthChallenge = ({ req }: { req: PayloadRequest }): Response => {
|
|
43
|
+
const { oauth } = getPluginConfig({ config: req.payload.config })
|
|
44
|
+
const response = bearerAuthChallengeResponse(
|
|
45
|
+
new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),
|
|
46
|
+
{
|
|
47
|
+
requiredScopes: oauth?.type === 'external' ? oauth.scopes : undefined,
|
|
48
|
+
resourceMetadataUrl: `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth-protected-resource`,
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// Lets browser-based MCP clients read the challenge, when Payload's `cors` setting allows them
|
|
53
|
+
response.headers.set('Access-Control-Expose-Headers', 'WWW-Authenticate')
|
|
54
|
+
|
|
55
|
+
return response
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The MCP endpoint's address, as advertised in the metadata's `resource`. Clients send it when
|
|
60
|
+
* they sign in, and authorization servers that support it put it in the access token's audience.
|
|
61
|
+
*/
|
|
62
|
+
export const getMCPResource = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
63
|
+
getPluginConfig({ config }).oauth?.resource ?? getMCPURL({ config, url })
|
|
64
|
+
|
|
65
|
+
export const getMCPURL = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
66
|
+
new URL(`${config.routes.api}/mcp`, config.serverURL || url).href
|
|
67
|
+
|
|
68
|
+
const getMetadataResponse = async ({ req }: { req: PayloadRequest }): Promise<Response> => {
|
|
69
|
+
const { config } = req.payload
|
|
70
|
+
const { oauth } = getPluginConfig({ config })
|
|
71
|
+
|
|
72
|
+
if (!oauth) {
|
|
73
|
+
return new Response(null, { status: 404 })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Response.json(
|
|
77
|
+
{
|
|
78
|
+
authorization_servers:
|
|
79
|
+
oauth.type === 'builtin'
|
|
80
|
+
? [`${getMCPURL({ config, url: req.url! })}/oauth`]
|
|
81
|
+
: typeof oauth.authorizationServers === 'function'
|
|
82
|
+
? await oauth.authorizationServers({ req })
|
|
83
|
+
: oauth.authorizationServers,
|
|
84
|
+
bearer_methods_supported: ['header'],
|
|
85
|
+
resource: getMCPResource({ config, url: req.url! }),
|
|
86
|
+
scopes_supported: oauth.type === 'external' ? oauth.scopes : undefined,
|
|
87
|
+
} satisfies OAuthProtectedResourceMetadata,
|
|
88
|
+
// Public document, readable by browser-based MCP clients on any origin
|
|
89
|
+
{ headers: { 'Access-Control-Allow-Origin': '*' } },
|
|
90
|
+
)
|
|
91
|
+
}
|