@payloadcms/plugin-mcp 4.0.0-canary.2 → 4.0.0-canary.20261117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +29 -6
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +133 -100
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +121 -16
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +37 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +105 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/endpoint/oauthLoginToken.d.ts +27 -0
- package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
- package/dist/endpoint/oauthLoginToken.js +86 -0
- package/dist/endpoint/oauthLoginToken.js.map +1 -0
- package/dist/endpoint/oauthServer.d.ts +28 -0
- package/dist/endpoint/oauthServer.d.ts.map +1 -0
- package/dist/endpoint/oauthServer.js +455 -0
- package/dist/endpoint/oauthServer.js.map +1 -0
- package/dist/exports/client.d.ts +1 -4
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -4
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/exports/rsc.d.ts +2 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -55
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +6 -6
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +70 -34
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +123 -61
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +63 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +109 -66
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +56 -45
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +88 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +58 -56
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +78 -10
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +75 -102
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +30 -10
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +26 -35
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +56 -10
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +38 -54
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +75 -12
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +75 -13
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +76 -27
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -3
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +86 -47
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +224 -95
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/seal.d.ts +17 -0
- package/dist/utils/seal.d.ts.map +1 -0
- package/dist/utils/seal.js +24 -0
- package/dist/utils/seal.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.js.map +1 -1
- package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
- package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
- package/dist/views/Authorize/AllowButtons/index.js +88 -0
- package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
- package/dist/views/Authorize/index.css +19 -0
- package/dist/views/Authorize/index.d.ts +9 -0
- package/dist/views/Authorize/index.d.ts.map +1 -0
- package/dist/views/Authorize/index.js +98 -0
- package/dist/views/Authorize/index.js.map +1 -0
- package/package.json +34 -38
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +149 -109
- package/src/endpoint/index.ts +103 -15
- package/src/endpoint/oauth.ts +108 -0
- package/src/endpoint/oauthLoginToken.ts +100 -0
- package/src/endpoint/oauthServer.ts +472 -0
- package/src/exports/client.ts +2 -4
- package/src/exports/internal.ts +1 -0
- package/src/exports/rsc.ts +1 -0
- package/src/index.ts +53 -63
- package/src/mcp/buildMcpServer.ts +88 -51
- package/src/mcp/builtin/collections/authTools.ts +124 -77
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +113 -82
- package/src/mcp/builtin/collections/deleteTool.ts +49 -66
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +54 -97
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +70 -7
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +72 -110
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +29 -5
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +27 -57
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +52 -7
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +49 -72
- package/src/mcp/builtinTools.ts +81 -18
- package/src/mcp/sanitizeMCPConfig.ts +53 -30
- package/src/stdio.ts +80 -47
- package/src/types.ts +232 -99
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/seal.ts +46 -0
- package/src/utils/toStandardSchema.ts +1 -1
- package/src/views/Authorize/AllowButtons/index.tsx +97 -0
- package/src/views/Authorize/index.css +19 -0
- package/src/views/Authorize/index.tsx +100 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -72
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -105
- package/dist/collection/index.js.map +0 -1
- package/dist/components/APIKeyField/index.client.d.ts +0 -9
- package/dist/components/APIKeyField/index.client.d.ts.map +0 -1
- package/dist/components/APIKeyField/index.client.js +0 -85
- package/dist/components/APIKeyField/index.client.js.map +0 -1
- package/dist/components/APIKeyField/index.css +0 -105
- package/dist/components/APIKeysEmptyState/index.client.d.ts +0 -4
- package/dist/components/APIKeysEmptyState/index.client.d.ts.map +0 -1
- package/dist/components/APIKeysEmptyState/index.client.js +0 -21
- package/dist/components/APIKeysEmptyState/index.client.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -247
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -99
- package/dist/components/SettingsMenu/index.client.d.ts +0 -8
- package/dist/components/SettingsMenu/index.client.d.ts.map +0 -1
- package/dist/components/SettingsMenu/index.client.js +0 -29
- package/dist/components/SettingsMenu/index.client.js.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- package/dist/translations/index.d.ts +0 -11
- package/dist/translations/index.d.ts.map +0 -1
- package/dist/translations/index.js +0 -92
- package/dist/translations/index.js.map +0 -1
- package/dist/translations/languages/ar.d.ts +0 -31
- package/dist/translations/languages/ar.d.ts.map +0 -1
- package/dist/translations/languages/ar.js +0 -34
- package/dist/translations/languages/ar.js.map +0 -1
- package/dist/translations/languages/az.d.ts +0 -31
- package/dist/translations/languages/az.d.ts.map +0 -1
- package/dist/translations/languages/az.js +0 -34
- package/dist/translations/languages/az.js.map +0 -1
- package/dist/translations/languages/bg.d.ts +0 -31
- package/dist/translations/languages/bg.d.ts.map +0 -1
- package/dist/translations/languages/bg.js +0 -34
- package/dist/translations/languages/bg.js.map +0 -1
- package/dist/translations/languages/bnBd.d.ts +0 -31
- package/dist/translations/languages/bnBd.d.ts.map +0 -1
- package/dist/translations/languages/bnBd.js +0 -34
- package/dist/translations/languages/bnBd.js.map +0 -1
- package/dist/translations/languages/bnIn.d.ts +0 -31
- package/dist/translations/languages/bnIn.d.ts.map +0 -1
- package/dist/translations/languages/bnIn.js +0 -34
- package/dist/translations/languages/bnIn.js.map +0 -1
- package/dist/translations/languages/ca.d.ts +0 -31
- package/dist/translations/languages/ca.d.ts.map +0 -1
- package/dist/translations/languages/ca.js +0 -34
- package/dist/translations/languages/ca.js.map +0 -1
- package/dist/translations/languages/cs.d.ts +0 -31
- package/dist/translations/languages/cs.d.ts.map +0 -1
- package/dist/translations/languages/cs.js +0 -34
- package/dist/translations/languages/cs.js.map +0 -1
- package/dist/translations/languages/da.d.ts +0 -31
- package/dist/translations/languages/da.d.ts.map +0 -1
- package/dist/translations/languages/da.js +0 -34
- package/dist/translations/languages/da.js.map +0 -1
- package/dist/translations/languages/de.d.ts +0 -31
- package/dist/translations/languages/de.d.ts.map +0 -1
- package/dist/translations/languages/de.js +0 -34
- package/dist/translations/languages/de.js.map +0 -1
- package/dist/translations/languages/en.d.ts +0 -31
- package/dist/translations/languages/en.d.ts.map +0 -1
- package/dist/translations/languages/en.js +0 -34
- package/dist/translations/languages/en.js.map +0 -1
- package/dist/translations/languages/es.d.ts +0 -31
- package/dist/translations/languages/es.d.ts.map +0 -1
- package/dist/translations/languages/es.js +0 -34
- package/dist/translations/languages/es.js.map +0 -1
- package/dist/translations/languages/et.d.ts +0 -31
- package/dist/translations/languages/et.d.ts.map +0 -1
- package/dist/translations/languages/et.js +0 -34
- package/dist/translations/languages/et.js.map +0 -1
- package/dist/translations/languages/fa.d.ts +0 -31
- package/dist/translations/languages/fa.d.ts.map +0 -1
- package/dist/translations/languages/fa.js +0 -34
- package/dist/translations/languages/fa.js.map +0 -1
- package/dist/translations/languages/fr.d.ts +0 -31
- package/dist/translations/languages/fr.d.ts.map +0 -1
- package/dist/translations/languages/fr.js +0 -34
- package/dist/translations/languages/fr.js.map +0 -1
- package/dist/translations/languages/he.d.ts +0 -31
- package/dist/translations/languages/he.d.ts.map +0 -1
- package/dist/translations/languages/he.js +0 -34
- package/dist/translations/languages/he.js.map +0 -1
- package/dist/translations/languages/hr.d.ts +0 -31
- package/dist/translations/languages/hr.d.ts.map +0 -1
- package/dist/translations/languages/hr.js +0 -34
- package/dist/translations/languages/hr.js.map +0 -1
- package/dist/translations/languages/hu.d.ts +0 -31
- package/dist/translations/languages/hu.d.ts.map +0 -1
- package/dist/translations/languages/hu.js +0 -34
- package/dist/translations/languages/hu.js.map +0 -1
- package/dist/translations/languages/hy.d.ts +0 -31
- package/dist/translations/languages/hy.d.ts.map +0 -1
- package/dist/translations/languages/hy.js +0 -34
- package/dist/translations/languages/hy.js.map +0 -1
- package/dist/translations/languages/id.d.ts +0 -31
- package/dist/translations/languages/id.d.ts.map +0 -1
- package/dist/translations/languages/id.js +0 -34
- package/dist/translations/languages/id.js.map +0 -1
- package/dist/translations/languages/is.d.ts +0 -31
- package/dist/translations/languages/is.d.ts.map +0 -1
- package/dist/translations/languages/is.js +0 -34
- package/dist/translations/languages/is.js.map +0 -1
- package/dist/translations/languages/it.d.ts +0 -31
- package/dist/translations/languages/it.d.ts.map +0 -1
- package/dist/translations/languages/it.js +0 -34
- package/dist/translations/languages/it.js.map +0 -1
- package/dist/translations/languages/ja.d.ts +0 -31
- package/dist/translations/languages/ja.d.ts.map +0 -1
- package/dist/translations/languages/ja.js +0 -34
- package/dist/translations/languages/ja.js.map +0 -1
- package/dist/translations/languages/ko.d.ts +0 -31
- package/dist/translations/languages/ko.d.ts.map +0 -1
- package/dist/translations/languages/ko.js +0 -34
- package/dist/translations/languages/ko.js.map +0 -1
- package/dist/translations/languages/lt.d.ts +0 -31
- package/dist/translations/languages/lt.d.ts.map +0 -1
- package/dist/translations/languages/lt.js +0 -34
- package/dist/translations/languages/lt.js.map +0 -1
- package/dist/translations/languages/lv.d.ts +0 -31
- package/dist/translations/languages/lv.d.ts.map +0 -1
- package/dist/translations/languages/lv.js +0 -34
- package/dist/translations/languages/lv.js.map +0 -1
- package/dist/translations/languages/my.d.ts +0 -31
- package/dist/translations/languages/my.d.ts.map +0 -1
- package/dist/translations/languages/my.js +0 -34
- package/dist/translations/languages/my.js.map +0 -1
- package/dist/translations/languages/nb.d.ts +0 -31
- package/dist/translations/languages/nb.d.ts.map +0 -1
- package/dist/translations/languages/nb.js +0 -34
- package/dist/translations/languages/nb.js.map +0 -1
- package/dist/translations/languages/nl.d.ts +0 -31
- package/dist/translations/languages/nl.d.ts.map +0 -1
- package/dist/translations/languages/nl.js +0 -34
- package/dist/translations/languages/nl.js.map +0 -1
- package/dist/translations/languages/pl.d.ts +0 -31
- package/dist/translations/languages/pl.d.ts.map +0 -1
- package/dist/translations/languages/pl.js +0 -34
- package/dist/translations/languages/pl.js.map +0 -1
- package/dist/translations/languages/pt.d.ts +0 -31
- package/dist/translations/languages/pt.d.ts.map +0 -1
- package/dist/translations/languages/pt.js +0 -34
- package/dist/translations/languages/pt.js.map +0 -1
- package/dist/translations/languages/ro.d.ts +0 -31
- package/dist/translations/languages/ro.d.ts.map +0 -1
- package/dist/translations/languages/ro.js +0 -34
- package/dist/translations/languages/ro.js.map +0 -1
- package/dist/translations/languages/rs.d.ts +0 -31
- package/dist/translations/languages/rs.d.ts.map +0 -1
- package/dist/translations/languages/rs.js +0 -34
- package/dist/translations/languages/rs.js.map +0 -1
- package/dist/translations/languages/rsLatin.d.ts +0 -31
- package/dist/translations/languages/rsLatin.d.ts.map +0 -1
- package/dist/translations/languages/rsLatin.js +0 -34
- package/dist/translations/languages/rsLatin.js.map +0 -1
- package/dist/translations/languages/ru.d.ts +0 -31
- package/dist/translations/languages/ru.d.ts.map +0 -1
- package/dist/translations/languages/ru.js +0 -34
- package/dist/translations/languages/ru.js.map +0 -1
- package/dist/translations/languages/sk.d.ts +0 -31
- package/dist/translations/languages/sk.d.ts.map +0 -1
- package/dist/translations/languages/sk.js +0 -34
- package/dist/translations/languages/sk.js.map +0 -1
- package/dist/translations/languages/sl.d.ts +0 -31
- package/dist/translations/languages/sl.d.ts.map +0 -1
- package/dist/translations/languages/sl.js +0 -34
- package/dist/translations/languages/sl.js.map +0 -1
- package/dist/translations/languages/sv.d.ts +0 -31
- package/dist/translations/languages/sv.d.ts.map +0 -1
- package/dist/translations/languages/sv.js +0 -34
- package/dist/translations/languages/sv.js.map +0 -1
- package/dist/translations/languages/ta.d.ts +0 -31
- package/dist/translations/languages/ta.d.ts.map +0 -1
- package/dist/translations/languages/ta.js +0 -34
- package/dist/translations/languages/ta.js.map +0 -1
- package/dist/translations/languages/th.d.ts +0 -31
- package/dist/translations/languages/th.d.ts.map +0 -1
- package/dist/translations/languages/th.js +0 -34
- package/dist/translations/languages/th.js.map +0 -1
- package/dist/translations/languages/tr.d.ts +0 -31
- package/dist/translations/languages/tr.d.ts.map +0 -1
- package/dist/translations/languages/tr.js +0 -34
- package/dist/translations/languages/tr.js.map +0 -1
- package/dist/translations/languages/uk.d.ts +0 -31
- package/dist/translations/languages/uk.d.ts.map +0 -1
- package/dist/translations/languages/uk.js +0 -34
- package/dist/translations/languages/uk.js.map +0 -1
- package/dist/translations/languages/vi.d.ts +0 -31
- package/dist/translations/languages/vi.d.ts.map +0 -1
- package/dist/translations/languages/vi.js +0 -34
- package/dist/translations/languages/vi.js.map +0 -1
- package/dist/translations/languages/zh.d.ts +0 -31
- package/dist/translations/languages/zh.d.ts.map +0 -1
- package/dist/translations/languages/zh.js +0 -34
- package/dist/translations/languages/zh.js.map +0 -1
- package/dist/translations/languages/zhTw.d.ts +0 -31
- package/dist/translations/languages/zhTw.d.ts.map +0 -1
- package/dist/translations/languages/zhTw.js +0 -34
- package/dist/translations/languages/zhTw.js.map +0 -1
- package/dist/translations/types.d.ts +0 -32
- package/dist/translations/types.d.ts.map +0 -1
- package/dist/translations/types.js +0 -3
- package/dist/translations/types.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/localAPIDefaults.d.ts +0 -20
- package/dist/utils/localAPIDefaults.d.ts.map +0 -1
- package/dist/utils/localAPIDefaults.js +0 -19
- package/dist/utils/localAPIDefaults.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -84
- package/src/collection/index.ts +0 -105
- package/src/components/APIKeyField/index.client.tsx +0 -73
- package/src/components/APIKeyField/index.css +0 -105
- package/src/components/APIKeysEmptyState/index.client.tsx +0 -36
- package/src/components/AccessField/index.client.tsx +0 -299
- package/src/components/AccessField/index.css +0 -99
- package/src/components/SettingsMenu/index.client.tsx +0 -34
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/translations/index.ts +0 -108
- package/src/translations/languages/ar.ts +0 -35
- package/src/translations/languages/az.ts +0 -35
- package/src/translations/languages/bg.ts +0 -35
- package/src/translations/languages/bnBd.ts +0 -35
- package/src/translations/languages/bnIn.ts +0 -35
- package/src/translations/languages/ca.ts +0 -35
- package/src/translations/languages/cs.ts +0 -35
- package/src/translations/languages/da.ts +0 -35
- package/src/translations/languages/de.ts +0 -35
- package/src/translations/languages/en.ts +0 -35
- package/src/translations/languages/es.ts +0 -35
- package/src/translations/languages/et.ts +0 -35
- package/src/translations/languages/fa.ts +0 -35
- package/src/translations/languages/fr.ts +0 -35
- package/src/translations/languages/he.ts +0 -35
- package/src/translations/languages/hr.ts +0 -35
- package/src/translations/languages/hu.ts +0 -35
- package/src/translations/languages/hy.ts +0 -35
- package/src/translations/languages/id.ts +0 -35
- package/src/translations/languages/is.ts +0 -35
- package/src/translations/languages/it.ts +0 -35
- package/src/translations/languages/ja.ts +0 -35
- package/src/translations/languages/ko.ts +0 -35
- package/src/translations/languages/lt.ts +0 -35
- package/src/translations/languages/lv.ts +0 -35
- package/src/translations/languages/my.ts +0 -35
- package/src/translations/languages/nb.ts +0 -35
- package/src/translations/languages/nl.ts +0 -35
- package/src/translations/languages/pl.ts +0 -35
- package/src/translations/languages/pt.ts +0 -35
- package/src/translations/languages/ro.ts +0 -35
- package/src/translations/languages/rs.ts +0 -35
- package/src/translations/languages/rsLatin.ts +0 -35
- package/src/translations/languages/ru.ts +0 -35
- package/src/translations/languages/sk.ts +0 -35
- package/src/translations/languages/sl.ts +0 -35
- package/src/translations/languages/sv.ts +0 -35
- package/src/translations/languages/ta.ts +0 -35
- package/src/translations/languages/th.ts +0 -35
- package/src/translations/languages/tr.ts +0 -35
- package/src/translations/languages/uk.ts +0 -35
- package/src/translations/languages/vi.ts +0 -35
- package/src/translations/languages/zh.ts +0 -35
- package/src/translations/languages/zhTw.ts +0 -35
- package/src/translations/types.ts +0 -34
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
package/src/endpoint/access.ts
CHANGED
|
@@ -1,144 +1,184 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequest, SanitizedPermissions } from 'payload'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { executeAuthStrategies, Forbidden, getAccessResults, UnauthorizedError } from 'payload'
|
|
4
|
+
import { extractBearerToken } from 'payload/shared'
|
|
5
5
|
|
|
6
|
-
import type { AuthorizedMCP,
|
|
6
|
+
import type { AuthorizedMCP, MCPItem } from '../types.js'
|
|
7
7
|
|
|
8
|
-
import { getLogger } from '../utils/getLogger.js'
|
|
9
8
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
9
|
+
import { authenticateLoginToken } from './oauthLoginToken.js'
|
|
10
|
+
|
|
11
|
+
export type GetAuthorizedMCPArgs = {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the request came through the HTTP endpoint, whose response can carry the OAuth
|
|
14
|
+
* challenge and headers from auth strategies. stdio has no response to carry them.
|
|
15
|
+
*/
|
|
16
|
+
isHTTP?: boolean
|
|
17
|
+
overrideAccess: boolean
|
|
18
|
+
req: PayloadRequest
|
|
19
|
+
}
|
|
10
20
|
|
|
11
21
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
22
|
+
* Authenticates an MCP request, rejects users the plugin's `access` denies, and removes items the
|
|
23
|
+
* user cannot access. `overrideAccess` skips Payload and MCP access checks.
|
|
14
24
|
*/
|
|
15
|
-
export const getAuthorizedMCP: (args:
|
|
25
|
+
export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
|
|
26
|
+
isHTTP = false,
|
|
27
|
+
overrideAccess,
|
|
16
28
|
req,
|
|
17
29
|
}) => {
|
|
18
|
-
const logger = getLogger({ payload: req.payload })
|
|
19
30
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
31
|
+
const isChallengedWhenSignedOut = isHTTP && Boolean(pluginConfig.oauth)
|
|
20
32
|
|
|
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),
|
|
33
|
+
if (pluginConfig.overrideGetAuthorizedMCP) {
|
|
34
|
+
return await pluginConfig.overrideGetAuthorizedMCP({
|
|
35
|
+
overrideAccess,
|
|
48
36
|
pluginConfig,
|
|
49
37
|
req,
|
|
50
38
|
})
|
|
51
39
|
}
|
|
52
40
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
if (req.headers) {
|
|
42
|
+
const headers = new Headers(req.headers)
|
|
43
|
+
const hasAuthorization = headers.has('Authorization')
|
|
44
|
+
|
|
45
|
+
headers.set('DisableAutologin', 'true')
|
|
46
|
+
// Not `payload.auth()`, which also computes permissions that filterMCPItems computes anyway
|
|
47
|
+
const { responseHeaders, user } = await executeAuthStrategies({
|
|
48
|
+
canSetHeaders: isHTTP,
|
|
49
|
+
headers,
|
|
50
|
+
payload: req.payload,
|
|
51
|
+
req,
|
|
60
52
|
})
|
|
53
|
+
req.user = user
|
|
54
|
+
if (responseHeaders) {
|
|
55
|
+
req.responseHeaders = responseHeaders
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Only bearer tokens that no auth strategy accepted get here, e.g. an OAuth access token.
|
|
59
|
+
// API keys use the `<collection> API-Key <key>` scheme instead of `Bearer`, so they never do.
|
|
60
|
+
const bearerToken = extractBearerToken({ headers })
|
|
61
|
+
// Sealed Payload login tokens from the built-in OAuth server
|
|
62
|
+
if (
|
|
63
|
+
!req.user &&
|
|
64
|
+
bearerToken &&
|
|
65
|
+
pluginConfig.oauth?.type === 'builtin' &&
|
|
66
|
+
!pluginConfig.oauth.issueToken
|
|
67
|
+
) {
|
|
68
|
+
req.user = await authenticateLoginToken({ req, token: bearerToken })
|
|
69
|
+
}
|
|
70
|
+
if (!req.user && bearerToken && pluginConfig.oauth?.authenticate) {
|
|
71
|
+
req.user = await pluginConfig.oauth.authenticate({ req, token: bearerToken })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// With OAuth, the endpoint answers with a challenge that starts the client's sign-in
|
|
75
|
+
if (hasAuthorization && !req.user && !isChallengedWhenSignedOut) {
|
|
76
|
+
throw new UnauthorizedError(req.t)
|
|
77
|
+
}
|
|
61
78
|
}
|
|
62
79
|
|
|
63
|
-
|
|
80
|
+
// Signed-out users only get the challenge, so they can't use any MCP items. Skipping the access
|
|
81
|
+
// checks saves work, and access callbacks only see signed-in users.
|
|
82
|
+
if (isChallengedWhenSignedOut && !req.user) {
|
|
83
|
+
return { items: [], overrideAccess }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Computed once for the plugin's `access` and every item's
|
|
87
|
+
const permissions = overrideAccess ? undefined : await getAccessResults({ req })
|
|
88
|
+
|
|
89
|
+
if (!overrideAccess && !(await canUseMCP({ permissions, req }))) {
|
|
90
|
+
throw new Forbidden(req.t)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
items: await filterMCPItems({
|
|
95
|
+
items: pluginConfig.items,
|
|
96
|
+
overrideAccess,
|
|
97
|
+
permissions,
|
|
98
|
+
req,
|
|
99
|
+
}),
|
|
100
|
+
overrideAccess,
|
|
101
|
+
}
|
|
64
102
|
}
|
|
65
103
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Runs the plugin's top-level `access`, which decides whether the user can use MCP at all. Doesn't
|
|
106
|
+
* check `overrideAccess`, so callers skip it themselves.
|
|
107
|
+
*/
|
|
108
|
+
export const canUseMCP = async ({
|
|
109
|
+
permissions,
|
|
70
110
|
req,
|
|
71
111
|
}: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pluginConfig: ReturnType<typeof getPluginConfig>
|
|
112
|
+
/** Computed when missing and `access` is set. */
|
|
113
|
+
permissions?: SanitizedPermissions
|
|
75
114
|
req: PayloadRequest
|
|
76
|
-
}): Promise<
|
|
77
|
-
const
|
|
78
|
-
const hasBearerToken = authHeader?.startsWith('Bearer ')
|
|
79
|
-
|
|
80
|
-
const apiKey =
|
|
81
|
-
overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null)
|
|
115
|
+
}): Promise<boolean> => {
|
|
116
|
+
const { access } = getPluginConfig({ config: req.payload.config })
|
|
82
117
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
return (
|
|
119
|
+
!access ||
|
|
120
|
+
(await access({ permissions: permissions ?? (await getAccessResults({ req })), req }))
|
|
121
|
+
)
|
|
122
|
+
}
|
|
86
123
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
124
|
+
export const filterMCPItems = async ({
|
|
125
|
+
items,
|
|
126
|
+
overrideAccess,
|
|
127
|
+
permissions: providedPermissions,
|
|
128
|
+
req,
|
|
129
|
+
}: {
|
|
130
|
+
items: MCPItem[]
|
|
131
|
+
overrideAccess: boolean
|
|
132
|
+
/** Computed when missing. */
|
|
133
|
+
permissions?: SanitizedPermissions
|
|
134
|
+
req: PayloadRequest
|
|
135
|
+
}): Promise<MCPItem[]> => {
|
|
136
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
137
|
+
if (overrideAccess) {
|
|
138
|
+
return items
|
|
102
139
|
}
|
|
103
140
|
|
|
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)
|
|
141
|
+
const authorizedItems: MCPItem[] = []
|
|
111
142
|
|
|
112
|
-
const
|
|
113
|
-
id: userID,
|
|
114
|
-
collection: pluginConfig.userCollection,
|
|
115
|
-
depth: 0,
|
|
116
|
-
disableErrors: true,
|
|
117
|
-
req,
|
|
118
|
-
})) as null | TypedUser
|
|
143
|
+
const permissions = providedPermissions ?? (await getAccessResults({ req }))
|
|
119
144
|
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
for (const item of items) {
|
|
146
|
+
if (!(await checkItemAccess({ item, permissions, req }))) {
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
authorizedItems.push(item)
|
|
122
150
|
}
|
|
123
151
|
|
|
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
|
-
}
|
|
152
|
+
return authorizedItems
|
|
153
|
+
}
|
|
135
154
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Runs MCP item access callbacks
|
|
157
|
+
*/
|
|
158
|
+
const checkItemAccess = async ({
|
|
159
|
+
item,
|
|
160
|
+
permissions,
|
|
161
|
+
req,
|
|
162
|
+
}: {
|
|
163
|
+
item: MCPItem
|
|
164
|
+
permissions?: SanitizedPermissions
|
|
165
|
+
req: PayloadRequest
|
|
166
|
+
}): Promise<boolean> => {
|
|
167
|
+
switch (item.type) {
|
|
168
|
+
case 'collectionTool':
|
|
169
|
+
return (
|
|
170
|
+
!item.tool.access ||
|
|
171
|
+
(await item.tool.access({ slug: item.collectionSlug, permissions, req }))
|
|
172
|
+
)
|
|
173
|
+
case 'globalTool':
|
|
174
|
+
return (
|
|
175
|
+
!item.tool.access || (await item.tool.access({ slug: item.globalSlug, permissions, req }))
|
|
176
|
+
)
|
|
177
|
+
case 'prompt':
|
|
178
|
+
return !item.prompt.access || (await item.prompt.access({ permissions, req }))
|
|
179
|
+
case 'resource':
|
|
180
|
+
return !item.resource.access || (await item.resource.access({ permissions, req }))
|
|
181
|
+
case 'tool':
|
|
182
|
+
return !item.tool.access || (await item.tool.access({ permissions, req }))
|
|
143
183
|
}
|
|
144
184
|
}
|
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,105 @@ 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({ req }) }
|
|
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
|
+
}
|
|
17
38
|
|
|
18
|
-
const
|
|
39
|
+
const authorizedMCP = await getAuthorizedMCP({ isHTTP: true, overrideAccess, req })
|
|
40
|
+
|
|
41
|
+
// Clients like Codex send a GET first to find out where to sign in, so this comes before the
|
|
42
|
+
// GET check
|
|
43
|
+
if (pluginConfig.oauth && !req.user) {
|
|
44
|
+
return oauthChallenge({ req })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Streamable HTTP's optional server-to-client stream. We don't offer one, so answer 405 per
|
|
48
|
+
// spec, and clients skip it
|
|
49
|
+
if (req.method === 'GET') {
|
|
50
|
+
return new Response(null, { headers: { Allow: 'POST' }, status: 405 })
|
|
51
|
+
}
|
|
19
52
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
53
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
|
|
54
|
+
// Payload augments the original web-standard Request in place.
|
|
55
|
+
const mcpRequest = req as PayloadRequest & Request
|
|
56
|
+
const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })
|
|
57
|
+
|
|
58
|
+
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
59
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {
|
|
60
|
+
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
61
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
62
|
+
enableJsonResponse: true,
|
|
63
|
+
maxRequestBodySize,
|
|
64
|
+
sessionIdGenerator: undefined, // stateless mode
|
|
65
|
+
})
|
|
66
|
+
transport.onerror = (err) => {
|
|
67
|
+
req.payload.logger.error({ err, msg: 'Error serving legacy MCP request' })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await server.connect(transport)
|
|
72
|
+
return await transport.handleRequest(mcpRequest, { parsedBody })
|
|
73
|
+
} finally {
|
|
74
|
+
await server.close().catch((err) => {
|
|
75
|
+
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
81
|
+
legacy: 'reject',
|
|
82
|
+
maxRequestBodySize,
|
|
83
|
+
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
84
|
+
maxSubscriptions: 0,
|
|
85
|
+
onerror: (err) => {
|
|
86
|
+
req.payload.logger.error({ err, msg: 'Error serving modern MCP request' })
|
|
87
|
+
},
|
|
88
|
+
responseMode: 'json',
|
|
23
89
|
})
|
|
24
90
|
|
|
25
|
-
|
|
91
|
+
try {
|
|
92
|
+
return await handler.fetch(mcpRequest, { parsedBody })
|
|
93
|
+
} finally {
|
|
94
|
+
await handler.close().catch((err) => {
|
|
95
|
+
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
26
99
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
102
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
103
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
104
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
105
|
+
*/
|
|
106
|
+
const parseRequestBody = async ({
|
|
107
|
+
maxRequestBodySize,
|
|
108
|
+
request,
|
|
109
|
+
}: {
|
|
110
|
+
maxRequestBodySize?: number
|
|
111
|
+
request: Request
|
|
112
|
+
}): Promise<unknown> => {
|
|
113
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
114
|
+
return undefined
|
|
115
|
+
}
|
|
33
116
|
|
|
34
|
-
|
|
117
|
+
try {
|
|
118
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize)
|
|
119
|
+
return body.tooLarge ? undefined : JSON.parse(body.text)
|
|
120
|
+
} catch {
|
|
121
|
+
return undefined
|
|
122
|
+
}
|
|
35
123
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
import { formatAdminURL, stripTrailingSlash } from 'payload/shared'
|
|
11
|
+
|
|
12
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
16
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
17
|
+
*/
|
|
18
|
+
export const oauthProtectedResourceEndpoint: PayloadHandler = (req) => getMetadataResponse({ req })
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
22
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
23
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import config from '@payload-config'
|
|
27
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
28
|
+
*
|
|
29
|
+
* export const GET = oauthProtectedResourceHandler({ config })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const oauthProtectedResourceHandler =
|
|
33
|
+
({ config }: { config: Promise<SanitizedConfig> | SanitizedConfig }) =>
|
|
34
|
+
async (request: Request): Promise<Response> =>
|
|
35
|
+
getMetadataResponse({
|
|
36
|
+
req: await createPayloadRequest({ payload: await getPayload({ config }), req: request }),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
41
|
+
* metadata, which starts the client's OAuth flow.
|
|
42
|
+
*/
|
|
43
|
+
export const oauthChallenge = ({ req }: { req: PayloadRequest }): Response => {
|
|
44
|
+
const { oauth } = getPluginConfig({ config: req.payload.config })
|
|
45
|
+
const response = bearerAuthChallengeResponse(
|
|
46
|
+
new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),
|
|
47
|
+
{
|
|
48
|
+
requiredScopes: oauth?.type === 'external' ? oauth.scopes : undefined,
|
|
49
|
+
resourceMetadataUrl: `${getMCPResource({ req })}/oauth-protected-resource`,
|
|
50
|
+
},
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
// Lets browser-based MCP clients read the challenge, when Payload's `cors` setting allows them
|
|
54
|
+
response.headers.set('Access-Control-Expose-Headers', 'WWW-Authenticate')
|
|
55
|
+
|
|
56
|
+
return response
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The MCP endpoint's address, as advertised in the metadata's `resource`. The metadata link and
|
|
61
|
+
* the built-in authorization server's issuer are based on it. Clients send it when they sign in,
|
|
62
|
+
* and authorization servers that support it put it in the access token's audience.
|
|
63
|
+
*/
|
|
64
|
+
export const getMCPResource = ({ req }: { req: PayloadRequest }): string => {
|
|
65
|
+
const { config } = req.payload
|
|
66
|
+
const resource = getPluginConfig({ config }).oauth?.resource
|
|
67
|
+
|
|
68
|
+
if (typeof resource === 'function') {
|
|
69
|
+
return resource({ req })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (resource) {
|
|
73
|
+
return resource
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Without the slash Next.js's `trailingSlash` would add, since the metadata link appends to it
|
|
77
|
+
const path = stripTrailingSlash(formatAdminURL({ apiRoute: config.routes.api, path: '/mcp' }))
|
|
78
|
+
|
|
79
|
+
return new URL(path, config.serverURL || req.url).href
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const getMetadataResponse = async ({ req }: { req: PayloadRequest }): Promise<Response> => {
|
|
83
|
+
const { config } = req.payload
|
|
84
|
+
const { oauth } = getPluginConfig({ config })
|
|
85
|
+
|
|
86
|
+
if (!oauth) {
|
|
87
|
+
return new Response(null, { status: 404 })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const resource = getMCPResource({ req })
|
|
91
|
+
|
|
92
|
+
return Response.json(
|
|
93
|
+
{
|
|
94
|
+
authorization_servers:
|
|
95
|
+
oauth.type === 'builtin'
|
|
96
|
+
? [`${resource}/oauth`]
|
|
97
|
+
: typeof oauth.authorizationServers === 'function'
|
|
98
|
+
? await oauth.authorizationServers({ req })
|
|
99
|
+
: oauth.authorizationServers,
|
|
100
|
+
bearer_methods_supported: ['header'],
|
|
101
|
+
resource,
|
|
102
|
+
scopes_supported: oauth.type === 'external' ? oauth.scopes : undefined,
|
|
103
|
+
} satisfies OAuthProtectedResourceMetadata,
|
|
104
|
+
// Public document, readable by browser-based MCP clients on any origin. Not cached, since its
|
|
105
|
+
// URLs can depend on the request.
|
|
106
|
+
{ headers: { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-store' } },
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { APIError, createAuthToken, executeAuthStrategies, redeemRefreshToken } from 'payload'
|
|
4
|
+
|
|
5
|
+
import type { MCPOAuthTokens } from '../types.js'
|
|
6
|
+
|
|
7
|
+
import { seal, unseal } from '../utils/seal.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The default `issueToken`: a Payload login token, sealed so it only works for MCP, where
|
|
11
|
+
* `authenticateLoginToken` unseals it. Otherwise an MCP client could use it as the user's admin
|
|
12
|
+
* panel login. When the collection uses sessions, the client also gets a refresh token.
|
|
13
|
+
*/
|
|
14
|
+
export const issueLoginToken = async ({
|
|
15
|
+
client,
|
|
16
|
+
req,
|
|
17
|
+
}: {
|
|
18
|
+
client: { name: string; redirectURI: string }
|
|
19
|
+
req: PayloadRequest
|
|
20
|
+
}): Promise<MCPOAuthTokens> => {
|
|
21
|
+
const collectionConfig = req.payload.collections[req.user!.collection]!.config
|
|
22
|
+
|
|
23
|
+
if (collectionConfig.auth.disableLocalStrategy) {
|
|
24
|
+
throw new APIError(
|
|
25
|
+
`MCP clients can't get Payload login tokens for the "${collectionConfig.slug}" collection because its local strategy is disabled. Pass oauth.issueToken to the MCP plugin.`,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The full document, like the one a password login starts its session on
|
|
30
|
+
const user = (await req.payload.db.findOne<NonNullable<PayloadRequest['user']>>({
|
|
31
|
+
collection: collectionConfig.slug,
|
|
32
|
+
req,
|
|
33
|
+
where: { id: { equals: req.user!.id } },
|
|
34
|
+
}))!
|
|
35
|
+
|
|
36
|
+
const { refreshToken, token } = await createAuthToken({
|
|
37
|
+
type: 'mcp',
|
|
38
|
+
collectionConfig,
|
|
39
|
+
// App schemes like `com.example.app:/callback` have no host
|
|
40
|
+
email: user.email!,
|
|
41
|
+
label: client.name,
|
|
42
|
+
metadata: { redirectHost: new URL(client.redirectURI).host || client.redirectURI },
|
|
43
|
+
req,
|
|
44
|
+
shouldCreateRefreshToken: true,
|
|
45
|
+
user,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
accessToken: sealLoginToken({ req, token }),
|
|
50
|
+
expiresIn: collectionConfig.auth.tokenExpiration,
|
|
51
|
+
refreshToken,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The default `refreshToken`. Payload logs out the session when a refresh token is reused. */
|
|
56
|
+
export const refreshLoginToken = async ({
|
|
57
|
+
refreshToken,
|
|
58
|
+
req,
|
|
59
|
+
reuseInterval,
|
|
60
|
+
}: {
|
|
61
|
+
refreshToken: string
|
|
62
|
+
req: PayloadRequest
|
|
63
|
+
/** See `redeemRefreshToken`. */
|
|
64
|
+
reuseInterval?: number
|
|
65
|
+
}): Promise<MCPOAuthTokens | null> => {
|
|
66
|
+
const refreshed = await redeemRefreshToken({ refreshToken, req, reuseInterval })
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
refreshed && {
|
|
70
|
+
accessToken: sealLoginToken({ req, token: refreshed.token }),
|
|
71
|
+
expiresIn: refreshed.collectionConfig.auth.tokenExpiration,
|
|
72
|
+
refreshToken: refreshed.refreshToken,
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Finds the user of an MCP request's access token from `issueLoginToken`. */
|
|
78
|
+
export const authenticateLoginToken = async ({
|
|
79
|
+
req,
|
|
80
|
+
token,
|
|
81
|
+
}: {
|
|
82
|
+
req: PayloadRequest
|
|
83
|
+
token: string
|
|
84
|
+
}): Promise<PayloadRequest['user']> => {
|
|
85
|
+
const loginToken = unseal<{ token: string }>({ type: 'access', req, value: token })
|
|
86
|
+
|
|
87
|
+
if (!loginToken) {
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const headers = new Headers({
|
|
92
|
+
Authorization: `JWT ${loginToken.token}`,
|
|
93
|
+
DisableAutologin: 'true',
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
return (await executeAuthStrategies({ headers, payload: req.payload, req })).user
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const sealLoginToken = ({ req, token }: { req: PayloadRequest; token: string }): string =>
|
|
100
|
+
seal({ type: 'access', data: { token }, req })
|