@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
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
OAuthClientInformationFull,
|
|
3
|
+
OAuthTokens,
|
|
4
|
+
OpenIdProviderDiscoveryMetadata,
|
|
5
|
+
} from '@modelcontextprotocol/server'
|
|
6
|
+
import type { Endpoint, PayloadHandler, PayloadRequest } from 'payload'
|
|
7
|
+
|
|
8
|
+
import { OAuthErrorCode } from '@modelcontextprotocol/server'
|
|
9
|
+
import { createHash } from 'crypto'
|
|
10
|
+
import { APIError, createAuthToken } from 'payload'
|
|
11
|
+
import { formatAdminURL } from 'payload/shared'
|
|
12
|
+
|
|
13
|
+
import type { MCPBuiltinOAuthConfig } from '../types.js'
|
|
14
|
+
|
|
15
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
16
|
+
import { getMCPURL } from './oauth.js'
|
|
17
|
+
|
|
18
|
+
type Client = { name: string; redirectURIs: string[] }
|
|
19
|
+
|
|
20
|
+
type Consent = {
|
|
21
|
+
clientID: string
|
|
22
|
+
codeChallenge: string
|
|
23
|
+
collection: string
|
|
24
|
+
redirectURI: string
|
|
25
|
+
state: null | string
|
|
26
|
+
userID: number | string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Code = {
|
|
30
|
+
accessToken: string
|
|
31
|
+
clientID: string
|
|
32
|
+
codeChallenge: string
|
|
33
|
+
expiresIn?: number
|
|
34
|
+
redirectURI: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Turns Payload into the OAuth authorization server for MCP clients when `oauth.type` is
|
|
39
|
+
* `'builtin'`. Clients register, the user allows them after logging in to the admin panel, and
|
|
40
|
+
* the client receives the access token `issueToken` creates.
|
|
41
|
+
*
|
|
42
|
+
* Clients, consent forms, and authorization codes are encrypted and handed to the client instead
|
|
43
|
+
* of being stored, so nothing is written to the database.
|
|
44
|
+
*/
|
|
45
|
+
export const oauthServerEndpoints: Endpoint[] = [
|
|
46
|
+
{
|
|
47
|
+
disableAuth: true,
|
|
48
|
+
handler: (req) => withIssuer(req, (issuer) => metadataResponse(issuer)),
|
|
49
|
+
method: 'get',
|
|
50
|
+
// OpenID discovery is the only metadata location MCP clients check below the issuer's path,
|
|
51
|
+
// which lets this work under /api without a route at the site root
|
|
52
|
+
path: '/mcp/oauth/.well-known/openid-configuration',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
disableAuth: true,
|
|
56
|
+
handler: (req) => withIssuer(req, () => Response.json({ keys: [] })),
|
|
57
|
+
method: 'get',
|
|
58
|
+
path: '/mcp/oauth/jwks',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
disableAuth: true,
|
|
62
|
+
handler: (req) => withIssuer(req, () => register(req)),
|
|
63
|
+
method: 'post',
|
|
64
|
+
path: '/mcp/oauth/register',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
handler: (req) => withIssuer(req, () => authorize(req)),
|
|
68
|
+
method: 'get',
|
|
69
|
+
path: '/mcp/oauth/authorize',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
handler: (req) => withIssuer(req, () => approve(req)),
|
|
73
|
+
method: 'post',
|
|
74
|
+
path: '/mcp/oauth/authorize',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
disableAuth: true,
|
|
78
|
+
handler: (req) => withIssuer(req, () => token(req)),
|
|
79
|
+
method: 'post',
|
|
80
|
+
path: '/mcp/oauth/token',
|
|
81
|
+
},
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
/** The authorization server URL, or `undefined` when Payload isn't the authorization server. */
|
|
85
|
+
const getIssuer = (req: PayloadRequest): string | undefined =>
|
|
86
|
+
getPluginConfig({ config: req.payload.config }).oauth?.type === 'builtin'
|
|
87
|
+
? `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth`
|
|
88
|
+
: undefined
|
|
89
|
+
|
|
90
|
+
const withIssuer = (
|
|
91
|
+
req: PayloadRequest,
|
|
92
|
+
handler: (issuer: string) => Promise<Response> | Response,
|
|
93
|
+
): Promise<Response> | Response => {
|
|
94
|
+
const issuer = getIssuer(req)
|
|
95
|
+
return issuer ? handler(issuer) : new Response(null, { status: 404 })
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const metadataResponse = (issuer: string): Response =>
|
|
99
|
+
Response.json(
|
|
100
|
+
{
|
|
101
|
+
authorization_endpoint: `${issuer}/authorize`,
|
|
102
|
+
code_challenge_methods_supported: ['S256'],
|
|
103
|
+
grant_types_supported: ['authorization_code'],
|
|
104
|
+
// Required by OpenID discovery. No ID tokens are issued.
|
|
105
|
+
id_token_signing_alg_values_supported: ['RS256'],
|
|
106
|
+
issuer,
|
|
107
|
+
jwks_uri: `${issuer}/jwks`,
|
|
108
|
+
registration_endpoint: `${issuer}/register`,
|
|
109
|
+
response_types_supported: ['code'],
|
|
110
|
+
subject_types_supported: ['public'],
|
|
111
|
+
token_endpoint: `${issuer}/token`,
|
|
112
|
+
token_endpoint_auth_methods_supported: ['none'],
|
|
113
|
+
} satisfies OpenIdProviderDiscoveryMetadata,
|
|
114
|
+
{ headers: { 'Access-Control-Allow-Origin': '*' } },
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
const register: PayloadHandler = async (req) => {
|
|
118
|
+
const { client_name, redirect_uris } = await req.json!().catch(() => ({}))
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
!Array.isArray(redirect_uris) ||
|
|
122
|
+
!redirect_uris.length ||
|
|
123
|
+
!redirect_uris.every(
|
|
124
|
+
(uri) => typeof uri === 'string' && URL.canParse(uri) && !uri.includes('#'),
|
|
125
|
+
)
|
|
126
|
+
) {
|
|
127
|
+
return Response.json({ error: OAuthErrorCode.InvalidRedirectUri }, { status: 400 })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const client: Client = {
|
|
131
|
+
name: typeof client_name === 'string' ? client_name : 'An MCP client',
|
|
132
|
+
redirectURIs: redirect_uris,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return Response.json(
|
|
136
|
+
{
|
|
137
|
+
client_id: seal({ type: 'client', data: client, req }),
|
|
138
|
+
client_name: client.name,
|
|
139
|
+
grant_types: ['authorization_code'],
|
|
140
|
+
redirect_uris: client.redirectURIs,
|
|
141
|
+
response_types: ['code'],
|
|
142
|
+
token_endpoint_auth_method: 'none',
|
|
143
|
+
} satisfies OAuthClientInformationFull,
|
|
144
|
+
{ status: 201 },
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const authorize: PayloadHandler = (req) => {
|
|
149
|
+
const url = new URL(req.url!)
|
|
150
|
+
const params = url.searchParams
|
|
151
|
+
const clientID = params.get('client_id')
|
|
152
|
+
const client = unseal<Client>({ type: 'client', req, value: clientID })
|
|
153
|
+
const redirectURI = params.get('redirect_uri')
|
|
154
|
+
|
|
155
|
+
// Never redirect to an address the client didn't register
|
|
156
|
+
if (!client || !redirectURI || !client.redirectURIs.includes(redirectURI)) {
|
|
157
|
+
return page({
|
|
158
|
+
content: '<p>Start the sign-in again from your MCP client.</p>',
|
|
159
|
+
status: 400,
|
|
160
|
+
title: 'This sign-in link is invalid',
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const state = params.get('state')
|
|
165
|
+
const codeChallenge = params.get('code_challenge')
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
params.get('response_type') !== 'code' ||
|
|
169
|
+
params.get('code_challenge_method') !== 'S256' ||
|
|
170
|
+
!codeChallenge
|
|
171
|
+
) {
|
|
172
|
+
return redirect({ params: { error: OAuthErrorCode.InvalidRequest, state }, redirectURI })
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!req.user) {
|
|
176
|
+
const loginURL = formatAdminURL({ adminRoute: req.payload.config.routes.admin, path: '/login' })
|
|
177
|
+
|
|
178
|
+
return new Response(null, {
|
|
179
|
+
headers: {
|
|
180
|
+
Location: `${loginURL}?redirect=${encodeURIComponent(url.pathname + url.search)}`,
|
|
181
|
+
},
|
|
182
|
+
status: 302,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const consent: Consent = {
|
|
187
|
+
clientID: clientID!,
|
|
188
|
+
codeChallenge,
|
|
189
|
+
collection: req.user.collection,
|
|
190
|
+
redirectURI,
|
|
191
|
+
state,
|
|
192
|
+
userID: req.user.id,
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return page({
|
|
196
|
+
content: `<p>It will be able to use this app's MCP tools as ${escapeHTML(String(req.user.email ?? req.user.id))}, and you will return to ${escapeHTML(new URL(redirectURI).host || redirectURI)}.</p>
|
|
197
|
+
<form method="post">
|
|
198
|
+
<input name="consent" type="hidden" value="${seal({ type: 'consent', data: consent, expiresIn: 20 * 60 * 60, req })}">
|
|
199
|
+
<button name="decision" type="submit" value="allow">Allow</button>
|
|
200
|
+
<button name="decision" type="submit" value="deny">Deny</button>
|
|
201
|
+
</form>`,
|
|
202
|
+
status: 200,
|
|
203
|
+
title: `Allow ${client.name} to use your account?`,
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const approve: PayloadHandler = async (req) => {
|
|
208
|
+
const form = new URLSearchParams(await req.text!())
|
|
209
|
+
const consent = unseal<Consent>({ type: 'consent', req, value: form.get('consent') })
|
|
210
|
+
|
|
211
|
+
// The form is only valid for the user it was shown to
|
|
212
|
+
if (!consent || req.user?.id !== consent.userID || req.user.collection !== consent.collection) {
|
|
213
|
+
return page({
|
|
214
|
+
content: '<p>Start the sign-in again from your MCP client.</p>',
|
|
215
|
+
status: 400,
|
|
216
|
+
title: 'This sign-in request expired',
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const { clientID, codeChallenge, redirectURI, state } = consent
|
|
221
|
+
|
|
222
|
+
if (form.get('decision') !== 'allow') {
|
|
223
|
+
return redirect({ params: { error: OAuthErrorCode.AccessDenied, state }, redirectURI })
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const { issueToken = issueLoginToken } = getPluginConfig({ config: req.payload.config })
|
|
227
|
+
.oauth as MCPBuiltinOAuthConfig
|
|
228
|
+
const { accessToken, expiresIn } = await issueToken({ req })
|
|
229
|
+
|
|
230
|
+
const code: Code = { accessToken, clientID, codeChallenge, expiresIn, redirectURI }
|
|
231
|
+
|
|
232
|
+
return redirect({
|
|
233
|
+
params: { code: seal({ type: 'code', data: code, expiresIn: 60, req }), state },
|
|
234
|
+
redirectURI,
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const token: PayloadHandler = async (req) => {
|
|
239
|
+
const form = new URLSearchParams(await req.text!())
|
|
240
|
+
const code = unseal<Code>({ type: 'code', req, value: form.get('code') })
|
|
241
|
+
|
|
242
|
+
if (
|
|
243
|
+
form.get('grant_type') !== 'authorization_code' ||
|
|
244
|
+
!code ||
|
|
245
|
+
code.clientID !== form.get('client_id') ||
|
|
246
|
+
code.redirectURI !== form.get('redirect_uri') ||
|
|
247
|
+
// PKCE: only the client that started the sign-in knows the verifier
|
|
248
|
+
createHash('sha256')
|
|
249
|
+
.update(form.get('code_verifier') ?? '')
|
|
250
|
+
.digest('base64url') !== code.codeChallenge
|
|
251
|
+
) {
|
|
252
|
+
return Response.json({ error: OAuthErrorCode.InvalidGrant }, { status: 400 })
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return Response.json(
|
|
256
|
+
{
|
|
257
|
+
access_token: code.accessToken,
|
|
258
|
+
expires_in: code.expiresIn,
|
|
259
|
+
token_type: 'Bearer',
|
|
260
|
+
} satisfies OAuthTokens,
|
|
261
|
+
{ headers: { 'Cache-Control': 'no-store' } },
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The default `issueToken`: a Payload login token, which Payload's JWT strategy accepts. */
|
|
266
|
+
const issueLoginToken: NonNullable<MCPBuiltinOAuthConfig['issueToken']> = async ({ req }) => {
|
|
267
|
+
const collection = req.payload.collections[req.user!.collection]!
|
|
268
|
+
|
|
269
|
+
if (collection.config.auth.disableLocalStrategy) {
|
|
270
|
+
throw new APIError(
|
|
271
|
+
`The "${collection.config.slug}" collection has its local strategy disabled, so MCP clients can't get Payload login tokens for it. Pass oauth.issueToken to the MCP plugin.`,
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// The full document, like the one a password login starts the session on
|
|
276
|
+
const user = (await req.payload.db.findOne<NonNullable<PayloadRequest['user']>>({
|
|
277
|
+
collection: collection.config.slug,
|
|
278
|
+
req,
|
|
279
|
+
where: { id: { equals: req.user!.id } },
|
|
280
|
+
}))!
|
|
281
|
+
|
|
282
|
+
const { token } = await createAuthToken({
|
|
283
|
+
collectionConfig: collection.config,
|
|
284
|
+
email: user.email!,
|
|
285
|
+
req,
|
|
286
|
+
user,
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
return { accessToken: token, expiresIn: collection.config.auth.tokenExpiration }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Encrypts data for the client to hold, so it doesn't need to be stored. `type` keeps one kind
|
|
294
|
+
* from being used as another, e.g. a client ID as an authorization code.
|
|
295
|
+
*/
|
|
296
|
+
const seal = ({
|
|
297
|
+
type,
|
|
298
|
+
data,
|
|
299
|
+
expiresIn,
|
|
300
|
+
req,
|
|
301
|
+
}: {
|
|
302
|
+
data: object
|
|
303
|
+
/** Seconds */
|
|
304
|
+
expiresIn?: number
|
|
305
|
+
req: PayloadRequest
|
|
306
|
+
type: string
|
|
307
|
+
}): string =>
|
|
308
|
+
req.payload.encrypt(
|
|
309
|
+
JSON.stringify({ ...data, type, exp: expiresIn && Date.now() + expiresIn * 1000 }),
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
const unseal = <T>({
|
|
313
|
+
type,
|
|
314
|
+
req,
|
|
315
|
+
value,
|
|
316
|
+
}: {
|
|
317
|
+
req: PayloadRequest
|
|
318
|
+
type: string
|
|
319
|
+
value: null | string
|
|
320
|
+
}): T | undefined => {
|
|
321
|
+
// Only the v1 format is authenticated. Older formats decrypt anything without an error.
|
|
322
|
+
if (!value?.startsWith('v1:')) {
|
|
323
|
+
return undefined
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
const data = JSON.parse(req.payload.decrypt(value))
|
|
328
|
+
return data.type === type && (!data.exp || data.exp > Date.now()) ? data : undefined
|
|
329
|
+
} catch {
|
|
330
|
+
return undefined
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const redirect = ({
|
|
335
|
+
params,
|
|
336
|
+
redirectURI,
|
|
337
|
+
}: {
|
|
338
|
+
params: Record<string, null | string>
|
|
339
|
+
redirectURI: string
|
|
340
|
+
}): Response => {
|
|
341
|
+
const location = new URL(redirectURI)
|
|
342
|
+
|
|
343
|
+
for (const [key, value] of Object.entries(params)) {
|
|
344
|
+
if (value) {
|
|
345
|
+
location.searchParams.set(key, value)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return new Response(null, { headers: { Location: location.href }, status: 302 })
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const page = ({
|
|
353
|
+
content,
|
|
354
|
+
status,
|
|
355
|
+
title,
|
|
356
|
+
}: {
|
|
357
|
+
content: string
|
|
358
|
+
status: number
|
|
359
|
+
title: string
|
|
360
|
+
}): Response =>
|
|
361
|
+
new Response(
|
|
362
|
+
`<!doctype html>
|
|
363
|
+
<html lang="en">
|
|
364
|
+
<head>
|
|
365
|
+
<meta charset="utf-8">
|
|
366
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
367
|
+
<title>${escapeHTML(title)}</title>
|
|
368
|
+
<style>
|
|
369
|
+
body { font-family: system-ui, sans-serif; margin: 4rem auto; max-width: 32rem; overflow-wrap: anywhere; padding: 0 1rem }
|
|
370
|
+
button { font: inherit; margin-inline-end: 0.5rem; padding: 0.5rem 1rem }
|
|
371
|
+
</style>
|
|
372
|
+
</head>
|
|
373
|
+
<body><h1>${escapeHTML(title)}</h1>${content}</body>
|
|
374
|
+
</html>`,
|
|
375
|
+
{
|
|
376
|
+
headers: {
|
|
377
|
+
// Stop other sites from framing the page to trick users into clicking Allow
|
|
378
|
+
'Content-Security-Policy': "frame-ancestors 'none'",
|
|
379
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
380
|
+
},
|
|
381
|
+
status,
|
|
382
|
+
},
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
const escapeHTML = (value: string): string =>
|
|
386
|
+
value.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`)
|
package/src/exports/client.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { APIKeysEmptyState } from '../components/APIKeysEmptyState/index.client.js'
|
|
5
|
-
export { MCPSettingsMenu } from '../components/SettingsMenu/index.client.js'
|
|
2
|
+
|
|
3
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { filterMCPItems, getAuthorizedMCP } from '../endpoint/access.js'
|
package/src/index.ts
CHANGED
|
@@ -1,111 +1,87 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { definePlugin } from 'payload'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
AuthorizedMCP,
|
|
5
|
+
MCPBuiltinOAuthConfig,
|
|
6
|
+
MCPExternalOAuthConfig,
|
|
7
|
+
MCPOAuthConfig,
|
|
8
|
+
MCPPluginConfig,
|
|
9
|
+
SanitizedMCPPluginConfig,
|
|
10
|
+
} from './types.js'
|
|
4
11
|
|
|
5
|
-
import type { PluginDefaultTranslationsObject } from './translations/types.js'
|
|
6
|
-
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
7
|
-
|
|
8
|
-
import { getAPIKeysCollection } from './collection/index.js'
|
|
9
12
|
import { mcpEndpoint } from './endpoint/index.js'
|
|
13
|
+
import { oauthProtectedResourceEndpoint } from './endpoint/oauth.js'
|
|
14
|
+
import { oauthServerEndpoints } from './endpoint/oauthServer.js'
|
|
10
15
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
11
|
-
import { translations } from './translations/index.js'
|
|
12
16
|
|
|
13
17
|
declare module 'payload' {
|
|
14
|
-
export interface
|
|
15
|
-
|
|
18
|
+
export interface PayloadRequestAPI {
|
|
19
|
+
MCP: true
|
|
16
20
|
}
|
|
17
21
|
interface RegisteredPlugins {
|
|
18
22
|
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
19
23
|
'@payloadcms/plugin-mcp': MCPPluginConfig
|
|
20
24
|
}
|
|
25
|
+
export interface RequestContext {
|
|
26
|
+
/** Set on MCP requests before they're authenticated. */
|
|
27
|
+
mcp?: {
|
|
28
|
+
/** The MCP endpoint's address, which OAuth access tokens for MCP are issued for. */
|
|
29
|
+
resource: string
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
}
|
|
22
33
|
|
|
23
|
-
export type {
|
|
34
|
+
export type {
|
|
35
|
+
AuthorizedMCP,
|
|
36
|
+
MCPBuiltinOAuthConfig,
|
|
37
|
+
MCPExternalOAuthConfig,
|
|
38
|
+
MCPOAuthConfig,
|
|
39
|
+
MCPPluginConfig,
|
|
40
|
+
SanitizedMCPPluginConfig,
|
|
41
|
+
}
|
|
24
42
|
|
|
25
43
|
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'
|
|
44
|
+
export { oauthProtectedResourceHandler } from './endpoint/oauth.js'
|
|
26
45
|
|
|
27
46
|
export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
28
47
|
slug: '@payloadcms/plugin-mcp',
|
|
29
48
|
order: 10,
|
|
30
|
-
plugin: ({ config,
|
|
31
|
-
|
|
32
|
-
// so the relationship target and default `userCollection` exist.
|
|
33
|
-
if (!config.admin?.user) {
|
|
34
|
-
const firstCollectionWithAuth = (config.collections ?? []).find(({ auth }) => Boolean(auth))
|
|
35
|
-
if (!firstCollectionWithAuth) {
|
|
36
|
-
;(config.collections ??= []).push(defaultUserCollection)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: rawConfig })
|
|
49
|
+
plugin: ({ config, options, plugins }) => {
|
|
50
|
+
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: options })
|
|
41
51
|
|
|
42
52
|
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
43
53
|
const registered = plugins['@payloadcms/plugin-mcp']
|
|
44
54
|
if (registered) {
|
|
45
55
|
// @ts-expect-error
|
|
46
|
-
registered.sanitizedOptions = pluginConfig
|
|
56
|
+
registered.sanitizedOptions = pluginConfig
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))
|
|
50
|
-
|
|
51
|
-
if (!config.i18n) {
|
|
52
|
-
config.i18n = {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!config.i18n.translations) {
|
|
56
|
-
config.i18n.translations = {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const supportedLanguageKeys = config.i18n.supportedLanguages
|
|
60
|
-
? Object.keys(config.i18n.supportedLanguages)
|
|
61
|
-
: ['en']
|
|
62
|
-
|
|
63
|
-
for (const lang of supportedLanguageKeys) {
|
|
64
|
-
const pluginEntry = translations[lang as keyof typeof translations]
|
|
65
|
-
if (!pluginEntry) {
|
|
66
|
-
continue
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const typedLocale = lang as AcceptedLanguages
|
|
70
|
-
const existing = (config.i18n.translations[typedLocale] ?? {}) as Record<string, unknown>
|
|
71
|
-
config.i18n.translations[typedLocale] = {
|
|
72
|
-
...existing,
|
|
73
|
-
'plugin-mcp': pluginEntry.translations['plugin-mcp'],
|
|
74
|
-
} as PluginDefaultTranslationsObject
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Keep the API-keys collection registered even when disabled, so DB schema
|
|
78
|
-
// and generated types don't drift between enabled/disabled environments.
|
|
79
59
|
if (pluginConfig.disabled) {
|
|
80
60
|
return config
|
|
81
61
|
}
|
|
82
62
|
|
|
83
63
|
return {
|
|
84
64
|
...config,
|
|
85
|
-
admin: {
|
|
86
|
-
...config.admin,
|
|
87
|
-
components: {
|
|
88
|
-
...config.admin?.components,
|
|
89
|
-
userMenuSettingsItems: [
|
|
90
|
-
...(config.admin?.components?.userMenuSettingsItems ?? []),
|
|
91
|
-
{
|
|
92
|
-
group: 'MCP',
|
|
93
|
-
items: ['@payloadcms/plugin-mcp/client#MCPSettingsMenu'],
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
65
|
endpoints: [
|
|
99
66
|
...(config.endpoints ?? []),
|
|
100
|
-
// Payload prefixes /api, so the full path is /api/mcp.
|
|
101
|
-
|
|
67
|
+
// Payload prefixes /api, so the full path is /api/mcp. getAuthorizedMCP authenticates the
|
|
68
|
+
// request with dev auto-login turned off, so Payload doesn't authenticate it first.
|
|
69
|
+
{ disableAuth: true, handler: mcpEndpoint, method: 'post', path: '/mcp' },
|
|
102
70
|
// Streamable HTTP's optional server=>client GET stream. We don't offer
|
|
103
71
|
// one, so answer 405 per spec-— clients then skip it cleanly
|
|
104
72
|
{
|
|
73
|
+
disableAuth: true,
|
|
105
74
|
handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),
|
|
106
75
|
method: 'get',
|
|
107
76
|
path: '/mcp',
|
|
108
77
|
},
|
|
78
|
+
{
|
|
79
|
+
disableAuth: true,
|
|
80
|
+
handler: oauthProtectedResourceEndpoint,
|
|
81
|
+
method: 'get',
|
|
82
|
+
path: '/mcp/oauth-protected-resource',
|
|
83
|
+
},
|
|
84
|
+
...oauthServerEndpoints,
|
|
109
85
|
],
|
|
110
86
|
}
|
|
111
87
|
},
|