@payloadcms/plugin-mcp 4.0.0-internal.c2b57ce → 4.0.0-internal.c6494b5
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/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +75 -88
- 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 +98 -18
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -20
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +6 -6
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +146 -74
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +123 -61
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +63 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +114 -64
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +55 -61
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- 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 +88 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +61 -74
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +103 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +118 -133
- 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/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +69 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +27 -36
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +81 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +44 -58
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +150 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +125 -20
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +124 -58
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -3
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +86 -47
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +123 -114
- 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/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +14 -21
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +80 -101
- package/src/endpoint/index.ts +88 -16
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +12 -20
- package/src/mcp/buildMcpServer.ts +180 -110
- package/src/mcp/builtin/collections/authTools.ts +122 -75
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +117 -88
- package/src/mcp/builtin/collections/deleteTool.ts +48 -74
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +57 -110
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +106 -138
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +27 -57
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +51 -77
- package/src/mcp/builtinTools.ts +118 -41
- package/src/mcp/sanitizeMCPConfig.ts +120 -78
- package/src/stdio.ts +80 -47
- package/src/types.ts +141 -120
- package/src/utils/getPluginConfig.ts +1 -1
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -57
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -59
- package/dist/collection/index.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -305
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -93
- package/dist/utils/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/prepareCollectionSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
- package/dist/utils/schemaConversion/prepareCollectionSchema.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/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -57
- package/dist/utils/schemaConversion/transformPointFields.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/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -63
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
- package/src/utils/schemaConversion/transformPointFields.ts +0 -56
- package/src/utils/transformPointDataToPayload.ts +0 -40
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { findVersionsInputSchema } from 'payload';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
const DEFAULT_DESCRIPTION = 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.';
|
|
6
|
+
export const findVersionsTool = defineCollectionTool({
|
|
7
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
|
|
8
|
+
annotations: {
|
|
9
|
+
destructiveHint: false,
|
|
10
|
+
idempotentHint: true,
|
|
11
|
+
openWorldHint: false,
|
|
12
|
+
readOnlyHint: true,
|
|
13
|
+
title: 'Find Versions'
|
|
14
|
+
},
|
|
15
|
+
description: DEFAULT_DESCRIPTION,
|
|
16
|
+
input: findVersionsInputSchema
|
|
17
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
18
|
+
const payload = req.payload;
|
|
19
|
+
const logger = getLogger({
|
|
20
|
+
payload
|
|
21
|
+
});
|
|
22
|
+
const { depth, draft, fallbackLocale, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
|
|
23
|
+
logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`);
|
|
24
|
+
try {
|
|
25
|
+
const result = await payload.findVersions({
|
|
26
|
+
collection: slug,
|
|
27
|
+
depth,
|
|
28
|
+
limit,
|
|
29
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
30
|
+
page,
|
|
31
|
+
req,
|
|
32
|
+
...draft !== undefined ? {
|
|
33
|
+
draft
|
|
34
|
+
} : {},
|
|
35
|
+
...fallbackLocale !== undefined ? {
|
|
36
|
+
fallbackLocale
|
|
37
|
+
} : {},
|
|
38
|
+
...locale ? {
|
|
39
|
+
locale
|
|
40
|
+
} : {},
|
|
41
|
+
...pagination !== undefined ? {
|
|
42
|
+
pagination
|
|
43
|
+
} : {},
|
|
44
|
+
...populate ? {
|
|
45
|
+
populate
|
|
46
|
+
} : {},
|
|
47
|
+
...select ? {
|
|
48
|
+
select
|
|
49
|
+
} : {},
|
|
50
|
+
...sort ? {
|
|
51
|
+
sort
|
|
52
|
+
} : {},
|
|
53
|
+
...trash !== undefined ? {
|
|
54
|
+
trash
|
|
55
|
+
} : {},
|
|
56
|
+
...where ? {
|
|
57
|
+
where
|
|
58
|
+
} : {}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
63
|
+
type: 'text',
|
|
64
|
+
text: `Versions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
doc: result
|
|
68
|
+
};
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
71
|
+
logger.error(`Error finding versions in ${slug}: ${errorMessage}`);
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: 'text',
|
|
76
|
+
text: `❌ **Error finding versions in collection "${slug}":** ${errorMessage}`
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
isError: true
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=findVersionsTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import { findVersionsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: findVersionsInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n draft,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","depth","draft","fallbackLocale","limit","locale","page","pagination","populate","select","sort","trash","where","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,UAAS;AAEjD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBH,qBAAqB;IACnDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IACnC,MAAM,EACJE,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,KAAK,EACLC,KAAK,EACN,GAAGjB;IAEJK,OAAOa,IAAI,CAAC,CAAC,gCAAgC,EAAE3B,KAAK,SAAS,EAAEkB,MAAM,QAAQ,EAAEE,MAAM;IAErF,IAAI;QACF,MAAMQ,SAAS,MAAMf,QAAQgB,YAAY,CAAC;YACxCC,YAAY9B;YACZe;YACAG;YACAa,gBAAgBpB,cAAcoB,cAAc;YAC5CX;YACAR;YACA,GAAII,UAAUgB,YAAY;gBAAEhB;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,mBAAmBe,YAAY;gBAAEf;YAAe,IAAI,CAAC,CAAC;YAC1D,GAAIE,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIE,eAAeW,YAAY;gBAAEX;YAAW,IAAI,CAAC,CAAC;YAClD,GAAIC,WAAW;gBAAEA;YAAS,IAAI,CAAC,CAAC;YAChC,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUO,YAAY;gBAAEP;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLO,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAEnC,KAAK,gBAAgB,EAAEoC,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC3F;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,0BAA0B,EAAEvC,KAAK,EAAE,EAAEwC,cAAc;QACjE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAEnC,KAAK,KAAK,EAAEwC,cAAc;gBAC/E;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,4CAoFlC,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload';
|
|
2
|
+
import { getLLMInstructions } from 'payload/internal';
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
4
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
5
|
+
export const getCollectionSchemaTool = defineCollectionTool({
|
|
6
|
+
access: (args)=>{
|
|
7
|
+
const permissions = args.permissions?.collections?.[args.slug];
|
|
8
|
+
return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
|
|
9
|
+
},
|
|
10
|
+
annotations: {
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
readOnlyHint: true,
|
|
15
|
+
title: 'Get Collection Schema'
|
|
16
|
+
},
|
|
17
|
+
description: 'Get the input schema and LLM instructions before creating or updating documents in a collection.',
|
|
18
|
+
input: getCollectionSchemaInputSchema
|
|
19
|
+
}).handler(async ({ slug, authorizedMCP, req })=>{
|
|
20
|
+
const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
|
|
21
|
+
req
|
|
22
|
+
})).collections?.[slug];
|
|
23
|
+
if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${slug}"`
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
isError: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const inputSchema = getCollectionInputSchema({
|
|
35
|
+
collectionSlug: slug,
|
|
36
|
+
req,
|
|
37
|
+
...permissions ? {
|
|
38
|
+
permissions
|
|
39
|
+
} : {}
|
|
40
|
+
});
|
|
41
|
+
if (!inputSchema) {
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: `Error: Collection "${slug}" not found`
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
isError: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const uploadConfig = req.payload.collections[slug]?.config.upload;
|
|
53
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize;
|
|
54
|
+
const upload = uploadConfig ? {
|
|
55
|
+
enabled: true,
|
|
56
|
+
filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
|
|
57
|
+
mimeTypes: uploadConfig.mimeTypes ?? [
|
|
58
|
+
'*/*'
|
|
59
|
+
],
|
|
60
|
+
sources: [
|
|
61
|
+
...uploadConfig.pasteURL !== false ? [
|
|
62
|
+
'externalURL'
|
|
63
|
+
] : [],
|
|
64
|
+
'base64',
|
|
65
|
+
'uploadReference'
|
|
66
|
+
],
|
|
67
|
+
...typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? {
|
|
68
|
+
maxFileSize
|
|
69
|
+
} : {}
|
|
70
|
+
} : {
|
|
71
|
+
enabled: false
|
|
72
|
+
};
|
|
73
|
+
const instructions = await getLLMInstructions({
|
|
74
|
+
slug,
|
|
75
|
+
type: 'collection',
|
|
76
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
77
|
+
req
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
|
|
84
|
+
},
|
|
85
|
+
...instructions ? [
|
|
86
|
+
{
|
|
87
|
+
type: 'text',
|
|
88
|
+
text: instructions
|
|
89
|
+
}
|
|
90
|
+
] : []
|
|
91
|
+
],
|
|
92
|
+
structuredContent: {
|
|
93
|
+
slug,
|
|
94
|
+
schema: inputSchema,
|
|
95
|
+
upload,
|
|
96
|
+
...instructions ? {
|
|
97
|
+
instructions
|
|
98
|
+
} : {}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=getCollectionSchemaTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload'\nimport { getLLMInstructions } from 'payload/internal'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.slug]\n\n return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description:\n 'Get the input schema and LLM instructions before creating or updating documents in a collection.',\n input: getCollectionSchemaInputSchema,\n}).handler(async ({ slug, authorizedMCP, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[slug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getCollectionSchema\" is not enabled for collection \"${slug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug: slug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${slug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[slug]?.config.upload\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n const upload = uploadConfig\n ? {\n enabled: true,\n filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,\n mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],\n sources: [\n ...(uploadConfig.pasteURL !== false ? ['externalURL'] : []),\n 'base64',\n 'uploadReference',\n ],\n ...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),\n }\n : { enabled: false }\n\n const instructions = await getLLMInstructions({\n slug,\n type: 'collection',\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ...(instructions ? [{ type: 'text' as const, text: instructions }] : []),\n ],\n structuredContent: {\n slug,\n schema: inputSchema,\n upload,\n ...(instructions ? { instructions } : {}),\n },\n }\n})\n"],"names":["getAccessResults","getCollectionInputSchema","getCollectionSchemaInputSchema","getLLMInstructions","defaultAccess","defineCollectionTool","getCollectionSchemaTool","access","args","permissions","collections","slug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","collectionSlug","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","instructions","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,wBAAwB,EAAEC,8BAA8B,QAAQ,UAAS;AACpG,SAASC,kBAAkB,QAAQ,mBAAkB;AAErD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAE7D,OAAO,MAAMC,0BAA0BD,qBAAqB;IAC1DE,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,IAAI,CAAC;QAE9D,OAAOP,cAAcI,SAASI,QAAQH,aAAaI,UAAUJ,aAAaK;IAC5E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aACE;IACFC,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEZ,IAAI,EAAEa,aAAa,EAAEC,GAAG,EAAE;IAC5C,MAAMhB,cAAce,cAAcE,cAAc,GAC5C,OACA,AAAC,CAAA,MAAM1B,iBAAiB;QAAEyB;IAAI,EAAC,EAAGf,WAAW,EAAE,CAACC,KAAK;IAEzD,IAAI,CAACa,cAAcE,cAAc,IAAI,CAACjB,aAAaI,UAAU,CAACJ,aAAaK,QAAQ;QACjF,OAAO;YACLa,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0EAA0E,EAAElB,KAAK,CAAC,CAAC;gBAC5F;aACD;YACDmB,SAAS;QACX;IACF;IAEA,MAAMC,cAAc9B,yBAAyB;QAC3C+B,gBAAgBrB;QAChBc;QACA,GAAIhB,cAAc;YAAEA;QAAY,IAAI,CAAC,CAAC;IACxC;IAEA,IAAI,CAACsB,aAAa;QAChB,OAAO;YACLJ,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAElB,KAAK,WAAW,CAAC;gBAAC;aAAE;YAC1EmB,SAAS;QACX;IACF;IAEA,MAAMG,eAAeR,IAAIS,OAAO,CAACxB,WAAW,CAACC,KAAK,EAAEwB,OAAOC;IAC3D,MAAMC,cAAcZ,IAAIS,OAAO,CAACC,MAAM,CAACC,MAAM,CAACE,MAAM,EAAEC;IACtD,MAAMH,SAASH,eACX;QACEO,SAAS;QACTC,uBAAuBR,aAAaQ,qBAAqB,KAAK;QAC9DC,WAAWT,aAAaS,SAAS,IAAI;YAAC;SAAM;QAC5CC,SAAS;eACHV,aAAaW,QAAQ,KAAK,QAAQ;gBAAC;aAAc,GAAG,EAAE;YAC1D;YACA;SACD;QACD,GAAI,OAAOP,gBAAgB,YAAYQ,OAAOC,QAAQ,CAACT,eAAe;YAAEA;QAAY,IAAI,CAAC,CAAC;IAC5F,IACA;QAAEG,SAAS;IAAM;IAErB,MAAMO,eAAe,MAAM5C,mBAAmB;QAC5CQ;QACAiB,MAAM;QACNF,gBAAgBF,cAAcE,cAAc;QAC5CD;IACF;IAEA,OAAO;QACLE,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAElB,KAAK,gBAAgB,EAAEqC,KAAKC,SAAS,CAAClB,aAAa,6CAA6C,EAAEiB,KAAKC,SAAS,CAACb,QAAQ,QAAQ,CAAC;YACpK;eACIW,eAAe;gBAAC;oBAAEnB,MAAM;oBAAiBC,MAAMkB;gBAAa;aAAE,GAAG,EAAE;SACxE;QACDG,mBAAmB;YACjBvC;YACAwC,QAAQpB;YACRK;YACA,GAAIW,eAAe;gBAAEA;YAAa,IAAI,CAAC,CAAC;QAC1C;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,4CAuD7B,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { restoreVersionInputSchema } from 'payload';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
|
|
6
|
+
export const restoreVersionTool = defineCollectionTool({
|
|
7
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
8
|
+
annotations: {
|
|
9
|
+
destructiveHint: true,
|
|
10
|
+
idempotentHint: false,
|
|
11
|
+
openWorldHint: false,
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
title: 'Restore Version'
|
|
14
|
+
},
|
|
15
|
+
description: DEFAULT_DESCRIPTION,
|
|
16
|
+
input: restoreVersionInputSchema
|
|
17
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
18
|
+
const payload = req.payload;
|
|
19
|
+
const logger = getLogger({
|
|
20
|
+
payload
|
|
21
|
+
});
|
|
22
|
+
const { id, depth, draft, fallbackLocale, locale, populate, select } = input;
|
|
23
|
+
logger.info(`Restoring version in collection: ${slug} with ID: ${id}`);
|
|
24
|
+
try {
|
|
25
|
+
const result = await payload.restoreVersion({
|
|
26
|
+
id: String(id),
|
|
27
|
+
collection: slug,
|
|
28
|
+
depth,
|
|
29
|
+
draft,
|
|
30
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
31
|
+
req,
|
|
32
|
+
...fallbackLocale !== undefined ? {
|
|
33
|
+
fallbackLocale
|
|
34
|
+
} : {},
|
|
35
|
+
...locale ? {
|
|
36
|
+
locale
|
|
37
|
+
} : {},
|
|
38
|
+
...populate ? {
|
|
39
|
+
populate
|
|
40
|
+
} : {},
|
|
41
|
+
...select ? {
|
|
42
|
+
select
|
|
43
|
+
} : {}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: `Version "${id}" restored successfully in collection "${slug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
doc: result
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
56
|
+
logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`);
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: `❌ **Error restoring version "${id}" in collection "${slug}":** ${errorMessage}`
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
isError: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=restoreVersionTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import { restoreVersionInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: restoreVersionInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select } = input\n\n logger.info(`Restoring version in collection: ${slug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id: String(id),\n collection: slug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${slug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["restoreVersionInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","slug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","locale","populate","select","info","result","restoreVersion","String","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,UAAS;AAEnD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBH,qBAAqB;IACrDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IACnC,MAAM,EAAEE,EAAE,EAAEC,KAAK,EAAEC,KAAK,EAAEC,cAAc,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGZ;IAEvEK,OAAOQ,IAAI,CAAC,CAAC,iCAAiC,EAAEtB,KAAK,UAAU,EAAEe,IAAI;IAErE,IAAI;QACF,MAAMQ,SAAS,MAAMV,QAAQW,cAAc,CAAC;YAC1CT,IAAIU,OAAOV;YACXW,YAAY1B;YACZgB;YACAC;YACAU,gBAAgBhB,cAAcgB,cAAc;YAC5Cf;YACA,GAAIM,mBAAmBU,YAAY;gBAAEV;YAAe,IAAI,CAAC,CAAC;YAC1D,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,WAAW;gBAAEA;YAAS,IAAI,CAAC,CAAC;YAChC,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;QAC9B;QAEA,OAAO;YACLQ,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEhB,GAAG,uCAAuC,EAAEf,KAAK,oCAAoC,EAAEgC,KAAKC,SAAS,CAACV,QAAQ,QAAQ,CAAC;gBAC3I;aACD;YACDW,KAAKX;QACP;IACF,EAAE,OAAOY,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DxB,OAAOqB,KAAK,CAAC,CAAC,wBAAwB,EAAEpB,GAAG,IAAI,EAAEf,KAAK,EAAE,EAAEoC,cAAc;QACxE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAEhB,GAAG,iBAAiB,EAAEf,KAAK,KAAK,EAAEoC,cAAc;gBACxF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const updateDocumentTool: import("../../../types.js").CollectionTool;
|
|
2
2
|
//# sourceMappingURL=updateTool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CAuJ7B,CAAA"}
|
|
@@ -1,162 +1,148 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCollectionInputSchema, getCollectionVirtualFieldNames, parseDocumentID, stripVirtualFields, transformPointDataToPayload, updateDocumentInputSchema, validateCollectionData } from 'payload';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
2
3
|
import { defineCollectionTool } from '../../../defineTool.js';
|
|
3
4
|
import { getLogger } from '../../../utils/getLogger.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { formatEntityError } from '../formatEntityError.js';
|
|
6
|
+
import { fileInputSchema, resolveFile } from './fileInput.js';
|
|
7
|
+
const DEFAULT_DESCRIPTION = 'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.';
|
|
8
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
9
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
10
|
+
annotations: {
|
|
11
|
+
destructiveHint: true,
|
|
12
|
+
idempotentHint: false,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
readOnlyHint: false,
|
|
15
|
+
title: 'Update Document'
|
|
16
|
+
},
|
|
10
17
|
description: DEFAULT_DESCRIPTION,
|
|
11
|
-
input: ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// Local API equivalent: packages/payload/src/collections/operations/local/update.ts#BaseOptions#data:
|
|
16
|
-
// data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>
|
|
17
|
-
delete partialSchema.required;
|
|
18
|
-
return z.object({
|
|
19
|
-
id: z.union([
|
|
20
|
-
z.string(),
|
|
21
|
-
z.number()
|
|
22
|
-
]).describe('The ID of the document to update').optional(),
|
|
23
|
-
data: z.fromJSONSchema(partialSchema).describe('The fields to update'),
|
|
24
|
-
depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
|
|
25
|
-
draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
|
|
26
|
-
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
27
|
-
filePath: z.string().describe('File path for file uploads').optional(),
|
|
28
|
-
locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
|
|
29
|
-
overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
|
|
30
|
-
overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
|
|
31
|
-
select: z.string().describe('Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'').optional(),
|
|
32
|
-
where: z.string().describe('JSON string for where clause to update multiple documents').optional()
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
18
|
+
input: updateDocumentInputSchema({
|
|
19
|
+
file: fileInputSchema
|
|
20
|
+
})
|
|
21
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
36
22
|
const payload = req.payload;
|
|
37
23
|
const logger = getLogger({
|
|
38
24
|
payload
|
|
39
25
|
});
|
|
40
|
-
const { id, data, depth, draft, fallbackLocale,
|
|
41
|
-
logger.info(`Updating document in collection: ${
|
|
26
|
+
const { id, data, depth, draft, fallbackLocale, file: fileInput, limit, locale, overrideLock, populate, publishAllLocales, returning, select, sort, trash, unpublishAllLocales, where } = input;
|
|
27
|
+
logger.info(`Updating document in collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
42
28
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
text: 'Error: Invalid JSON in where clause'
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
let selectClause;
|
|
73
|
-
if (select) {
|
|
74
|
-
try {
|
|
75
|
-
selectClause = JSON.parse(select);
|
|
76
|
-
} catch {
|
|
77
|
-
logger.warn(`Invalid select clause JSON: ${select}`);
|
|
78
|
-
return {
|
|
79
|
-
content: [
|
|
80
|
-
{
|
|
81
|
-
type: 'text',
|
|
82
|
-
text: 'Error: Invalid JSON in select clause'
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (id) {
|
|
89
|
-
const updateOptions = {
|
|
90
|
-
id,
|
|
91
|
-
collection: collectionSlug,
|
|
29
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug);
|
|
30
|
+
const inputData = stripVirtualFields(data, virtualFieldNames);
|
|
31
|
+
validateCollectionData({
|
|
32
|
+
slug,
|
|
33
|
+
data: inputData,
|
|
34
|
+
partial: true,
|
|
35
|
+
req
|
|
36
|
+
});
|
|
37
|
+
const parsedData = transformPointDataToPayload(inputData);
|
|
38
|
+
const file = await resolveFile({
|
|
39
|
+
slug,
|
|
40
|
+
input: fileInput,
|
|
41
|
+
req
|
|
42
|
+
});
|
|
43
|
+
const whereClause = where ?? {};
|
|
44
|
+
if (id !== undefined) {
|
|
45
|
+
const result = await payload.update({
|
|
46
|
+
id: parseDocumentID({
|
|
47
|
+
id,
|
|
48
|
+
collectionSlug: slug,
|
|
49
|
+
payload
|
|
50
|
+
}),
|
|
51
|
+
collection: slug,
|
|
92
52
|
data: parsedData,
|
|
93
53
|
depth,
|
|
94
54
|
draft,
|
|
55
|
+
fallbackLocale,
|
|
56
|
+
locale,
|
|
57
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
95
58
|
overrideLock,
|
|
59
|
+
populate,
|
|
60
|
+
publishAllLocales,
|
|
96
61
|
req,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
...locale ? {
|
|
105
|
-
locale
|
|
106
|
-
} : {},
|
|
107
|
-
...fallbackLocale ? {
|
|
108
|
-
fallbackLocale
|
|
109
|
-
} : {},
|
|
110
|
-
...selectClause ? {
|
|
111
|
-
select: selectClause
|
|
62
|
+
select: returning ? select : {
|
|
63
|
+
id: true
|
|
64
|
+
},
|
|
65
|
+
trash,
|
|
66
|
+
unpublishAllLocales,
|
|
67
|
+
...file ? {
|
|
68
|
+
file
|
|
112
69
|
} : {}
|
|
70
|
+
});
|
|
71
|
+
const responseResult = returning ? result : {
|
|
72
|
+
id: result.id
|
|
113
73
|
};
|
|
114
|
-
const result = await payload.update(updateOptions);
|
|
115
74
|
return {
|
|
116
75
|
content: [
|
|
117
76
|
{
|
|
118
77
|
type: 'text',
|
|
119
|
-
text: `Document updated successfully in collection "${
|
|
78
|
+
text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``
|
|
120
79
|
}
|
|
121
80
|
],
|
|
122
|
-
doc:
|
|
81
|
+
doc: responseResult
|
|
123
82
|
};
|
|
124
83
|
}
|
|
125
|
-
const
|
|
126
|
-
collection:
|
|
84
|
+
const result = await payload.update({
|
|
85
|
+
collection: slug,
|
|
127
86
|
data: parsedData,
|
|
128
87
|
depth,
|
|
129
88
|
draft,
|
|
89
|
+
fallbackLocale,
|
|
90
|
+
limit,
|
|
91
|
+
locale,
|
|
92
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
130
93
|
overrideLock,
|
|
94
|
+
populate,
|
|
95
|
+
publishAllLocales,
|
|
131
96
|
req,
|
|
132
|
-
|
|
97
|
+
select: returning ? select : {
|
|
98
|
+
id: true
|
|
99
|
+
},
|
|
100
|
+
sort,
|
|
101
|
+
trash,
|
|
102
|
+
unpublishAllLocales,
|
|
133
103
|
where: whereClause,
|
|
134
|
-
...
|
|
135
|
-
|
|
136
|
-
} : {},
|
|
137
|
-
...overwriteExistingFiles ? {
|
|
138
|
-
overwriteExistingFiles
|
|
139
|
-
} : {},
|
|
140
|
-
...locale ? {
|
|
141
|
-
locale
|
|
142
|
-
} : {},
|
|
143
|
-
...fallbackLocale ? {
|
|
144
|
-
fallbackLocale
|
|
145
|
-
} : {},
|
|
146
|
-
...selectClause ? {
|
|
147
|
-
select: selectClause
|
|
104
|
+
...file ? {
|
|
105
|
+
file
|
|
148
106
|
} : {}
|
|
149
|
-
};
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const errors =
|
|
154
|
-
let responseText = `Multiple documents updated in collection "${
|
|
107
|
+
});
|
|
108
|
+
const docs = returning ? result.docs : result.docs.map(({ id })=>({
|
|
109
|
+
id
|
|
110
|
+
}));
|
|
111
|
+
const errors = result.errors || [];
|
|
112
|
+
let responseText = `Multiple documents updated in collection "${slug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
|
|
155
113
|
if (docs.length > 0) {
|
|
156
114
|
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
|
|
157
115
|
}
|
|
158
116
|
if (errors.length > 0) {
|
|
159
117
|
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
|
|
118
|
+
const errorSchema = getCollectionInputSchema({
|
|
119
|
+
collectionSlug: slug,
|
|
120
|
+
req
|
|
121
|
+
});
|
|
122
|
+
if (errorSchema) {
|
|
123
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: responseText
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
doc: {
|
|
133
|
+
docs,
|
|
134
|
+
errors
|
|
135
|
+
},
|
|
136
|
+
isError: true,
|
|
137
|
+
...errorSchema ? {
|
|
138
|
+
structuredContent: {
|
|
139
|
+
slug,
|
|
140
|
+
docs,
|
|
141
|
+
errors,
|
|
142
|
+
schema: errorSchema
|
|
143
|
+
}
|
|
144
|
+
} : {}
|
|
145
|
+
};
|
|
160
146
|
}
|
|
161
147
|
return {
|
|
162
148
|
content: [
|
|
@@ -172,15 +158,14 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
172
158
|
};
|
|
173
159
|
} catch (error) {
|
|
174
160
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
175
|
-
logger.error(`Error updating document in ${
|
|
176
|
-
return {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
161
|
+
logger.error(`Error updating document in ${slug}: ${errorMessage}`);
|
|
162
|
+
return formatEntityError({
|
|
163
|
+
slug,
|
|
164
|
+
action: 'updating',
|
|
165
|
+
entity: 'collection',
|
|
166
|
+
error,
|
|
167
|
+
req
|
|
168
|
+
});
|
|
184
169
|
}
|
|
185
170
|
});
|
|
186
171
|
|