@payloadcms/plugin-mcp 4.0.0-internal.811e0a4 → 4.0.0-internal.8ba6b5b
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/endpoint/access.d.ts +2 -7
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +4 -11
- package/dist/endpoint/access.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +1 -2
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +1 -2
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +1 -2
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +1 -2
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +2 -3
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +1 -2
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +1 -2
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +21 -3
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +1 -2
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +2 -3
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +1 -2
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +2 -2
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +1 -2
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +1 -2
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +21 -3
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +1 -2
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +2 -2
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/types.d.ts +44 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +40 -6
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
- package/package.json +3 -3
- package/src/endpoint/access.ts +3 -10
- package/src/mcp/builtin/collections/countTool.ts +1 -2
- package/src/mcp/builtin/collections/countVersionsTool.ts +2 -6
- package/src/mcp/builtin/collections/createTool.ts +1 -2
- package/src/mcp/builtin/collections/deleteTool.ts +1 -2
- package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
- package/src/mcp/builtin/collections/findDistinctTool.ts +3 -3
- package/src/mcp/builtin/collections/findTool.ts +2 -3
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +25 -8
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/collections/updateTool.ts +2 -3
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
- package/src/mcp/builtin/globals/countVersionsTool.ts +2 -6
- package/src/mcp/builtin/globals/findTool.ts +2 -2
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
- package/src/mcp/builtin/globals/restoreVersionTool.ts +3 -3
- package/src/mcp/builtin/globals/updateTool.ts +2 -2
- package/src/types.ts +43 -7
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +47 -13
- package/dist/utils/localAPIDefaults.d.ts +0 -20
- package/dist/utils/localAPIDefaults.d.ts.map +0 -1
- package/dist/utils/localAPIDefaults.js +0 -19
- package/dist/utils/localAPIDefaults.js.map +0 -1
- package/src/utils/localAPIDefaults.ts +0 -22
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
|
|
3
|
+
* operations allowed by the entity, field, and its parents and decides whether to remove the
|
|
4
|
+
* field.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
|
|
7
|
+
* flattened by Payload, so their children are filtered at the containing level.
|
|
8
|
+
*
|
|
9
|
+
* @example Include fields writable through any collection operation the user can perform.
|
|
10
|
+
* ```ts
|
|
11
|
+
* filterFieldsByAccess({
|
|
12
|
+
* fields,
|
|
13
|
+
* permissions: collectionPermissions,
|
|
14
|
+
* shouldExcludeField: ({ create, update }) => !create && !update,
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/ export const filterFieldsByAccess = ({ blocks, fields, permissions, shouldExcludeField })=>{
|
|
18
|
+
const filterFields = (nestedFields, nestedPermissions, parentAllowedOperations)=>{
|
|
19
|
+
const accessibleFields = [];
|
|
20
|
+
for (const field of nestedFields){
|
|
21
|
+
const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name];
|
|
22
|
+
const isOperationAllowed = (operation)=>parentAllowedOperations[operation] && (fieldPermissions === true || fieldPermissions?.[operation] === true);
|
|
23
|
+
const allowedOperations = {
|
|
24
|
+
create: isOperationAllowed('create'),
|
|
25
|
+
read: isOperationAllowed('read'),
|
|
26
|
+
update: isOperationAllowed('update')
|
|
27
|
+
};
|
|
28
|
+
if (shouldExcludeField(allowedOperations)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (field.type === 'blocks') {
|
|
32
|
+
const accessibleBlocks = [];
|
|
33
|
+
for (const blockOrReference of field.blocks){
|
|
34
|
+
const block = typeof blockOrReference === 'string' ? blocks?.find(({ slug })=>slug === blockOrReference) : blockOrReference;
|
|
35
|
+
if (!block) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const blockPermissions = fieldPermissions === true ? true : fieldPermissions?.blocks === true ? true : fieldPermissions?.blocks?.[block.slug];
|
|
39
|
+
accessibleBlocks.push({
|
|
40
|
+
...block,
|
|
41
|
+
flattenedFields: filterFields(block.flattenedFields, blockPermissions === true ? true : blockPermissions?.fields, allowedOperations)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (accessibleBlocks.length === 0) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
accessibleFields.push({
|
|
48
|
+
...field,
|
|
49
|
+
blocks: accessibleBlocks
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {
|
|
54
|
+
accessibleFields.push({
|
|
55
|
+
...field,
|
|
56
|
+
flattenedFields: filterFields(field.flattenedFields, fieldPermissions === true ? true : fieldPermissions?.fields, allowedOperations)
|
|
57
|
+
});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
accessibleFields.push(field);
|
|
61
|
+
}
|
|
62
|
+
return accessibleFields;
|
|
63
|
+
};
|
|
64
|
+
return filterFields(fields, permissions.fields, {
|
|
65
|
+
create: 'create' in permissions && permissions.create === true,
|
|
66
|
+
read: permissions.read === true,
|
|
67
|
+
update: permissions.update === true
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=filterFieldsByAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedField,\n Operation,\n SanitizedDocumentPermissions,\n SanitizedFieldsPermissions,\n} from 'payload'\n\ntype FieldOperation = Exclude<Operation, 'delete'>\ntype AllowedFieldOperations = Record<FieldOperation, boolean>\n\n/**\n * Filters fields using the access results in `permissions`. `shouldExcludeField` receives the\n * operations allowed by the entity, field, and its parents and decides whether to remove the\n * field.\n *\n * Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are\n * flattened by Payload, so their children are filtered at the containing level.\n *\n * @example Include fields writable through any collection operation the user can perform.\n * ```ts\n * filterFieldsByAccess({\n * fields,\n * permissions: collectionPermissions,\n * shouldExcludeField: ({ create, update }) => !create && !update,\n * })\n * ```\n */\nexport const filterFieldsByAccess = ({\n blocks,\n fields,\n permissions,\n shouldExcludeField,\n}: {\n blocks?: FlattenedBlock[]\n fields: FlattenedField[]\n permissions: SanitizedDocumentPermissions\n shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean\n}): FlattenedField[] => {\n const filterFields = (\n nestedFields: FlattenedField[],\n nestedPermissions: SanitizedFieldsPermissions | undefined,\n parentAllowedOperations: AllowedFieldOperations,\n ): FlattenedField[] => {\n const accessibleFields: FlattenedField[] = []\n\n for (const field of nestedFields) {\n const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name]\n const isOperationAllowed = (operation: FieldOperation): boolean =>\n parentAllowedOperations[operation] &&\n (fieldPermissions === true || fieldPermissions?.[operation] === true)\n const allowedOperations: AllowedFieldOperations = {\n create: isOperationAllowed('create'),\n read: isOperationAllowed('read'),\n update: isOperationAllowed('update'),\n }\n\n if (shouldExcludeField(allowedOperations)) {\n continue\n }\n\n if (field.type === 'blocks') {\n const accessibleBlocks: (FlattenedBlock | string)[] = []\n\n for (const blockOrReference of field.blocks) {\n const block =\n typeof blockOrReference === 'string'\n ? blocks?.find(({ slug }) => slug === blockOrReference)\n : blockOrReference\n\n if (!block) {\n continue\n }\n\n const blockPermissions =\n fieldPermissions === true\n ? true\n : fieldPermissions?.blocks === true\n ? true\n : fieldPermissions?.blocks?.[block.slug]\n\n accessibleBlocks.push({\n ...block,\n flattenedFields: filterFields(\n block.flattenedFields,\n blockPermissions === true ? true : blockPermissions?.fields,\n allowedOperations,\n ),\n })\n }\n\n if (accessibleBlocks.length === 0) {\n continue\n }\n\n accessibleFields.push({ ...field, blocks: accessibleBlocks })\n continue\n }\n\n if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {\n accessibleFields.push({\n ...field,\n flattenedFields: filterFields(\n field.flattenedFields,\n fieldPermissions === true ? true : fieldPermissions?.fields,\n allowedOperations,\n ),\n })\n continue\n }\n\n accessibleFields.push(field)\n }\n\n return accessibleFields\n }\n\n return filterFields(fields, permissions.fields, {\n create: 'create' in permissions && permissions.create === true,\n read: permissions.read === true,\n update: permissions.update === true,\n })\n}\n"],"names":["filterFieldsByAccess","blocks","fields","permissions","shouldExcludeField","filterFields","nestedFields","nestedPermissions","parentAllowedOperations","accessibleFields","field","fieldPermissions","name","isOperationAllowed","operation","allowedOperations","create","read","update","type","accessibleBlocks","blockOrReference","block","find","slug","blockPermissions","push","flattenedFields","length"],"mappings":"AAWA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMA,uBAAuB,CAAC,EACnCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,kBAAkB,EAMnB;IACC,MAAMC,eAAe,CACnBC,cACAC,mBACAC;QAEA,MAAMC,mBAAqC,EAAE;QAE7C,KAAK,MAAMC,SAASJ,aAAc;YAChC,MAAMK,mBAAmBJ,sBAAsB,OAAO,OAAOA,mBAAmB,CAACG,MAAME,IAAI,CAAC;YAC5F,MAAMC,qBAAqB,CAACC,YAC1BN,uBAAuB,CAACM,UAAU,IACjCH,CAAAA,qBAAqB,QAAQA,kBAAkB,CAACG,UAAU,KAAK,IAAG;YACrE,MAAMC,oBAA4C;gBAChDC,QAAQH,mBAAmB;gBAC3BI,MAAMJ,mBAAmB;gBACzBK,QAAQL,mBAAmB;YAC7B;YAEA,IAAIT,mBAAmBW,oBAAoB;gBACzC;YACF;YAEA,IAAIL,MAAMS,IAAI,KAAK,UAAU;gBAC3B,MAAMC,mBAAgD,EAAE;gBAExD,KAAK,MAAMC,oBAAoBX,MAAMT,MAAM,CAAE;oBAC3C,MAAMqB,QACJ,OAAOD,qBAAqB,WACxBpB,QAAQsB,KAAK,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASH,oBACpCA;oBAEN,IAAI,CAACC,OAAO;wBACV;oBACF;oBAEA,MAAMG,mBACJd,qBAAqB,OACjB,OACAA,kBAAkBV,WAAW,OAC3B,OACAU,kBAAkBV,QAAQ,CAACqB,MAAME,IAAI,CAAC;oBAE9CJ,iBAAiBM,IAAI,CAAC;wBACpB,GAAGJ,KAAK;wBACRK,iBAAiBtB,aACfiB,MAAMK,eAAe,EACrBF,qBAAqB,OAAO,OAAOA,kBAAkBvB,QACrDa;oBAEJ;gBACF;gBAEA,IAAIK,iBAAiBQ,MAAM,KAAK,GAAG;oBACjC;gBACF;gBAEAnB,iBAAiBiB,IAAI,CAAC;oBAAE,GAAGhB,KAAK;oBAAET,QAAQmB;gBAAiB;gBAC3D;YACF;YAEA,IAAIV,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,OAAO;gBAC5EV,iBAAiBiB,IAAI,CAAC;oBACpB,GAAGhB,KAAK;oBACRiB,iBAAiBtB,aACfK,MAAMiB,eAAe,EACrBhB,qBAAqB,OAAO,OAAOA,kBAAkBT,QACrDa;gBAEJ;gBACA;YACF;YAEAN,iBAAiBiB,IAAI,CAAChB;QACxB;QAEA,OAAOD;IACT;IAEA,OAAOJ,aAAaH,QAAQC,YAAYD,MAAM,EAAE;QAC9Cc,QAAQ,YAAYb,eAAeA,YAAYa,MAAM,KAAK;QAC1DC,MAAMd,YAAYc,IAAI,KAAK;QAC3BC,QAAQf,YAAYe,MAAM,KAAK;IACjC;AACF,EAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { type CollectionSlug, type GlobalSlug, type PayloadRequest } from 'payload';
|
|
1
|
+
import { type CollectionSlug, type GlobalSlug, type PayloadRequest, type SanitizedCollectionPermission, type SanitizedGlobalPermission } from 'payload';
|
|
2
2
|
import type { JsonSchemaType } from '../../types.js';
|
|
3
|
-
export declare const getCollectionInputSchema: ({ collectionSlug, req, }: {
|
|
3
|
+
export declare const getCollectionInputSchema: ({ collectionSlug, permissions, req, }: {
|
|
4
4
|
collectionSlug: CollectionSlug;
|
|
5
|
+
permissions?: SanitizedCollectionPermission;
|
|
5
6
|
req: PayloadRequest;
|
|
6
7
|
}) => JsonSchemaType | null;
|
|
7
|
-
export declare const getGlobalInputSchema: ({ globalSlug, req, }: {
|
|
8
|
+
export declare const getGlobalInputSchema: ({ globalSlug, permissions, req, }: {
|
|
8
9
|
globalSlug: GlobalSlug;
|
|
10
|
+
permissions?: SanitizedGlobalPermission;
|
|
9
11
|
req: PayloadRequest;
|
|
10
12
|
}) => JsonSchemaType | null;
|
|
11
13
|
//# sourceMappingURL=getEntityInputSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,GAAI,uCAItC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,mCAIlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
|
|
@@ -1,32 +1,66 @@
|
|
|
1
1
|
import { entityToStandaloneJSONSchema } from 'payload';
|
|
2
|
+
import { filterFieldsByAccess } from './filterFieldsByAccess.js';
|
|
2
3
|
import { sanitizeEntitySchema } from './sanitizeEntitySchema.js';
|
|
3
|
-
export const getCollectionInputSchema = ({ collectionSlug, req })=>{
|
|
4
|
+
export const getCollectionInputSchema = ({ collectionSlug, permissions, req })=>{
|
|
4
5
|
const collection = req.payload.collections[collectionSlug]?.config;
|
|
5
6
|
if (!collection) {
|
|
6
7
|
return null;
|
|
7
8
|
}
|
|
9
|
+
if (!permissions) {
|
|
10
|
+
return buildEntityInputSchema({
|
|
11
|
+
entity: collection,
|
|
12
|
+
req
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
16
|
+
blocks: req.payload.config.blocks,
|
|
17
|
+
fields: collection.flattenedFields,
|
|
18
|
+
permissions,
|
|
19
|
+
shouldExcludeField: ({ create, update })=>!create && !update
|
|
20
|
+
});
|
|
8
21
|
return buildEntityInputSchema({
|
|
9
22
|
entity: collection,
|
|
23
|
+
fields: fieldsAllowedByAccess,
|
|
10
24
|
req
|
|
11
25
|
});
|
|
12
26
|
};
|
|
13
|
-
export const getGlobalInputSchema = ({ globalSlug, req })=>{
|
|
27
|
+
export const getGlobalInputSchema = ({ globalSlug, permissions, req })=>{
|
|
14
28
|
const global = req.payload.config.globals.find((globalConfig)=>globalConfig.slug === globalSlug);
|
|
15
29
|
if (!global) {
|
|
16
30
|
return null;
|
|
17
31
|
}
|
|
32
|
+
if (!permissions) {
|
|
33
|
+
return buildEntityInputSchema({
|
|
34
|
+
entity: global,
|
|
35
|
+
req
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
39
|
+
blocks: req.payload.config.blocks,
|
|
40
|
+
fields: global.flattenedFields,
|
|
41
|
+
permissions,
|
|
42
|
+
shouldExcludeField: ({ create, update })=>!create && !update
|
|
43
|
+
});
|
|
18
44
|
return buildEntityInputSchema({
|
|
19
45
|
entity: global,
|
|
46
|
+
fields: fieldsAllowedByAccess,
|
|
20
47
|
req
|
|
21
48
|
});
|
|
22
49
|
};
|
|
23
|
-
const buildEntityInputSchema = ({ entity, req })
|
|
24
|
-
|
|
50
|
+
const buildEntityInputSchema = ({ entity, fields = entity.flattenedFields, req })=>{
|
|
51
|
+
// The core schema generator reads flattenedFields from the entity and has no fields argument.
|
|
52
|
+
const entityForSchema = {
|
|
53
|
+
...entity,
|
|
54
|
+
flattenedFields: fields
|
|
55
|
+
};
|
|
56
|
+
const schema = entityToStandaloneJSONSchema({
|
|
25
57
|
config: req.payload.config,
|
|
26
58
|
defaultIDType: req.payload.db.defaultIDType,
|
|
27
|
-
entity,
|
|
59
|
+
entity: entityForSchema,
|
|
28
60
|
i18n: req.i18n,
|
|
29
61
|
variant: 'input'
|
|
30
|
-
})
|
|
62
|
+
});
|
|
63
|
+
return sanitizeEntitySchema(schema);
|
|
64
|
+
};
|
|
31
65
|
|
|
32
66
|
//# sourceMappingURL=getEntityInputSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedGlobalConfig,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n req,\n}: {\n collectionSlug: CollectionSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n return buildEntityInputSchema({ entity: collection, req })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n req,\n}: {\n globalSlug: GlobalSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n return buildEntityInputSchema({ entity: global, req })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n req,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n req: PayloadRequest\n}): JsonSchemaType
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type FlattenedField,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedCollectionPermission,\n type SanitizedGlobalConfig,\n type SanitizedGlobalPermission,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { filterFieldsByAccess } from './filterFieldsByAccess.js'\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n permissions,\n req,\n}: {\n collectionSlug: CollectionSlug\n permissions?: SanitizedCollectionPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: collection, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: collection.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: collection, fields: fieldsAllowedByAccess, req })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n permissions,\n req,\n}: {\n globalSlug: GlobalSlug\n permissions?: SanitizedGlobalPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: global, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: global.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: global, fields: fieldsAllowedByAccess, req })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n fields = entity.flattenedFields,\n req,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n fields?: FlattenedField[]\n req: PayloadRequest\n}): JsonSchemaType => {\n // The core schema generator reads flattenedFields from the entity and has no fields argument.\n const entityForSchema = { ...entity, flattenedFields: fields }\n const schema = entityToStandaloneJSONSchema({\n config: req.payload.config,\n defaultIDType: req.payload.db.defaultIDType,\n entity: entityForSchema,\n i18n: req.i18n,\n variant: 'input',\n }) as unknown as JsonSchemaType\n\n return sanitizeEntitySchema(schema)\n}\n"],"names":["entityToStandaloneJSONSchema","filterFieldsByAccess","sanitizeEntitySchema","getCollectionInputSchema","collectionSlug","permissions","req","collection","payload","collections","config","buildEntityInputSchema","entity","fieldsAllowedByAccess","blocks","fields","flattenedFields","shouldExcludeField","create","update","getGlobalInputSchema","globalSlug","global","globals","find","globalConfig","slug","entityForSchema","schema","defaultIDType","db","i18n","variant"],"mappings":"AAAA,SAEEA,4BAA4B,QAQvB,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,cAAc,EACdC,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACL,eAAe,EAAEM;IAE5D,IAAI,CAACH,YAAY;QACf,OAAO;IACT;IAEA,IAAI,CAACF,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQL;YAAYD;QAAI;IAC1D;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQR,WAAWS,eAAe;QAClCX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQL;QAAYQ,QAAQF;QAAuBP;IAAI;AACzF,EAAC;AAED,OAAO,MAAMc,uBAAuB,CAAC,EACnCC,UAAU,EACVhB,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMgB,SAAShB,IAAIE,OAAO,CAACE,MAAM,CAACa,OAAO,CAACC,IAAI,CAAC,CAACC,eAAiBA,aAAaC,IAAI,KAAKL;IAEvF,IAAI,CAACC,QAAQ;QACX,OAAO;IACT;IAEA,IAAI,CAACjB,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQU;YAAQhB;QAAI;IACtD;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQO,OAAON,eAAe;QAC9BX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQU;QAAQP,QAAQF;QAAuBP;IAAI;AACrF,EAAC;AAED,MAAMK,yBAAyB,CAAC,EAC9BC,MAAM,EACNG,SAASH,OAAOI,eAAe,EAC/BV,GAAG,EAKJ;IACC,8FAA8F;IAC9F,MAAMqB,kBAAkB;QAAE,GAAGf,MAAM;QAAEI,iBAAiBD;IAAO;IAC7D,MAAMa,SAAS5B,6BAA6B;QAC1CU,QAAQJ,IAAIE,OAAO,CAACE,MAAM;QAC1BmB,eAAevB,IAAIE,OAAO,CAACsB,EAAE,CAACD,aAAa;QAC3CjB,QAAQe;QACRI,MAAMzB,IAAIyB,IAAI;QACdC,SAAS;IACX;IAEA,OAAO9B,qBAAqB0B;AAC9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.8ba6b5b",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@payloadcms/eslint-config": "3.28.0",
|
|
64
|
-
"payload": "4.0.0-internal.
|
|
64
|
+
"payload": "4.0.0-internal.8ba6b5b"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"payload": "4.0.0-internal.
|
|
67
|
+
"payload": "4.0.0-internal.8ba6b5b"
|
|
68
68
|
},
|
|
69
69
|
"//deps_notes": {
|
|
70
70
|
"zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
|
package/src/endpoint/access.ts
CHANGED
|
@@ -12,13 +12,8 @@ export type GetAuthorizedMCPArgs = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Authorization has two layers:
|
|
18
|
-
* 1. Payload collection/global permissions determine whether built-in operation tools are shown.
|
|
19
|
-
* 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
|
|
20
|
-
*
|
|
21
|
-
* Like Payload core operations, `overrideAccess` skips both layers.
|
|
15
|
+
* Authenticates an MCP request and removes items the user cannot access.
|
|
16
|
+
* `overrideAccess` skips Payload and MCP item access checks.
|
|
22
17
|
*/
|
|
23
18
|
export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
|
|
24
19
|
overrideAccess,
|
|
@@ -53,7 +48,6 @@ export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<Authorize
|
|
|
53
48
|
req,
|
|
54
49
|
}),
|
|
55
50
|
overrideAccess,
|
|
56
|
-
user: req.user,
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
|
|
@@ -66,8 +60,7 @@ export const filterMCPItems = async ({
|
|
|
66
60
|
overrideAccess: boolean
|
|
67
61
|
req: PayloadRequest
|
|
68
62
|
}): Promise<MCPItem[]> => {
|
|
69
|
-
// Match Payload core: overrideAccess bypasses access evaluation
|
|
70
|
-
// forcing each access function to return true.
|
|
63
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
71
64
|
if (overrideAccess) {
|
|
72
65
|
return items
|
|
73
66
|
}
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -42,8 +41,8 @@ export const countDocumentsTool = defineCollectionTool({
|
|
|
42
41
|
try {
|
|
43
42
|
const result = await payload.count({
|
|
44
43
|
collection: collectionSlug,
|
|
44
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
45
45
|
req,
|
|
46
|
-
...localAPIDefaults(authorizedMCP),
|
|
47
46
|
...(locale ? { locale } : {}),
|
|
48
47
|
...(trash !== undefined ? { trash } : {}),
|
|
49
48
|
...(where ? { where } : {}),
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -22,10 +21,7 @@ export const countVersionsTool = defineCollectionTool({
|
|
|
22
21
|
},
|
|
23
22
|
description: DEFAULT_DESCRIPTION,
|
|
24
23
|
input: z.object({
|
|
25
|
-
locale: z
|
|
26
|
-
.string()
|
|
27
|
-
.describe('Optional: locale code to count versions in')
|
|
28
|
-
.optional(),
|
|
24
|
+
locale: z.string().describe('Optional: locale code to count versions in').optional(),
|
|
29
25
|
where: whereSchema
|
|
30
26
|
.describe(
|
|
31
27
|
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}',
|
|
@@ -42,8 +38,8 @@ export const countVersionsTool = defineCollectionTool({
|
|
|
42
38
|
try {
|
|
43
39
|
const result = await payload.countVersions({
|
|
44
40
|
collection: collectionSlug,
|
|
41
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
45
42
|
req,
|
|
46
|
-
...localAPIDefaults(authorizedMCP),
|
|
47
43
|
...(locale ? { locale } : {}),
|
|
48
44
|
...(where ? { where } : {}),
|
|
49
45
|
})
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
getCollectionVirtualFieldNames,
|
|
10
10
|
stripVirtualFields,
|
|
11
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
12
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
13
|
import { validateCollectionData } from '../validateEntityData.js'
|
|
15
14
|
import { formatCollectionError } from './formatCollectionError.js'
|
|
@@ -86,8 +85,8 @@ export const createDocumentTool = defineCollectionTool({
|
|
|
86
85
|
data: parsedData,
|
|
87
86
|
depth,
|
|
88
87
|
draft,
|
|
88
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
89
89
|
req,
|
|
90
|
-
...localAPIDefaults(authorizedMCP),
|
|
91
90
|
...(locale ? { locale } : {}),
|
|
92
91
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
93
92
|
...(select ? { select: select as SelectType } : {}),
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -69,8 +68,8 @@ export const deleteDocumentsTool = defineCollectionTool({
|
|
|
69
68
|
const deleteOptions: Record<string, unknown> = {
|
|
70
69
|
collection: collectionSlug,
|
|
71
70
|
depth,
|
|
71
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
72
72
|
req,
|
|
73
|
-
...localAPIDefaults(authorizedMCP),
|
|
74
73
|
...(locale && { locale }),
|
|
75
74
|
...(fallbackLocale && { fallbackLocale }),
|
|
76
75
|
}
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
getCollectionVirtualFieldNames,
|
|
10
10
|
stripVirtualFields,
|
|
11
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
12
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
13
|
import { formatCollectionError } from './formatCollectionError.js'
|
|
15
14
|
|
|
@@ -105,8 +104,8 @@ export const duplicateDocumentTool = defineCollectionTool({
|
|
|
105
104
|
collection: collectionSlug,
|
|
106
105
|
depth,
|
|
107
106
|
draft,
|
|
107
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
108
108
|
req,
|
|
109
|
-
...localAPIDefaults(authorizedMCP),
|
|
110
109
|
...(parsedData ? { data: parsedData } : {}),
|
|
111
110
|
...(locale ? { locale } : {}),
|
|
112
111
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -73,7 +72,8 @@ export const findDistinctTool = defineCollectionTool({
|
|
|
73
72
|
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
74
73
|
const payload = req.payload
|
|
75
74
|
const logger = getLogger({ payload })
|
|
76
|
-
const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } =
|
|
75
|
+
const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } =
|
|
76
|
+
input
|
|
77
77
|
|
|
78
78
|
logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`)
|
|
79
79
|
|
|
@@ -82,8 +82,8 @@ export const findDistinctTool = defineCollectionTool({
|
|
|
82
82
|
collection: collectionSlug,
|
|
83
83
|
depth,
|
|
84
84
|
field,
|
|
85
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
85
86
|
req,
|
|
86
|
-
...localAPIDefaults(authorizedMCP),
|
|
87
87
|
...(limit ? { limit } : {}),
|
|
88
88
|
...(locale ? { locale } : {}),
|
|
89
89
|
...(page ? { page } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -134,8 +133,8 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
134
133
|
id,
|
|
135
134
|
collection: collectionSlug,
|
|
136
135
|
depth,
|
|
136
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
137
137
|
req,
|
|
138
|
-
...localAPIDefaults(authorizedMCP),
|
|
139
138
|
...(select && { select: select as SelectType }),
|
|
140
139
|
...(populate && { populate: populate as PopulateType }),
|
|
141
140
|
...(joins !== undefined && { joins: joins as JoinQuery }),
|
|
@@ -171,9 +170,9 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
171
170
|
collection: collectionSlug,
|
|
172
171
|
depth,
|
|
173
172
|
limit,
|
|
173
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
174
174
|
page,
|
|
175
175
|
req,
|
|
176
|
-
...localAPIDefaults(authorizedMCP),
|
|
177
176
|
...(select && { select: select as SelectType }),
|
|
178
177
|
...(populate && { populate: populate as PopulateType }),
|
|
179
178
|
...(joins !== undefined && { joins: joins as JoinQuery }),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'
|
|
@@ -75,8 +74,8 @@ export const findVersionByIDTool = defineCollectionTool({
|
|
|
75
74
|
id,
|
|
76
75
|
collection: collectionSlug,
|
|
77
76
|
depth,
|
|
77
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
78
78
|
req,
|
|
79
|
-
...localAPIDefaults(authorizedMCP),
|
|
80
79
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
81
80
|
...(locale ? { locale } : {}),
|
|
82
81
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -116,9 +115,9 @@ export const findVersionsTool = defineCollectionTool({
|
|
|
116
115
|
collection: collectionSlug,
|
|
117
116
|
depth,
|
|
118
117
|
limit,
|
|
118
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
119
119
|
page,
|
|
120
120
|
req,
|
|
121
|
-
...localAPIDefaults(authorizedMCP),
|
|
122
121
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
123
122
|
...(locale ? { locale } : {}),
|
|
124
123
|
...(pagination !== undefined ? { pagination } : {}),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getAccessResults } from 'payload'
|
|
2
|
+
|
|
1
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
2
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
3
5
|
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
@@ -6,12 +8,7 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
6
8
|
access: (args) => {
|
|
7
9
|
const permissions = args.permissions?.collections?.[args.collectionSlug]
|
|
8
10
|
|
|
9
|
-
return (
|
|
10
|
-
defaultAccess(args) &&
|
|
11
|
-
Boolean(
|
|
12
|
-
permissions?.create || permissions?.delete || permissions?.read || permissions?.update,
|
|
13
|
-
)
|
|
14
|
-
)
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)
|
|
15
12
|
},
|
|
16
13
|
annotations: {
|
|
17
14
|
destructiveHint: false,
|
|
@@ -21,8 +18,28 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
21
18
|
title: 'Get Collection Schema',
|
|
22
19
|
},
|
|
23
20
|
description: 'Get the input schema for creating or updating documents in a collection.',
|
|
24
|
-
}).handler(({ collectionSlug, req }) => {
|
|
25
|
-
const
|
|
21
|
+
}).handler(async ({ authorizedMCP, collectionSlug, req }) => {
|
|
22
|
+
const permissions = authorizedMCP.overrideAccess
|
|
23
|
+
? null
|
|
24
|
+
: (await getAccessResults({ req })).collections?.[collectionSlug]
|
|
25
|
+
|
|
26
|
+
if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const inputSchema = getCollectionInputSchema({
|
|
39
|
+
collectionSlug,
|
|
40
|
+
req,
|
|
41
|
+
...(permissions ? { permissions } : {}),
|
|
42
|
+
})
|
|
26
43
|
|
|
27
44
|
if (!inputSchema) {
|
|
28
45
|
return {
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Restore a document from a previous version in any version-enabled collection.'
|
|
@@ -74,8 +73,8 @@ export const restoreVersionTool = defineCollectionTool({
|
|
|
74
73
|
collection: collectionSlug,
|
|
75
74
|
depth,
|
|
76
75
|
draft,
|
|
76
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
77
77
|
req,
|
|
78
|
-
...localAPIDefaults(authorizedMCP),
|
|
79
78
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
80
79
|
...(locale ? { locale } : {}),
|
|
81
80
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
getCollectionVirtualFieldNames,
|
|
10
10
|
stripVirtualFields,
|
|
11
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
12
|
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
14
13
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
15
14
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
@@ -129,9 +128,9 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
129
128
|
data: parsedData,
|
|
130
129
|
depth,
|
|
131
130
|
draft,
|
|
131
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
132
132
|
overrideLock,
|
|
133
133
|
req,
|
|
134
|
-
...localAPIDefaults(authorizedMCP),
|
|
135
134
|
...(filePath ? { filePath } : {}),
|
|
136
135
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
137
136
|
...(locale ? { locale } : {}),
|
|
@@ -155,10 +154,10 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
155
154
|
data: parsedData,
|
|
156
155
|
depth,
|
|
157
156
|
draft,
|
|
157
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
158
158
|
overrideLock,
|
|
159
159
|
req,
|
|
160
160
|
where: whereClause,
|
|
161
|
-
...localAPIDefaults(authorizedMCP),
|
|
162
161
|
...(filePath ? { filePath } : {}),
|
|
163
162
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
164
163
|
...(locale ? { locale } : {}),
|
|
@@ -12,10 +12,8 @@ export const getConfigInfoTool = defineTool({
|
|
|
12
12
|
},
|
|
13
13
|
description: 'List the Payload collection and global slugs visible to this MCP client.',
|
|
14
14
|
}).handler(async ({ authorizedMCP, req }) => {
|
|
15
|
-
const user =
|
|
16
|
-
const permissions = authorizedMCP.overrideAccess
|
|
17
|
-
? null
|
|
18
|
-
: await getAccessResults({ req: { ...req, user } })
|
|
15
|
+
const user = req.user
|
|
16
|
+
const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })
|
|
19
17
|
const authorizedCollectionSlugs = new Set<string>()
|
|
20
18
|
const authorizedGlobalSlugs = new Set<string>()
|
|
21
19
|
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -21,10 +20,7 @@ export const countGlobalVersionsTool = defineGlobalTool({
|
|
|
21
20
|
},
|
|
22
21
|
description: DEFAULT_DESCRIPTION,
|
|
23
22
|
input: z.object({
|
|
24
|
-
locale: z
|
|
25
|
-
.string()
|
|
26
|
-
.describe('Optional: locale code to count versions in')
|
|
27
|
-
.optional(),
|
|
23
|
+
locale: z.string().describe('Optional: locale code to count versions in').optional(),
|
|
28
24
|
where: whereSchema
|
|
29
25
|
.describe(
|
|
30
26
|
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
|
|
@@ -41,8 +37,8 @@ export const countGlobalVersionsTool = defineGlobalTool({
|
|
|
41
37
|
try {
|
|
42
38
|
const result = await payload.countGlobalVersions({
|
|
43
39
|
global: globalSlug,
|
|
40
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
44
41
|
req,
|
|
45
|
-
...localAPIDefaults(authorizedMCP),
|
|
46
42
|
...(locale ? { locale } : {}),
|
|
47
43
|
...(where ? { where } : {}),
|
|
48
44
|
})
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
11
10
|
|
|
@@ -66,7 +65,8 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
66
65
|
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
67
66
|
slug: globalSlug,
|
|
68
67
|
depth,
|
|
69
|
-
|
|
68
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
69
|
+
req,
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (locale) {
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Find a specific global version in any version-enabled global by passing the global slug and version ID.'
|
|
@@ -70,8 +69,8 @@ export const findGlobalVersionByIDTool = defineGlobalTool({
|
|
|
70
69
|
id,
|
|
71
70
|
slug: globalSlug,
|
|
72
71
|
depth,
|
|
72
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
73
73
|
req,
|
|
74
|
-
...localAPIDefaults(authorizedMCP),
|
|
75
74
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
76
75
|
...(locale ? { locale } : {}),
|
|
77
76
|
...(populate ? { populate: populate as PopulateType } : {}),
|