@payloadcms/plugin-mcp 4.0.0-internal.811e0a4 → 4.0.0-internal.8867dba
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/bin.js +7 -0
- package/dist/defaultAccess.d.ts.map +1 -1
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- 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/buildMcpServer.d.ts.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 +15 -6
- 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/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +117 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
- 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 +3 -4
- 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/formatCollectionError.d.ts +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +45 -5
- 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 +24 -12
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- 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/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtinTools.d.ts +6 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +6 -0
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +4 -1
- package/dist/mcp/sanitizeMCPConfig.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/camelCase.d.ts.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.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/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +2 -2
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +4 -4
- 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 +15 -6
- package/src/mcp/builtin/collections/deleteTool.ts +1 -2
- package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +154 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +3 -3
- package/src/mcp/builtin/collections/findTool.ts +3 -4
- 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 +43 -9
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/collections/updateTool.ts +26 -10
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- 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/mcp/builtinTools.ts +7 -0
- package/src/mcp/sanitizeMCPConfig.ts +4 -1
- package/src/types.ts +43 -7
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +47 -13
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +2 -2
- 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
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type CollectionSlug,
|
|
3
3
|
entityToStandaloneJSONSchema,
|
|
4
|
+
type FlattenedField,
|
|
4
5
|
type GlobalSlug,
|
|
5
6
|
type PayloadRequest,
|
|
6
7
|
type SanitizedCollectionConfig,
|
|
8
|
+
type SanitizedCollectionPermission,
|
|
7
9
|
type SanitizedGlobalConfig,
|
|
10
|
+
type SanitizedGlobalPermission,
|
|
8
11
|
} from 'payload'
|
|
9
12
|
|
|
10
13
|
import type { JsonSchemaType } from '../../types.js'
|
|
11
14
|
|
|
15
|
+
import { filterFieldsByAccess } from './filterFieldsByAccess.js'
|
|
12
16
|
import { sanitizeEntitySchema } from './sanitizeEntitySchema.js'
|
|
13
17
|
|
|
14
18
|
export const getCollectionInputSchema = ({
|
|
15
19
|
collectionSlug,
|
|
20
|
+
permissions,
|
|
16
21
|
req,
|
|
17
22
|
}: {
|
|
18
23
|
collectionSlug: CollectionSlug
|
|
24
|
+
permissions?: SanitizedCollectionPermission
|
|
19
25
|
req: PayloadRequest
|
|
20
26
|
}): JsonSchemaType | null => {
|
|
21
27
|
const collection = req.payload.collections[collectionSlug]?.config
|
|
@@ -24,14 +30,27 @@ export const getCollectionInputSchema = ({
|
|
|
24
30
|
return null
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
if (!permissions) {
|
|
34
|
+
return buildEntityInputSchema({ entity: collection, req })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
38
|
+
blocks: req.payload.config.blocks,
|
|
39
|
+
fields: collection.flattenedFields,
|
|
40
|
+
permissions,
|
|
41
|
+
shouldExcludeField: ({ create, update }) => !create && !update,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return buildEntityInputSchema({ entity: collection, fields: fieldsAllowedByAccess, req })
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
export const getGlobalInputSchema = ({
|
|
31
48
|
globalSlug,
|
|
49
|
+
permissions,
|
|
32
50
|
req,
|
|
33
51
|
}: {
|
|
34
52
|
globalSlug: GlobalSlug
|
|
53
|
+
permissions?: SanitizedGlobalPermission
|
|
35
54
|
req: PayloadRequest
|
|
36
55
|
}): JsonSchemaType | null => {
|
|
37
56
|
const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)
|
|
@@ -40,23 +59,38 @@ export const getGlobalInputSchema = ({
|
|
|
40
59
|
return null
|
|
41
60
|
}
|
|
42
61
|
|
|
43
|
-
|
|
62
|
+
if (!permissions) {
|
|
63
|
+
return buildEntityInputSchema({ entity: global, req })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
67
|
+
blocks: req.payload.config.blocks,
|
|
68
|
+
fields: global.flattenedFields,
|
|
69
|
+
permissions,
|
|
70
|
+
shouldExcludeField: ({ create, update }) => !create && !update,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
return buildEntityInputSchema({ entity: global, fields: fieldsAllowedByAccess, req })
|
|
44
74
|
}
|
|
45
75
|
|
|
46
76
|
const buildEntityInputSchema = ({
|
|
47
77
|
entity,
|
|
78
|
+
fields = entity.flattenedFields,
|
|
48
79
|
req,
|
|
49
80
|
}: {
|
|
50
81
|
entity: SanitizedCollectionConfig | SanitizedGlobalConfig
|
|
82
|
+
fields?: FlattenedField[]
|
|
51
83
|
req: PayloadRequest
|
|
52
|
-
}): JsonSchemaType =>
|
|
53
|
-
// The
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
84
|
+
}): JsonSchemaType => {
|
|
85
|
+
// The core schema generator reads flattenedFields from the entity and has no fields argument.
|
|
86
|
+
const entityForSchema = { ...entity, flattenedFields: fields }
|
|
87
|
+
const schema = entityToStandaloneJSONSchema({
|
|
88
|
+
config: req.payload.config,
|
|
89
|
+
defaultIDType: req.payload.db.defaultIDType,
|
|
90
|
+
entity: entityForSchema,
|
|
91
|
+
i18n: req.i18n,
|
|
92
|
+
variant: 'input',
|
|
93
|
+
}) as unknown as JsonSchemaType
|
|
94
|
+
|
|
95
|
+
return sanitizeEntitySchema(schema)
|
|
96
|
+
}
|
|
@@ -76,8 +76,8 @@ describe('sanitizeEntitySchema', () => {
|
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
78
|
properties: {
|
|
79
|
-
// Managed
|
|
80
|
-
//
|
|
79
|
+
// Managed timestamps are excluded upstream by the `input` variant. `id` stays because it's
|
|
80
|
+
// a valid optional input (a client may supply a custom ID).
|
|
81
81
|
id: { type: 'string' },
|
|
82
82
|
content: {
|
|
83
83
|
type: 'object',
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AuthorizedMCP } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the `user` and `overrideAccess` arguments every Payload local API call
|
|
4
|
-
* should receive when initiated from an MCP request. Spread the result into the
|
|
5
|
-
* call's arg object so the two pieces of caller state can't drift apart.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* await req.payload.create({
|
|
10
|
-
* collection: 'posts',
|
|
11
|
-
* data,
|
|
12
|
-
* ...localAPIDefaults(authorizedMCP),
|
|
13
|
-
* })
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare const localAPIDefaults: (authorizedMCP: AuthorizedMCP) => {
|
|
17
|
-
overrideAccess: boolean;
|
|
18
|
-
user: AuthorizedMCP["user"];
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=localAPIDefaults.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localAPIDefaults.d.ts","sourceRoot":"","sources":["../../src/utils/localAPIDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,eAAe,aAAa,KAC3B;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAGvD,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the `user` and `overrideAccess` arguments every Payload local API call
|
|
3
|
-
* should receive when initiated from an MCP request. Spread the result into the
|
|
4
|
-
* call's arg object so the two pieces of caller state can't drift apart.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* await req.payload.create({
|
|
9
|
-
* collection: 'posts',
|
|
10
|
-
* data,
|
|
11
|
-
* ...localAPIDefaults(authorizedMCP),
|
|
12
|
-
* })
|
|
13
|
-
* ```
|
|
14
|
-
*/ export const localAPIDefaults = (authorizedMCP)=>({
|
|
15
|
-
overrideAccess: authorizedMCP.overrideAccess,
|
|
16
|
-
user: authorizedMCP.user
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=localAPIDefaults.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/localAPIDefaults.ts"],"sourcesContent":["import type { AuthorizedMCP } from '../types.js'\n\n/**\n * Returns the `user` and `overrideAccess` arguments every Payload local API call\n * should receive when initiated from an MCP request. Spread the result into the\n * call's arg object so the two pieces of caller state can't drift apart.\n *\n * @example\n * ```ts\n * await req.payload.create({\n * collection: 'posts',\n * data,\n * ...localAPIDefaults(authorizedMCP),\n * })\n * ```\n */\nexport const localAPIDefaults = (\n authorizedMCP: AuthorizedMCP,\n): { overrideAccess: boolean; user: AuthorizedMCP['user'] } => ({\n overrideAccess: authorizedMCP.overrideAccess,\n user: authorizedMCP.user,\n})\n"],"names":["localAPIDefaults","authorizedMCP","overrideAccess","user"],"mappings":"AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMA,mBAAmB,CAC9BC,gBAC8D,CAAA;QAC9DC,gBAAgBD,cAAcC,cAAc;QAC5CC,MAAMF,cAAcE,IAAI;IAC1B,CAAA,EAAE"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AuthorizedMCP } from '../types.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the `user` and `overrideAccess` arguments every Payload local API call
|
|
5
|
-
* should receive when initiated from an MCP request. Spread the result into the
|
|
6
|
-
* call's arg object so the two pieces of caller state can't drift apart.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* await req.payload.create({
|
|
11
|
-
* collection: 'posts',
|
|
12
|
-
* data,
|
|
13
|
-
* ...localAPIDefaults(authorizedMCP),
|
|
14
|
-
* })
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export const localAPIDefaults = (
|
|
18
|
-
authorizedMCP: AuthorizedMCP,
|
|
19
|
-
): { overrideAccess: boolean; user: AuthorizedMCP['user'] } => ({
|
|
20
|
-
overrideAccess: authorizedMCP.overrideAccess,
|
|
21
|
-
user: authorizedMCP.user,
|
|
22
|
-
})
|