@payloadcms/plugin-mcp 4.0.0-internal.011fd46 → 4.0.0-internal.17c13d2
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/dist/@types/assets.d.js +2 -0
- package/dist/@types/assets.d.js.map +1 -0
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/endpoint/access.d.ts +17 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +81 -103
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +11 -0
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -4
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -4
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -54
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.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 +69 -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 +65 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +2 -0
- 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 +2 -0
- 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 +97 -0
- package/dist/mcp/builtin/collections/duplicateTool.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 +93 -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 +2 -0
- 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 +84 -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 +99 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +5 -0
- 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 +82 -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 +2 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +20 -5
- 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 +65 -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 +2 -0
- 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 +80 -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 +95 -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 +5 -0
- 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 +78 -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 +2 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +67 -2
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +64 -0
- 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 +44 -17
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -2
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +27 -8
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +43 -85
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/dist/types.js.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/package.json +10 -14
- package/src/@types/assets.d.ts +3 -0
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +87 -112
- package/src/endpoint/index.ts +14 -1
- package/src/exports/client.ts +2 -4
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +1 -58
- package/src/mcp/buildMcpServer.ts +6 -1
- package/src/mcp/builtin/collections/countTool.ts +74 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
- package/src/mcp/builtin/collections/createTool.ts +3 -0
- package/src/mcp/builtin/collections/deleteTool.ts +3 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
- package/src/mcp/builtin/collections/findTool.ts +3 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +1 -1
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +11 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
- package/src/mcp/builtin/collections/updateTool.ts +3 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +22 -4
- package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/findTool.ts +3 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +6 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
- package/src/mcp/builtin/globals/updateTool.ts +3 -0
- package/src/mcp/builtinTools.ts +63 -4
- package/src/mcp/sanitizeMCPConfig.ts +32 -19
- package/src/stdio.ts +23 -8
- package/src/types.ts +50 -88
- package/src/utils/getPluginConfig.ts +1 -1
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -72
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -105
- package/dist/collection/index.js.map +0 -1
- package/dist/components/APIKeyField/index.client.d.ts +0 -9
- package/dist/components/APIKeyField/index.client.d.ts.map +0 -1
- package/dist/components/APIKeyField/index.client.js +0 -85
- package/dist/components/APIKeyField/index.client.js.map +0 -1
- package/dist/components/APIKeyField/index.css +0 -105
- package/dist/components/APIKeysEmptyState/index.client.d.ts +0 -4
- package/dist/components/APIKeysEmptyState/index.client.d.ts.map +0 -1
- package/dist/components/APIKeysEmptyState/index.client.js +0 -21
- package/dist/components/APIKeysEmptyState/index.client.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -247
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -99
- package/dist/components/SettingsMenu/index.client.d.ts +0 -8
- package/dist/components/SettingsMenu/index.client.d.ts.map +0 -1
- package/dist/components/SettingsMenu/index.client.js +0 -24
- package/dist/components/SettingsMenu/index.client.js.map +0 -1
- package/dist/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/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/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/endpoint/access.ts
CHANGED
|
@@ -1,144 +1,119 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequest, SanitizedPermissions } from 'payload'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { UnauthorizedError } from 'payload'
|
|
3
|
+
import { getAccessResults, UnauthorizedError } from 'payload'
|
|
5
4
|
|
|
6
|
-
import type { AuthorizedMCP,
|
|
5
|
+
import type { AuthorizedMCP, MCPItem } from '../types.js'
|
|
7
6
|
|
|
8
|
-
import { getLogger } from '../utils/getLogger.js'
|
|
9
7
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
10
8
|
|
|
9
|
+
export type GetAuthorizedMCPArgs = {
|
|
10
|
+
overrideAccess: boolean
|
|
11
|
+
req: PayloadRequest
|
|
12
|
+
}
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
|
-
* Resolves the
|
|
13
|
-
*
|
|
15
|
+
* Resolves the MCP caller and returns the MCP surface authorized for that request.
|
|
16
|
+
*
|
|
17
|
+
* Authorization has two layers:
|
|
18
|
+
* 1. Payload collection/global permissions determine whether built-in operation tools are shown.
|
|
19
|
+
* 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
|
|
20
|
+
*
|
|
21
|
+
* Like Payload core operations, `overrideAccess` skips both layers.
|
|
14
22
|
*/
|
|
15
|
-
export const getAuthorizedMCP: (args:
|
|
23
|
+
export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
|
|
24
|
+
overrideAccess,
|
|
16
25
|
req,
|
|
17
26
|
}) => {
|
|
18
|
-
const logger = getLogger({ payload: req.payload })
|
|
19
27
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
20
28
|
|
|
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),
|
|
29
|
+
if (pluginConfig.overrideGetAuthorizedMCP) {
|
|
30
|
+
return await pluginConfig.overrideGetAuthorizedMCP({
|
|
31
|
+
overrideAccess,
|
|
48
32
|
pluginConfig,
|
|
49
33
|
req,
|
|
50
34
|
})
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
37
|
+
if (req.headers) {
|
|
38
|
+
const headers = new Headers(req.headers)
|
|
39
|
+
const hasAuthorization = headers.has('Authorization')
|
|
40
|
+
|
|
41
|
+
headers.set('DisableAutologin', 'true')
|
|
42
|
+
req.user = (await req.payload.auth({ headers, req })).user
|
|
43
|
+
|
|
44
|
+
if (hasAuthorization && !req.user) {
|
|
45
|
+
throw new UnauthorizedError(req.t)
|
|
46
|
+
}
|
|
61
47
|
}
|
|
62
48
|
|
|
63
|
-
return
|
|
49
|
+
return {
|
|
50
|
+
items: await filterMCPItems({
|
|
51
|
+
items: pluginConfig.items,
|
|
52
|
+
overrideAccess,
|
|
53
|
+
req,
|
|
54
|
+
}),
|
|
55
|
+
overrideAccess,
|
|
56
|
+
user: req.user,
|
|
57
|
+
}
|
|
64
58
|
}
|
|
65
59
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
pluginConfig,
|
|
60
|
+
export const filterMCPItems = async ({
|
|
61
|
+
items,
|
|
62
|
+
overrideAccess,
|
|
70
63
|
req,
|
|
71
64
|
}: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pluginConfig: ReturnType<typeof getPluginConfig>
|
|
65
|
+
items: MCPItem[]
|
|
66
|
+
overrideAccess: boolean
|
|
75
67
|
req: PayloadRequest
|
|
76
|
-
}): Promise<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null)
|
|
82
|
-
|
|
83
|
-
if (!apiKey) {
|
|
84
|
-
throw new UnauthorizedError()
|
|
68
|
+
}): Promise<MCPItem[]> => {
|
|
69
|
+
// Match Payload core: overrideAccess bypasses access evaluation instead of
|
|
70
|
+
// forcing each access function to return true.
|
|
71
|
+
if (overrideAccess) {
|
|
72
|
+
return items
|
|
85
73
|
}
|
|
86
74
|
|
|
87
|
-
const
|
|
88
|
-
.createHmac('sha256', req.payload.secret)
|
|
89
|
-
.update(apiKey)
|
|
90
|
-
.digest('hex')
|
|
91
|
-
|
|
92
|
-
const doc = await req.payload.db.findOne<MCPAPIKeysDoc>({
|
|
93
|
-
collection: 'payload-mcp-api-keys',
|
|
94
|
-
req,
|
|
95
|
-
where: {
|
|
96
|
-
apiKeyIndex: { equals: sha256APIKeyIndex },
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
if (!doc || !doc.user) {
|
|
101
|
-
throw new UnauthorizedError()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
logger.info('API Key is valid')
|
|
75
|
+
const authorizedItems: MCPItem[] = []
|
|
105
76
|
|
|
106
|
-
const
|
|
107
|
-
const userID =
|
|
108
|
-
typeof userRef === 'object' && userRef !== null && 'id' in userRef
|
|
109
|
-
? userRef.id
|
|
110
|
-
: (userRef as unknown as DefaultDocumentIDType)
|
|
77
|
+
const permissions = await getAccessResults({ req })
|
|
111
78
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
req,
|
|
118
|
-
})) as null | TypedUser
|
|
119
|
-
|
|
120
|
-
if (!user) {
|
|
121
|
-
throw new UnauthorizedError()
|
|
79
|
+
for (const item of items) {
|
|
80
|
+
if (!(await checkItemAccess({ item, permissions, req }))) {
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
authorizedItems.push(item)
|
|
122
84
|
}
|
|
123
85
|
|
|
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
|
-
}
|
|
86
|
+
return authorizedItems
|
|
87
|
+
}
|
|
135
88
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Runs MCP item access callbacks
|
|
91
|
+
*/
|
|
92
|
+
const checkItemAccess = async ({
|
|
93
|
+
item,
|
|
94
|
+
permissions,
|
|
95
|
+
req,
|
|
96
|
+
}: {
|
|
97
|
+
item: MCPItem
|
|
98
|
+
permissions?: SanitizedPermissions
|
|
99
|
+
req: PayloadRequest
|
|
100
|
+
}): Promise<boolean> => {
|
|
101
|
+
switch (item.type) {
|
|
102
|
+
case 'collectionTool':
|
|
103
|
+
return (
|
|
104
|
+
!item.tool.access ||
|
|
105
|
+
(await item.tool.access({ collectionSlug: item.collectionSlug, permissions, req }))
|
|
106
|
+
)
|
|
107
|
+
case 'globalTool':
|
|
108
|
+
return (
|
|
109
|
+
!item.tool.access ||
|
|
110
|
+
(await item.tool.access({ globalSlug: item.globalSlug, permissions, req }))
|
|
111
|
+
)
|
|
112
|
+
case 'prompt':
|
|
113
|
+
return !item.prompt.access || (await item.prompt.access({ permissions, req }))
|
|
114
|
+
case 'resource':
|
|
115
|
+
return !item.resource.access || (await item.resource.access({ permissions, req }))
|
|
116
|
+
case 'tool':
|
|
117
|
+
return !item.tool.access || (await item.tool.access({ permissions, req }))
|
|
143
118
|
}
|
|
144
119
|
}
|
package/src/endpoint/index.ts
CHANGED
|
@@ -13,7 +13,20 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
13
13
|
req.payloadAPI = 'MCP' as const
|
|
14
14
|
|
|
15
15
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
16
|
-
const
|
|
16
|
+
const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
|
|
17
|
+
|
|
18
|
+
if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {
|
|
19
|
+
throw new APIError('MCP overrideAccess is only available in development.', 400)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let overrideAccess = false
|
|
23
|
+
if (overrideAccessParam === 'true') {
|
|
24
|
+
overrideAccess = true
|
|
25
|
+
} else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {
|
|
26
|
+
throw new APIError('MCP overrideAccess must be "true" or "false".', 400)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
17
30
|
|
|
18
31
|
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
19
32
|
|
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,14 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { definePlugin } from 'payload'
|
|
2
2
|
|
|
3
|
-
import { defaultUserCollection, definePlugin } from 'payload'
|
|
4
|
-
|
|
5
|
-
import type { PluginDefaultTranslationsObject } from './translations/types.js'
|
|
6
3
|
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
7
4
|
|
|
8
|
-
import { getAPIKeysCollection } from './collection/index.js'
|
|
9
5
|
import { mcpEndpoint } from './endpoint/index.js'
|
|
10
6
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
11
|
-
import { translations } from './translations/index.js'
|
|
12
7
|
|
|
13
8
|
declare module 'payload' {
|
|
14
9
|
export interface PayloadRequest {
|
|
@@ -28,15 +23,6 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
28
23
|
slug: '@payloadcms/plugin-mcp',
|
|
29
24
|
order: 10,
|
|
30
25
|
plugin: ({ config, plugins, ...rawConfig }) => {
|
|
31
|
-
// If a project has no auth collection yet, add the default users collection
|
|
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
26
|
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: rawConfig })
|
|
41
27
|
|
|
42
28
|
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
@@ -46,55 +32,12 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
46
32
|
registered.sanitizedOptions = pluginConfig as unknown as typeof registered.options
|
|
47
33
|
}
|
|
48
34
|
|
|
49
|
-
;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))
|
|
50
|
-
|
|
51
|
-
if (!config.i18n) {
|
|
52
|
-
config.i18n = {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!config.i18n.translations) {
|
|
56
|
-
config.i18n.translations = {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const supportedLanguageKeys = config.i18n.supportedLanguages
|
|
60
|
-
? Object.keys(config.i18n.supportedLanguages)
|
|
61
|
-
: ['en']
|
|
62
|
-
|
|
63
|
-
for (const lang of supportedLanguageKeys) {
|
|
64
|
-
const pluginEntry = translations[lang as keyof typeof translations]
|
|
65
|
-
if (!pluginEntry) {
|
|
66
|
-
continue
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const typedLocale = lang as AcceptedLanguages
|
|
70
|
-
const existing = (config.i18n.translations[typedLocale] ?? {}) as Record<string, unknown>
|
|
71
|
-
config.i18n.translations[typedLocale] = {
|
|
72
|
-
...existing,
|
|
73
|
-
'plugin-mcp': pluginEntry.translations['plugin-mcp'],
|
|
74
|
-
} as PluginDefaultTranslationsObject
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Keep the API-keys collection registered even when disabled, so DB schema
|
|
78
|
-
// and generated types don't drift between enabled/disabled environments.
|
|
79
35
|
if (pluginConfig.disabled) {
|
|
80
36
|
return config
|
|
81
37
|
}
|
|
82
38
|
|
|
83
39
|
return {
|
|
84
40
|
...config,
|
|
85
|
-
admin: {
|
|
86
|
-
...config.admin,
|
|
87
|
-
components: {
|
|
88
|
-
...config.admin?.components,
|
|
89
|
-
userMenuSettingsItems: [
|
|
90
|
-
...(config.admin?.components?.userMenuSettingsItems ?? []),
|
|
91
|
-
{
|
|
92
|
-
group: 'MCP',
|
|
93
|
-
items: ['@payloadcms/plugin-mcp/client#MCPSettingsMenu'],
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
41
|
endpoints: [
|
|
99
42
|
...(config.endpoints ?? []),
|
|
100
43
|
// Payload prefixes /api, so the full path is /api/mcp.
|
|
@@ -109,7 +109,12 @@ export const buildMcpServer = ({
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const handlerArgs = {
|
|
112
|
+
const handlerArgs = {
|
|
113
|
+
authorizedMCP,
|
|
114
|
+
input: toolInput,
|
|
115
|
+
req,
|
|
116
|
+
serverContext,
|
|
117
|
+
}
|
|
113
118
|
const response = await (match.type === 'collectionTool'
|
|
114
119
|
? match.tool.handler({ ...handlerArgs, collectionSlug: slug })
|
|
115
120
|
: match.tool.handler({ ...handlerArgs, globalSlug: slug }))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Count documents in any collection by passing the collection slug and optional where clause.'
|
|
11
|
+
|
|
12
|
+
export const countDocumentsTool = defineCollectionTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
idempotentHint: true,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: true,
|
|
20
|
+
title: 'Count Documents',
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
locale: z.string().describe('Optional: locale code to count documents in').optional(),
|
|
25
|
+
trash: z
|
|
26
|
+
.boolean()
|
|
27
|
+
.describe('Optional: include soft-deleted documents when trash is enabled on the collection')
|
|
28
|
+
.optional(),
|
|
29
|
+
where: whereSchema
|
|
30
|
+
.describe(
|
|
31
|
+
'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
32
|
+
)
|
|
33
|
+
.optional(),
|
|
34
|
+
}),
|
|
35
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
36
|
+
const payload = req.payload
|
|
37
|
+
const logger = getLogger({ payload })
|
|
38
|
+
const { locale, trash, where } = input
|
|
39
|
+
|
|
40
|
+
logger.info(`Counting documents in collection: ${collectionSlug}`)
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = await payload.count({
|
|
44
|
+
collection: collectionSlug,
|
|
45
|
+
req,
|
|
46
|
+
...localAPIDefaults(authorizedMCP),
|
|
47
|
+
...(locale ? { locale } : {}),
|
|
48
|
+
...(trash !== undefined ? { trash } : {}),
|
|
49
|
+
...(where ? { where } : {}),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
text: `Collection "${collectionSlug}" contains ${result.totalDocs} matching documents.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
doc: result,
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
63
|
+
logger.error(`Error counting documents in ${collectionSlug}: ${errorMessage}`)
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
text: `❌ **Error counting documents in collection "${collectionSlug}":** ${errorMessage}`,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
isError: true,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Count document versions in any version-enabled collection by passing the collection slug and optional where clause.'
|
|
11
|
+
|
|
12
|
+
export const countVersionsTool = defineCollectionTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) &&
|
|
15
|
+
Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
|
|
16
|
+
annotations: {
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
readOnlyHint: true,
|
|
21
|
+
title: 'Count Versions',
|
|
22
|
+
},
|
|
23
|
+
description: DEFAULT_DESCRIPTION,
|
|
24
|
+
input: z.object({
|
|
25
|
+
locale: z.string().describe('Optional: locale code to count versions in').optional(),
|
|
26
|
+
where: whereSchema
|
|
27
|
+
.describe(
|
|
28
|
+
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}',
|
|
29
|
+
)
|
|
30
|
+
.optional(),
|
|
31
|
+
}),
|
|
32
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
33
|
+
const payload = req.payload
|
|
34
|
+
const logger = getLogger({ payload })
|
|
35
|
+
const { locale, where } = input
|
|
36
|
+
|
|
37
|
+
logger.info(`Counting versions in collection: ${collectionSlug}`)
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const result = await payload.countVersions({
|
|
41
|
+
collection: collectionSlug,
|
|
42
|
+
req,
|
|
43
|
+
...localAPIDefaults(authorizedMCP),
|
|
44
|
+
...(locale ? { locale } : {}),
|
|
45
|
+
...(where ? { where } : {}),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: 'text',
|
|
52
|
+
text: `Collection "${collectionSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
doc: result,
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
59
|
+
logger.error(`Error counting versions in ${collectionSlug}: ${errorMessage}`)
|
|
60
|
+
return {
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
63
|
+
type: 'text',
|
|
64
|
+
text: `❌ **Error counting versions in collection "${collectionSlug}":** ${errorMessage}`,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
isError: true,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
@@ -2,6 +2,7 @@ import type { SelectType } from 'payload'
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
8
|
import {
|
|
@@ -17,6 +18,8 @@ const DEFAULT_DESCRIPTION =
|
|
|
17
18
|
'Create a document in any collection by passing the collection slug and data.'
|
|
18
19
|
|
|
19
20
|
export const createDocumentTool = defineCollectionTool({
|
|
21
|
+
access: (args) =>
|
|
22
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),
|
|
20
23
|
annotations: {
|
|
21
24
|
destructiveHint: false,
|
|
22
25
|
idempotentHint: false,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
3
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
4
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
5
6
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
@@ -9,6 +10,8 @@ const DEFAULT_DESCRIPTION =
|
|
|
9
10
|
'Delete documents in any collection by passing the collection slug and ID or where clause.'
|
|
10
11
|
|
|
11
12
|
export const deleteDocumentsTool = defineCollectionTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.delete),
|
|
12
15
|
annotations: {
|
|
13
16
|
destructiveHint: true,
|
|
14
17
|
idempotentHint: false,
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
import {
|
|
9
|
+
getCollectionVirtualFieldNames,
|
|
10
|
+
stripVirtualFields,
|
|
11
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
|
+
import { formatCollectionError } from './formatCollectionError.js'
|
|
15
|
+
|
|
16
|
+
const DEFAULT_DESCRIPTION =
|
|
17
|
+
'Duplicate a document in any collection by passing the collection slug and source document ID.'
|
|
18
|
+
|
|
19
|
+
export const duplicateDocumentTool = defineCollectionTool({
|
|
20
|
+
access: (args) =>
|
|
21
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),
|
|
22
|
+
annotations: {
|
|
23
|
+
destructiveHint: false,
|
|
24
|
+
idempotentHint: false,
|
|
25
|
+
openWorldHint: false,
|
|
26
|
+
readOnlyHint: false,
|
|
27
|
+
title: 'Duplicate Document',
|
|
28
|
+
},
|
|
29
|
+
description: DEFAULT_DESCRIPTION,
|
|
30
|
+
input: z.object({
|
|
31
|
+
id: z.union([z.string(), z.number()]).describe('The ID of the document to duplicate'),
|
|
32
|
+
data: z
|
|
33
|
+
.record(z.string(), z.unknown())
|
|
34
|
+
.describe('Optional: fields to override on the duplicated document')
|
|
35
|
+
.optional(),
|
|
36
|
+
depth: z
|
|
37
|
+
.number()
|
|
38
|
+
.int()
|
|
39
|
+
.min(0)
|
|
40
|
+
.max(10)
|
|
41
|
+
.describe('How many levels deep to populate relationships in response')
|
|
42
|
+
.optional()
|
|
43
|
+
.default(0),
|
|
44
|
+
draft: z
|
|
45
|
+
.boolean()
|
|
46
|
+
.describe('Whether to create the duplicate as a draft')
|
|
47
|
+
.optional()
|
|
48
|
+
.default(false),
|
|
49
|
+
fallbackLocale: z
|
|
50
|
+
.string()
|
|
51
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
52
|
+
.optional(),
|
|
53
|
+
locale: z
|
|
54
|
+
.string()
|
|
55
|
+
.describe(
|
|
56
|
+
'Optional: locale code to duplicate in (e.g., "en", "es"). Defaults to the default locale',
|
|
57
|
+
)
|
|
58
|
+
.optional(),
|
|
59
|
+
populate: z
|
|
60
|
+
.record(z.string(), z.unknown())
|
|
61
|
+
.describe(
|
|
62
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
63
|
+
)
|
|
64
|
+
.optional(),
|
|
65
|
+
select: z
|
|
66
|
+
.record(z.string(), z.unknown())
|
|
67
|
+
.describe(
|
|
68
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
|
|
69
|
+
)
|
|
70
|
+
.optional(),
|
|
71
|
+
selectedLocales: z
|
|
72
|
+
.array(z.string())
|
|
73
|
+
.describe('Optional: localized field locales to include in the duplicated document')
|
|
74
|
+
.optional(),
|
|
75
|
+
showHiddenFields: z
|
|
76
|
+
.boolean()
|
|
77
|
+
.describe('Optional: include hidden fields in the duplicated document response')
|
|
78
|
+
.optional(),
|
|
79
|
+
}),
|
|
80
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
81
|
+
const payload = req.payload
|
|
82
|
+
const logger = getLogger({ payload })
|
|
83
|
+
const {
|
|
84
|
+
id,
|
|
85
|
+
data,
|
|
86
|
+
depth,
|
|
87
|
+
draft,
|
|
88
|
+
fallbackLocale,
|
|
89
|
+
locale,
|
|
90
|
+
populate,
|
|
91
|
+
select,
|
|
92
|
+
selectedLocales,
|
|
93
|
+
showHiddenFields,
|
|
94
|
+
} = input
|
|
95
|
+
|
|
96
|
+
logger.info(`Duplicating document in collection: ${collectionSlug} with ID: ${id}`)
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
100
|
+
const inputData = data ? stripVirtualFields(data, virtualFieldNames) : undefined
|
|
101
|
+
const parsedData = inputData ? transformPointDataToPayload(inputData) : undefined
|
|
102
|
+
|
|
103
|
+
const result = await payload.duplicate({
|
|
104
|
+
id,
|
|
105
|
+
collection: collectionSlug,
|
|
106
|
+
depth,
|
|
107
|
+
draft,
|
|
108
|
+
req,
|
|
109
|
+
...localAPIDefaults(authorizedMCP),
|
|
110
|
+
...(parsedData ? { data: parsedData } : {}),
|
|
111
|
+
...(locale ? { locale } : {}),
|
|
112
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
113
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
114
|
+
...(select ? { select: select as SelectType } : {}),
|
|
115
|
+
...(selectedLocales ? { selectedLocales } : {}),
|
|
116
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
logger.info(`Successfully duplicated document in ${collectionSlug} from ID: ${id}`)
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: `Document duplicated successfully in collection "${collectionSlug}"!\nDuplicated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
doc: result as Record<string, unknown>,
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
132
|
+
logger.error(`Error duplicating document in ${collectionSlug}: ${errorMessage}`)
|
|
133
|
+
return formatCollectionError({ action: 'duplicating', collectionSlug, error, req })
|
|
134
|
+
}
|
|
135
|
+
})
|