@payloadcms/plugin-mcp 3.70.0-canary.9 → 3.71.0-canary.2
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/collections/createApiKeysCollection.d.ts +1 -1
- package/dist/collections/createApiKeysCollection.d.ts.map +1 -1
- package/dist/collections/createApiKeysCollection.js +10 -75
- package/dist/collections/createApiKeysCollection.js.map +1 -1
- package/dist/endpoints/mcp.d.ts.map +1 -1
- package/dist/endpoints/mcp.js +1 -0
- package/dist/endpoints/mcp.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +24 -10
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/dist/mcp/tools/global/find.d.ts +5 -0
- package/dist/mcp/tools/global/find.d.ts.map +1 -0
- package/dist/mcp/tools/global/find.js +59 -0
- package/dist/mcp/tools/global/find.js.map +1 -0
- package/dist/mcp/tools/global/update.d.ts +6 -0
- package/dist/mcp/tools/global/update.d.ts.map +1 -0
- package/dist/mcp/tools/global/update.js +97 -0
- package/dist/mcp/tools/global/update.js.map +1 -0
- package/dist/mcp/tools/resource/find.d.ts.map +1 -1
- package/dist/mcp/tools/resource/find.js +9 -3
- package/dist/mcp/tools/resource/find.js.map +1 -1
- package/dist/mcp/tools/schemas.d.ts +58 -17
- package/dist/mcp/tools/schemas.d.ts.map +1 -1
- package/dist/mcp/tools/schemas.js +19 -0
- package/dist/mcp/tools/schemas.js.map +1 -1
- package/dist/types.d.ts +40 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/adminEntitySettings.d.ts +17 -0
- package/dist/utils/adminEntitySettings.d.ts.map +1 -0
- package/dist/utils/adminEntitySettings.js +41 -0
- package/dist/utils/adminEntitySettings.js.map +1 -0
- package/dist/utils/createApiKeyFields.d.ts +15 -0
- package/dist/utils/createApiKeyFields.d.ts.map +1 -0
- package/dist/utils/createApiKeyFields.js +57 -0
- package/dist/utils/createApiKeyFields.js.map +1 -0
- package/dist/utils/getEnabledSlugs.d.ts +13 -0
- package/dist/utils/getEnabledSlugs.d.ts.map +1 -0
- package/dist/utils/getEnabledSlugs.js +32 -0
- package/dist/utils/getEnabledSlugs.js.map +1 -0
- package/package.json +5 -5
- package/src/collections/createApiKeysCollection.ts +11 -111
- package/src/endpoints/mcp.ts +1 -0
- package/src/index.ts +4 -0
- package/src/mcp/getMcpHandler.ts +62 -26
- package/src/mcp/tools/global/find.ts +104 -0
- package/src/mcp/tools/global/update.ts +168 -0
- package/src/mcp/tools/resource/find.ts +5 -2
- package/src/mcp/tools/schemas.ts +56 -0
- package/src/types.ts +59 -1
- package/src/utils/adminEntitySettings.ts +40 -0
- package/src/utils/createApiKeyFields.ts +72 -0
- package/src/utils/getEnabledSlugs.ts +42 -0
package/src/types.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CollectionConfig,
|
|
3
|
+
CollectionSlug,
|
|
4
|
+
GlobalSlug,
|
|
5
|
+
PayloadRequest,
|
|
6
|
+
TypedUser,
|
|
7
|
+
} from 'payload'
|
|
2
8
|
import type { z } from 'zod'
|
|
3
9
|
|
|
4
10
|
import { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
@@ -115,6 +121,51 @@ export type PluginMCPServerConfig = {
|
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Set the globals that should be available as resources via MCP.
|
|
126
|
+
* Globals are singleton configuration objects (e.g., site settings, navigation).
|
|
127
|
+
* Note: Globals only support find and update operations.
|
|
128
|
+
*/
|
|
129
|
+
globals?: Partial<
|
|
130
|
+
Record<
|
|
131
|
+
GlobalSlug,
|
|
132
|
+
{
|
|
133
|
+
/**
|
|
134
|
+
* Set the description of the global. This is used by MCP clients to determine when to use the global as a resource.
|
|
135
|
+
*/
|
|
136
|
+
description?: string
|
|
137
|
+
/**
|
|
138
|
+
* Set the enabled capabilities of the global. Admins can then allow or disallow the use of the capability by MCP clients.
|
|
139
|
+
* Note: Globals only support find and update operations as they are singletons.
|
|
140
|
+
*/
|
|
141
|
+
enabled:
|
|
142
|
+
| {
|
|
143
|
+
find?: boolean
|
|
144
|
+
update?: boolean
|
|
145
|
+
}
|
|
146
|
+
| boolean
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
|
|
150
|
+
*/
|
|
151
|
+
overrideResponse?: (
|
|
152
|
+
response: {
|
|
153
|
+
content: Array<{
|
|
154
|
+
text: string
|
|
155
|
+
type: string
|
|
156
|
+
}>
|
|
157
|
+
},
|
|
158
|
+
doc: Record<string, unknown>,
|
|
159
|
+
req: PayloadRequest,
|
|
160
|
+
) => {
|
|
161
|
+
content: Array<{
|
|
162
|
+
text: string
|
|
163
|
+
type: string
|
|
164
|
+
}>
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
>
|
|
168
|
+
>
|
|
118
169
|
/**
|
|
119
170
|
* MCP Server options.
|
|
120
171
|
*/
|
|
@@ -349,6 +400,11 @@ export type MCPAccessSettings = {
|
|
|
349
400
|
find?: boolean
|
|
350
401
|
update?: boolean
|
|
351
402
|
}
|
|
403
|
+
custom?: Record<string, boolean>
|
|
404
|
+
globals?: {
|
|
405
|
+
find?: boolean
|
|
406
|
+
update?: boolean
|
|
407
|
+
}
|
|
352
408
|
jobs?: {
|
|
353
409
|
create?: boolean
|
|
354
410
|
run?: boolean
|
|
@@ -360,6 +416,8 @@ export type MCPAccessSettings = {
|
|
|
360
416
|
user: TypedUser
|
|
361
417
|
} & Record<string, unknown>
|
|
362
418
|
|
|
419
|
+
export type EntityConfig = PluginMCPServerConfig['collections'] | PluginMCPServerConfig['globals']
|
|
420
|
+
|
|
363
421
|
export type FieldDefinition = {
|
|
364
422
|
description?: string
|
|
365
423
|
name: string
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the default admin entity settings for Collections and Globals.
|
|
3
|
+
* This is used to create the MCP API key permission fields for the API Keys collection.
|
|
4
|
+
*/
|
|
5
|
+
export const adminEntitySettings = {
|
|
6
|
+
collection: [
|
|
7
|
+
{
|
|
8
|
+
name: 'find',
|
|
9
|
+
description: (slug: string) => `Allow clients to find ${slug}.`,
|
|
10
|
+
label: 'Find',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'create',
|
|
14
|
+
description: (slug: string) => `Allow clients to create ${slug}.`,
|
|
15
|
+
label: 'Create',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'update',
|
|
19
|
+
description: (slug: string) => `Allow clients to update ${slug}.`,
|
|
20
|
+
label: 'Update',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'delete',
|
|
24
|
+
description: (slug: string) => `Allow clients to delete ${slug}.`,
|
|
25
|
+
label: 'Delete',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
global: [
|
|
29
|
+
{
|
|
30
|
+
name: 'find',
|
|
31
|
+
description: (slug: string) => `Allow clients to find ${slug} global.`,
|
|
32
|
+
label: 'Find',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'update',
|
|
36
|
+
description: (slug: string) => `Allow clients to update ${slug} global.`,
|
|
37
|
+
label: 'Update',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Field } from 'payload'
|
|
2
|
+
|
|
3
|
+
import type { EntityConfig } from '../types.js'
|
|
4
|
+
|
|
5
|
+
import { adminEntitySettings } from './adminEntitySettings.js'
|
|
6
|
+
import { toCamelCase } from './camelCase.js'
|
|
7
|
+
import { getEnabledSlugs } from './getEnabledSlugs.js'
|
|
8
|
+
/**
|
|
9
|
+
* Creates MCP API key permission fields using collections or globals.
|
|
10
|
+
* Generates collapsible field groups with checkboxes for each enabled operation.
|
|
11
|
+
*
|
|
12
|
+
* @param config - The collections or globals configuration object
|
|
13
|
+
* @param configType - The type of configuration ('collection' or 'global')
|
|
14
|
+
* @returns Array of fields for the MCP API Keys collection
|
|
15
|
+
*/
|
|
16
|
+
export const createApiKeyFields = ({
|
|
17
|
+
config,
|
|
18
|
+
configType,
|
|
19
|
+
}: {
|
|
20
|
+
config: EntityConfig | undefined
|
|
21
|
+
configType: 'collection' | 'global'
|
|
22
|
+
}): Field[] => {
|
|
23
|
+
const operations = adminEntitySettings[configType]
|
|
24
|
+
const enabledSlugs = getEnabledSlugs(config, configType)
|
|
25
|
+
|
|
26
|
+
return enabledSlugs.map((slug) => {
|
|
27
|
+
const entityConfig = config?.[slug]
|
|
28
|
+
|
|
29
|
+
const enabledOperations = operations.filter((operation) => {
|
|
30
|
+
// If fully enabled, all operations are available
|
|
31
|
+
if (entityConfig?.enabled === true) {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// If partially enabled, check if this specific operation is enabled
|
|
36
|
+
const enabled = entityConfig?.enabled
|
|
37
|
+
if (typeof enabled !== 'boolean' && enabled) {
|
|
38
|
+
const operationEnabled = enabled[operation.name as keyof typeof enabled]
|
|
39
|
+
return typeof operationEnabled === 'boolean' && operationEnabled === true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return false
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Generate checkbox fields for each enabled operation
|
|
46
|
+
const operationFields = enabledOperations.map((operation) => ({
|
|
47
|
+
name: operation.name,
|
|
48
|
+
type: 'checkbox' as const,
|
|
49
|
+
admin: {
|
|
50
|
+
description: operation.description(slug),
|
|
51
|
+
},
|
|
52
|
+
defaultValue: false,
|
|
53
|
+
label: operation.label,
|
|
54
|
+
}))
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
type: 'collapsible' as const,
|
|
58
|
+
admin: {
|
|
59
|
+
position: 'sidebar' as const,
|
|
60
|
+
},
|
|
61
|
+
fields: [
|
|
62
|
+
{
|
|
63
|
+
name: toCamelCase(slug),
|
|
64
|
+
type: 'group' as const,
|
|
65
|
+
fields: operationFields,
|
|
66
|
+
label: configType,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
label: `${slug.charAt(0).toUpperCase() + toCamelCase(slug).slice(1)}`,
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EntityConfig } from '../types.js'
|
|
2
|
+
|
|
3
|
+
import { adminEntitySettings } from './adminEntitySettings.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Extracts enabled slugs from collections or globals configuration.
|
|
7
|
+
* A slug is considered enabled if:
|
|
8
|
+
* 1. enabled is set to true (fully enabled)
|
|
9
|
+
* 2. enabled is an object with at least one operation set to true
|
|
10
|
+
*
|
|
11
|
+
* @param config - The collections or globals configuration object
|
|
12
|
+
* @param configType - The type of configuration ('collection' or 'global')
|
|
13
|
+
* @returns Array of enabled slugs
|
|
14
|
+
*/
|
|
15
|
+
export const getEnabledSlugs = (
|
|
16
|
+
config: EntityConfig | undefined,
|
|
17
|
+
configType: 'collection' | 'global',
|
|
18
|
+
): string[] => {
|
|
19
|
+
return Object.keys(config || {}).filter((slug) => {
|
|
20
|
+
const entityConfig = config?.[slug]
|
|
21
|
+
const operations = adminEntitySettings[configType]
|
|
22
|
+
|
|
23
|
+
// Check if fully enabled (boolean true)
|
|
24
|
+
const fullyEnabled =
|
|
25
|
+
typeof entityConfig?.enabled === 'boolean' && entityConfig?.enabled === true
|
|
26
|
+
|
|
27
|
+
if (fullyEnabled) {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check if partially enabled (at least one operation is enabled)
|
|
32
|
+
const enabled = entityConfig?.enabled
|
|
33
|
+
if (typeof enabled !== 'boolean' && enabled) {
|
|
34
|
+
return operations.some((operation) => {
|
|
35
|
+
const operationEnabled = enabled[operation.name as keyof typeof enabled]
|
|
36
|
+
return typeof operationEnabled === 'boolean' && operationEnabled === true
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return false
|
|
41
|
+
})
|
|
42
|
+
}
|