@payloadcms/plugin-mcp 4.0.0-internal.40de3ec → 4.0.0-internal.4cbdd50
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 +34 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.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 +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 +78 -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 -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/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
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { CheckboxInput, Collapsible, useField } from '@payloadcms/ui';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import './index.css';
|
|
6
|
-
const baseClass = 'mcp-access-field';
|
|
7
|
-
/** Drop a key from an object and return a new object — or `undefined` if it'd be empty. */ const without = (obj, key)=>{
|
|
8
|
-
if (!obj || !(key in obj)) {
|
|
9
|
-
return obj;
|
|
10
|
-
}
|
|
11
|
-
const { [key]: _omitted, ...rest } = obj;
|
|
12
|
-
return Object.keys(rest).length === 0 ? undefined : rest;
|
|
13
|
-
};
|
|
14
|
-
const setKey = (obj, key, value)=>({
|
|
15
|
-
...obj ?? {},
|
|
16
|
-
[key]: value
|
|
17
|
-
});
|
|
18
|
-
export const AccessField = ({ path, pluginConfig })=>{
|
|
19
|
-
const { setValue, value } = useField({
|
|
20
|
-
path
|
|
21
|
-
});
|
|
22
|
-
const access = value ?? {};
|
|
23
|
-
// Bucket items for rendering. (Bucketing is cheap and runs once per render;
|
|
24
|
-
// memoizing would mean managing inputs/refs for marginal benefit.)
|
|
25
|
-
const collectionsBySlug = {};
|
|
26
|
-
const globalsBySlug = {};
|
|
27
|
-
const tools = [];
|
|
28
|
-
const prompts = [];
|
|
29
|
-
const resources = [];
|
|
30
|
-
for (const item of pluginConfig.items){
|
|
31
|
-
switch(item.type){
|
|
32
|
-
case 'collectionTool':
|
|
33
|
-
;
|
|
34
|
-
(collectionsBySlug[item.collectionSlug] ??= []).push(item);
|
|
35
|
-
break;
|
|
36
|
-
case 'globalTool':
|
|
37
|
-
;
|
|
38
|
-
(globalsBySlug[item.globalSlug] ??= []).push(item);
|
|
39
|
-
break;
|
|
40
|
-
case 'prompt':
|
|
41
|
-
prompts.push(item);
|
|
42
|
-
break;
|
|
43
|
-
case 'resource':
|
|
44
|
-
resources.push(item);
|
|
45
|
-
break;
|
|
46
|
-
case 'tool':
|
|
47
|
-
tools.push(item);
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const isScopedAllowed = (scope, slug, key)=>access[scope]?.[slug]?.[key] !== false;
|
|
52
|
-
const isFlatAllowed = (scope, key)=>access[scope]?.[key] !== false;
|
|
53
|
-
const toggleScoped = (scope, slug, key, allow)=>{
|
|
54
|
-
if (allow) {
|
|
55
|
-
const slugBucket = without(access[scope]?.[slug], key);
|
|
56
|
-
const scopeBucket = slugBucket ? setKey(access[scope], slug, slugBucket) : without(access[scope], slug);
|
|
57
|
-
setValue(scopeBucket ? setKey(access, scope, scopeBucket) : without(access, scope) ?? {});
|
|
58
|
-
} else {
|
|
59
|
-
setValue(setKey(access, scope, setKey(access[scope], slug, setKey(access[scope]?.[slug], key, false))));
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const toggleFlat = (scope, key, allow)=>{
|
|
63
|
-
if (allow) {
|
|
64
|
-
const bucket = without(access[scope], key);
|
|
65
|
-
setValue(bucket ? setKey(access, scope, bucket) : without(access, scope) ?? {});
|
|
66
|
-
} else {
|
|
67
|
-
setValue(setKey(access, scope, setKey(access[scope], key, false)));
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const setAllScoped = (scope, slug, leaves, allow)=>{
|
|
71
|
-
if (allow) {
|
|
72
|
-
const scopeBucket = without(access[scope], slug);
|
|
73
|
-
setValue(scopeBucket ? setKey(access, scope, scopeBucket) : without(access, scope) ?? {});
|
|
74
|
-
} else {
|
|
75
|
-
const slugBucket = leaves.reduce((acc, leaf)=>({
|
|
76
|
-
...acc,
|
|
77
|
-
[leaf.key]: false
|
|
78
|
-
}), {});
|
|
79
|
-
setValue(setKey(access, scope, setKey(access[scope], slug, slugBucket)));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const setAllFlat = (scope, leaves, allow)=>{
|
|
83
|
-
if (allow) {
|
|
84
|
-
setValue(without(access, scope) ?? {});
|
|
85
|
-
} else {
|
|
86
|
-
const bucket = leaves.reduce((acc, leaf)=>({
|
|
87
|
-
...acc,
|
|
88
|
-
[leaf.key]: false
|
|
89
|
-
}), {});
|
|
90
|
-
setValue(setKey(access, scope, bucket));
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const collectionSlugs = Object.keys(collectionsBySlug);
|
|
94
|
-
const globalSlugs = Object.keys(globalsBySlug);
|
|
95
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
96
|
-
className: baseClass,
|
|
97
|
-
children: [
|
|
98
|
-
collectionSlugs.length > 0 && /*#__PURE__*/ _jsxs("section", {
|
|
99
|
-
className: `${baseClass}__section`,
|
|
100
|
-
children: [
|
|
101
|
-
/*#__PURE__*/ _jsxs("header", {
|
|
102
|
-
className: `${baseClass}__section-header`,
|
|
103
|
-
children: [
|
|
104
|
-
/*#__PURE__*/ _jsx("h4", {
|
|
105
|
-
children: "Collection-level permissions"
|
|
106
|
-
}),
|
|
107
|
-
/*#__PURE__*/ _jsx("p", {
|
|
108
|
-
children: "Allow MCP clients to perform the following actions within these collections:"
|
|
109
|
-
})
|
|
110
|
-
]
|
|
111
|
-
}),
|
|
112
|
-
collectionSlugs.map((slug)=>{
|
|
113
|
-
const leaves = collectionsBySlug[slug];
|
|
114
|
-
return /*#__PURE__*/ _jsx(Collapsible, {
|
|
115
|
-
actions: /*#__PURE__*/ _jsx(GroupActions, {
|
|
116
|
-
onSetAll: (allow)=>setAllScoped('collections', slug, leaves, allow)
|
|
117
|
-
}),
|
|
118
|
-
className: `${baseClass}__group`,
|
|
119
|
-
header: /*#__PURE__*/ _jsx("span", {
|
|
120
|
-
className: `${baseClass}__group-label`,
|
|
121
|
-
children: titleCase(slug)
|
|
122
|
-
}),
|
|
123
|
-
initCollapsed: true,
|
|
124
|
-
children: /*#__PURE__*/ _jsx("ul", {
|
|
125
|
-
className: `${baseClass}__list`,
|
|
126
|
-
children: leaves.map((leaf)=>/*#__PURE__*/ _jsx("li", {
|
|
127
|
-
children: /*#__PURE__*/ _jsx(CheckboxInput, {
|
|
128
|
-
checked: isScopedAllowed('collections', slug, leaf.key),
|
|
129
|
-
id: `${path}.collections.${slug}.${leaf.key}`,
|
|
130
|
-
label: leaf.label,
|
|
131
|
-
onToggle: (e)=>toggleScoped('collections', slug, leaf.key, e.target.checked),
|
|
132
|
-
tooltip: leaf.description
|
|
133
|
-
})
|
|
134
|
-
}, leaf.key))
|
|
135
|
-
})
|
|
136
|
-
}, `collection-${slug}`);
|
|
137
|
-
})
|
|
138
|
-
]
|
|
139
|
-
}),
|
|
140
|
-
globalSlugs.length > 0 && /*#__PURE__*/ _jsxs("section", {
|
|
141
|
-
className: `${baseClass}__section`,
|
|
142
|
-
children: [
|
|
143
|
-
/*#__PURE__*/ _jsxs("header", {
|
|
144
|
-
className: `${baseClass}__section-header`,
|
|
145
|
-
children: [
|
|
146
|
-
/*#__PURE__*/ _jsx("h4", {
|
|
147
|
-
children: "Global-level permissions"
|
|
148
|
-
}),
|
|
149
|
-
/*#__PURE__*/ _jsx("p", {
|
|
150
|
-
children: "Allow MCP clients to perform the following actions on these globals:"
|
|
151
|
-
})
|
|
152
|
-
]
|
|
153
|
-
}),
|
|
154
|
-
globalSlugs.map((slug)=>{
|
|
155
|
-
const leaves = globalsBySlug[slug];
|
|
156
|
-
return /*#__PURE__*/ _jsx(Collapsible, {
|
|
157
|
-
actions: /*#__PURE__*/ _jsx(GroupActions, {
|
|
158
|
-
onSetAll: (allow)=>setAllScoped('globals', slug, leaves, allow)
|
|
159
|
-
}),
|
|
160
|
-
className: `${baseClass}__group`,
|
|
161
|
-
header: /*#__PURE__*/ _jsx("span", {
|
|
162
|
-
className: `${baseClass}__group-label`,
|
|
163
|
-
children: titleCase(slug)
|
|
164
|
-
}),
|
|
165
|
-
initCollapsed: true,
|
|
166
|
-
children: /*#__PURE__*/ _jsx("ul", {
|
|
167
|
-
className: `${baseClass}__list`,
|
|
168
|
-
children: leaves.map((leaf)=>/*#__PURE__*/ _jsx("li", {
|
|
169
|
-
children: /*#__PURE__*/ _jsx(CheckboxInput, {
|
|
170
|
-
checked: isScopedAllowed('globals', slug, leaf.key),
|
|
171
|
-
id: `${path}.globals.${slug}.${leaf.key}`,
|
|
172
|
-
label: leaf.label,
|
|
173
|
-
onToggle: (e)=>toggleScoped('globals', slug, leaf.key, e.target.checked),
|
|
174
|
-
tooltip: leaf.description
|
|
175
|
-
})
|
|
176
|
-
}, leaf.key))
|
|
177
|
-
})
|
|
178
|
-
}, `global-${slug}`);
|
|
179
|
-
})
|
|
180
|
-
]
|
|
181
|
-
}),
|
|
182
|
-
(tools.length > 0 || prompts.length > 0 || resources.length > 0) && /*#__PURE__*/ _jsxs("section", {
|
|
183
|
-
className: `${baseClass}__section`,
|
|
184
|
-
children: [
|
|
185
|
-
/*#__PURE__*/ _jsxs("header", {
|
|
186
|
-
className: `${baseClass}__section-header`,
|
|
187
|
-
children: [
|
|
188
|
-
/*#__PURE__*/ _jsx("h4", {
|
|
189
|
-
children: "Project-level permissions"
|
|
190
|
-
}),
|
|
191
|
-
/*#__PURE__*/ _jsx("p", {
|
|
192
|
-
children: "Cross-cutting tools, prompts, and resources not scoped to a single collection."
|
|
193
|
-
})
|
|
194
|
-
]
|
|
195
|
-
}),
|
|
196
|
-
tools.length > 0 && /*#__PURE__*/ _jsx(Collapsible, {
|
|
197
|
-
actions: /*#__PURE__*/ _jsx(GroupActions, {
|
|
198
|
-
onSetAll: (allow)=>setAllFlat('tools', tools, allow)
|
|
199
|
-
}),
|
|
200
|
-
className: `${baseClass}__group`,
|
|
201
|
-
header: /* TODO: needs i18n once design is finalized */ /*#__PURE__*/ _jsx("span", {
|
|
202
|
-
className: `${baseClass}__group-label`,
|
|
203
|
-
children: "Tools"
|
|
204
|
-
}),
|
|
205
|
-
initCollapsed: true,
|
|
206
|
-
children: /*#__PURE__*/ _jsx("ul", {
|
|
207
|
-
className: `${baseClass}__list`,
|
|
208
|
-
children: tools.map((leaf)=>/*#__PURE__*/ _jsx("li", {
|
|
209
|
-
children: /*#__PURE__*/ _jsx(CheckboxInput, {
|
|
210
|
-
checked: isFlatAllowed('tools', leaf.key),
|
|
211
|
-
id: `${path}.tools.${leaf.key}`,
|
|
212
|
-
label: leaf.label,
|
|
213
|
-
onToggle: (e)=>toggleFlat('tools', leaf.key, e.target.checked),
|
|
214
|
-
tooltip: leaf.description
|
|
215
|
-
})
|
|
216
|
-
}, leaf.key))
|
|
217
|
-
})
|
|
218
|
-
}),
|
|
219
|
-
prompts.length > 0 && /*#__PURE__*/ _jsx(Collapsible, {
|
|
220
|
-
actions: /*#__PURE__*/ _jsx(GroupActions, {
|
|
221
|
-
onSetAll: (allow)=>setAllFlat('prompts', prompts, allow)
|
|
222
|
-
}),
|
|
223
|
-
className: `${baseClass}__group`,
|
|
224
|
-
header: /* TODO: needs i18n once design is finalized */ /*#__PURE__*/ _jsx("span", {
|
|
225
|
-
className: `${baseClass}__group-label`,
|
|
226
|
-
children: "Prompts"
|
|
227
|
-
}),
|
|
228
|
-
initCollapsed: true,
|
|
229
|
-
children: /*#__PURE__*/ _jsx("ul", {
|
|
230
|
-
className: `${baseClass}__list`,
|
|
231
|
-
children: prompts.map((leaf)=>/*#__PURE__*/ _jsx("li", {
|
|
232
|
-
children: /*#__PURE__*/ _jsx(CheckboxInput, {
|
|
233
|
-
checked: isFlatAllowed('prompts', leaf.key),
|
|
234
|
-
id: `${path}.prompts.${leaf.key}`,
|
|
235
|
-
label: leaf.label,
|
|
236
|
-
onToggle: (e)=>toggleFlat('prompts', leaf.key, e.target.checked),
|
|
237
|
-
tooltip: leaf.description
|
|
238
|
-
})
|
|
239
|
-
}, leaf.key))
|
|
240
|
-
})
|
|
241
|
-
}),
|
|
242
|
-
resources.length > 0 && /*#__PURE__*/ _jsx(Collapsible, {
|
|
243
|
-
actions: /*#__PURE__*/ _jsx(GroupActions, {
|
|
244
|
-
onSetAll: (allow)=>setAllFlat('resources', resources, allow)
|
|
245
|
-
}),
|
|
246
|
-
className: `${baseClass}__group`,
|
|
247
|
-
header: /* TODO: needs i18n once design is finalized */ /*#__PURE__*/ _jsx("span", {
|
|
248
|
-
className: `${baseClass}__group-label`,
|
|
249
|
-
children: "Resources"
|
|
250
|
-
}),
|
|
251
|
-
initCollapsed: true,
|
|
252
|
-
children: /*#__PURE__*/ _jsx("ul", {
|
|
253
|
-
className: `${baseClass}__list`,
|
|
254
|
-
children: resources.map((leaf)=>/*#__PURE__*/ _jsx("li", {
|
|
255
|
-
children: /*#__PURE__*/ _jsx(CheckboxInput, {
|
|
256
|
-
checked: isFlatAllowed('resources', leaf.key),
|
|
257
|
-
id: `${path}.resources.${leaf.key}`,
|
|
258
|
-
label: leaf.label,
|
|
259
|
-
onToggle: (e)=>toggleFlat('resources', leaf.key, e.target.checked),
|
|
260
|
-
tooltip: leaf.description
|
|
261
|
-
})
|
|
262
|
-
}, leaf.key))
|
|
263
|
-
})
|
|
264
|
-
})
|
|
265
|
-
]
|
|
266
|
-
})
|
|
267
|
-
]
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
const GroupActions = ({ onSetAll })=>// TODO: button labels + aria-labels need i18n once design is finalized
|
|
271
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
272
|
-
className: `${baseClass}__group-actions`,
|
|
273
|
-
children: [
|
|
274
|
-
/*#__PURE__*/ _jsx("button", {
|
|
275
|
-
"aria-label": "Select all",
|
|
276
|
-
className: `${baseClass}__action`,
|
|
277
|
-
onClick: (e)=>{
|
|
278
|
-
e.stopPropagation();
|
|
279
|
-
onSetAll(true);
|
|
280
|
-
},
|
|
281
|
-
title: "Select all",
|
|
282
|
-
type: "button",
|
|
283
|
-
children: "all"
|
|
284
|
-
}),
|
|
285
|
-
/*#__PURE__*/ _jsx("span", {
|
|
286
|
-
"aria-hidden": true,
|
|
287
|
-
className: `${baseClass}__action-sep`,
|
|
288
|
-
children: "/"
|
|
289
|
-
}),
|
|
290
|
-
/*#__PURE__*/ _jsx("button", {
|
|
291
|
-
"aria-label": "Clear all",
|
|
292
|
-
className: `${baseClass}__action`,
|
|
293
|
-
onClick: (e)=>{
|
|
294
|
-
e.stopPropagation();
|
|
295
|
-
onSetAll(false);
|
|
296
|
-
},
|
|
297
|
-
title: "Clear all",
|
|
298
|
-
type: "button",
|
|
299
|
-
children: "none"
|
|
300
|
-
})
|
|
301
|
-
]
|
|
302
|
-
});
|
|
303
|
-
const titleCase = (slug)=>slug.replace(/(^|[-_])(.)/g, (_, sep, ch)=>sep ? ` ${ch.toUpperCase()}` : ch.toUpperCase());
|
|
304
|
-
|
|
305
|
-
//# sourceMappingURL=index.client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/AccessField/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { JSONFieldClientProps } from 'payload'\n\nimport { CheckboxInput, Collapsible, useField } from '@payloadcms/ui'\nimport React from 'react'\n\nimport type { ClientMCPPluginConfig, MCPAPIKeysDocAccessTree } from '../../types.js'\n\nimport './index.css'\n\nconst baseClass = 'mcp-access-field'\n\ntype ClientItem = ClientMCPPluginConfig['items'][number]\ntype ScopeKey = 'collections' | 'globals'\ntype FlatKey = 'prompts' | 'resources' | 'tools'\n\ntype Props = {\n pluginConfig: ClientMCPPluginConfig\n} & JSONFieldClientProps\n\n/** Drop a key from an object and return a new object — or `undefined` if it'd be empty. */\nconst without = <T extends Record<string, unknown>>(\n obj: T | undefined,\n key: string,\n): T | undefined => {\n if (!obj || !(key in obj)) {\n return obj\n }\n const { [key]: _omitted, ...rest } = obj\n return Object.keys(rest).length === 0 ? undefined : (rest as T)\n}\n\nconst setKey = <T extends Record<string, unknown>>(\n obj: T | undefined,\n key: string,\n value: unknown,\n): T => ({ ...(obj ?? {}), [key]: value }) as T\n\nexport const AccessField: React.FC<Props> = ({ path, pluginConfig }) => {\n const { setValue, value } = useField<MCPAPIKeysDocAccessTree>({ path })\n const access = value ?? {}\n\n // Bucket items for rendering. (Bucketing is cheap and runs once per render;\n // memoizing would mean managing inputs/refs for marginal benefit.)\n const collectionsBySlug: Record<string, ClientItem[]> = {}\n const globalsBySlug: Record<string, ClientItem[]> = {}\n const tools: ClientItem[] = []\n const prompts: ClientItem[] = []\n const resources: ClientItem[] = []\n for (const item of pluginConfig.items) {\n switch (item.type) {\n case 'collectionTool':\n ;(collectionsBySlug[item.collectionSlug!] ??= []).push(item)\n break\n case 'globalTool':\n ;(globalsBySlug[item.globalSlug!] ??= []).push(item)\n break\n case 'prompt':\n prompts.push(item)\n break\n case 'resource':\n resources.push(item)\n break\n case 'tool':\n tools.push(item)\n break\n }\n }\n\n const isScopedAllowed = (scope: ScopeKey, slug: string, key: string): boolean =>\n access[scope]?.[slug]?.[key] !== false\n\n const isFlatAllowed = (scope: FlatKey, key: string): boolean => access[scope]?.[key] !== false\n\n const toggleScoped = (scope: ScopeKey, slug: string, key: string, allow: boolean) => {\n if (allow) {\n const slugBucket = without(access[scope]?.[slug], key)\n const scopeBucket = slugBucket\n ? setKey(access[scope], slug, slugBucket)\n : without(access[scope], slug)\n setValue(scopeBucket ? setKey(access, scope, scopeBucket) : (without(access, scope) ?? {}))\n } else {\n setValue(\n setKey(\n access,\n scope,\n setKey(access[scope], slug, setKey(access[scope]?.[slug], key, false)),\n ),\n )\n }\n }\n\n const toggleFlat = (scope: FlatKey, key: string, allow: boolean) => {\n if (allow) {\n const bucket = without(access[scope], key)\n setValue(bucket ? setKey(access, scope, bucket) : (without(access, scope) ?? {}))\n } else {\n setValue(setKey(access, scope, setKey(access[scope], key, false)))\n }\n }\n\n const setAllScoped = (scope: ScopeKey, slug: string, leaves: ClientItem[], allow: boolean) => {\n if (allow) {\n const scopeBucket = without(access[scope], slug)\n setValue(scopeBucket ? setKey(access, scope, scopeBucket) : (without(access, scope) ?? {}))\n } else {\n const slugBucket = leaves.reduce<Record<string, boolean>>(\n (acc, leaf) => ({ ...acc, [leaf.key]: false }),\n {},\n )\n setValue(setKey(access, scope, setKey(access[scope], slug, slugBucket)))\n }\n }\n\n const setAllFlat = (scope: FlatKey, leaves: ClientItem[], allow: boolean) => {\n if (allow) {\n setValue(without(access, scope) ?? {})\n } else {\n const bucket = leaves.reduce<Record<string, boolean>>(\n (acc, leaf) => ({ ...acc, [leaf.key]: false }),\n {},\n )\n setValue(setKey(access, scope, bucket))\n }\n }\n\n const collectionSlugs = Object.keys(collectionsBySlug)\n const globalSlugs = Object.keys(globalsBySlug)\n\n return (\n <div className={baseClass}>\n {collectionSlugs.length > 0 && (\n <section className={`${baseClass}__section`}>\n <header className={`${baseClass}__section-header`}>\n {/* TODO: needs i18n once design is finalized */}\n <h4>Collection-level permissions</h4>\n {/* TODO: needs i18n once design is finalized */}\n <p>Allow MCP clients to perform the following actions within these collections:</p>\n </header>\n {collectionSlugs.map((slug) => {\n const leaves = collectionsBySlug[slug]!\n return (\n <Collapsible\n actions={\n <GroupActions\n onSetAll={(allow) => setAllScoped('collections', slug, leaves, allow)}\n />\n }\n className={`${baseClass}__group`}\n header={<span className={`${baseClass}__group-label`}>{titleCase(slug)}</span>}\n initCollapsed\n key={`collection-${slug}`}\n >\n <ul className={`${baseClass}__list`}>\n {leaves.map((leaf) => (\n <li key={leaf.key}>\n <CheckboxInput\n checked={isScopedAllowed('collections', slug, leaf.key)}\n id={`${path}.collections.${slug}.${leaf.key}`}\n label={leaf.label}\n onToggle={(e) =>\n toggleScoped('collections', slug, leaf.key, e.target.checked)\n }\n tooltip={leaf.description}\n />\n </li>\n ))}\n </ul>\n </Collapsible>\n )\n })}\n </section>\n )}\n\n {globalSlugs.length > 0 && (\n <section className={`${baseClass}__section`}>\n <header className={`${baseClass}__section-header`}>\n {/* TODO: needs i18n once design is finalized */}\n <h4>Global-level permissions</h4>\n {/* TODO: needs i18n once design is finalized */}\n <p>Allow MCP clients to perform the following actions on these globals:</p>\n </header>\n {globalSlugs.map((slug) => {\n const leaves = globalsBySlug[slug]!\n return (\n <Collapsible\n actions={\n <GroupActions\n onSetAll={(allow) => setAllScoped('globals', slug, leaves, allow)}\n />\n }\n className={`${baseClass}__group`}\n header={<span className={`${baseClass}__group-label`}>{titleCase(slug)}</span>}\n initCollapsed\n key={`global-${slug}`}\n >\n <ul className={`${baseClass}__list`}>\n {leaves.map((leaf) => (\n <li key={leaf.key}>\n <CheckboxInput\n checked={isScopedAllowed('globals', slug, leaf.key)}\n id={`${path}.globals.${slug}.${leaf.key}`}\n label={leaf.label}\n onToggle={(e) => toggleScoped('globals', slug, leaf.key, e.target.checked)}\n tooltip={leaf.description}\n />\n </li>\n ))}\n </ul>\n </Collapsible>\n )\n })}\n </section>\n )}\n\n {(tools.length > 0 || prompts.length > 0 || resources.length > 0) && (\n <section className={`${baseClass}__section`}>\n <header className={`${baseClass}__section-header`}>\n {/* TODO: needs i18n once design is finalized */}\n <h4>Project-level permissions</h4>\n {/* TODO: needs i18n once design is finalized */}\n <p>Cross-cutting tools, prompts, and resources not scoped to a single collection.</p>\n </header>\n {tools.length > 0 && (\n <Collapsible\n actions={<GroupActions onSetAll={(allow) => setAllFlat('tools', tools, allow)} />}\n className={`${baseClass}__group`}\n header={\n /* TODO: needs i18n once design is finalized */\n <span className={`${baseClass}__group-label`}>Tools</span>\n }\n initCollapsed\n >\n <ul className={`${baseClass}__list`}>\n {tools.map((leaf) => (\n <li key={leaf.key}>\n <CheckboxInput\n checked={isFlatAllowed('tools', leaf.key)}\n id={`${path}.tools.${leaf.key}`}\n label={leaf.label}\n onToggle={(e) => toggleFlat('tools', leaf.key, e.target.checked)}\n tooltip={leaf.description}\n />\n </li>\n ))}\n </ul>\n </Collapsible>\n )}\n {prompts.length > 0 && (\n <Collapsible\n actions={<GroupActions onSetAll={(allow) => setAllFlat('prompts', prompts, allow)} />}\n className={`${baseClass}__group`}\n header={\n /* TODO: needs i18n once design is finalized */\n <span className={`${baseClass}__group-label`}>Prompts</span>\n }\n initCollapsed\n >\n <ul className={`${baseClass}__list`}>\n {prompts.map((leaf) => (\n <li key={leaf.key}>\n <CheckboxInput\n checked={isFlatAllowed('prompts', leaf.key)}\n id={`${path}.prompts.${leaf.key}`}\n label={leaf.label}\n onToggle={(e) => toggleFlat('prompts', leaf.key, e.target.checked)}\n tooltip={leaf.description}\n />\n </li>\n ))}\n </ul>\n </Collapsible>\n )}\n {resources.length > 0 && (\n <Collapsible\n actions={\n <GroupActions onSetAll={(allow) => setAllFlat('resources', resources, allow)} />\n }\n className={`${baseClass}__group`}\n header={\n /* TODO: needs i18n once design is finalized */\n <span className={`${baseClass}__group-label`}>Resources</span>\n }\n initCollapsed\n >\n <ul className={`${baseClass}__list`}>\n {resources.map((leaf) => (\n <li key={leaf.key}>\n <CheckboxInput\n checked={isFlatAllowed('resources', leaf.key)}\n id={`${path}.resources.${leaf.key}`}\n label={leaf.label}\n onToggle={(e) => toggleFlat('resources', leaf.key, e.target.checked)}\n tooltip={leaf.description}\n />\n </li>\n ))}\n </ul>\n </Collapsible>\n )}\n </section>\n )}\n </div>\n )\n}\n\nconst GroupActions: React.FC<{ onSetAll: (allow: boolean) => void }> = ({ onSetAll }) => (\n // TODO: button labels + aria-labels need i18n once design is finalized\n <div className={`${baseClass}__group-actions`}>\n <button\n aria-label=\"Select all\"\n className={`${baseClass}__action`}\n onClick={(e) => {\n e.stopPropagation()\n onSetAll(true)\n }}\n title=\"Select all\"\n type=\"button\"\n >\n all\n </button>\n <span aria-hidden className={`${baseClass}__action-sep`}>\n /\n </span>\n <button\n aria-label=\"Clear all\"\n className={`${baseClass}__action`}\n onClick={(e) => {\n e.stopPropagation()\n onSetAll(false)\n }}\n title=\"Clear all\"\n type=\"button\"\n >\n none\n </button>\n </div>\n)\n\nconst titleCase = (slug: string): string =>\n slug.replace(/(^|[-_])(.)/g, (_, sep: string, ch: string) =>\n sep ? ` ${ch.toUpperCase()}` : ch.toUpperCase(),\n )\n"],"names":["CheckboxInput","Collapsible","useField","React","baseClass","without","obj","key","_omitted","rest","Object","keys","length","undefined","setKey","value","AccessField","path","pluginConfig","setValue","access","collectionsBySlug","globalsBySlug","tools","prompts","resources","item","items","type","collectionSlug","push","globalSlug","isScopedAllowed","scope","slug","isFlatAllowed","toggleScoped","allow","slugBucket","scopeBucket","toggleFlat","bucket","setAllScoped","leaves","reduce","acc","leaf","setAllFlat","collectionSlugs","globalSlugs","div","className","section","header","h4","p","map","actions","GroupActions","onSetAll","span","titleCase","initCollapsed","ul","li","checked","id","label","onToggle","e","target","tooltip","description","button","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B,KAAKqB,KAAK;wCACjBC,UAAU,CAACC,IAAM7B,WAAW,aAAaM,KAAKvC,GAAG,EAAE8D,EAAEC,MAAM,CAACL,OAAO;wCACnEM,SAASzB,KAAK0B,WAAW;;mCANpB1B,KAAKvC,GAAG;;;;;;;AAiBnC,EAAC;AAED,MAAMmD,eAAiE,CAAC,EAAEC,QAAQ,EAAE,GAClF,uEAAuE;kBACvE,MAACT;QAAIC,WAAW,GAAG/C,UAAU,eAAe,CAAC;;0BAC3C,KAACqE;gBACCC,cAAW;gBACXvB,WAAW,GAAG/C,UAAU,QAAQ,CAAC;gBACjCuE,SAAS,CAACN;oBACRA,EAAEO,eAAe;oBACjBjB,SAAS;gBACX;gBACAkB,OAAM;gBACNjD,MAAK;0BACN;;0BAGD,KAACgC;gBAAKkB,aAAW;gBAAC3B,WAAW,GAAG/C,UAAU,YAAY,CAAC;0BAAE;;0BAGzD,KAACqE;gBACCC,cAAW;gBACXvB,WAAW,GAAG/C,UAAU,QAAQ,CAAC;gBACjCuE,SAAS,CAACN;oBACRA,EAAEO,eAAe;oBACjBjB,SAAS;gBACX;gBACAkB,OAAM;gBACNjD,MAAK;0BACN;;;;AAML,MAAMiC,YAAY,CAAC3B,OACjBA,KAAK6C,OAAO,CAAC,gBAAgB,CAACC,GAAGC,KAAaC,KAC5CD,MAAM,CAAC,CAAC,EAAEC,GAAGC,WAAW,IAAI,GAAGD,GAAGC,WAAW"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
@layer payload-default {
|
|
2
|
-
.mcp-access-field {
|
|
3
|
-
display: flex;
|
|
4
|
-
flex-direction: column;
|
|
5
|
-
gap: var(--base);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.mcp-access-field__section {
|
|
9
|
-
display: flex;
|
|
10
|
-
flex-direction: column;
|
|
11
|
-
gap: calc(var(--base) / 2);
|
|
12
|
-
padding-bottom: var(--base);
|
|
13
|
-
/* Full-bleed separator: extend past the sidebar's horizontal gutter so the
|
|
14
|
-
border-block-end spans the entire sidebar width. */
|
|
15
|
-
margin-inline-start: calc(-1 * var(--sidebar-gutter-h-left, var(--gutter-h)));
|
|
16
|
-
margin-inline-end: calc(-1 * var(--sidebar-gutter-h-right, var(--gutter-h)));
|
|
17
|
-
padding-inline-start: var(--sidebar-gutter-h-left, var(--gutter-h));
|
|
18
|
-
padding-inline-end: var(--sidebar-gutter-h-right, var(--gutter-h));
|
|
19
|
-
border-block-end: 1px solid var(--theme-elevation-100);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.mcp-access-field__section:last-child {
|
|
23
|
-
border-block-end: none;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.mcp-access-field__section-header {
|
|
27
|
-
display: flex;
|
|
28
|
-
flex-direction: column;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.mcp-access-field__section-header h4 {
|
|
32
|
-
margin: 0;
|
|
33
|
-
color: var(--color-text);
|
|
34
|
-
font-family: var(--text-heading-small-font-family);
|
|
35
|
-
font-size: var(--text-heading-small-font-size);
|
|
36
|
-
font-weight: var(--text-heading-small-font-weight);
|
|
37
|
-
line-height: var(--text-heading-small-line-height);
|
|
38
|
-
letter-spacing: var(--text-heading-small-letter-spacing);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.mcp-access-field__section-header p {
|
|
42
|
-
margin: 0;
|
|
43
|
-
color: var(--color-text-secondary);
|
|
44
|
-
font-family: var(--text-body-medium-font-family);
|
|
45
|
-
font-size: var(--text-body-medium-font-size);
|
|
46
|
-
font-weight: var(--text-body-medium-font-weight);
|
|
47
|
-
line-height: var(--text-body-medium-line-height);
|
|
48
|
-
letter-spacing: var(--text-body-medium-letter-spacing);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.mcp-access-field__group {
|
|
52
|
-
margin-block-end: calc(var(--base) / 2);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.mcp-access-field__group-label {
|
|
56
|
-
font-weight: 600;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.mcp-access-field__group-actions {
|
|
60
|
-
display: flex;
|
|
61
|
-
align-items: center;
|
|
62
|
-
gap: calc(var(--base) / 6);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.mcp-access-field__action {
|
|
66
|
-
appearance: none;
|
|
67
|
-
background: none;
|
|
68
|
-
border: none;
|
|
69
|
-
color: var(--theme-elevation-500);
|
|
70
|
-
cursor: pointer;
|
|
71
|
-
font-size: 0.75rem;
|
|
72
|
-
padding: 0;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.mcp-access-field__action:hover {
|
|
76
|
-
color: var(--theme-text);
|
|
77
|
-
text-decoration: underline;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.mcp-access-field__action-sep {
|
|
81
|
-
color: var(--theme-elevation-300);
|
|
82
|
-
font-size: 0.75rem;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.mcp-access-field__list {
|
|
86
|
-
list-style: none;
|
|
87
|
-
margin: 0;
|
|
88
|
-
padding: 0;
|
|
89
|
-
display: flex;
|
|
90
|
-
flex-direction: column;
|
|
91
|
-
gap: calc(var(--base) / 3);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like
|
|
6
|
-
* `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated
|
|
7
|
-
* in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).
|
|
8
|
-
* Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a
|
|
12
|
-
* reused def is duplicated at every use:
|
|
13
|
-
* `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* Lossier - zod drops the `description` on `enum`/`const` fields:
|
|
17
|
-
* `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`
|
|
18
|
-
*/
|
|
19
|
-
export declare const buildToolInput: <TControls extends z.ZodRawShape>({ controls, dataDescription, dataSchema, }: {
|
|
20
|
-
/** Tool options alongside `data` (depth, draft, where, …) as plain zod - inferred into `input`. */
|
|
21
|
-
controls: TControls;
|
|
22
|
-
dataDescription: string;
|
|
23
|
-
dataSchema: JsonSchemaType;
|
|
24
|
-
}) => StandardSchemaWithJSON<{
|
|
25
|
-
data: Record<string, unknown>;
|
|
26
|
-
} & Omit<z.output<z.ZodObject<{
|
|
27
|
-
data: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
28
|
-
} & TControls extends infer T ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strip>>, "data">>;
|
|
29
|
-
//# sourceMappingURL=buildToolInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildToolInput.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/buildToolInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,CAAC,CAAC,WAAW,EAAE,4CAI7D;IACD,mGAAmG;IACnG,QAAQ,EAAE,SAAS,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,cAAc,CAAA;CAC3B,KAkCM,sBAAsB,CACzB;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM;;4FAAe,EAAE,MAAM,CAAC,CAE5E,CAAA"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like
|
|
4
|
-
* `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated
|
|
5
|
-
* in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).
|
|
6
|
-
* Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a
|
|
10
|
-
* reused def is duplicated at every use:
|
|
11
|
-
* `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Lossier - zod drops the `description` on `enum`/`const` fields:
|
|
15
|
-
* `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`
|
|
16
|
-
*/ export const buildToolInput = ({ controls, dataDescription, dataSchema })=>{
|
|
17
|
-
// `sanitizeEntitySchema` already emits draft 2020-12 with `$defs`, which is what zod's `fromJSONSchema`
|
|
18
|
-
// and MCP clients both expect. Drop only the root `$schema` keyword, redundant once it's a sub-schema.
|
|
19
|
-
const { $schema: _schema, ...entitySchema } = dataSchema;
|
|
20
|
-
const schema = z.object({
|
|
21
|
-
data: z.fromJSONSchema(entitySchema),
|
|
22
|
-
...controls
|
|
23
|
-
});
|
|
24
|
-
const standard = schema['~standard'];
|
|
25
|
-
return {
|
|
26
|
-
'~standard': {
|
|
27
|
-
...standard,
|
|
28
|
-
jsonSchema: {
|
|
29
|
-
...standard.jsonSchema,
|
|
30
|
-
input: (options)=>{
|
|
31
|
-
// Start from zod's JSON Schema for the whole input, then replace its lossy `data` schema with
|
|
32
|
-
// the sanitized entity schema. The entity's `$defs` move to the root so the `$ref`s resolve.
|
|
33
|
-
const generated = standard.jsonSchema.input(options);
|
|
34
|
-
const { $defs, ...entityBody } = entitySchema;
|
|
35
|
-
generated.properties.data = {
|
|
36
|
-
...entityBody,
|
|
37
|
-
description: dataDescription
|
|
38
|
-
};
|
|
39
|
-
if ($defs) {
|
|
40
|
-
generated.$defs = $defs;
|
|
41
|
-
} else {
|
|
42
|
-
delete generated.$defs;
|
|
43
|
-
}
|
|
44
|
-
return generated;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=buildToolInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/buildToolInput.ts"],"sourcesContent":["import type { StandardSchemaWithJSON } from '@modelcontextprotocol/server'\n\nimport { z } from 'zod'\n\nimport type { JsonSchemaType } from '../../types.js'\n\n/**\n * Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like\n * `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated\n * in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).\n * Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.\n *\n * @example\n * Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a\n * reused def is duplicated at every use:\n * `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`\n *\n * @example\n * Lossier - zod drops the `description` on `enum`/`const` fields:\n * `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`\n */\nexport const buildToolInput = <TControls extends z.ZodRawShape>({\n controls,\n dataDescription,\n dataSchema,\n}: {\n /** Tool options alongside `data` (depth, draft, where, …) as plain zod - inferred into `input`. */\n controls: TControls\n dataDescription: string\n dataSchema: JsonSchemaType\n}) => {\n // `sanitizeEntitySchema` already emits draft 2020-12 with `$defs`, which is what zod's `fromJSONSchema`\n // and MCP clients both expect. Drop only the root `$schema` keyword, redundant once it's a sub-schema.\n const { $schema: _schema, ...entitySchema } = dataSchema as Record<string, unknown>\n\n const schema = z.object({\n data: z.fromJSONSchema(entitySchema as unknown as z.core.JSONSchema.JSONSchema),\n ...controls,\n })\n const standard = (schema as unknown as StandardSchemaWithJSON)['~standard']\n\n return {\n '~standard': {\n ...standard,\n jsonSchema: {\n ...standard.jsonSchema,\n input: (options) => {\n // Start from zod's JSON Schema for the whole input, then replace its lossy `data` schema with\n // the sanitized entity schema. The entity's `$defs` move to the root so the `$ref`s resolve.\n const generated = standard.jsonSchema.input(options)\n const { $defs, ...entityBody } = entitySchema\n ;(generated.properties as Record<string, unknown>).data = {\n ...entityBody,\n description: dataDescription,\n }\n if ($defs) {\n generated.$defs = $defs as object\n } else {\n delete generated.$defs\n }\n return generated\n },\n },\n },\n } as StandardSchemaWithJSON<\n { data: Record<string, unknown> } & Omit<z.output<typeof schema>, 'data'>\n >\n}\n"],"names":["z","buildToolInput","controls","dataDescription","dataSchema","$schema","_schema","entitySchema","schema","object","data","fromJSONSchema","standard","jsonSchema","input","options","generated","$defs","entityBody","properties","description"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAIvB;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,iBAAiB,CAAkC,EAC9DC,QAAQ,EACRC,eAAe,EACfC,UAAU,EAMX;IACC,wGAAwG;IACxG,uGAAuG;IACvG,MAAM,EAAEC,SAASC,OAAO,EAAE,GAAGC,cAAc,GAAGH;IAE9C,MAAMI,SAASR,EAAES,MAAM,CAAC;QACtBC,MAAMV,EAAEW,cAAc,CAACJ;QACvB,GAAGL,QAAQ;IACb;IACA,MAAMU,WAAW,AAACJ,MAA4C,CAAC,YAAY;IAE3E,OAAO;QACL,aAAa;YACX,GAAGI,QAAQ;YACXC,YAAY;gBACV,GAAGD,SAASC,UAAU;gBACtBC,OAAO,CAACC;oBACN,8FAA8F;oBAC9F,6FAA6F;oBAC7F,MAAMC,YAAYJ,SAASC,UAAU,CAACC,KAAK,CAACC;oBAC5C,MAAM,EAAEE,KAAK,EAAE,GAAGC,YAAY,GAAGX;oBAC/BS,UAAUG,UAAU,CAA6BT,IAAI,GAAG;wBACxD,GAAGQ,UAAU;wBACbE,aAAajB;oBACf;oBACA,IAAIc,OAAO;wBACTD,UAAUC,KAAK,GAAGA;oBACpB,OAAO;wBACL,OAAOD,UAAUC,KAAK;oBACxB;oBACA,OAAOD;gBACT;YACF;QACF;IACF;AAGF,EAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { JSONField } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { ClientMCPPluginConfig, MCPItem, SanitizedMCPPluginConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the API key collection's `access` field — a JSON field whose value
|
|
7
|
-
* is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
|
|
8
|
-
* a custom client component (`AccessField`) which renders a permissions
|
|
9
|
-
* matrix; the field's stored shape is just the runtime access tree.
|
|
10
|
-
*/
|
|
11
|
-
export const getAccessField = ({
|
|
12
|
-
pluginConfig,
|
|
13
|
-
}: {
|
|
14
|
-
pluginConfig: SanitizedMCPPluginConfig
|
|
15
|
-
}): JSONField => {
|
|
16
|
-
const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig)
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
name: 'access',
|
|
20
|
-
type: 'json',
|
|
21
|
-
admin: {
|
|
22
|
-
components: {
|
|
23
|
-
Field: {
|
|
24
|
-
clientProps: { pluginConfig: clientPluginConfig },
|
|
25
|
-
path: '@payloadcms/plugin-mcp/client#AccessField',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
// TODO: needs i18n once design is finalized
|
|
29
|
-
description: 'Access for this API key — uncheck to revoke individual tools.',
|
|
30
|
-
position: 'sidebar',
|
|
31
|
-
},
|
|
32
|
-
defaultValue: {},
|
|
33
|
-
// TODO: needs i18n once design is finalized
|
|
34
|
-
label: 'Access',
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,
|
|
40
|
-
* input/argsSchema functions, etc.) so the result is safe to thread to a
|
|
41
|
-
* client component via `clientProps`.
|
|
42
|
-
*/
|
|
43
|
-
const sanitizeClientPluginConfig = (
|
|
44
|
-
pluginConfig: SanitizedMCPPluginConfig,
|
|
45
|
-
): ClientMCPPluginConfig => ({
|
|
46
|
-
items: pluginConfig.items.map((item) => ({
|
|
47
|
-
...(item.type === 'collectionTool' ? { collectionSlug: item.collectionSlug } : {}),
|
|
48
|
-
...(item.type === 'globalTool' ? { globalSlug: item.globalSlug } : {}),
|
|
49
|
-
type: item.type,
|
|
50
|
-
description: itemDescription(item),
|
|
51
|
-
key: item.key,
|
|
52
|
-
label: item.label,
|
|
53
|
-
})),
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const itemDescription = (item: MCPItem): string => {
|
|
57
|
-
if (item.type === 'prompt') {
|
|
58
|
-
return item.prompt.description
|
|
59
|
-
}
|
|
60
|
-
if (item.type === 'resource') {
|
|
61
|
-
return item.resource.description
|
|
62
|
-
}
|
|
63
|
-
return item.tool.description
|
|
64
|
-
}
|