@payloadcms/plugin-mcp 4.0.0-internal.40de3ec → 4.0.0-internal.4804abd
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/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 +82 -88
- 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 -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.map +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +102 -71
- 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 +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 +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +38 -42
- 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 +14 -20
- 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 +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +49 -43
- 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 +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 +47 -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 +82 -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 +87 -86
- 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 +71 -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 +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 +18 -21
- 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 +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +47 -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 +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 +31 -40
- 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 +120 -58
- 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 +62 -108
- 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/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +32 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- 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 +8 -11
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +88 -101
- package/src/endpoint/index.ts +14 -1
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +8 -16
- package/src/mcp/buildMcpServer.ts +131 -96
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- 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 +55 -59
- package/src/mcp/builtin/collections/deleteTool.ts +19 -16
- 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 +63 -33
- 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 +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
- package/src/mcp/builtin/collections/updateTool.ts +111 -110
- package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/findTool.ts +26 -17
- 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 +41 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
- package/src/mcp/builtin/globals/updateTool.ts +50 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +116 -78
- package/src/stdio.ts +23 -8
- package/src/types.ts +77 -112
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/getEntityInputSchema.ts +62 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
- 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 -60
- 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/schemaConversion/buildToolInput.d.ts +0 -29
- package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
- package/dist/utils/schemaConversion/buildToolInput.js +0 -51
- package/dist/utils/schemaConversion/buildToolInput.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/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -64
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/schemaConversion/buildToolInput.ts +0 -68
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defaultAccess } from '../defaultAccess.js';
|
|
2
|
+
import { COLLECTION_AUTH_BUILTIN_ENTRIES, COLLECTION_AUTH_BUILTINS, COLLECTION_BUILTIN_ENTRIES, COLLECTION_BUILTINS, GLOBAL_BUILTIN_ENTRIES, GLOBAL_BUILTINS, TOOL_BUILTIN_ENTRIES, TOOL_BUILTINS } from './builtinTools.js';
|
|
2
3
|
/**
|
|
3
4
|
* Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
|
|
4
5
|
* - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
|
|
5
6
|
* tool maps into a single `items` array.
|
|
6
7
|
* - Applies built-in tools for collections and globals, respecting opt-out user overrides.
|
|
7
|
-
* - Applies the `userCollection` default
|
|
8
8
|
*
|
|
9
9
|
* Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
|
|
10
10
|
* ?.options` holds the sanitized result
|
|
@@ -22,83 +22,136 @@ import { COLLECTION_AUTH_BUILTIN_ENTRIES, COLLECTION_AUTH_BUILTINS, COLLECTION_B
|
|
|
22
22
|
pluginConfig
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
|
-
for (const [
|
|
25
|
+
for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES){
|
|
26
26
|
items.push({
|
|
27
27
|
type: 'tool',
|
|
28
|
-
|
|
29
|
-
label:
|
|
30
|
-
|
|
28
|
+
configKey,
|
|
29
|
+
label: tool.annotations?.title ?? configKey,
|
|
30
|
+
mcpName,
|
|
31
|
+
tool: {
|
|
32
|
+
...tool,
|
|
33
|
+
access: tool.access ?? defaultAccess
|
|
34
|
+
}
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
|
-
for (const [
|
|
37
|
+
for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})){
|
|
38
|
+
if (configKey in TOOL_BUILTINS) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
items.push({
|
|
42
|
+
type: 'tool',
|
|
43
|
+
configKey,
|
|
44
|
+
label: tool.annotations?.title ?? configKey,
|
|
45
|
+
mcpName: configKey,
|
|
46
|
+
tool: {
|
|
47
|
+
...tool,
|
|
48
|
+
access: tool.access ?? defaultAccess
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})){
|
|
34
53
|
items.push({
|
|
35
54
|
type: 'prompt',
|
|
36
|
-
|
|
37
|
-
label: prompt.title ??
|
|
38
|
-
|
|
55
|
+
configKey,
|
|
56
|
+
label: prompt.title ?? configKey,
|
|
57
|
+
mcpName: configKey,
|
|
58
|
+
prompt: {
|
|
59
|
+
...prompt,
|
|
60
|
+
access: prompt.access ?? defaultAccess
|
|
61
|
+
}
|
|
39
62
|
});
|
|
40
63
|
}
|
|
41
|
-
for (const [
|
|
64
|
+
for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})){
|
|
42
65
|
items.push({
|
|
43
66
|
type: 'resource',
|
|
44
|
-
|
|
45
|
-
label: resource.title ??
|
|
46
|
-
|
|
67
|
+
configKey,
|
|
68
|
+
label: resource.title ?? configKey,
|
|
69
|
+
mcpName: configKey,
|
|
70
|
+
resource: {
|
|
71
|
+
...resource,
|
|
72
|
+
access: resource.access ?? defaultAccess
|
|
73
|
+
}
|
|
47
74
|
});
|
|
48
75
|
}
|
|
49
|
-
// Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
|
|
50
|
-
const firstCollectionWithAuth = config.collections.find(({ auth })=>Boolean(auth));
|
|
51
76
|
return {
|
|
52
77
|
disabled: pluginConfig.disabled,
|
|
53
78
|
items,
|
|
54
79
|
mcp: pluginConfig.mcp,
|
|
55
|
-
|
|
56
|
-
overrideAuth: pluginConfig.overrideAuth,
|
|
57
|
-
userCollection: pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users'
|
|
80
|
+
overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP
|
|
58
81
|
};
|
|
59
82
|
};
|
|
60
83
|
const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
|
|
61
|
-
if (collection.slug === 'payload-mcp-api-keys') {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
84
|
const slug = collection.slug;
|
|
65
85
|
const collectionPluginConfig = pluginConfig.collections?.[slug];
|
|
66
86
|
const items = [];
|
|
67
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Payload disables duplicate for auth collections by default unless the
|
|
89
|
+
* collection explicitly opts back in with `disableDuplicate: false`.
|
|
90
|
+
*/ const isDuplicateDisabled = collection.disableDuplicate === true || Boolean(collection.auth) && collection.disableDuplicate !== false;
|
|
91
|
+
for (const [toolKey, { mcpName, requiresDuplicateEnabled, requiresVersions, tool }] of COLLECTION_BUILTIN_ENTRIES){
|
|
92
|
+
if (requiresVersions && !collection.versions) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
68
98
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey];
|
|
69
99
|
if (matchedConfigEntry === false) {
|
|
70
100
|
continue;
|
|
71
101
|
}
|
|
102
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
|
|
103
|
+
const annotations = {
|
|
104
|
+
...tool.annotations,
|
|
105
|
+
...override?.annotations
|
|
106
|
+
};
|
|
72
107
|
items.push({
|
|
73
108
|
type: 'collectionTool',
|
|
74
109
|
collectionSlug: slug,
|
|
75
|
-
|
|
76
|
-
label:
|
|
77
|
-
|
|
110
|
+
configKey: toolKey,
|
|
111
|
+
label: annotations.title ?? toolKey,
|
|
112
|
+
mcpName,
|
|
113
|
+
tool: {
|
|
114
|
+
...tool,
|
|
115
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
116
|
+
annotations,
|
|
117
|
+
description: override?.description ?? tool.description,
|
|
118
|
+
overrideResponse: override?.overrideResponse ?? collectionPluginConfig?.overrideResponse ?? tool.overrideResponse
|
|
119
|
+
}
|
|
78
120
|
});
|
|
79
121
|
}
|
|
80
122
|
if (collection.auth) {
|
|
81
|
-
for (const [authToolKey, {
|
|
123
|
+
for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES){
|
|
82
124
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey];
|
|
83
125
|
if (!matchedConfigEntry) {
|
|
84
126
|
continue;
|
|
85
127
|
}
|
|
86
128
|
// `true` means "enable, no override"; only the object form carries fields.
|
|
87
129
|
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
|
|
130
|
+
const annotations = {
|
|
131
|
+
...tool.annotations,
|
|
132
|
+
...override?.annotations
|
|
133
|
+
};
|
|
88
134
|
items.push({
|
|
89
135
|
type: 'collectionTool',
|
|
90
136
|
collectionSlug: slug,
|
|
91
|
-
|
|
92
|
-
label,
|
|
93
|
-
|
|
137
|
+
configKey: authToolKey,
|
|
138
|
+
label: annotations.title ?? authToolKey,
|
|
139
|
+
mcpName,
|
|
140
|
+
tool: {
|
|
141
|
+
...tool,
|
|
142
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
143
|
+
annotations,
|
|
144
|
+
description: override?.description ?? tool.description,
|
|
145
|
+
overrideResponse: override?.overrideResponse ?? collectionPluginConfig?.overrideResponse ?? tool.overrideResponse
|
|
146
|
+
}
|
|
94
147
|
});
|
|
95
148
|
}
|
|
96
149
|
}
|
|
97
150
|
// Cast: builtin keys are filtered out below, so the remaining values are
|
|
98
151
|
// always custom tools (`CollectionTool`) or undefined
|
|
99
152
|
const customEntries = Object.entries(collectionPluginConfig?.tools ?? {});
|
|
100
|
-
for (const [
|
|
101
|
-
if (
|
|
153
|
+
for (const [configKey, customTool] of customEntries){
|
|
154
|
+
if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
|
|
102
155
|
continue;
|
|
103
156
|
}
|
|
104
157
|
if (!customTool) {
|
|
@@ -107,9 +160,13 @@ const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
|
|
|
107
160
|
items.push({
|
|
108
161
|
type: 'collectionTool',
|
|
109
162
|
collectionSlug: slug,
|
|
110
|
-
|
|
111
|
-
label:
|
|
112
|
-
|
|
163
|
+
configKey,
|
|
164
|
+
label: customTool.annotations?.title ?? configKey,
|
|
165
|
+
mcpName: configKey,
|
|
166
|
+
tool: {
|
|
167
|
+
...customTool,
|
|
168
|
+
access: customTool.access ?? defaultAccess
|
|
169
|
+
}
|
|
113
170
|
});
|
|
114
171
|
}
|
|
115
172
|
return items;
|
|
@@ -118,22 +175,37 @@ const sanitizeGlobalConfig = ({ global, pluginConfig })=>{
|
|
|
118
175
|
const slug = global.slug;
|
|
119
176
|
const globalPluginConfig = pluginConfig.globals?.[slug];
|
|
120
177
|
const items = [];
|
|
121
|
-
for (const [toolKey,
|
|
178
|
+
for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES){
|
|
179
|
+
if (requiresVersions && !global.versions) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
122
182
|
const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey];
|
|
123
183
|
if (matchedConfigEntry === false) {
|
|
124
184
|
continue;
|
|
125
185
|
}
|
|
186
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
|
|
187
|
+
const annotations = {
|
|
188
|
+
...tool.annotations,
|
|
189
|
+
...override?.annotations
|
|
190
|
+
};
|
|
126
191
|
items.push({
|
|
127
192
|
type: 'globalTool',
|
|
193
|
+
configKey: toolKey,
|
|
128
194
|
globalSlug: slug,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
tool:
|
|
195
|
+
label: annotations.title ?? toolKey,
|
|
196
|
+
mcpName,
|
|
197
|
+
tool: {
|
|
198
|
+
...tool,
|
|
199
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
200
|
+
annotations,
|
|
201
|
+
description: override?.description ?? tool.description,
|
|
202
|
+
overrideResponse: override?.overrideResponse ?? globalPluginConfig?.overrideResponse ?? tool.overrideResponse
|
|
203
|
+
}
|
|
132
204
|
});
|
|
133
205
|
}
|
|
134
206
|
const customEntries = Object.entries(globalPluginConfig?.tools ?? {});
|
|
135
|
-
for (const [
|
|
136
|
-
if (
|
|
207
|
+
for (const [configKey, customTool] of customEntries){
|
|
208
|
+
if (configKey in GLOBAL_BUILTINS) {
|
|
137
209
|
continue;
|
|
138
210
|
}
|
|
139
211
|
if (!customTool) {
|
|
@@ -141,27 +213,17 @@ const sanitizeGlobalConfig = ({ global, pluginConfig })=>{
|
|
|
141
213
|
}
|
|
142
214
|
items.push({
|
|
143
215
|
type: 'globalTool',
|
|
216
|
+
configKey,
|
|
144
217
|
globalSlug: slug,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
tool:
|
|
218
|
+
label: customTool.annotations?.title ?? configKey,
|
|
219
|
+
mcpName: configKey,
|
|
220
|
+
tool: {
|
|
221
|
+
...customTool,
|
|
222
|
+
access: customTool.access ?? defaultAccess
|
|
223
|
+
}
|
|
148
224
|
});
|
|
149
225
|
}
|
|
150
226
|
return items;
|
|
151
227
|
};
|
|
152
|
-
const capitalize = (s)=>s.charAt(0).toUpperCase() + s.slice(1);
|
|
153
|
-
/**
|
|
154
|
-
* Spread the static built-in tool and apply consumer-side overrides.
|
|
155
|
-
* Precedence: per-tool override > scope-level (collection/global) override >
|
|
156
|
-
* the static tool's defaults. `toolEntry` is whatever the user put under
|
|
157
|
-
* `tools: { find: ... }` — could be `true`, `false`, or an override object —
|
|
158
|
-
* so it's narrowed internally.
|
|
159
|
-
*/ const overrideBuiltinTool = (tool, toolOverride, entityPluginConfig)=>{
|
|
160
|
-
return {
|
|
161
|
-
...tool,
|
|
162
|
-
description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,
|
|
163
|
-
overrideResponse: toolOverride?.overrideResponse ?? entityPluginConfig?.overrideResponse ?? tool.overrideResponse
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
228
|
|
|
167
229
|
//# sourceMappingURL=sanitizeMCPConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionTool,\n GlobalTool,\n MCPBuiltInToolOverride,\n MCPItem,\n MCPPluginCollectionConfig,\n MCPPluginConfig,\n MCPPluginGlobalConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n * - Applies the `userCollection` default\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})) {\n items.push({\n type: 'tool',\n key,\n label: key,\n tool,\n })\n }\n\n for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n key,\n label: prompt.title ?? key,\n prompt,\n })\n }\n\n for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n key,\n label: resource.title ?? key,\n resource,\n })\n }\n\n // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.\n const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,\n overrideAuth: pluginConfig.overrideAuth,\n userCollection:\n pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n if (collection.slug === 'payload-mcp-api-keys') {\n return []\n }\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig),\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: authToolKey,\n label,\n tool: overrideBuiltinTool(tool, override, collectionPluginConfig),\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES) {\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig),\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)\n\n/**\n * Spread the static built-in tool and apply consumer-side overrides.\n * Precedence: per-tool override > scope-level (collection/global) override >\n * the static tool's defaults. `toolEntry` is whatever the user put under\n * `tools: { find: ... }` — could be `true`, `false`, or an override object —\n * so it's narrowed internally.\n */\nconst overrideBuiltinTool = <TTool extends CollectionTool | GlobalTool>(\n tool: TTool,\n toolOverride?: MCPBuiltInToolOverride,\n entityPluginConfig?: TTool extends CollectionTool\n ? MCPPluginCollectionConfig<any>\n : MCPPluginGlobalConfig,\n): TTool => {\n return {\n ...tool,\n description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,\n overrideResponse:\n toolOverride?.overrideResponse ??\n entityPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n }\n}\n"],"names":["COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","key","tool","Object","entries","tools","type","label","prompt","prompts","title","resource","resources","firstCollectionWithAuth","find","auth","Boolean","disabled","mcp","overrideApiKeyCollection","overrideAuth","userCollection","admin","user","slug","collectionPluginConfig","toolKey","matchedConfigEntry","collectionSlug","capitalize","overrideBuiltinTool","authToolKey","override","undefined","customEntries","customTool","globalPluginConfig","baseTool","globalSlug","s","charAt","toUpperCase","slice","toolOverride","entityPluginConfig","description","overrideResponse"],"mappings":"AAoBA,SACEA,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,QACV,oBAAmB;AAE1B;;;;;;;;;CASC,GACD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gB;IACzB;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionMCPItem,\n CollectionTool,\n GlobalMCPItem,\n GlobalTool,\n MCPItem,\n MCPPluginConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport { defaultAccess } from '../defaultAccess.js'\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n TOOL_BUILTIN_ENTRIES,\n TOOL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {\n if (configKey in TOOL_BUILTINS) {\n continue\n }\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n configKey,\n label: prompt.title ?? configKey,\n mcpName: configKey,\n prompt: { ...prompt, access: prompt.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n configKey,\n label: resource.title ?? configKey,\n mcpName: configKey,\n resource: { ...resource, access: resource.access ?? defaultAccess },\n })\n }\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): CollectionMCPItem[] => {\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: CollectionMCPItem[] = []\n /**\n * Payload disables duplicate for auth collections by default unless the\n * collection explicitly opts back in with `disableDuplicate: false`.\n */\n const isDuplicateDisabled =\n collection.disableDuplicate === true ||\n (Boolean(collection.auth) && collection.disableDuplicate !== false)\n\n for (const [\n toolKey,\n { mcpName, requiresDuplicateEnabled, requiresVersions, tool },\n ] of COLLECTION_BUILTIN_ENTRIES) {\n if (requiresVersions && !collection.versions) {\n continue\n }\n if (requiresDuplicateEnabled && isDuplicateDisabled) {\n continue\n }\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: toolKey,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: authToolKey,\n label: annotations.title ?? authToolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): GlobalMCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: GlobalMCPItem[] = []\n\n for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {\n if (requiresVersions && !global.versions) {\n continue\n }\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'globalTool',\n configKey: toolKey,\n globalSlug: slug,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n globalPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n configKey,\n globalSlug: slug,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n"],"names":["defaultAccess","COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","TOOL_BUILTIN_ENTRIES","TOOL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","configKey","mcpName","tool","type","label","annotations","title","access","Object","entries","tools","prompt","prompts","resource","resources","disabled","mcp","overrideGetAuthorizedMCP","slug","collectionPluginConfig","isDuplicateDisabled","disableDuplicate","Boolean","auth","toolKey","requiresDuplicateEnabled","requiresVersions","versions","matchedConfigEntry","override","undefined","collectionSlug","description","overrideResponse","authToolKey","customEntries","customTool","globalPluginConfig","globalSlug"],"mappings":"AAmBA,SAASA,aAAa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UI,oBACVI,oBAAoBJ,oBACpB/B,KAAK+B,gBAAgB;YACzB;QACF;IACF;IAEA,MAAME,gBAAgB3B,OAAOC,OAAO,CAAC4B,oBAAoB3B,SAAS,CAAC;IAGnE,KAAK,MAAM,CAACV,WAAWoC,WAAW,IAAID,cAAe;QACnD,IAAInC,aAAad,iBAAiB;YAChC;QACF;QACA,IAAI,CAACkD,YAAY;YACf;QACF;QACA5C,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH;YACAsC,YAAYpB;YACZd,OAAOgC,WAAW/B,WAAW,EAAEC,SAASN;YACxCC,SAASD;YACTE,MAAM;gBAAE,GAAGkC,UAAU;gBAAE7B,QAAQ6B,WAAW7B,MAAM,IAAI3B;YAAc;QACpE;IACF;IAEA,OAAOY;AACT"}
|
package/dist/stdio.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stdio adapter for the Payload MCP server.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Pass PAYLOAD_MCP_AUTHORIZATION when stdio should authenticate with the same
|
|
5
|
+
* Payload auth header as HTTP. In development, PAYLOAD_MCP_OVERRIDE_ACCESS=true
|
|
6
|
+
* skips access control for local setup.
|
|
6
7
|
*/
|
|
7
8
|
export declare const runMcpStdio: () => Promise<void>;
|
|
8
9
|
//# sourceMappingURL=stdio.d.ts.map
|
package/dist/stdio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAyFhD,CAAA"}
|
package/dist/stdio.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import { createLocalReq, getPayload } from 'payload';
|
|
4
4
|
import { findConfig } from 'payload/node';
|
|
5
|
+
import { getAuthorizedMCP } from './endpoint/access.js';
|
|
5
6
|
import { buildMcpServer } from './mcp/buildMcpServer.js';
|
|
6
7
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
|
|
7
8
|
import { getPluginConfig } from './utils/getPluginConfig.js';
|
|
@@ -9,8 +10,9 @@ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
|
|
|
9
10
|
/**
|
|
10
11
|
* Stdio adapter for the Payload MCP server.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* Pass PAYLOAD_MCP_AUTHORIZATION when stdio should authenticate with the same
|
|
14
|
+
* Payload auth header as HTTP. In development, PAYLOAD_MCP_OVERRIDE_ACCESS=true
|
|
15
|
+
* skips access control for local setup.
|
|
14
16
|
*/ export const runMcpStdio = async ()=>{
|
|
15
17
|
/**
|
|
16
18
|
* If MCP clients spawn stdio servers from an arbitrary working directory,
|
|
@@ -52,13 +54,30 @@ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
|
|
|
52
54
|
fakePluginFn.sanitizedOptions = pluginConfig;
|
|
53
55
|
(payload.config.plugins ??= []).push(fakePluginFn);
|
|
54
56
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
57
|
+
const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS;
|
|
58
|
+
let overrideAccess = false;
|
|
59
|
+
if (overrideAccessEnv === 'true') {
|
|
60
|
+
overrideAccess = true;
|
|
61
|
+
} else if (overrideAccessEnv && overrideAccessEnv !== 'false') {
|
|
62
|
+
throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be "true" or "false".');
|
|
63
|
+
}
|
|
64
|
+
if (overrideAccess && process.env.NODE_ENV !== 'development') {
|
|
65
|
+
throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.');
|
|
66
|
+
}
|
|
67
|
+
const headers = new Headers();
|
|
68
|
+
if (process.env.PAYLOAD_MCP_AUTHORIZATION) {
|
|
69
|
+
headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION);
|
|
70
|
+
}
|
|
71
|
+
const req = await createLocalReq({
|
|
72
|
+
req: {
|
|
73
|
+
headers
|
|
74
|
+
}
|
|
75
|
+
}, payload);
|
|
61
76
|
req.payloadAPI = 'MCP';
|
|
77
|
+
const authorizedMCP = await getAuthorizedMCP({
|
|
78
|
+
overrideAccess,
|
|
79
|
+
req
|
|
80
|
+
});
|
|
62
81
|
const server = buildMcpServer({
|
|
63
82
|
authorizedMCP,
|
|
64
83
|
pluginConfig,
|
package/dist/stdio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { SanitizedMCPPluginConfig } from './types.js'\n\nimport { getAuthorizedMCP } from './endpoint/access.js'\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Stdio adapter for the Payload MCP server.\n *\n * Pass PAYLOAD_MCP_AUTHORIZATION when stdio should authenticate with the same\n * Payload auth header as HTTP. In development, PAYLOAD_MCP_OVERRIDE_ACCESS=true\n * skips access control for local setup.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n /**\n * If MCP clients spawn stdio servers from an arbitrary working directory,\n * Payload's cwd-anchored `findConfig()` can't locate the project on\n * its own. This module always lives inside the project's `node_modules`, so\n * we derive the project root from its own path and `chdir` into it.\n *\n * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual\n * layouts (e.g. a monorepo where the package is hoisted above the app) can\n * fall back to it. See the implementation of findConfig for details.\n */\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as MaybePromise<SanitizedConfig>\n\n const payload = await getPayload({ config })\n\n /**\n * If the user added `mcpPlugin({...})` to their `plugins` array, read the\n * sanitized config they registered. Otherwise fall back to the defaults. That way,\n * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,\n * even if the plugin is not added to the plugins array.\n */\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fakePluginFn: Plugin = (config) => config\n fakePluginFn.slug = '@payloadcms/plugin-mcp'\n // @ts-expect-error\n fakePluginFn.sanitizedOptions = pluginConfig\n\n // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work\n ;(payload.config.plugins ??= []).push(fakePluginFn)\n }\n\n const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS\n let overrideAccess = false\n\n if (overrideAccessEnv === 'true') {\n overrideAccess = true\n } else if (overrideAccessEnv && overrideAccessEnv !== 'false') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be \"true\" or \"false\".')\n }\n\n if (overrideAccess && process.env.NODE_ENV !== 'development') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.')\n }\n\n const headers = new Headers()\n if (process.env.PAYLOAD_MCP_AUTHORIZATION) {\n headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)\n }\n\n const req = await createLocalReq({ req: { headers } }, payload)\n req.payloadAPI = 'MCP' as const\n const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // Process now lives until stdin closes. Wire graceful shutdown so DB\n // connections (and any other Payload-managed resources) get released.\n const shutdown = async (code = 0) => {\n try {\n await server.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n process.exit(code)\n }\n\n process.on('SIGINT', () => void shutdown(0))\n process.on('SIGTERM', () => void shutdown(0))\n process.stdin.on('close', () => void shutdown(0))\n}\n"],"names":["StdioServerTransport","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","getAuthorizedMCP","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","payload","pluginConfig","fakePluginFn","slug","sanitizedOptions","plugins","push","overrideAccessEnv","env","PAYLOAD_MCP_OVERRIDE_ACCESS","overrideAccess","Error","NODE_ENV","headers","Headers","PAYLOAD_MCP_AUTHORIZATION","set","req","payloadAPI","authorizedMCP","server","transport","connect","shutdown","code","close","err","console","error","destroy","exit","on","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD,SAASC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AACpD,SAASC,UAAU,QAAQ,eAAc;AAIzC,SAAS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