@payloadcms/plugin-mcp 4.0.0-internal.5f0cd13 → 4.0.0-internal.63f8536
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/endpoint/access.d.ts +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +75 -88
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +68 -17
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -20
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +4 -4
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +133 -73
- 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 +44 -6
- 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 +68 -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 +64 -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 +39 -40
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +15 -22
- 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 +96 -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 +92 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +51 -46
- 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 +83 -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 +98 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- 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 +81 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +88 -84
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- 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 +64 -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 +20 -23
- 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 +79 -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 +94 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- 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 +77 -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 +33 -38
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +144 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +119 -20
- 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 +121 -58
- 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 +82 -45
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +112 -110
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -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/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +11 -16
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +81 -101
- package/src/endpoint/index.ts +58 -16
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +12 -20
- package/src/mcp/buildMcpServer.ts +169 -109
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- package/src/mcp/builtin/collections/countTool.ts +73 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/collections/createTool.ts +56 -61
- package/src/mcp/builtin/collections/deleteTool.ts +20 -18
- package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +65 -36
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
- package/src/mcp/builtin/collections/updateTool.ts +112 -107
- package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
- package/src/mcp/builtin/globals/findTool.ts +28 -19
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
- package/src/mcp/builtin/globals/updateTool.ts +52 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +117 -78
- package/src/stdio.ts +77 -45
- package/src/types.ts +128 -115
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -57
- 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 -59
- package/dist/collection/index.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 -305
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -93
- 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/prepareCollectionSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
- package/dist/utils/schemaConversion/prepareCollectionSchema.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/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -57
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -63
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
- package/src/utils/schemaConversion/transformPointFields.ts +0 -56
package/src/mcp/builtinTools.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionTool, GlobalTool } from '../types.js'
|
|
1
|
+
import type { CollectionTool, GlobalTool, Tool } from '../types.js'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
authCollectionTool,
|
|
@@ -8,62 +8,128 @@ import {
|
|
|
8
8
|
unlockCollectionTool,
|
|
9
9
|
verifyCollectionTool,
|
|
10
10
|
} from './builtin/collections/authTools.js'
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import { countDocumentsTool } from './builtin/collections/countTool.js'
|
|
12
|
+
import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
|
|
13
|
+
import { createDocumentTool } from './builtin/collections/createTool.js'
|
|
14
|
+
import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
|
|
15
|
+
import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
|
|
16
|
+
import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
|
|
17
|
+
import { findDocumentsTool } from './builtin/collections/findTool.js'
|
|
18
|
+
import { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'
|
|
19
|
+
import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
|
|
20
|
+
import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
|
|
21
|
+
import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
|
|
22
|
+
import { updateDocumentTool } from './builtin/collections/updateTool.js'
|
|
23
|
+
import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
|
|
24
|
+
import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
|
|
15
25
|
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
26
|
+
import { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'
|
|
27
|
+
import { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'
|
|
28
|
+
import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'
|
|
29
|
+
import { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'
|
|
16
30
|
import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
17
31
|
|
|
32
|
+
type CollectionBuiltin = {
|
|
33
|
+
mcpName: string
|
|
34
|
+
requiresDuplicateEnabled?: boolean
|
|
35
|
+
requiresVersions?: boolean
|
|
36
|
+
tool: CollectionTool
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type GlobalBuiltin = {
|
|
40
|
+
mcpName: string
|
|
41
|
+
requiresVersions?: boolean
|
|
42
|
+
tool: GlobalTool
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const TOOL_BUILTINS = {
|
|
46
|
+
getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },
|
|
47
|
+
} satisfies Record<string, { mcpName: string; tool: Tool }>
|
|
48
|
+
|
|
18
49
|
/**
|
|
19
50
|
* The static built-in collection CRUD tools. Keys here are the source of truth
|
|
20
51
|
* for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
|
|
21
52
|
* automatically.
|
|
22
53
|
*/
|
|
23
|
-
export const COLLECTION_BUILTINS
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
export const COLLECTION_BUILTINS = {
|
|
55
|
+
count: { mcpName: 'countDocuments', tool: countDocumentsTool },
|
|
56
|
+
countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
|
|
57
|
+
create: { mcpName: 'createDocument', tool: createDocumentTool },
|
|
58
|
+
delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
|
|
59
|
+
duplicate: {
|
|
60
|
+
mcpName: 'duplicateDocument',
|
|
61
|
+
requiresDuplicateEnabled: true,
|
|
62
|
+
tool: duplicateDocumentTool,
|
|
63
|
+
},
|
|
64
|
+
find: { mcpName: 'findDocuments', tool: findDocumentsTool },
|
|
65
|
+
findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },
|
|
66
|
+
findVersionByID: {
|
|
67
|
+
mcpName: 'findVersionByID',
|
|
68
|
+
requiresVersions: true,
|
|
69
|
+
tool: findVersionByIDTool,
|
|
70
|
+
},
|
|
71
|
+
findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
|
|
72
|
+
getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
|
|
73
|
+
restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
|
|
74
|
+
update: { mcpName: 'updateDocument', tool: updateDocumentTool },
|
|
75
|
+
} satisfies Record<string, CollectionBuiltin>
|
|
29
76
|
|
|
30
77
|
/**
|
|
31
|
-
* The static auth tools surfaced under auth-enabled collections.
|
|
32
|
-
*
|
|
33
|
-
* for `MCPCollectionAuthToolName`.
|
|
78
|
+
* The static auth tools surfaced under auth-enabled collections. Keys are the
|
|
79
|
+
* source of truth for `MCPCollectionAuthToolName`.
|
|
34
80
|
*/
|
|
35
|
-
export const COLLECTION_AUTH_BUILTINS
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
login: {
|
|
42
|
-
resetPassword: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
81
|
+
export const COLLECTION_AUTH_BUILTINS = {
|
|
82
|
+
auth: { mcpName: 'auth', tool: authCollectionTool },
|
|
83
|
+
forgotPassword: {
|
|
84
|
+
mcpName: 'forgotPassword',
|
|
85
|
+
tool: forgotPasswordCollectionTool,
|
|
86
|
+
},
|
|
87
|
+
login: { mcpName: 'login', tool: loginCollectionTool },
|
|
88
|
+
resetPassword: {
|
|
89
|
+
mcpName: 'resetPassword',
|
|
90
|
+
tool: resetPasswordCollectionTool,
|
|
91
|
+
},
|
|
92
|
+
unlock: { mcpName: 'unlock', tool: unlockCollectionTool },
|
|
93
|
+
verify: { mcpName: 'verify', tool: verifyCollectionTool },
|
|
94
|
+
} satisfies Record<string, { mcpName: string; tool: CollectionTool }>
|
|
46
95
|
|
|
47
96
|
/**
|
|
48
97
|
* The static built-in global tools. Keys are the source of truth for
|
|
49
98
|
* `MCPGlobalBuiltinName`.
|
|
50
99
|
*/
|
|
51
|
-
export const GLOBAL_BUILTINS
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
export const GLOBAL_BUILTINS = {
|
|
101
|
+
countGlobalVersions: {
|
|
102
|
+
mcpName: 'countGlobalVersions',
|
|
103
|
+
requiresVersions: true,
|
|
104
|
+
tool: countGlobalVersionsTool,
|
|
105
|
+
},
|
|
106
|
+
find: { mcpName: 'findGlobal', tool: findGlobalTool },
|
|
107
|
+
findGlobalVersionByID: {
|
|
108
|
+
mcpName: 'findGlobalVersionByID',
|
|
109
|
+
requiresVersions: true,
|
|
110
|
+
tool: findGlobalVersionByIDTool,
|
|
111
|
+
},
|
|
112
|
+
findGlobalVersions: {
|
|
113
|
+
mcpName: 'findGlobalVersions',
|
|
114
|
+
requiresVersions: true,
|
|
115
|
+
tool: findGlobalVersionsTool,
|
|
116
|
+
},
|
|
117
|
+
getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },
|
|
118
|
+
restoreGlobalVersion: {
|
|
119
|
+
mcpName: 'restoreGlobalVersion',
|
|
120
|
+
requiresVersions: true,
|
|
121
|
+
tool: restoreGlobalVersionTool,
|
|
122
|
+
},
|
|
123
|
+
update: { mcpName: 'updateGlobal', tool: updateGlobalTool },
|
|
124
|
+
} satisfies Record<string, GlobalBuiltin>
|
|
125
|
+
|
|
126
|
+
export type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS
|
|
55
127
|
|
|
56
|
-
export type
|
|
128
|
+
export type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS
|
|
57
129
|
|
|
58
|
-
export type
|
|
59
|
-
| 'auth'
|
|
60
|
-
| 'forgotPassword'
|
|
61
|
-
| 'login'
|
|
62
|
-
| 'resetPassword'
|
|
63
|
-
| 'unlock'
|
|
64
|
-
| 'verify'
|
|
130
|
+
export type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS
|
|
65
131
|
|
|
66
|
-
export type
|
|
132
|
+
export type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS
|
|
67
133
|
|
|
68
134
|
/**
|
|
69
135
|
* Pre-typed `Object.entries` for each registry. The cast from `string` to the
|
|
@@ -71,14 +137,18 @@ export type MCPGlobalBuiltinName = 'find' | 'update'
|
|
|
71
137
|
* cast — TypeScript's `Object.entries` always widens keys to `string`, which
|
|
72
138
|
* defeats the narrow type lookups on `MCPCollectionToolsMap`.
|
|
73
139
|
*/
|
|
140
|
+
export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<
|
|
141
|
+
[MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]
|
|
142
|
+
>
|
|
143
|
+
|
|
74
144
|
export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
|
|
75
|
-
[MCPCollectionBuiltinName,
|
|
145
|
+
[MCPCollectionBuiltinName, CollectionBuiltin]
|
|
76
146
|
>
|
|
77
147
|
|
|
78
148
|
export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
|
|
79
|
-
[MCPCollectionAuthToolName,
|
|
149
|
+
[MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]
|
|
80
150
|
>
|
|
81
151
|
|
|
82
152
|
export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
|
|
83
|
-
[MCPGlobalBuiltinName,
|
|
153
|
+
[MCPGlobalBuiltinName, GlobalBuiltin]
|
|
84
154
|
>
|
|
@@ -8,16 +8,16 @@ import type {
|
|
|
8
8
|
} from 'payload'
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
|
+
CollectionMCPItem,
|
|
11
12
|
CollectionTool,
|
|
13
|
+
GlobalMCPItem,
|
|
12
14
|
GlobalTool,
|
|
13
|
-
MCPBuiltInToolOverride,
|
|
14
15
|
MCPItem,
|
|
15
|
-
MCPPluginCollectionConfig,
|
|
16
16
|
MCPPluginConfig,
|
|
17
|
-
MCPPluginGlobalConfig,
|
|
18
17
|
SanitizedMCPPluginConfig,
|
|
19
18
|
} from '../types.js'
|
|
20
19
|
|
|
20
|
+
import { defaultAccess } from '../defaultAccess.js'
|
|
21
21
|
import {
|
|
22
22
|
COLLECTION_AUTH_BUILTIN_ENTRIES,
|
|
23
23
|
COLLECTION_AUTH_BUILTINS,
|
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
COLLECTION_BUILTINS,
|
|
26
26
|
GLOBAL_BUILTIN_ENTRIES,
|
|
27
27
|
GLOBAL_BUILTINS,
|
|
28
|
+
TOOL_BUILTIN_ENTRIES,
|
|
29
|
+
TOOL_BUILTINS,
|
|
28
30
|
} from './builtinTools.js'
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -32,7 +34,6 @@ import {
|
|
|
32
34
|
* - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
|
|
33
35
|
* tool maps into a single `items` array.
|
|
34
36
|
* - Applies built-in tools for collections and globals, respecting opt-out user overrides.
|
|
35
|
-
* - Applies the `userCollection` default
|
|
36
37
|
*
|
|
37
38
|
* Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
|
|
38
39
|
* ?.options` holds the sanitized result
|
|
@@ -54,44 +55,55 @@ export const sanitizeMCPConfig = ({
|
|
|
54
55
|
items.push(...sanitizeGlobalConfig({ global, pluginConfig }))
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
for (const [
|
|
58
|
+
for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {
|
|
58
59
|
items.push({
|
|
59
60
|
type: 'tool',
|
|
60
|
-
|
|
61
|
-
label:
|
|
62
|
-
|
|
61
|
+
configKey,
|
|
62
|
+
label: tool.annotations?.title ?? configKey,
|
|
63
|
+
mcpName,
|
|
64
|
+
tool: { ...tool, access: tool.access ?? defaultAccess },
|
|
63
65
|
})
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
for (const [
|
|
68
|
+
for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {
|
|
69
|
+
if (configKey in TOOL_BUILTINS) {
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
items.push({
|
|
73
|
+
type: 'tool',
|
|
74
|
+
configKey,
|
|
75
|
+
label: tool.annotations?.title ?? configKey,
|
|
76
|
+
mcpName: configKey,
|
|
77
|
+
tool: { ...tool, access: tool.access ?? defaultAccess },
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {
|
|
67
82
|
items.push({
|
|
68
83
|
type: 'prompt',
|
|
69
|
-
|
|
70
|
-
label: prompt.title ??
|
|
71
|
-
|
|
84
|
+
configKey,
|
|
85
|
+
label: prompt.title ?? configKey,
|
|
86
|
+
mcpName: configKey,
|
|
87
|
+
prompt: { ...prompt, access: prompt.access ?? defaultAccess },
|
|
72
88
|
})
|
|
73
89
|
}
|
|
74
90
|
|
|
75
|
-
for (const [
|
|
91
|
+
for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {
|
|
76
92
|
items.push({
|
|
77
93
|
type: 'resource',
|
|
78
|
-
|
|
79
|
-
label: resource.title ??
|
|
80
|
-
|
|
94
|
+
configKey,
|
|
95
|
+
label: resource.title ?? configKey,
|
|
96
|
+
mcpName: configKey,
|
|
97
|
+
resource: { ...resource, access: resource.access ?? defaultAccess },
|
|
81
98
|
})
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
// Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
|
|
85
|
-
const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))
|
|
86
|
-
|
|
87
101
|
return {
|
|
88
102
|
disabled: pluginConfig.disabled,
|
|
103
|
+
hooks: pluginConfig.hooks,
|
|
89
104
|
items,
|
|
90
105
|
mcp: pluginConfig.mcp,
|
|
91
|
-
|
|
92
|
-
overrideAuth: pluginConfig.overrideAuth,
|
|
93
|
-
userCollection:
|
|
94
|
-
pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',
|
|
106
|
+
overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
|
|
95
107
|
}
|
|
96
108
|
}
|
|
97
109
|
|
|
@@ -101,42 +113,78 @@ const sanitizeCollectionConfig = ({
|
|
|
101
113
|
}: {
|
|
102
114
|
collection: CollectionConfig | SanitizedCollectionConfig
|
|
103
115
|
pluginConfig: MCPPluginConfig
|
|
104
|
-
}):
|
|
105
|
-
if (collection.slug === 'payload-mcp-api-keys') {
|
|
106
|
-
return []
|
|
107
|
-
}
|
|
116
|
+
}): CollectionMCPItem[] => {
|
|
108
117
|
const slug = collection.slug
|
|
109
118
|
const collectionPluginConfig = pluginConfig.collections?.[slug]
|
|
110
|
-
const items:
|
|
119
|
+
const items: CollectionMCPItem[] = []
|
|
120
|
+
/**
|
|
121
|
+
* Payload disables duplicate for auth collections by default unless the
|
|
122
|
+
* collection explicitly opts back in with `disableDuplicate: false`.
|
|
123
|
+
*/
|
|
124
|
+
const isDuplicateDisabled =
|
|
125
|
+
collection.disableDuplicate === true ||
|
|
126
|
+
(Boolean(collection.auth) && collection.disableDuplicate !== false)
|
|
111
127
|
|
|
112
|
-
for (const [
|
|
128
|
+
for (const [
|
|
129
|
+
toolKey,
|
|
130
|
+
{ mcpName, requiresDuplicateEnabled, requiresVersions, tool },
|
|
131
|
+
] of COLLECTION_BUILTIN_ENTRIES) {
|
|
132
|
+
if (requiresVersions && !collection.versions) {
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
136
|
+
continue
|
|
137
|
+
}
|
|
113
138
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
|
|
114
139
|
if (matchedConfigEntry === false) {
|
|
115
140
|
continue
|
|
116
141
|
}
|
|
142
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
143
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
117
144
|
items.push({
|
|
118
145
|
type: 'collectionTool',
|
|
119
146
|
collectionSlug: slug,
|
|
120
|
-
|
|
121
|
-
label:
|
|
122
|
-
|
|
147
|
+
configKey: toolKey,
|
|
148
|
+
label: annotations.title ?? toolKey,
|
|
149
|
+
mcpName,
|
|
150
|
+
tool: {
|
|
151
|
+
...tool,
|
|
152
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
153
|
+
annotations,
|
|
154
|
+
description: override?.description ?? tool.description,
|
|
155
|
+
overrideResponse:
|
|
156
|
+
override?.overrideResponse ??
|
|
157
|
+
collectionPluginConfig?.overrideResponse ??
|
|
158
|
+
tool.overrideResponse,
|
|
159
|
+
},
|
|
123
160
|
})
|
|
124
161
|
}
|
|
125
162
|
|
|
126
163
|
if (collection.auth) {
|
|
127
|
-
for (const [authToolKey, {
|
|
164
|
+
for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {
|
|
128
165
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]
|
|
129
166
|
if (!matchedConfigEntry) {
|
|
130
167
|
continue
|
|
131
168
|
}
|
|
132
169
|
// `true` means "enable, no override"; only the object form carries fields.
|
|
133
170
|
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
171
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
134
172
|
items.push({
|
|
135
173
|
type: 'collectionTool',
|
|
136
174
|
collectionSlug: slug,
|
|
137
|
-
|
|
138
|
-
label,
|
|
139
|
-
|
|
175
|
+
configKey: authToolKey,
|
|
176
|
+
label: annotations.title ?? authToolKey,
|
|
177
|
+
mcpName,
|
|
178
|
+
tool: {
|
|
179
|
+
...tool,
|
|
180
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
181
|
+
annotations,
|
|
182
|
+
description: override?.description ?? tool.description,
|
|
183
|
+
overrideResponse:
|
|
184
|
+
override?.overrideResponse ??
|
|
185
|
+
collectionPluginConfig?.overrideResponse ??
|
|
186
|
+
tool.overrideResponse,
|
|
187
|
+
},
|
|
140
188
|
})
|
|
141
189
|
}
|
|
142
190
|
}
|
|
@@ -146,8 +194,8 @@ const sanitizeCollectionConfig = ({
|
|
|
146
194
|
const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<
|
|
147
195
|
[string, CollectionTool | undefined]
|
|
148
196
|
>
|
|
149
|
-
for (const [
|
|
150
|
-
if (
|
|
197
|
+
for (const [configKey, customTool] of customEntries) {
|
|
198
|
+
if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
|
|
151
199
|
continue
|
|
152
200
|
}
|
|
153
201
|
if (!customTool) {
|
|
@@ -156,9 +204,10 @@ const sanitizeCollectionConfig = ({
|
|
|
156
204
|
items.push({
|
|
157
205
|
type: 'collectionTool',
|
|
158
206
|
collectionSlug: slug,
|
|
159
|
-
|
|
160
|
-
label:
|
|
161
|
-
|
|
207
|
+
configKey,
|
|
208
|
+
label: customTool.annotations?.title ?? configKey,
|
|
209
|
+
mcpName: configKey,
|
|
210
|
+
tool: { ...customTool, access: customTool.access ?? defaultAccess },
|
|
162
211
|
})
|
|
163
212
|
}
|
|
164
213
|
|
|
@@ -171,30 +220,45 @@ const sanitizeGlobalConfig = ({
|
|
|
171
220
|
}: {
|
|
172
221
|
global: GlobalConfig | SanitizedGlobalConfig
|
|
173
222
|
pluginConfig: MCPPluginConfig
|
|
174
|
-
}):
|
|
223
|
+
}): GlobalMCPItem[] => {
|
|
175
224
|
const slug = global.slug
|
|
176
225
|
const globalPluginConfig = pluginConfig.globals?.[slug]
|
|
177
|
-
const items:
|
|
226
|
+
const items: GlobalMCPItem[] = []
|
|
178
227
|
|
|
179
|
-
for (const [toolKey,
|
|
228
|
+
for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {
|
|
229
|
+
if (requiresVersions && !global.versions) {
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
180
232
|
const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]
|
|
181
233
|
if (matchedConfigEntry === false) {
|
|
182
234
|
continue
|
|
183
235
|
}
|
|
236
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
237
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
184
238
|
items.push({
|
|
185
239
|
type: 'globalTool',
|
|
240
|
+
configKey: toolKey,
|
|
186
241
|
globalSlug: slug,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
tool:
|
|
242
|
+
label: annotations.title ?? toolKey,
|
|
243
|
+
mcpName,
|
|
244
|
+
tool: {
|
|
245
|
+
...tool,
|
|
246
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
247
|
+
annotations,
|
|
248
|
+
description: override?.description ?? tool.description,
|
|
249
|
+
overrideResponse:
|
|
250
|
+
override?.overrideResponse ??
|
|
251
|
+
globalPluginConfig?.overrideResponse ??
|
|
252
|
+
tool.overrideResponse,
|
|
253
|
+
},
|
|
190
254
|
})
|
|
191
255
|
}
|
|
192
256
|
|
|
193
257
|
const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<
|
|
194
258
|
[string, GlobalTool | undefined]
|
|
195
259
|
>
|
|
196
|
-
for (const [
|
|
197
|
-
if (
|
|
260
|
+
for (const [configKey, customTool] of customEntries) {
|
|
261
|
+
if (configKey in GLOBAL_BUILTINS) {
|
|
198
262
|
continue
|
|
199
263
|
}
|
|
200
264
|
if (!customTool) {
|
|
@@ -202,38 +266,13 @@ const sanitizeGlobalConfig = ({
|
|
|
202
266
|
}
|
|
203
267
|
items.push({
|
|
204
268
|
type: 'globalTool',
|
|
269
|
+
configKey,
|
|
205
270
|
globalSlug: slug,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
tool: customTool,
|
|
271
|
+
label: customTool.annotations?.title ?? configKey,
|
|
272
|
+
mcpName: configKey,
|
|
273
|
+
tool: { ...customTool, access: customTool.access ?? defaultAccess },
|
|
209
274
|
})
|
|
210
275
|
}
|
|
211
276
|
|
|
212
277
|
return items
|
|
213
278
|
}
|
|
214
|
-
|
|
215
|
-
const capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Spread the static built-in tool and apply consumer-side overrides.
|
|
219
|
-
* Precedence: per-tool override > scope-level (collection/global) override >
|
|
220
|
-
* the static tool's defaults. `toolEntry` is whatever the user put under
|
|
221
|
-
* `tools: { find: ... }` — could be `true`, `false`, or an override object —
|
|
222
|
-
* so it's narrowed internally.
|
|
223
|
-
*/
|
|
224
|
-
const overrideBuiltinTool = <TTool extends CollectionTool | GlobalTool>(
|
|
225
|
-
tool: TTool,
|
|
226
|
-
toolOverride?: MCPBuiltInToolOverride,
|
|
227
|
-
entityPluginConfig?: TTool extends CollectionTool
|
|
228
|
-
? MCPPluginCollectionConfig<any>
|
|
229
|
-
: MCPPluginGlobalConfig,
|
|
230
|
-
): TTool => {
|
|
231
|
-
return {
|
|
232
|
-
...tool,
|
|
233
|
-
description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,
|
|
234
|
-
overrideResponse:
|
|
235
|
-
toolOverride?.overrideResponse ??
|
|
236
|
-
entityPluginConfig?.overrideResponse ??
|
|
237
|
-
tool.overrideResponse,
|
|
238
|
-
}
|
|
239
|
-
}
|