@payloadcms/plugin-mcp 4.0.0-internal.4cbdd50 → 4.0.0-internal.532221d
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/LICENSE.md +1 -1
- 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/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +57 -17
- package/dist/endpoint/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +4 -4
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +32 -10
- package/dist/mcp/buildMcpServer.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 +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +92 -42
- 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 +2 -4
- 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 +124 -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/formatCollectionError.js +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +45 -6
- 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 +25 -15
- 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 -4
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.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 +3 -4
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtin/validateEntityData.js +2 -2
- package/dist/mcp/builtin/validateEntityData.js.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 +9 -3
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +5 -1
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -4
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +61 -42
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +57 -9
- 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/toStandardSchema.d.ts.map +1 -1
- package/package.json +8 -10
- package/src/endpoint/access.ts +3 -10
- package/src/endpoint/index.ts +45 -16
- package/src/index.ts +4 -4
- package/src/mcp/buildMcpServer.ts +40 -20
- package/src/mcp/builtin/collections/countTool.ts +1 -2
- package/src/mcp/builtin/collections/countVersionsTool.ts +1 -2
- package/src/mcp/builtin/collections/createTool.ts +95 -39
- package/src/mcp/builtin/collections/deleteTool.ts +1 -2
- package/src/mcp/builtin/collections/duplicateTool.ts +6 -7
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +164 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +1 -2
- 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/formatCollectionError.ts +2 -2
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +43 -10
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/collections/updateTool.ts +32 -16
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
- package/src/mcp/builtin/globals/countVersionsTool.ts +1 -2
- 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 -4
- package/src/mcp/builtin/globals/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/globals/updateTool.ts +7 -7
- package/src/mcp/builtin/validateEntityData.ts +4 -8
- package/src/mcp/builtinTools.ts +9 -2
- package/src/mcp/sanitizeMCPConfig.ts +5 -1
- package/src/stdio.ts +61 -43
- package/src/types.ts +57 -9
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- 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/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/src/@types/assets.d.ts +0 -3
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
- package/src/utils/transformPointDataToPayload.ts +0 -40
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { getAccessResults, getGlobalInputSchema } from 'payload'
|
|
2
|
+
|
|
1
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
2
4
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
3
|
-
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
4
5
|
|
|
5
6
|
export const getGlobalSchemaTool = defineGlobalTool({
|
|
6
7
|
access: (args) => {
|
|
7
8
|
const permissions = args.permissions?.globals?.[args.globalSlug]
|
|
8
9
|
|
|
9
|
-
return defaultAccess(args) && Boolean(permissions?.
|
|
10
|
+
return defaultAccess(args) && Boolean(permissions?.update)
|
|
10
11
|
},
|
|
11
12
|
annotations: {
|
|
12
13
|
destructiveHint: false,
|
|
@@ -16,8 +17,28 @@ export const getGlobalSchemaTool = defineGlobalTool({
|
|
|
16
17
|
title: 'Get Global Schema',
|
|
17
18
|
},
|
|
18
19
|
description: 'Get the input schema for updating a global.',
|
|
19
|
-
}).handler(({ globalSlug, req }) => {
|
|
20
|
-
const
|
|
20
|
+
}).handler(async ({ authorizedMCP, globalSlug, req }) => {
|
|
21
|
+
const permissions = authorizedMCP.overrideAccess
|
|
22
|
+
? null
|
|
23
|
+
: (await getAccessResults({ req })).globals?.[globalSlug]
|
|
24
|
+
|
|
25
|
+
if (!authorizedMCP.overrideAccess && !permissions?.update) {
|
|
26
|
+
return {
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: 'text',
|
|
30
|
+
text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${globalSlug}"`,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
isError: true,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const inputSchema = getGlobalInputSchema({
|
|
38
|
+
globalSlug,
|
|
39
|
+
req,
|
|
40
|
+
...(permissions ? { permissions } : {}),
|
|
41
|
+
})
|
|
21
42
|
|
|
22
43
|
if (!inputSchema) {
|
|
23
44
|
return {
|
|
@@ -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
|
'Restore a global from a previous version in any version-enabled global.'
|
|
@@ -62,8 +61,8 @@ export const restoreGlobalVersionTool = defineGlobalTool({
|
|
|
62
61
|
id,
|
|
63
62
|
slug: globalSlug,
|
|
64
63
|
depth,
|
|
64
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
65
65
|
req,
|
|
66
|
-
...localAPIDefaults(authorizedMCP),
|
|
67
66
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
68
67
|
...(locale ? { locale } : {}),
|
|
69
68
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { SelectType } from 'payload'
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
getGlobalVirtualFieldNames,
|
|
5
|
+
stripVirtualFields,
|
|
6
|
+
transformPointDataToPayload,
|
|
7
|
+
} from 'payload'
|
|
3
8
|
import { z } from 'zod'
|
|
4
9
|
|
|
5
10
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
11
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
12
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import {
|
|
9
|
-
getGlobalVirtualFieldNames,
|
|
10
|
-
stripVirtualFields,
|
|
11
|
-
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
|
-
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
13
|
import { validateGlobalData } from '../validateEntityData.js'
|
|
15
14
|
|
|
16
15
|
const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
|
|
@@ -81,7 +80,8 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
81
80
|
data: parsedData,
|
|
82
81
|
depth,
|
|
83
82
|
draft,
|
|
84
|
-
|
|
83
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
84
|
+
req,
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (locale) {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
|
|
2
2
|
|
|
3
|
-
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'
|
|
3
|
+
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'
|
|
4
|
+
import { getCollectionInputSchema, getGlobalInputSchema } from 'payload'
|
|
4
5
|
|
|
5
6
|
import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
getCollectionInputSchema,
|
|
9
|
-
getGlobalInputSchema,
|
|
10
|
-
} from '../../utils/schemaConversion/getEntityInputSchema.js'
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
9
|
* Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
|
|
14
10
|
*/
|
|
@@ -38,7 +34,7 @@ export const validateCollectionData = ({
|
|
|
38
34
|
}): MCPToolResponse | null =>
|
|
39
35
|
validateData({
|
|
40
36
|
slug: collectionSlug,
|
|
41
|
-
buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
|
|
37
|
+
buildSchema: () => getCollectionInputSchema({ collectionSlug, req }) as JsonSchemaType | null,
|
|
42
38
|
data,
|
|
43
39
|
entity: 'collection',
|
|
44
40
|
partial,
|
|
@@ -56,7 +52,7 @@ export const validateGlobalData = ({
|
|
|
56
52
|
}): MCPToolResponse | null =>
|
|
57
53
|
validateData({
|
|
58
54
|
slug: globalSlug,
|
|
59
|
-
buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
|
|
55
|
+
buildSchema: () => getGlobalInputSchema({ globalSlug, req }) as JsonSchemaType | null,
|
|
60
56
|
data,
|
|
61
57
|
entity: 'global',
|
|
62
58
|
partial: true,
|
package/src/mcp/builtinTools.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './builtin/collections/authTools.js'
|
|
11
11
|
import { countDocumentsTool } from './builtin/collections/countTool.js'
|
|
12
12
|
import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
|
|
13
|
-
import {
|
|
13
|
+
import { createDocumentsTool } from './builtin/collections/createTool.js'
|
|
14
14
|
import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
|
|
15
15
|
import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
|
|
16
16
|
import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
|
|
@@ -20,6 +20,7 @@ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
|
|
|
20
20
|
import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
|
|
21
21
|
import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
|
|
22
22
|
import { updateDocumentTool } from './builtin/collections/updateTool.js'
|
|
23
|
+
import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
|
|
23
24
|
import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
|
|
24
25
|
import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
|
|
25
26
|
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
@@ -32,6 +33,7 @@ import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
|
32
33
|
type CollectionBuiltin = {
|
|
33
34
|
mcpName: string
|
|
34
35
|
requiresDuplicateEnabled?: boolean
|
|
36
|
+
requiresUpload?: boolean
|
|
35
37
|
requiresVersions?: boolean
|
|
36
38
|
tool: CollectionTool
|
|
37
39
|
}
|
|
@@ -54,7 +56,7 @@ export const TOOL_BUILTINS = {
|
|
|
54
56
|
export const COLLECTION_BUILTINS = {
|
|
55
57
|
count: { mcpName: 'countDocuments', tool: countDocumentsTool },
|
|
56
58
|
countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
|
|
57
|
-
create: { mcpName: '
|
|
59
|
+
create: { mcpName: 'createDocuments', tool: createDocumentsTool },
|
|
58
60
|
delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
|
|
59
61
|
duplicate: {
|
|
60
62
|
mcpName: 'duplicateDocument',
|
|
@@ -70,6 +72,11 @@ export const COLLECTION_BUILTINS = {
|
|
|
70
72
|
},
|
|
71
73
|
findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
|
|
72
74
|
getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
|
|
75
|
+
getUploadInstructions: {
|
|
76
|
+
mcpName: 'getUploadInstructions',
|
|
77
|
+
requiresUpload: true,
|
|
78
|
+
tool: getUploadInstructionsTool,
|
|
79
|
+
},
|
|
73
80
|
restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
|
|
74
81
|
update: { mcpName: 'updateDocument', tool: updateDocumentTool },
|
|
75
82
|
} satisfies Record<string, CollectionBuiltin>
|
|
@@ -100,6 +100,7 @@ export const sanitizeMCPConfig = ({
|
|
|
100
100
|
|
|
101
101
|
return {
|
|
102
102
|
disabled: pluginConfig.disabled,
|
|
103
|
+
hooks: pluginConfig.hooks,
|
|
103
104
|
items,
|
|
104
105
|
mcp: pluginConfig.mcp,
|
|
105
106
|
overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
|
|
@@ -126,7 +127,7 @@ const sanitizeCollectionConfig = ({
|
|
|
126
127
|
|
|
127
128
|
for (const [
|
|
128
129
|
toolKey,
|
|
129
|
-
{ mcpName, requiresDuplicateEnabled, requiresVersions, tool },
|
|
130
|
+
{ mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
|
|
130
131
|
] of COLLECTION_BUILTIN_ENTRIES) {
|
|
131
132
|
if (requiresVersions && !collection.versions) {
|
|
132
133
|
continue
|
|
@@ -134,6 +135,9 @@ const sanitizeCollectionConfig = ({
|
|
|
134
135
|
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
135
136
|
continue
|
|
136
137
|
}
|
|
138
|
+
if (requiresUpload && !collection.upload) {
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
137
141
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
|
|
138
142
|
if (matchedConfigEntry === false) {
|
|
139
143
|
continue
|
package/src/stdio.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config, Plugin, SanitizedConfig } from 'payload'
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
|
-
import {
|
|
4
|
+
import { serveStdio } from '@modelcontextprotocol/server/stdio'
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
6
|
import { createLocalReq, getPayload } from 'payload'
|
|
7
|
-
import { findConfig } from 'payload/node'
|
|
7
|
+
import { findConfig, loadEnv } from 'payload/node'
|
|
8
8
|
|
|
9
9
|
import type { SanitizedMCPPluginConfig } from './types.js'
|
|
10
10
|
|
|
@@ -15,53 +15,62 @@ import { getPluginConfig } from './utils/getPluginConfig.js'
|
|
|
15
15
|
import { resolveProjectRoot } from './utils/resolveProjectRoot.js'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Starts Payload's MCP server over stdin and stdout.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* skips access control for local setup.
|
|
20
|
+
* Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
|
|
21
|
+
* `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
|
|
23
22
|
*/
|
|
24
23
|
export const runMcpStdio = async (): Promise<void> => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Payload's cwd-anchored `findConfig()` can't locate the project on
|
|
28
|
-
* its own. This module always lives inside the project's `node_modules`, so
|
|
29
|
-
* we derive the project root from its own path and `chdir` into it.
|
|
30
|
-
*
|
|
31
|
-
* An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
|
|
32
|
-
* layouts (e.g. a monorepo where the package is hoisted above the app) can
|
|
33
|
-
* fall back to it. See the implementation of findConfig for details.
|
|
34
|
-
*/
|
|
24
|
+
// MCP clients may start this command from another folder. Move to the Payload
|
|
25
|
+
// project so findConfig() can find the config.
|
|
35
26
|
const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))
|
|
36
27
|
if (projectRoot) {
|
|
37
28
|
process.chdir(projectRoot)
|
|
38
29
|
}
|
|
39
30
|
|
|
31
|
+
loadEnv()
|
|
40
32
|
const configPath = findConfig()
|
|
41
33
|
const configModule = await import(pathToFileURL(configPath).toString())
|
|
42
|
-
const config = (await (configModule.default ?? configModule)) as
|
|
43
|
-
|
|
44
|
-
const payload = await getPayload({ config })
|
|
34
|
+
const config = (await (configModule.default ?? configModule)) as SanitizedConfig
|
|
45
35
|
|
|
46
36
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
37
|
+
* stdout is only for MCP messages. The spec says the server must not write
|
|
38
|
+
* logs there and may write them to stderr instead.
|
|
39
|
+
*
|
|
40
|
+
* The 2.0 client library recovers from stray stdout logs, but that behavior is not
|
|
41
|
+
* guaranteed. Move Payload logs to stderr so Payload does not add invalid data
|
|
42
|
+
* to stdout. Keep options from configurable loggers. Replace pre-built loggers
|
|
43
|
+
* because their output cannot be redirected.
|
|
44
|
+
*
|
|
45
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio
|
|
51
46
|
*/
|
|
47
|
+
const loggerConfig: { logger?: Config['logger'] } = config
|
|
48
|
+
if (
|
|
49
|
+
loggerConfig.logger &&
|
|
50
|
+
typeof loggerConfig.logger === 'object' &&
|
|
51
|
+
'options' in loggerConfig.logger
|
|
52
|
+
) {
|
|
53
|
+
loggerConfig.logger.destination = process.stderr
|
|
54
|
+
} else {
|
|
55
|
+
loggerConfig.logger = { destination: process.stderr, options: {} }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const payload = await getPayload({ config, cron: false, disableOnInit: true })
|
|
59
|
+
|
|
52
60
|
let pluginConfig: SanitizedMCPPluginConfig
|
|
53
61
|
try {
|
|
54
62
|
pluginConfig = getPluginConfig({ config: payload.config })
|
|
55
63
|
} catch {
|
|
64
|
+
// The command also works when mcpPlugin() is not in the Payload config.
|
|
56
65
|
pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })
|
|
57
66
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
const fallbackPlugin: Plugin = (config) => config
|
|
68
|
+
Object.assign(fallbackPlugin, {
|
|
69
|
+
slug: '@payloadcms/plugin-mcp',
|
|
70
|
+
sanitizedOptions: pluginConfig,
|
|
71
|
+
})
|
|
72
|
+
payload.config.plugins ??= []
|
|
73
|
+
payload.config.plugins.push(fallbackPlugin)
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS
|
|
@@ -86,28 +95,37 @@ export const runMcpStdio = async (): Promise<void> => {
|
|
|
86
95
|
req.payloadAPI = 'MCP' as const
|
|
87
96
|
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
88
97
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
99
|
+
onerror: (err) => {
|
|
100
|
+
// MCP messages use stdout, so write SDK errors to stderr.
|
|
101
|
+
console.error('[payload-mcp] error serving MCP over stdio:', err)
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// Close the MCP server and Payload when the client disconnects or the process stops.
|
|
106
|
+
let isShuttingDown = false
|
|
107
|
+
const shutdown = async () => {
|
|
108
|
+
if (isShuttingDown) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
isShuttingDown = true
|
|
93
112
|
|
|
94
|
-
// Process now lives until stdin closes. Wire graceful shutdown so DB
|
|
95
|
-
// connections (and any other Payload-managed resources) get released.
|
|
96
|
-
const shutdown = async (code = 0) => {
|
|
97
113
|
try {
|
|
98
|
-
await
|
|
114
|
+
await stdioServer.close()
|
|
99
115
|
} catch (err) {
|
|
100
116
|
console.error('[payload-mcp] error closing server:', err)
|
|
101
117
|
}
|
|
118
|
+
|
|
102
119
|
try {
|
|
103
120
|
await payload.destroy()
|
|
104
121
|
} catch (err) {
|
|
105
122
|
console.error('[payload-mcp] error destroying payload:', err)
|
|
106
123
|
}
|
|
107
|
-
|
|
124
|
+
|
|
125
|
+
process.exit(0)
|
|
108
126
|
}
|
|
109
127
|
|
|
110
|
-
process.
|
|
111
|
-
process.
|
|
112
|
-
process.stdin.
|
|
128
|
+
process.once('SIGINT', () => void shutdown())
|
|
129
|
+
process.once('SIGTERM', () => void shutdown())
|
|
130
|
+
process.stdin.once('close', () => void shutdown())
|
|
113
131
|
}
|
package/src/types.ts
CHANGED
|
@@ -15,7 +15,6 @@ import type {
|
|
|
15
15
|
MaybePromise,
|
|
16
16
|
PayloadRequest,
|
|
17
17
|
SanitizedPermissions,
|
|
18
|
-
TypedUser,
|
|
19
18
|
} from 'payload'
|
|
20
19
|
|
|
21
20
|
import type { GetAuthorizedMCPArgs } from './endpoint/access.js'
|
|
@@ -32,7 +31,8 @@ export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }
|
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
|
|
35
|
-
* JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
34
|
+
* JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
35
|
+
* Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
|
|
36
36
|
*/
|
|
37
37
|
export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON
|
|
38
38
|
|
|
@@ -52,6 +52,13 @@ export type MCPResponseOverride = (
|
|
|
52
52
|
req: PayloadRequest,
|
|
53
53
|
) => MCPToolResponse
|
|
54
54
|
|
|
55
|
+
export type MCPAfterToolCallHook = (args: {
|
|
56
|
+
input: unknown
|
|
57
|
+
req: PayloadRequest
|
|
58
|
+
response: MCPToolResponse
|
|
59
|
+
toolName: string
|
|
60
|
+
}) => MaybePromise<MCPToolResponse>
|
|
61
|
+
|
|
55
62
|
/**
|
|
56
63
|
* The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
|
|
57
64
|
* its inferred output; anything else falls back to `Record<string, unknown>`.
|
|
@@ -91,6 +98,11 @@ export type GlobalToolHandlerArgs<TSchema = undefined> = {
|
|
|
91
98
|
} & ToolHandlerArgs<TSchema>
|
|
92
99
|
|
|
93
100
|
export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
101
|
+
/**
|
|
102
|
+
* Runs while authorizing each MCP request, before the tool is advertised or called. Return
|
|
103
|
+
* `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
|
|
104
|
+
* is enabled.
|
|
105
|
+
*/
|
|
94
106
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
95
107
|
annotations?: ToolAnnotations
|
|
96
108
|
description: string
|
|
@@ -105,6 +117,12 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
|
|
|
105
117
|
export type CollectionTool<
|
|
106
118
|
TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,
|
|
107
119
|
> = {
|
|
120
|
+
/**
|
|
121
|
+
* Runs while authorizing each MCP request for this collection. Return `false` to reject calls
|
|
122
|
+
* to this tool for the collection. The shared tool is not advertised when no collections allow
|
|
123
|
+
* it, but can remain advertised when it is available for another collection. This is skipped
|
|
124
|
+
* when `overrideAccess` is enabled.
|
|
125
|
+
*/
|
|
108
126
|
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
|
|
109
127
|
handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
|
|
110
128
|
input?: TSchema
|
|
@@ -112,6 +130,12 @@ export type CollectionTool<
|
|
|
112
130
|
|
|
113
131
|
export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =
|
|
114
132
|
{
|
|
133
|
+
/**
|
|
134
|
+
* Runs while authorizing each MCP request for this global. Return `false` to reject calls to
|
|
135
|
+
* this tool for the global. The shared tool is not advertised when no globals allow it, but
|
|
136
|
+
* can remain advertised when it is available for another global. This is skipped when
|
|
137
|
+
* `overrideAccess` is enabled.
|
|
138
|
+
*/
|
|
115
139
|
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
|
|
116
140
|
handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
|
|
117
141
|
input?: TSchema
|
|
@@ -123,6 +147,10 @@ export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSc
|
|
|
123
147
|
* required handler) from being silently accepted at a built-in key slot.
|
|
124
148
|
*/
|
|
125
149
|
export type MCPBuiltInCollectionToolOverride = {
|
|
150
|
+
/**
|
|
151
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
152
|
+
* this collection. This is skipped when `overrideAccess` is enabled.
|
|
153
|
+
*/
|
|
126
154
|
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
|
|
127
155
|
annotations?: ToolAnnotations
|
|
128
156
|
description?: string
|
|
@@ -131,6 +159,10 @@ export type MCPBuiltInCollectionToolOverride = {
|
|
|
131
159
|
}
|
|
132
160
|
|
|
133
161
|
export type MCPBuiltInGlobalToolOverride = {
|
|
162
|
+
/**
|
|
163
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
164
|
+
* this global. This is skipped when `overrideAccess` is enabled.
|
|
165
|
+
*/
|
|
134
166
|
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
|
|
135
167
|
annotations?: ToolAnnotations
|
|
136
168
|
description?: string
|
|
@@ -175,6 +207,11 @@ export type PromptHandlerArgs<TSchema = undefined> = {
|
|
|
175
207
|
}
|
|
176
208
|
|
|
177
209
|
export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
|
|
210
|
+
/**
|
|
211
|
+
* Runs while authorizing each MCP request, before the prompt is advertised or used. Return
|
|
212
|
+
* `false` to make the prompt unavailable for that request. This is skipped when
|
|
213
|
+
* `overrideAccess` is enabled.
|
|
214
|
+
*/
|
|
178
215
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
179
216
|
argsSchema: TSchema
|
|
180
217
|
description: string
|
|
@@ -193,6 +230,11 @@ export type ResourceHandlerArgs = {
|
|
|
193
230
|
}
|
|
194
231
|
|
|
195
232
|
export type Resource = {
|
|
233
|
+
/**
|
|
234
|
+
* Runs while authorizing each MCP request, before the resource is advertised or read. Return
|
|
235
|
+
* `false` to make the resource unavailable for that request. This is skipped when
|
|
236
|
+
* `overrideAccess` is enabled.
|
|
237
|
+
*/
|
|
196
238
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
197
239
|
description: string
|
|
198
240
|
handler: (args: ResourceHandlerArgs) => MaybePromise<{
|
|
@@ -232,11 +274,20 @@ export type MCPPluginConfig = {
|
|
|
232
274
|
globals?: {
|
|
233
275
|
[Slug in GlobalSlug]?: MCPPluginGlobalConfig
|
|
234
276
|
}
|
|
277
|
+
hooks?: {
|
|
278
|
+
/** Transform a tool response after its handler returns */
|
|
279
|
+
afterToolCall?: MCPAfterToolCallHook[]
|
|
280
|
+
}
|
|
235
281
|
mcp?: {
|
|
236
282
|
serverOptions?: MCPServerOptions
|
|
237
283
|
verboseLogs?: boolean
|
|
238
284
|
}
|
|
239
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Replace the default MCP authorization resolver.
|
|
287
|
+
*
|
|
288
|
+
* This hook replaces the default authentication flow. It must set `req.user` to the
|
|
289
|
+
* authenticated Payload user, or to `null` for an anonymous caller, before returning.
|
|
290
|
+
*/
|
|
240
291
|
overrideGetAuthorizedMCP?: (
|
|
241
292
|
args: {
|
|
242
293
|
pluginConfig: SanitizedMCPPluginConfig
|
|
@@ -250,7 +301,7 @@ export type MCPPluginConfig = {
|
|
|
250
301
|
|
|
251
302
|
export type SanitizedMCPPluginConfig = {
|
|
252
303
|
items: MCPItem[]
|
|
253
|
-
} & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideGetAuthorizedMCP'>
|
|
304
|
+
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
|
|
254
305
|
|
|
255
306
|
export type MCPServerOptions = {
|
|
256
307
|
options?: ConstructorParameters<typeof McpServer>[1]
|
|
@@ -300,13 +351,10 @@ export type MCPItem =
|
|
|
300
351
|
| GlobalMCPItem
|
|
301
352
|
|
|
302
353
|
/**
|
|
303
|
-
* The
|
|
304
|
-
*
|
|
305
|
-
* absent from `items`. Tool handlers receive this via `args.authorizedMCP` so
|
|
306
|
-
* they can spread `localAPIDefaults(authorizedMCP)` into every local API call.
|
|
354
|
+
* The MCP items and access mode authorized for this request. The authenticated user is available
|
|
355
|
+
* as `req.user`.
|
|
307
356
|
*/
|
|
308
357
|
export type AuthorizedMCP = {
|
|
309
358
|
items: MCPItem[]
|
|
310
359
|
overrideAccess: boolean
|
|
311
|
-
user: null | TypedUser
|
|
312
360
|
}
|
package/dist/@types/assets.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/@types/assets.d.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SanitizedConfig } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the names of all top-level virtual fields for a given collection slug.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
|
|
6
|
-
/**
|
|
7
|
-
* Returns the names of all top-level virtual fields for a given global slug.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
|
|
10
|
-
/**
|
|
11
|
-
* Strips virtual field values from a data object given a list of virtual field names.
|
|
12
|
-
*/
|
|
13
|
-
export declare function stripVirtualFields(data: Record<string, unknown>, virtualFieldNames: string[]): Record<string, unknown>;
|
|
14
|
-
//# sourceMappingURL=getVirtualFieldNames.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getVirtualFieldNames.d.ts","sourceRoot":"","sources":["../../src/utils/getVirtualFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU9F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU1F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { fieldIsVirtual } from 'payload/shared';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the names of all top-level virtual fields for a given collection slug.
|
|
4
|
-
*/ export function getCollectionVirtualFieldNames(config, slug) {
|
|
5
|
-
const collection = config.collections.find((c)=>c.slug === slug);
|
|
6
|
-
if (!collection) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
return collection.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the names of all top-level virtual fields for a given global slug.
|
|
13
|
-
*/ export function getGlobalVirtualFieldNames(config, slug) {
|
|
14
|
-
const global = config.globals.find((g)=>g.slug === slug);
|
|
15
|
-
if (!global) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
return global.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Strips virtual field values from a data object given a list of virtual field names.
|
|
22
|
-
*/ export function stripVirtualFields(data, virtualFieldNames) {
|
|
23
|
-
if (virtualFieldNames.length === 0) {
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
const stripped = {
|
|
27
|
-
...data
|
|
28
|
-
};
|
|
29
|
-
for (const name of virtualFieldNames){
|
|
30
|
-
delete stripped[name];
|
|
31
|
-
}
|
|
32
|
-
return stripped;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=getVirtualFieldNames.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/getVirtualFieldNames.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual } from 'payload/shared'\n\n/**\n * Returns the names of all top-level virtual fields for a given collection slug.\n */\nexport function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const collection = config.collections.find((c) => c.slug === slug)\n\n if (!collection) {\n return []\n }\n\n return collection.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Returns the names of all top-level virtual fields for a given global slug.\n */\nexport function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const global = config.globals.find((g) => g.slug === slug)\n\n if (!global) {\n return []\n }\n\n return global.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Strips virtual field values from a data object given a list of virtual field names.\n */\nexport function stripVirtualFields(\n data: Record<string, unknown>,\n virtualFieldNames: string[],\n): Record<string, unknown> {\n if (virtualFieldNames.length === 0) {\n return data\n }\n\n const stripped = { ...data }\n\n for (const name of virtualFieldNames) {\n delete stripped[name]\n }\n\n return stripped\n}\n"],"names":["fieldIsVirtual","getCollectionVirtualFieldNames","config","slug","collection","collections","find","c","flattenedFields","filter","field","map","name","getGlobalVirtualFieldNames","global","globals","g","stripVirtualFields","data","virtualFieldNames","length","stripped"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C;;CAEC,GACD,OAAO,SAASC,+BAA+BC,MAAuB,EAAEC,IAAY;IAClF,MAAMC,aAAaF,OAAOG,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEJ,IAAI,KAAKA;IAE7D,IAAI,CAACC,YAAY;QACf,OAAO,EAAE;IACX;IAEA,OAAOA,WAAWI,eAAe,CAC9BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASC,2BAA2BX,MAAuB,EAAEC,IAAY;IAC9E,MAAMW,SAASZ,OAAOa,OAAO,CAACT,IAAI,CAAC,CAACU,IAAMA,EAAEb,IAAI,KAAKA;IAErD,IAAI,CAACW,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,OAAOA,OAAON,eAAe,CAC1BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASK,mBACdC,IAA6B,EAC7BC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,MAAMG,WAAW;QAAE,GAAGH,IAAI;IAAC;IAE3B,KAAK,MAAMN,QAAQO,kBAAmB;QACpC,OAAOE,QAAQ,CAACT,KAAK;IACvB;IAEA,OAAOS;AACT"}
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
import { type CollectionSlug, type GlobalSlug, type PayloadRequest } from 'payload';
|
|
2
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
3
|
-
export declare const getCollectionInputSchema: ({ collectionSlug, req, }: {
|
|
4
|
-
collectionSlug: CollectionSlug;
|
|
5
|
-
req: PayloadRequest;
|
|
6
|
-
}) => JsonSchemaType | null;
|
|
7
|
-
export declare const getGlobalInputSchema: ({ globalSlug, req, }: {
|
|
8
|
-
globalSlug: GlobalSlug;
|
|
9
|
-
req: PayloadRequest;
|
|
10
|
-
}) => JsonSchemaType | null;
|
|
11
|
-
//# sourceMappingURL=getEntityInputSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,UAAU,EACf,KAAK,cAAc,EAGpB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AASpD,eAAO,MAAM,wBAAwB,GAAI,0BAGtC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAYpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,sBAGlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAYpB,CAAA"}
|