@payloadcms/plugin-mcp 3.65.0-internal.5b33fe0 → 3.65.0-internal.cebb1a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/tools/resource/create.d.ts.map +1 -1
- package/dist/mcp/tools/resource/create.js +22 -6
- package/dist/mcp/tools/resource/create.js.map +1 -1
- package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
- package/dist/mcp/tools/resource/delete.js +11 -5
- package/dist/mcp/tools/resource/delete.js.map +1 -1
- package/dist/mcp/tools/resource/find.d.ts.map +1 -1
- package/dist/mcp/tools/resource/find.js +18 -6
- package/dist/mcp/tools/resource/find.js.map +1 -1
- package/dist/mcp/tools/resource/update.d.ts.map +1 -1
- package/dist/mcp/tools/resource/update.js +24 -6
- package/dist/mcp/tools/resource/update.js.map +1 -1
- package/dist/mcp/tools/schemas.d.ts +33 -9
- package/dist/mcp/tools/schemas.d.ts.map +1 -1
- package/dist/mcp/tools/schemas.js +21 -4
- package/dist/mcp/tools/schemas.js.map +1 -1
- package/package.json +3 -3
- package/src/mcp/tools/resource/create.ts +40 -4
- package/src/mcp/tools/resource/delete.ts +8 -4
- package/src/mcp/tools/resource/find.ts +10 -4
- package/src/mcp/tools/resource/update.ts +26 -5
- package/src/mcp/tools/schemas.ts +49 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,SA2IpB,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { toCamelCase } from '../../../utils/camelCase.js';
|
|
2
3
|
import { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js';
|
|
3
4
|
import { toolSchemas } from '../schemas.js';
|
|
4
5
|
export const createResourceTool = (server, req, user, verboseLogs, collectionSlug, collections, schema)=>{
|
|
5
|
-
const tool = async (data)=>{
|
|
6
|
+
const tool = async (data, draft, locale, fallbackLocale)=>{
|
|
6
7
|
const payload = req.payload;
|
|
7
8
|
if (verboseLogs) {
|
|
8
|
-
payload.logger.info(`[payload-mcp] Creating resource in collection: ${collectionSlug}`);
|
|
9
|
+
payload.logger.info(`[payload-mcp] Creating resource in collection: ${collectionSlug}${locale ? ` with locale: ${locale}` : ''}`);
|
|
9
10
|
}
|
|
10
11
|
try {
|
|
11
12
|
// Parse the data JSON
|
|
@@ -30,9 +31,16 @@ export const createResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
30
31
|
const result = await payload.create({
|
|
31
32
|
collection: collectionSlug,
|
|
32
33
|
data: parsedData,
|
|
34
|
+
draft,
|
|
33
35
|
overrideAccess: false,
|
|
34
36
|
req,
|
|
35
|
-
user
|
|
37
|
+
user,
|
|
38
|
+
...locale && {
|
|
39
|
+
locale
|
|
40
|
+
},
|
|
41
|
+
...fallbackLocale && {
|
|
42
|
+
fallbackLocale
|
|
43
|
+
}
|
|
36
44
|
});
|
|
37
45
|
if (verboseLogs) {
|
|
38
46
|
payload.logger.info(`[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`);
|
|
@@ -66,9 +74,17 @@ ${JSON.stringify(result, null, 2)}
|
|
|
66
74
|
};
|
|
67
75
|
if (collections?.[collectionSlug]?.enabled) {
|
|
68
76
|
const convertedFields = convertCollectionSchemaToZod(schema);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
// Create a new schema that combines the converted fields with create-specific parameters
|
|
78
|
+
const createResourceSchema = z.object({
|
|
79
|
+
...convertedFields.shape,
|
|
80
|
+
draft: z.boolean().optional().default(false).describe('Whether to create the document as a draft'),
|
|
81
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
82
|
+
locale: z.string().optional().describe('Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale')
|
|
83
|
+
});
|
|
84
|
+
server.tool(`create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`, createResourceSchema.shape, async (params)=>{
|
|
85
|
+
const { draft, fallbackLocale, locale, ...fieldData } = params;
|
|
86
|
+
const data = JSON.stringify(fieldData);
|
|
87
|
+
return await tool(data, draft, locale, fallbackLocale);
|
|
72
88
|
});
|
|
73
89
|
}
|
|
74
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Creating resource in collection: ${collectionSlug}`)\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n overrideAccess: false,\n req,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n server.tool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n draft: boolean,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Creating resource in collection: ${collectionSlug}${locale ? ` with locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n draft,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Create a new schema that combines the converted fields with create-specific parameters\n const createResourceSchema = z.object({\n ...convertedFields.shape,\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to create the document as a draft'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to create the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n })\n\n server.tool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n createResourceSchema.shape,\n async (params: Record<string, unknown>) => {\n const { draft, fallbackLocale, locale, ...fieldData } = params\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n draft as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","draft","locale","fallbackLocale","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","content","type","text","result","create","collection","overrideAccess","id","response","overrideResponse","errorMessage","Error","message","enabled","convertedFields","createResourceSchema","object","shape","boolean","optional","default","describe","string","charAt","toUpperCase","slice","description","createResource","trim","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,OACAC,QACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEV,iBAAiBM,SAAS,CAAC,cAAc,EAAEA,QAAQ,GAAG,IAAI;QAEhH;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIK;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACT;gBACxB,IAAIL,aAAa;oBACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEV,eAAe,EAAE,EAAEY,KAAKE,SAAS,CAACH,aAAa;gBAEpF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAEZ,MAAM;gBACxE,OAAO;oBACLa,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;YACF;YAEA,sBAAsB;YACtB,MAAMC,SAAS,MAAMZ,QAAQa,MAAM,CAAC;gBAClCC,YAAYtB;gBACZI,MAAMO;gBACNN;gBACAkB,gBAAgB;gBAChB1B;gBACAC;gBACA,GAAIQ,UAAU;oB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N;QAEA1C,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,eAAewC,MAAM,CAAC,GAAGC,WAAW,KAAKjD,YAAYQ,gBAAgB0C,KAAK,CAAC,IAAI,EACxF,GAAGzC,aAAa,CAACD,eAAe,EAAE2C,eAAejD,YAAYkD,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGb,qBAAqBE,KAAK,EAC1B,OAAOY;YACL,MAAM,EAAEzC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAE,GAAGyC,WAAW,GAAGD;YACxD,MAAM1C,OAAOQ,KAAKE,SAAS,CAACiC;YAC5B,OAAO,MAAM5C,KACXC,MACAC,OACAC,QACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SAyMlD,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { toCamelCase } from '../../../utils/camelCase.js';
|
|
2
2
|
import { toolSchemas } from '../schemas.js';
|
|
3
3
|
export const deleteResourceTool = (server, req, user, verboseLogs, collectionSlug, collections)=>{
|
|
4
|
-
const tool = async (id, where, depth = 0)=>{
|
|
4
|
+
const tool = async (id, where, depth = 0, locale, fallbackLocale)=>{
|
|
5
5
|
const payload = req.payload;
|
|
6
6
|
if (verboseLogs) {
|
|
7
|
-
payload.logger.info(`[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}`);
|
|
7
|
+
payload.logger.info(`[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`);
|
|
8
8
|
}
|
|
9
9
|
try {
|
|
10
10
|
// Validate that either id or where is provided
|
|
@@ -47,7 +47,13 @@ export const deleteResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
47
47
|
depth,
|
|
48
48
|
overrideAccess: false,
|
|
49
49
|
req,
|
|
50
|
-
user
|
|
50
|
+
user,
|
|
51
|
+
...locale && {
|
|
52
|
+
locale
|
|
53
|
+
},
|
|
54
|
+
...fallbackLocale && {
|
|
55
|
+
fallbackLocale
|
|
56
|
+
}
|
|
51
57
|
};
|
|
52
58
|
// Delete by ID or where clause
|
|
53
59
|
if (id) {
|
|
@@ -133,8 +139,8 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
133
139
|
}
|
|
134
140
|
};
|
|
135
141
|
if (collections?.[collectionSlug]?.enabled) {
|
|
136
|
-
server.tool(`delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`, toolSchemas.deleteResource.parameters.shape, async ({ id, depth, where })=>{
|
|
137
|
-
return await tool(id, where, depth);
|
|
142
|
+
server.tool(`delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`, toolSchemas.deleteResource.parameters.shape, async ({ id, depth, fallbackLocale, locale, where })=>{
|
|
143
|
+
return await tool(id, where, depth, locale, fallbackLocale);
|
|
138
144
|
});
|
|
139
145
|
}
|
|
140
146
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/resource/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const deleteResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: string,\n where?: string,\n depth: number = 0,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}`,\n )\n }\n\n try {\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Build delete options\n const deleteOptions: Record<string, unknown> = {\n collection: collectionSlug,\n depth,\n overrideAccess: false,\n req,\n user,\n }\n\n // Delete by ID or where clause\n if (id) {\n deleteOptions.id = id\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting single document with ID: ${id}`)\n }\n } else {\n deleteOptions.where = whereClause\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting multiple documents with where clause`)\n }\n }\n\n const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])\n\n // Handle different result types\n if (id) {\n // Single document deletion\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully deleted document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted document:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } else {\n // Multiple documents deletion\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nDeleted documents:\n\\`\\`\\`json\n${JSON.stringify(docs, null, 2)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors, null, 2)}\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting resource from ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting resource from collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n toolSchemas.deleteResource.parameters.shape,\n async ({ id, depth, where }) => {\n return await tool(id, where, depth)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","payload","logger","info","error","response","content","type","text","overrideResponse","whereClause","JSON","parse","_parseError","warn","deleteOptions","collection","overrideAccess","result","delete","stringify","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","deleteResource","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,OACAC,QAAgB,CAAC;QAOjB,MAAMC,UAAUT,IAAIS,OAAO;QAE3B,IAAIP,aAAa;YACfO,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAER,iBAAiBG,KAAK,CAA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,EAAEc,mBACrCJ,UACA;oBAAEiB;oBAAMC;gBAAO,GACf/B,QACGa;YAMP;QACF,EAAE,OAAOD,OAAO;YACd,MAAMsB,eAAetB,iBAAiBuB,QAAQvB,MAAMwB,OAAO,GAAG;YAC9D3B,QAAQC,MAAM,CAACE,KAAK,CAClB,CAAC,2CAA2C,EAAET,eAAe,EAAE,EAAE+B,cAAc;YAGjF,MAAMrB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,yCAAyC,EAAEb,eAAe,GAAG,EAAE+B,cAAc;oBACtF;iBACD;YACH;YAEA,OAAQ9B,aAAa,CAACD,eAAe,EAAEc,mBAAmBJ,UAAU,CAAC,GAAGb,QAAQa;QAMlF;IACF;IAEA,IAAIT,aAAa,CAACD,eAAe,EAAEkC,SAAS;QAC1CtC,OAAOM,IAAI,CACT,CAAC,MAAM,EAAEF,eAAemC,MAAM,CAAC,GAAGC,WAAW,KAAK3C,YAAYO,gBAAgBqC,KAAK,CAAC,IAAI,EACxF,GAAGpC,aAAa,CAACD,eAAe,EAAEsC,eAAe5C,YAAY6C,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChG9C,YAAY6C,cAAc,CAACE,UAAU,CAACC,KAAK,EAC3C,OAAO,EAAEvC,EAAE,EAAEE,KAAK,EAAED,KAAK,EAAE;YACzB,OAAO,MAAMF,KAAKC,IAAIC,OAAOC;QAC/B;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/resource/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const deleteResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: number | string,\n where?: string,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Build delete options\n const deleteOptions: Record<string, unknown> = {\n collection: collectionSlug,\n depth,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n // Delete by ID or where clause\n if (id) {\n deleteOptions.id = id\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting single document with ID: ${id}`)\n }\n } else {\n deleteOptions.where = whereClause\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Deleting multiple documents with where clause`)\n }\n }\n\n const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])\n\n // Handle different result types\n if (id) {\n // Single document deletion\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully deleted document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted document:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } else {\n // Multiple documents deletion\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Document deleted successfully from collection \"${collectionSlug}\"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nDeleted documents:\n\\`\\`\\`json\n${JSON.stringify(docs, null, 2)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors, null, 2)}\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error deleting resource from ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting resource from collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n toolSchemas.deleteResource.parameters.shape,\n async ({ id, depth, fallbackLocale, locale, where }) => {\n return await tool(id, where, depth, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","deleteResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","where","depth","locale","fallbackLocale","payload","logger","info","error","response","content","type","text","overrideResponse","whereClause","JSON","parse","_parseError","warn","deleteOptions","collection","overrideAccess","result","delete","stringify","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","deleteResource","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,OACAC,QAAgB,CAAC,EACjBC,QACAC;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,uBAAuBG,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE9J;QAEA,IAAI;YACF,+CAA+C;YAC/C,IAAI,CAACH,MAAM,CAACC,OAAO;gBACjBI,QAAQC,MAAM,CAACE,KAAK,CAAC;gBACrB,MAAMC,WAAW;oBACfC,SAAS;wBACP;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoD;qBACpF;gBACH;gBACA,OAAQd,aAAa,CAACD,eAAe,EAAEgB,mBAAmBJ,UAAU,CAAC,GAAGf,QACtEe;YAMJ;YAEA,iCAAiC;YACjC,IAAIK,cAAc,CAAC;YACnB,IAAIb,OAAO;gBACT,IAAI;oBACFa,cAAcC,KAAKC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AyC,EAAEf,eAAe,GAAG,EAAEiC,cAAc;oBACtF;iBACD;YACH;YAEA,OAAQhC,aAAa,CAACD,eAAe,EAAEgB,mBAAmBJ,UAAU,CAAC,GAAGf,QAAQe;QAMlF;IACF;IAEA,IAAIX,aAAa,CAACD,eAAe,EAAEoC,SAAS;QAC1CxC,OAAOM,IAAI,CACT,CAAC,MAAM,EAAEF,eAAeqC,MAAM,CAAC,GAAGC,WAAW,KAAK7C,YAAYO,gBAAgBuC,KAAK,CAAC,IAAI,EACxF,GAAGtC,aAAa,CAACD,eAAe,EAAEwC,eAAe9C,YAAY+C,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGhD,YAAY+C,cAAc,CAACE,UAAU,CAACC,KAAK,EAC3C,OAAO,EAAEzC,EAAE,EAAEE,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEF,KAAK,EAAE;YACjD,OAAO,MAAMF,KAAKC,IAAIC,OAAOC,OAAOC,QAAQC;QAC9C;IAEJ;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,SA6LlD,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { toCamelCase } from '../../../utils/camelCase.js';
|
|
2
2
|
import { toolSchemas } from '../schemas.js';
|
|
3
3
|
export const findResourceTool = (server, req, user, verboseLogs, collectionSlug, collections)=>{
|
|
4
|
-
const tool = async (id, limit = 10, page = 1, sort, where)=>{
|
|
4
|
+
const tool = async (id, limit = 10, page = 1, sort, where, locale, fallbackLocale)=>{
|
|
5
5
|
const payload = req.payload;
|
|
6
6
|
if (verboseLogs) {
|
|
7
|
-
payload.logger.info(`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}`);
|
|
7
|
+
payload.logger.info(`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
|
|
8
8
|
}
|
|
9
9
|
try {
|
|
10
10
|
// Parse where clause if provided
|
|
@@ -36,7 +36,13 @@ export const findResourceTool = (server, req, user, verboseLogs, collectionSlug,
|
|
|
36
36
|
collection: collectionSlug,
|
|
37
37
|
overrideAccess: false,
|
|
38
38
|
req,
|
|
39
|
-
user
|
|
39
|
+
user,
|
|
40
|
+
...locale && {
|
|
41
|
+
locale
|
|
42
|
+
},
|
|
43
|
+
...fallbackLocale && {
|
|
44
|
+
fallbackLocale
|
|
45
|
+
}
|
|
40
46
|
});
|
|
41
47
|
if (verboseLogs) {
|
|
42
48
|
payload.logger.info(`[payload-mcp] Found document with ID: ${id}`);
|
|
@@ -71,7 +77,13 @@ ${JSON.stringify(doc, null, 2)}`
|
|
|
71
77
|
overrideAccess: false,
|
|
72
78
|
page,
|
|
73
79
|
req,
|
|
74
|
-
user
|
|
80
|
+
user,
|
|
81
|
+
...locale && {
|
|
82
|
+
locale
|
|
83
|
+
},
|
|
84
|
+
...fallbackLocale && {
|
|
85
|
+
fallbackLocale
|
|
86
|
+
}
|
|
75
87
|
};
|
|
76
88
|
if (sort) {
|
|
77
89
|
findOptions.sort = sort;
|
|
@@ -114,8 +126,8 @@ Page: ${result.page} of ${result.totalPages}
|
|
|
114
126
|
}
|
|
115
127
|
};
|
|
116
128
|
if (collections?.[collectionSlug]?.enabled) {
|
|
117
|
-
server.tool(`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`, toolSchemas.findResources.parameters.shape, async ({ id, limit, page, sort, where })=>{
|
|
118
|
-
return await tool(id, limit, page, sort, where);
|
|
129
|
+
server.tool(`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`, toolSchemas.findResources.parameters.shape, async ({ id, fallbackLocale, limit, locale, page, sort, where })=>{
|
|
130
|
+
return await tool(id, limit, page, sort, where, locale, fallbackLocale);
|
|
119
131
|
});
|
|
120
132
|
}
|
|
121
133
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n req,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, limit, page, sort, where }) => {\n return await tool(id, limit, page, sort, where)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperC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AAE;gBAC7BC,gBAAgB,CAAC,cAAc,EAAEtB,KAAKa,SAAS,CAACJ,KAAK,MAAM,GAAG,QAAQ,CAAC;YACzE;YAEA,MAAML,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAMe;oBACR;iBACD;YACH;YAEA,OAAQjC,aAAa,CAACD,eAAe,EAAEoB,mBAAmBJ,UAAUe,QAAQlC,QAC1EmB;QAMJ,EAAE,OAAOqB,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9DhC,QAAQC,MAAM,CAAC4B,KAAK,CAClB,CAAC,sDAAsD,EAAErC,eAAe,EAAE,EAAEsC,cAAc;YAE5F,MAAMtB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,6CAA6C,EAAEnB,eAAe,KAAK,EAAEsC,cAAc;oBAC5F;iBACD;YACH;YACA,OAAQrC,aAAa,CAACD,eAAe,EAAEoB,mBAAmBJ,UAAU,CAAC,GAAGnB,QAAQmB;QAMlF;IACF;IAEA,IAAIf,aAAa,CAACD,eAAe,EAAEyC,SAAS;QAC1C7C,OAAOM,IAAI,CACT,CAAC,IAAI,EAAEF,eAAe0C,MAAM,CAAC,GAAGC,WAAW,KAAKlD,YAAYO,gBAAgB4C,KAAK,CAAC,IAAI,EACtF,GAAG3C,aAAa,CAACD,eAAe,EAAE6C,eAAenD,YAAYoD,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI,EAC/FrD,YAAYoD,aAAa,CAACE,UAAU,CAACC,KAAK,EAC1C,OAAO,EAAE9C,EAAE,EAAEC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;YACrC,OAAO,MAAML,KAAKC,IAAIC,OAAOC,MAAMC,MAAMC;QAC3C;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/resource/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const findResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n) => {\n const tool = async (\n id?: number | string,\n limit: number = 10,\n page: number = 1,\n sort?: string,\n where?: string,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // If ID is provided, use findByID\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource from collection \"${collectionSlug}\":\n${JSON.stringify(doc, null, 2)}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (_findError) {\n payload.logger.warn(\n `[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Otherwise, use find to get multiple documents\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause\n }\n\n const result = await payload.find(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,\n )\n }\n\n let responseText = `Collection: \"${collectionSlug}\"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`\n\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc, null, 2)}\\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,\n )\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading resources from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n server.tool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n toolSchemas.findResources.parameters.shape,\n async ({ id, fallbackLocale, limit, locale, page, sort, where }) => {\n return await tool(id, limit, page, sort, where, locale, fallbackLocale)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","locale","fallbackLocale","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","doc","findByID","collection","overrideAccess","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","charAt","toUpperCase","slice","description","findResources","trim","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,QACAC,KACAC,MACAC,aACAC,gBACAC;IAEA,MAAMC,OAAO,OACXC,IACAC,QAAgB,EAAE,EAClBC,OAAe,CAAC,EAChBC,MACAC,OACAC,QACAC;QAOA,MAAMC,UAAUb,IAAIa,OAAO;QAE3B,IAAIX,aAAa;YACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEZ,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,OAAOG,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE3K;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIK,cAAc,CAAC;YACnB,IAAIN,OAAO;gBACT,IAAI;oBACFM,cAAcC,KAAKC,KAAK,CAACR;oBACzB,IAAIR,aAAa;wBACfW,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEL,OAAO;oBAClE;gBACF,EAAE,OAAOS,aAAa;oB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B,eAAe,KAAK,EAAEwC,cAAc;oBAC5F;iBACD;YACH;YACA,OAAQvC,aAAa,CAACD,eAAe,EAAEsB,mBAAmBJ,UAAU,CAAC,GAAGrB,QAAQqB;QAMlF;IACF;IAEA,IAAIjB,aAAa,CAACD,eAAe,EAAE2C,SAAS;QAC1C/C,OAAOM,IAAI,CACT,CAAC,IAAI,EAAEF,eAAe4C,MAAM,CAAC,GAAGC,WAAW,KAAKpD,YAAYO,gBAAgB8C,KAAK,CAAC,IAAI,EACtF,GAAG7C,aAAa,CAACD,eAAe,EAAE+C,eAAerD,YAAYsD,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI,EAC/FvD,YAAYsD,aAAa,CAACE,UAAU,CAACC,KAAK,EAC1C,OAAO,EAAEhD,EAAE,EAAEM,cAAc,EAAEL,KAAK,EAAEI,MAAM,EAAEH,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;YAC7D,OAAO,MAAML,KAAKC,IAAIC,OAAOC,MAAMC,MAAMC,OAAOC,QAAQC;QAC1D;IAEJ;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,SAgUpB,CAAA"}
|
|
@@ -3,10 +3,10 @@ import { toCamelCase } from '../../../utils/camelCase.js';
|
|
|
3
3
|
import { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js';
|
|
4
4
|
import { toolSchemas } from '../schemas.js';
|
|
5
5
|
export const updateResourceTool = (server, req, user, verboseLogs, collectionSlug, collections, schema)=>{
|
|
6
|
-
const tool = async (data, id, where, draft = false, depth = 0, overrideLock = true, filePath, overwriteExistingFiles = false)=>{
|
|
6
|
+
const tool = async (data, id, where, draft = false, depth = 0, overrideLock = true, filePath, overwriteExistingFiles = false, locale, fallbackLocale)=>{
|
|
7
7
|
const payload = req.payload;
|
|
8
8
|
if (verboseLogs) {
|
|
9
|
-
payload.logger.info(`[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}`);
|
|
9
|
+
payload.logger.info(`[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
10
10
|
}
|
|
11
11
|
try {
|
|
12
12
|
// Parse the data JSON
|
|
@@ -80,6 +80,12 @@ export const updateResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
80
80
|
},
|
|
81
81
|
...overwriteExistingFiles && {
|
|
82
82
|
overwriteExistingFiles
|
|
83
|
+
},
|
|
84
|
+
...locale && {
|
|
85
|
+
locale
|
|
86
|
+
},
|
|
87
|
+
...fallbackLocale && {
|
|
88
|
+
fallbackLocale
|
|
83
89
|
}
|
|
84
90
|
};
|
|
85
91
|
if (verboseLogs) {
|
|
@@ -122,6 +128,12 @@ ${JSON.stringify(result, null, 2)}
|
|
|
122
128
|
},
|
|
123
129
|
...overwriteExistingFiles && {
|
|
124
130
|
overwriteExistingFiles
|
|
131
|
+
},
|
|
132
|
+
...locale && {
|
|
133
|
+
locale
|
|
134
|
+
},
|
|
135
|
+
...fallbackLocale && {
|
|
136
|
+
fallbackLocale
|
|
125
137
|
}
|
|
126
138
|
};
|
|
127
139
|
if (verboseLogs) {
|
|
@@ -183,21 +195,27 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
183
195
|
if (collections?.[collectionSlug]?.enabled) {
|
|
184
196
|
const convertedFields = convertCollectionSchemaToZod(schema);
|
|
185
197
|
// Create a new schema that combines the converted fields with update-specific parameters
|
|
198
|
+
// Use .partial() to make all fields optional for partial updates
|
|
186
199
|
const updateResourceSchema = z.object({
|
|
187
|
-
...convertedFields.shape,
|
|
188
|
-
id: z.
|
|
200
|
+
...convertedFields.partial().shape,
|
|
201
|
+
id: z.union([
|
|
202
|
+
z.string(),
|
|
203
|
+
z.number()
|
|
204
|
+
]).optional().describe('The ID of the document to update'),
|
|
189
205
|
depth: z.number().optional().default(0).describe('How many levels deep to populate relationships'),
|
|
190
206
|
draft: z.boolean().optional().default(false).describe('Whether to update the document as a draft'),
|
|
207
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
191
208
|
filePath: z.string().optional().describe('File path for file uploads'),
|
|
209
|
+
locale: z.string().optional().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale'),
|
|
192
210
|
overrideLock: z.boolean().optional().default(true).describe('Whether to override document locks'),
|
|
193
211
|
overwriteExistingFiles: z.boolean().optional().default(false).describe('Whether to overwrite existing files'),
|
|
194
212
|
where: z.string().optional().describe('JSON string for where clause to update multiple documents')
|
|
195
213
|
});
|
|
196
214
|
server.tool(`update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`, `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`, updateResourceSchema.shape, async (params)=>{
|
|
197
|
-
const { id, depth, draft, filePath, overrideLock, overwriteExistingFiles, where, ...fieldData } = params;
|
|
215
|
+
const { id, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, where, ...fieldData } = params;
|
|
198
216
|
// Convert field data back to JSON string format expected by the tool
|
|
199
217
|
const data = JSON.stringify(fieldData);
|
|
200
|
-
return await tool(data, id, where, draft, depth, overrideLock, filePath, overwriteExistingFiles);
|
|
218
|
+
return await tool(data, id, where, draft, depth, overrideLock, filePath, overwriteExistingFiles, locale, fallbackLocale);
|
|
201
219
|
});
|
|
202
220
|
}
|
|
203
221
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/resource/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const updateResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n id?: string,\n where?: string,\n draft: boolean = false,\n depth: number = 0,\n overrideLock: boolean = true,\n filePath?: string,\n overwriteExistingFiles: boolean = false,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Update by ID or where clause\n if (id) {\n // Single document update\n const updateOptions = {\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating single document with ID: ${id}`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: parsedData,\n } as any)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document updated successfully in collection \"${collectionSlug}\"!\nUpdated document:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } else {\n // Multiple documents update\n const updateOptions = {\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n where: whereClause,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating multiple documents with where clause`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: parsedData,\n } as any)\n\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully updated ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\n\\`\\`\\`json\n${JSON.stringify(docs, null, 2)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors, null, 2)}\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error updating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Create a new schema that combines the converted fields with update-specific parameters\n const updateResourceSchema = z.object({\n ...convertedFields.shape,\n id: z.string().optional().describe('The ID of the document to update'),\n depth: z\n .number()\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update the document as a draft'),\n filePath: z.string().optional().describe('File path for file uploads'),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.tool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n updateResourceSchema.shape,\n async (params: Record<string, unknown>) => {\n const {\n id,\n depth,\n draft,\n filePath,\n overrideLock,\n overwriteExistingFiles,\n where,\n ...fieldData\n } = params\n // Convert field data back to JSON string format expected by the tool\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n id as string | undefined,\n where as string | undefined,\n draft as boolean,\n depth as number,\n overrideLock as boolean,\n filePath as string | undefined,\n overwriteExistingFiles as boolean,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","updateOptions","collection","overrideAccess","result","update","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","convertedFields","updateResourceSchema","object","shape","string","optional","describe","number","default","boolean","charAt","toUpperCase","slice","description","updateResource","trim","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,IACAC,OACAC,QAAiB,KAAK,EACtBC,QAAgB,CAAC,EACjBC,eAAwB,IAAI,EAC5BC,UACAC,yBAAkC,KAAK;QAOvC,MAAMC,UAAUf,IAAIe,OAAO;QAE3B,IAAIb,aAAa;YACfa,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEd,iBAAiBK,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,qBAAqB,SAAS,EAAEE,OAAO;QAEvI;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIQ;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACb;gBACxB,IAAIL,aAAa;oBACfa,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEd,eAAe,EAAE,EAAEgB,KAAKE,SAAS,CAACH,aAAa;gBAEpF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAEhB,MAAM;gBACxE,MAAMiB,WAAW;oBACfC,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;gBACA,OAAQvB,aAAa,CAACD,eAAe,EAAEyB,mBAAmBJ,UAAU,CAAC,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AAEsD,MAAM,GAAGC,QAAQ,GAAGC,QAAQ,CAAC;YACzCtC,cAAclB,EACX2D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,MACRF,QAAQ,CAAC;YACZpC,wBAAwBpB,EACrB2D,OAAO,GACPJ,QAAQ,GACRG,OAAO,CAAC,OACRF,QAAQ,CAAC;YACZzC,OAAOf,EACJsD,MAAM,GACNC,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEAnD,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,eAAemD,MAAM,CAAC,GAAGC,WAAW,KAAK5D,YAAYQ,gBAAgBqD,KAAK,CAAC,IAAI,EACxF,GAAGpD,aAAa,CAACD,eAAe,EAAEsD,eAAe5D,YAAY6D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGd,qBAAqBE,KAAK,EAC1B,OAAOa;YACL,MAAM,EACJpD,EAAE,EACFG,KAAK,EACLD,KAAK,EACLG,QAAQ,EACRD,YAAY,EACZE,sBAAsB,EACtBL,KAAK,EACL,GAAGoD,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMrD,OAAOY,KAAKE,SAAS,CAACwC;YAC5B,OAAO,MAAMvD,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/resource/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const updateResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n id?: number | string,\n where?: string,\n draft: boolean = false,\n depth: number = 0,\n overrideLock: boolean = true,\n filePath?: string,\n overwriteExistingFiles: boolean = false,\n locale?: string,\n fallbackLocale?: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Validate that either id or where is provided\n if (!id && !where) {\n payload.logger.error('[payload-mcp] Either id or where clause must be provided')\n const response = {\n content: [\n { type: 'text' as const, text: 'Error: Either id or where clause must be provided' },\n ],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n // Parse where clause if provided\n let whereClause = {}\n if (where) {\n try {\n whereClause = JSON.parse(where)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using where clause: ${where}`)\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid where clause JSON: ${where}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],\n }\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Update by ID or where clause\n if (id) {\n // Single document update\n const updateOptions = {\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating single document with ID: ${id}`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: parsedData,\n } as any)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated document with ID: ${id}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Document updated successfully in collection \"${collectionSlug}\"!\nUpdated document:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } else {\n // Multiple documents update\n const updateOptions = {\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n overrideLock,\n req,\n user,\n where: whereClause,\n ...(filePath && { filePath }),\n ...(overwriteExistingFiles && { overwriteExistingFiles }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating multiple documents with where clause`)\n }\n const result = await payload.update({\n ...updateOptions,\n data: parsedData,\n } as any)\n\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully updated ${docs.length} documents, ${errors.length} errors`,\n )\n }\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`\n\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\n\\`\\`\\`json\n${JSON.stringify(docs, null, 2)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors, null, 2)}\n\\`\\`\\``\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(\n response,\n { docs, errors },\n req,\n ) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error updating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Create a new schema that combines the converted fields with update-specific parameters\n // Use .partial() to make all fields optional for partial updates\n const updateResourceSchema = z.object({\n ...convertedFields.partial().shape,\n id: z.union([z.string(), z.number()]).optional().describe('The ID of the document to update'),\n depth: z\n .number()\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update the document as a draft'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n filePath: z.string().optional().describe('File path for file uploads'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.tool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n updateResourceSchema.shape,\n async (params: Record<string, unknown>) => {\n const {\n id,\n depth,\n draft,\n fallbackLocale,\n filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\n where,\n ...fieldData\n } = params\n // Convert field data back to JSON string format expected by the tool\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n id as number | string | undefined,\n where as string | undefined,\n draft as boolean,\n depth as number,\n overrideLock as boolean,\n filePath as string | undefined,\n overwriteExistingFiles as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","convertCollectionSchemaToZod","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","locale","fallbackLocale","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","updateOptions","collection","overrideAccess","result","update","bulkResult","docs","errors","length","responseText","errorMessage","Error","message","enabled","convertedFields","updateResourceSchema","object","partial","shape","union","string","number","optional","describe","default","boolean","charAt","toUpperCase","slice","description","updateResource","trim","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,IACAC,OACAC,QAAiB,KAAK,EACtBC,QAAgB,CAAC,EACjBC,eAAwB,IAAI,EAC5BC,UACAC,yBAAkC,KAAK,EACvCC,QACAC;QAOA,MAAMC,UAAUjB,IAAIiB,OAAO;QAE3B,IA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AQ,GACRE,OAAO,CAAC,OACRD,QAAQ,CAAC;YACZ9C,OAAOf,EACJ0D,MAAM,GACNE,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEAxD,OAAOO,IAAI,CACT,CAAC,MAAM,EAAEH,eAAeuD,MAAM,CAAC,GAAGC,WAAW,KAAKhE,YAAYQ,gBAAgByD,KAAK,CAAC,IAAI,EACxF,GAAGxD,aAAa,CAACD,eAAe,EAAE0D,eAAehE,YAAYiE,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI,EAChGhB,qBAAqBG,KAAK,EAC1B,OAAOc;YACL,MAAM,EACJxD,EAAE,EACFG,KAAK,EACLD,KAAK,EACLM,cAAc,EACdH,QAAQ,EACRE,MAAM,EACNH,YAAY,EACZE,sBAAsB,EACtBL,KAAK,EACL,GAAGwD,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMzD,OAAOc,KAAKE,SAAS,CAAC0C;YAC5B,OAAO,MAAM3D,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC,wBACAC,QACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
@@ -3,8 +3,10 @@ export declare const toolSchemas: {
|
|
|
3
3
|
findResources: {
|
|
4
4
|
description: string;
|
|
5
5
|
parameters: z.ZodObject<{
|
|
6
|
-
id: z.ZodOptional<z.ZodString
|
|
6
|
+
id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
7
|
+
fallbackLocale: z.ZodOptional<z.ZodString>;
|
|
7
8
|
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
9
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
8
10
|
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
9
11
|
sort: z.ZodOptional<z.ZodString>;
|
|
10
12
|
where: z.ZodOptional<z.ZodString>;
|
|
@@ -12,11 +14,15 @@ export declare const toolSchemas: {
|
|
|
12
14
|
limit: number;
|
|
13
15
|
page: number;
|
|
14
16
|
sort?: string | undefined;
|
|
15
|
-
|
|
17
|
+
locale?: string | undefined;
|
|
18
|
+
id?: string | number | undefined;
|
|
19
|
+
fallbackLocale?: string | undefined;
|
|
16
20
|
where?: string | undefined;
|
|
17
21
|
}, {
|
|
18
22
|
sort?: string | undefined;
|
|
19
|
-
|
|
23
|
+
locale?: string | undefined;
|
|
24
|
+
id?: string | number | undefined;
|
|
25
|
+
fallbackLocale?: string | undefined;
|
|
20
26
|
limit?: number | undefined;
|
|
21
27
|
page?: number | undefined;
|
|
22
28
|
where?: string | undefined;
|
|
@@ -27,22 +33,30 @@ export declare const toolSchemas: {
|
|
|
27
33
|
parameters: z.ZodObject<{
|
|
28
34
|
data: z.ZodString;
|
|
29
35
|
draft: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
36
|
+
fallbackLocale: z.ZodOptional<z.ZodString>;
|
|
37
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
30
38
|
}, "strip", z.ZodTypeAny, {
|
|
31
39
|
draft: boolean;
|
|
32
40
|
data: string;
|
|
41
|
+
locale?: string | undefined;
|
|
42
|
+
fallbackLocale?: string | undefined;
|
|
33
43
|
}, {
|
|
34
44
|
data: string;
|
|
45
|
+
locale?: string | undefined;
|
|
35
46
|
draft?: boolean | undefined;
|
|
47
|
+
fallbackLocale?: string | undefined;
|
|
36
48
|
}>;
|
|
37
49
|
};
|
|
38
50
|
updateResource: {
|
|
39
51
|
description: string;
|
|
40
52
|
parameters: z.ZodObject<{
|
|
41
|
-
id: z.ZodOptional<z.ZodString
|
|
53
|
+
id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
42
54
|
data: z.ZodString;
|
|
43
55
|
depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
44
56
|
draft: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
57
|
+
fallbackLocale: z.ZodOptional<z.ZodString>;
|
|
45
58
|
filePath: z.ZodOptional<z.ZodString>;
|
|
59
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
46
60
|
overrideLock: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
47
61
|
overwriteExistingFiles: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
48
62
|
where: z.ZodOptional<z.ZodString>;
|
|
@@ -52,14 +66,18 @@ export declare const toolSchemas: {
|
|
|
52
66
|
data: string;
|
|
53
67
|
overrideLock: boolean;
|
|
54
68
|
overwriteExistingFiles: boolean;
|
|
55
|
-
|
|
69
|
+
locale?: string | undefined;
|
|
70
|
+
id?: string | number | undefined;
|
|
71
|
+
fallbackLocale?: string | undefined;
|
|
56
72
|
where?: string | undefined;
|
|
57
73
|
filePath?: string | undefined;
|
|
58
74
|
}, {
|
|
59
75
|
data: string;
|
|
60
76
|
depth?: number | undefined;
|
|
77
|
+
locale?: string | undefined;
|
|
61
78
|
draft?: boolean | undefined;
|
|
62
|
-
id?: string | undefined;
|
|
79
|
+
id?: string | number | undefined;
|
|
80
|
+
fallbackLocale?: string | undefined;
|
|
63
81
|
where?: string | undefined;
|
|
64
82
|
filePath?: string | undefined;
|
|
65
83
|
overrideLock?: boolean | undefined;
|
|
@@ -69,16 +87,22 @@ export declare const toolSchemas: {
|
|
|
69
87
|
deleteResource: {
|
|
70
88
|
description: string;
|
|
71
89
|
parameters: z.ZodObject<{
|
|
72
|
-
id: z.ZodOptional<z.ZodString
|
|
90
|
+
id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
73
91
|
depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
92
|
+
fallbackLocale: z.ZodOptional<z.ZodString>;
|
|
93
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
74
94
|
where: z.ZodOptional<z.ZodString>;
|
|
75
95
|
}, "strip", z.ZodTypeAny, {
|
|
76
96
|
depth: number;
|
|
77
|
-
|
|
97
|
+
locale?: string | undefined;
|
|
98
|
+
id?: string | number | undefined;
|
|
99
|
+
fallbackLocale?: string | undefined;
|
|
78
100
|
where?: string | undefined;
|
|
79
101
|
}, {
|
|
80
102
|
depth?: number | undefined;
|
|
81
|
-
|
|
103
|
+
locale?: string | undefined;
|
|
104
|
+
id?: string | number | undefined;
|
|
105
|
+
fallbackLocale?: string | undefined;
|
|
82
106
|
where?: string | undefined;
|
|
83
107
|
}>;
|
|
84
108
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgavB,CAAA"}
|
|
@@ -3,8 +3,13 @@ export const toolSchemas = {
|
|
|
3
3
|
findResources: {
|
|
4
4
|
description: 'Find documents in a collection by ID or where clause using Find or FindByID.',
|
|
5
5
|
parameters: z.object({
|
|
6
|
-
id: z.
|
|
6
|
+
id: z.union([
|
|
7
|
+
z.string(),
|
|
8
|
+
z.number()
|
|
9
|
+
]).optional().describe('Optional: specific document ID to retrieve. If not provided, returns all documents'),
|
|
10
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
7
11
|
limit: z.number().int().min(1, 'Limit must be at least 1').max(100, 'Limit cannot exceed 100').optional().default(10).describe('Maximum number of documents to return (default: 10, max: 100)'),
|
|
12
|
+
locale: z.string().optional().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields'),
|
|
8
13
|
page: z.number().int().min(1, 'Page must be at least 1').optional().default(1).describe('Page number for pagination (default: 1)'),
|
|
9
14
|
sort: z.string().optional().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)'),
|
|
10
15
|
where: z.string().optional().describe('Optional JSON string for where clause filtering (e.g., \'{"title": {"contains": "test"}}\')')
|
|
@@ -14,17 +19,24 @@ export const toolSchemas = {
|
|
|
14
19
|
description: 'Create a document in a collection.',
|
|
15
20
|
parameters: z.object({
|
|
16
21
|
data: z.string().describe('JSON string containing the data for the new document'),
|
|
17
|
-
draft: z.boolean().optional().default(false).describe('Whether to create the document as a draft')
|
|
22
|
+
draft: z.boolean().optional().default(false).describe('Whether to create the document as a draft'),
|
|
23
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
24
|
+
locale: z.string().optional().describe('Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale')
|
|
18
25
|
})
|
|
19
26
|
},
|
|
20
27
|
updateResource: {
|
|
21
28
|
description: 'Update documents in a collection by ID or where clause.',
|
|
22
29
|
parameters: z.object({
|
|
23
|
-
id: z.
|
|
30
|
+
id: z.union([
|
|
31
|
+
z.string(),
|
|
32
|
+
z.number()
|
|
33
|
+
]).optional().describe('Optional: specific document ID to update'),
|
|
24
34
|
data: z.string().describe('JSON string containing the data to update'),
|
|
25
35
|
depth: z.number().int().min(0).max(10).optional().default(0).describe('Depth of population for relationships'),
|
|
26
36
|
draft: z.boolean().optional().default(false).describe('Whether to update as a draft'),
|
|
37
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
27
38
|
filePath: z.string().optional().describe('Optional: absolute file path for file uploads'),
|
|
39
|
+
locale: z.string().optional().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale'),
|
|
28
40
|
overrideLock: z.boolean().optional().default(true).describe('Whether to override document locks'),
|
|
29
41
|
overwriteExistingFiles: z.boolean().optional().default(false).describe('Whether to overwrite existing files'),
|
|
30
42
|
where: z.string().optional().describe('Optional: JSON string for where clause to update multiple documents')
|
|
@@ -33,8 +45,13 @@ export const toolSchemas = {
|
|
|
33
45
|
deleteResource: {
|
|
34
46
|
description: 'Delete documents in a collection by ID or where clause.',
|
|
35
47
|
parameters: z.object({
|
|
36
|
-
id: z.
|
|
48
|
+
id: z.union([
|
|
49
|
+
z.string(),
|
|
50
|
+
z.number()
|
|
51
|
+
]).optional().describe('Optional: specific document ID to delete'),
|
|
37
52
|
depth: z.number().int().min(0).max(10).optional().default(0).describe('Depth of population for relationships in response'),
|
|
53
|
+
fallbackLocale: z.string().optional().describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
54
|
+
locale: z.string().optional().describe('Optional: locale code for the operation (e.g., "en", "es"). Defaults to the default locale'),
|
|
38
55
|
where: z.string().optional().describe('Optional: JSON string for where clause to delete multiple documents')
|
|
39
56
|
})
|
|
40
57
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mcp/tools/schemas.ts"],"sourcesContent":["import { z } from 'zod'\n\nexport const toolSchemas = {\n findResources: {\n description: 'Find documents in a collection by ID or where clause using Find or FindByID.',\n parameters: z.object({\n id: z\n .string()\n .optional()\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n ),\n limit: z\n .number()\n .int()\n .min(1, 'Limit must be at least 1')\n .max(100, 'Limit cannot exceed 100')\n .optional()\n .default(10)\n .describe('Maximum number of documents to return (default: 10, max: 100)'),\n page: z\n .number()\n .int()\n .min(1, 'Page must be at least 1')\n .optional()\n .default(1)\n .describe('Page number for pagination (default: 1)'),\n sort: z\n .string()\n .optional()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)'),\n where: z\n .string()\n .optional()\n .describe(\n 'Optional JSON string for where clause filtering (e.g., \\'{\"title\": {\"contains\": \"test\"}}\\')',\n ),\n }),\n },\n\n createResource: {\n description: 'Create a document in a collection.',\n parameters: z.object({\n data: z.string().describe('JSON string containing the data for the new document'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to create the document as a draft'),\n }),\n },\n\n updateResource: {\n description: 'Update documents in a collection by ID or where clause.',\n parameters: z.object({\n id: z.string().optional().describe('Optional: specific document ID to update'),\n data: z.string().describe('JSON string containing the data to update'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships'),\n draft: z.boolean().optional().default(false).describe('Whether to update as a draft'),\n filePath: z.string().optional().describe('Optional: absolute file path for file uploads'),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('Optional: JSON string for where clause to update multiple documents'),\n }),\n },\n\n deleteResource: {\n description: 'Delete documents in a collection by ID or where clause.',\n parameters: z.object({\n id: z.string().optional().describe('Optional: specific document ID to delete'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships in response'),\n where: z\n .string()\n .optional()\n .describe('Optional: JSON string for where clause to delete multiple documents'),\n }),\n },\n\n // Experimental Below This Line\n createCollection: {\n description: 'Creates a new collection with specified fields and configuration.',\n parameters: z.object({\n collectionDescription: z\n .string()\n .optional()\n .describe('Optional description for the collection'),\n collectionName: z.string().describe('The name of the collection to create'),\n fields: z.array(z.any()).describe('Array of field definitions for the collection'),\n hasUpload: z\n .boolean()\n .optional()\n .describe('Whether the collection should have upload capabilities'),\n }),\n },\n\n findCollections: {\n description: 'Finds and lists collections with optional content and document counts.',\n parameters: z.object({\n collectionName: z\n .string()\n .optional()\n .describe('Optional: specific collection name to retrieve'),\n includeContent: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include collection file content'),\n includeCount: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include document counts for each collection'),\n }),\n },\n\n updateCollection: {\n description:\n 'Updates an existing collection with new fields, modifications, or configuration changes.',\n parameters: z.object({\n collectionName: z.string().describe('The name of the collection to update'),\n configUpdates: z.any().optional().describe('Configuration updates (for update_config type)'),\n fieldModifications: z\n .array(z.any())\n .optional()\n .describe('Field modifications (for modify_field type)'),\n fieldNamesToRemove: z\n .array(z.string())\n .optional()\n .describe('Field names to remove (for remove_field type)'),\n newContent: z\n .string()\n .optional()\n .describe('New content to replace entire collection (for replace_content type)'),\n newFields: z.array(z.any()).optional().describe('New fields to add (for add_field type)'),\n updateType: z\n .enum(['add_field', 'remove_field', 'modify_field', 'update_config', 'replace_content'])\n .describe('Type of update to perform'),\n }),\n },\n\n deleteCollection: {\n description: 'Deletes a collection and optionally updates the configuration.',\n parameters: z.object({\n collectionName: z.string().describe('The name of the collection to delete'),\n confirmDeletion: z.boolean().describe('Confirmation flag to prevent accidental deletion'),\n updateConfig: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update payload.config.ts to remove collection reference'),\n }),\n },\n\n findConfig: {\n description: 'Reads and displays the current configuration file.',\n parameters: z.object({\n includeMetadata: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include file metadata (size, modified date, etc.)'),\n }),\n },\n\n updateConfig: {\n description: 'Updates the configuration file with various modifications.',\n parameters: z.object({\n adminConfig: z\n .any()\n .optional()\n .describe('Admin configuration updates (for update_admin type)'),\n collectionName: z\n .string()\n .optional()\n .describe('Collection name (required for add_collection and remove_collection)'),\n databaseConfig: z\n .any()\n .optional()\n .describe('Database configuration updates (for update_database type)'),\n generalConfig: z.any().optional().describe('General configuration updates'),\n newContent: z\n .string()\n .optional()\n .describe('New configuration content (for replace_content type)'),\n pluginUpdates: z\n .any()\n .optional()\n .describe('Plugin configuration updates (for update_plugins type)'),\n updateType: z\n .enum([\n 'add_collection',\n 'remove_collection',\n 'update_admin',\n 'update_database',\n 'update_plugins',\n 'replace_content',\n ])\n .describe('Type of configuration update to perform'),\n }),\n },\n\n auth: {\n description: 'Checks authentication status for the current user.',\n parameters: z.object({\n headers: z\n .string()\n .optional()\n .describe(\n 'Optional JSON string containing custom headers to send with the authentication request',\n ),\n }),\n },\n\n login: {\n description: 'Authenticates a user with email and password.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships'),\n email: z.string().email().describe('The user email address'),\n overrideAccess: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to override access controls'),\n password: z.string().describe('The user password'),\n showHiddenFields: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to show hidden fields in the response'),\n }),\n },\n\n verify: {\n description: 'Verifies a user email with a verification token.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n token: z.string().describe('The verification token sent to the user email'),\n }),\n },\n\n resetPassword: {\n description: 'Resets a user password with a reset token.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n password: z.string().describe('The new password for the user'),\n token: z.string().describe('The password reset token sent to the user email'),\n }),\n },\n\n forgotPassword: {\n description: 'Sends a password reset email to a user.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n disableEmail: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to disable sending the email (for testing)'),\n email: z.string().email().describe('The user email address'),\n }),\n },\n\n unlock: {\n description: 'Unlocks a user account that has been locked due to failed login attempts.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n email: z.string().email().describe('The user email address'),\n }),\n },\n\n createJob: {\n description: 'Creates a new job (task or workflow) with specified configuration.',\n parameters: z.object({\n description: z.string().describe('Description of what the job does'),\n inputSchema: z.record(z.any()).optional().default({}).describe('Input schema for the job'),\n jobData: z\n .record(z.any())\n .optional()\n .default({})\n .describe('Additional job configuration data'),\n jobName: z\n .string()\n .min(1, 'Job name cannot be empty')\n .regex(/^[a-z][\\w-]*$/i, 'Job name must be alphanumeric and can contain underscores/dashes')\n .describe('The name of the job to create'),\n jobSlug: z\n .string()\n .min(1, 'Job slug cannot be empty')\n .regex(/^[a-z][a-z0-9-]*$/, 'Job slug must be kebab-case')\n .describe('The slug for the job (kebab-case format)'),\n jobType: z\n .enum(['task', 'workflow'])\n .describe('Whether to create a task (individual unit) or workflow (orchestrates tasks)'),\n outputSchema: z.record(z.any()).optional().default({}).describe('Output schema for the job'),\n }),\n },\n\n updateJob: {\n description: 'Updates an existing job with new configuration, schema, or handler code.',\n parameters: z.object({\n configUpdate: z.record(z.any()).optional().describe('New configuration for the job'),\n handlerCode: z\n .string()\n .optional()\n .describe('New handler code to replace the existing handler'),\n inputSchema: z.record(z.any()).optional().describe('New input schema for the job'),\n jobSlug: z.string().describe('The slug of the job to update'),\n outputSchema: z.record(z.any()).optional().describe('New output schema for the job'),\n taskSequence: z.array(z.any()).optional().describe('New task sequence for workflows'),\n updateType: z\n .enum(['modify_schema', 'update_tasks', 'change_config', 'replace_handler'])\n .describe('Type of update to perform on the job'),\n }),\n },\n\n runJob: {\n description: 'Runs a job with specified input data and queue options.',\n parameters: z.object({\n delay: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe('Delay in milliseconds before job execution'),\n input: z.record(z.any()).describe('Input data for the job execution'),\n jobSlug: z.string().describe('The slug of the job to run'),\n priority: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('Job priority (1-10, higher is more important)'),\n queue: z\n .string()\n .optional()\n .describe('Queue name to use for job execution (default: \"default\")'),\n }),\n },\n}\n"],"names":["z","toolSchemas","findResources","description","parameters","object","id","string","optional","describe","limit","number","int","min","max","default","page","sort","where","createResource","data","draft","boolean","updateResource","depth","filePath","overrideLock","overwriteExistingFiles","deleteResource","createCollection","collectionDescription","collectionName","fields","array","any","hasUpload","findCollections","includeContent","includeCount","updateCollection","configUpdates","fieldModifications","fieldNamesToRemove","newContent","newFields","updateType","enum","deleteCollection","confirmDeletion","updateConfig","findConfig","includeMetadata","adminConfig","databaseConfig","generalConfig","pluginUpdates","auth","headers","login","collection","email","overrideAccess","password","showHiddenFields","verify","token","resetPassword","forgotPassword","disableEmail","unlock","createJob","inputSchema","record","jobData","jobName","regex","jobSlug","jobType","outputSchema","updateJob","configUpdate","handlerCode","taskSequence","runJob","delay","input","priority","queue"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,OAAO,MAAMC,cAAc;IACzBC,eAAe;QACbC,aAAa;QACbC,YAAYJ,EAAEK,MAAM,CAAC;YACnBC,IAAIN,EACDO,MAAM,GACNC,QAAQ,GACRC,QAAQ,CACP;YAEJC,OAAOV,EACJW,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GAAG,4BACPC,GAAG,CAAC,KAAK,2BACTN,QAAQ,GACRO,OAAO,CAAC,IACRN,QAAQ,CAAC;YACZO,MAAMhB,EACHW,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GAAG,2BACPL,QAAQ,GACRO,OAAO,CAAC,GACRN,QAAQ,CAAC;YACZQ,MAAMjB,EACHO,MAAM,GACNC,QAAQ,GACRC,QAAQ,CAAC;YACZS,OAAOlB,EACJO,MAAM,GACNC,QAAQ,GACRC,QAAQ,CACP;QAEN;IACF;IAEAU,gBAAgB;QACdhB,aAAa;QACbC,YAAYJ,EAAEK,MAAM,CAAC;YACnBe,MAAMpB,EAAEO,MAAM,GAAGE,QAAQ,CAAC;YAC1BY,OAAOrB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BAAiB;aAAkB,EAC1ErC,QAAQ,CAAC;QACd;IACF;IAEA0E,QAAQ;QACNhF,aAAa;QACbC,YAAYJ,EAAEK,MAAM,CAAC;YACnB+E,OAAOpF,EACJW,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJL,QAAQ,GACRC,QAAQ,CAAC;YACZ4E,OAAOrF,EAAEwE,MAAM,CAACxE,EAAEkC,GAAG,IAAIzB,QAAQ,CAAC;YAClCmE,SAAS5E,EAAEO,MAAM,GAAGE,QAAQ,CAAC;YAC7B6E,UAAUtF,EACPW,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJN,QAAQ,GACRC,QAAQ,CAAC;YACZ8E,OAAOvF,EACJO,MAAM,GACNC,QAAQ,GACRC,QAAQ,CAAC;QACd;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/mcp/tools/schemas.ts"],"sourcesContent":["import { z } from 'zod'\n\nexport const toolSchemas = {\n findResources: {\n description: 'Find documents in a collection by ID or where clause using Find or FindByID.',\n parameters: z.object({\n id: z\n .union([z.string(), z.number()])\n .optional()\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n ),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n limit: z\n .number()\n .int()\n .min(1, 'Limit must be at least 1')\n .max(100, 'Limit cannot exceed 100')\n .optional()\n .default(10)\n .describe('Maximum number of documents to return (default: 10, max: 100)'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n ),\n page: z\n .number()\n .int()\n .min(1, 'Page must be at least 1')\n .optional()\n .default(1)\n .describe('Page number for pagination (default: 1)'),\n sort: z\n .string()\n .optional()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)'),\n where: z\n .string()\n .optional()\n .describe(\n 'Optional JSON string for where clause filtering (e.g., \\'{\"title\": {\"contains\": \"test\"}}\\')',\n ),\n }),\n },\n\n createResource: {\n description: 'Create a document in a collection.',\n parameters: z.object({\n data: z.string().describe('JSON string containing the data for the new document'),\n draft: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to create the document as a draft'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to create the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n }),\n },\n\n updateResource: {\n description: 'Update documents in a collection by ID or where clause.',\n parameters: z.object({\n id: z\n .union([z.string(), z.number()])\n .optional()\n .describe('Optional: specific document ID to update'),\n data: z.string().describe('JSON string containing the data to update'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships'),\n draft: z.boolean().optional().default(false).describe('Whether to update as a draft'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n filePath: z.string().optional().describe('Optional: absolute file path for file uploads'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n overrideLock: z\n .boolean()\n .optional()\n .default(true)\n .describe('Whether to override document locks'),\n overwriteExistingFiles: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to overwrite existing files'),\n where: z\n .string()\n .optional()\n .describe('Optional: JSON string for where clause to update multiple documents'),\n }),\n },\n\n deleteResource: {\n description: 'Delete documents in a collection by ID or where clause.',\n parameters: z.object({\n id: z\n .union([z.string(), z.number()])\n .optional()\n .describe('Optional: specific document ID to delete'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships in response'),\n fallbackLocale: z\n .string()\n .optional()\n .describe('Optional: fallback locale code to use when requested locale is not available'),\n locale: z\n .string()\n .optional()\n .describe(\n 'Optional: locale code for the operation (e.g., \"en\", \"es\"). Defaults to the default locale',\n ),\n where: z\n .string()\n .optional()\n .describe('Optional: JSON string for where clause to delete multiple documents'),\n }),\n },\n\n // Experimental Below This Line\n createCollection: {\n description: 'Creates a new collection with specified fields and configuration.',\n parameters: z.object({\n collectionDescription: z\n .string()\n .optional()\n .describe('Optional description for the collection'),\n collectionName: z.string().describe('The name of the collection to create'),\n fields: z.array(z.any()).describe('Array of field definitions for the collection'),\n hasUpload: z\n .boolean()\n .optional()\n .describe('Whether the collection should have upload capabilities'),\n }),\n },\n\n findCollections: {\n description: 'Finds and lists collections with optional content and document counts.',\n parameters: z.object({\n collectionName: z\n .string()\n .optional()\n .describe('Optional: specific collection name to retrieve'),\n includeContent: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include collection file content'),\n includeCount: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include document counts for each collection'),\n }),\n },\n\n updateCollection: {\n description:\n 'Updates an existing collection with new fields, modifications, or configuration changes.',\n parameters: z.object({\n collectionName: z.string().describe('The name of the collection to update'),\n configUpdates: z.any().optional().describe('Configuration updates (for update_config type)'),\n fieldModifications: z\n .array(z.any())\n .optional()\n .describe('Field modifications (for modify_field type)'),\n fieldNamesToRemove: z\n .array(z.string())\n .optional()\n .describe('Field names to remove (for remove_field type)'),\n newContent: z\n .string()\n .optional()\n .describe('New content to replace entire collection (for replace_content type)'),\n newFields: z.array(z.any()).optional().describe('New fields to add (for add_field type)'),\n updateType: z\n .enum(['add_field', 'remove_field', 'modify_field', 'update_config', 'replace_content'])\n .describe('Type of update to perform'),\n }),\n },\n\n deleteCollection: {\n description: 'Deletes a collection and optionally updates the configuration.',\n parameters: z.object({\n collectionName: z.string().describe('The name of the collection to delete'),\n confirmDeletion: z.boolean().describe('Confirmation flag to prevent accidental deletion'),\n updateConfig: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to update payload.config.ts to remove collection reference'),\n }),\n },\n\n findConfig: {\n description: 'Reads and displays the current configuration file.',\n parameters: z.object({\n includeMetadata: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to include file metadata (size, modified date, etc.)'),\n }),\n },\n\n updateConfig: {\n description: 'Updates the configuration file with various modifications.',\n parameters: z.object({\n adminConfig: z\n .any()\n .optional()\n .describe('Admin configuration updates (for update_admin type)'),\n collectionName: z\n .string()\n .optional()\n .describe('Collection name (required for add_collection and remove_collection)'),\n databaseConfig: z\n .any()\n .optional()\n .describe('Database configuration updates (for update_database type)'),\n generalConfig: z.any().optional().describe('General configuration updates'),\n newContent: z\n .string()\n .optional()\n .describe('New configuration content (for replace_content type)'),\n pluginUpdates: z\n .any()\n .optional()\n .describe('Plugin configuration updates (for update_plugins type)'),\n updateType: z\n .enum([\n 'add_collection',\n 'remove_collection',\n 'update_admin',\n 'update_database',\n 'update_plugins',\n 'replace_content',\n ])\n .describe('Type of configuration update to perform'),\n }),\n },\n\n auth: {\n description: 'Checks authentication status for the current user.',\n parameters: z.object({\n headers: z\n .string()\n .optional()\n .describe(\n 'Optional JSON string containing custom headers to send with the authentication request',\n ),\n }),\n },\n\n login: {\n description: 'Authenticates a user with email and password.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('Depth of population for relationships'),\n email: z.string().email().describe('The user email address'),\n overrideAccess: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to override access controls'),\n password: z.string().describe('The user password'),\n showHiddenFields: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to show hidden fields in the response'),\n }),\n },\n\n verify: {\n description: 'Verifies a user email with a verification token.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n token: z.string().describe('The verification token sent to the user email'),\n }),\n },\n\n resetPassword: {\n description: 'Resets a user password with a reset token.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n password: z.string().describe('The new password for the user'),\n token: z.string().describe('The password reset token sent to the user email'),\n }),\n },\n\n forgotPassword: {\n description: 'Sends a password reset email to a user.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n disableEmail: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to disable sending the email (for testing)'),\n email: z.string().email().describe('The user email address'),\n }),\n },\n\n unlock: {\n description: 'Unlocks a user account that has been locked due to failed login attempts.',\n parameters: z.object({\n collection: z.string().describe('The collection containing the user (e.g., \"users\")'),\n email: z.string().email().describe('The user email address'),\n }),\n },\n\n createJob: {\n description: 'Creates a new job (task or workflow) with specified configuration.',\n parameters: z.object({\n description: z.string().describe('Description of what the job does'),\n inputSchema: z.record(z.any()).optional().default({}).describe('Input schema for the job'),\n jobData: z\n .record(z.any())\n .optional()\n .default({})\n .describe('Additional job configuration data'),\n jobName: z\n .string()\n .min(1, 'Job name cannot be empty')\n .regex(/^[a-z][\\w-]*$/i, 'Job name must be alphanumeric and can contain underscores/dashes')\n .describe('The name of the job to create'),\n jobSlug: z\n .string()\n .min(1, 'Job slug cannot be empty')\n .regex(/^[a-z][a-z0-9-]*$/, 'Job slug must be kebab-case')\n .describe('The slug for the job (kebab-case format)'),\n jobType: z\n .enum(['task', 'workflow'])\n .describe('Whether to create a task (individual unit) or workflow (orchestrates tasks)'),\n outputSchema: z.record(z.any()).optional().default({}).describe('Output schema for the job'),\n }),\n },\n\n updateJob: {\n description: 'Updates an existing job with new configuration, schema, or handler code.',\n parameters: z.object({\n configUpdate: z.record(z.any()).optional().describe('New configuration for the job'),\n handlerCode: z\n .string()\n .optional()\n .describe('New handler code to replace the existing handler'),\n inputSchema: z.record(z.any()).optional().describe('New input schema for the job'),\n jobSlug: z.string().describe('The slug of the job to update'),\n outputSchema: z.record(z.any()).optional().describe('New output schema for the job'),\n taskSequence: z.array(z.any()).optional().describe('New task sequence for workflows'),\n updateType: z\n .enum(['modify_schema', 'update_tasks', 'change_config', 'replace_handler'])\n .describe('Type of update to perform on the job'),\n }),\n },\n\n runJob: {\n description: 'Runs a job with specified input data and queue options.',\n parameters: z.object({\n delay: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe('Delay in milliseconds before job execution'),\n input: z.record(z.any()).describe('Input data for the job execution'),\n jobSlug: z.string().describe('The slug of the job to run'),\n priority: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('Job priority (1-10, higher is more important)'),\n queue: z\n .string()\n .optional()\n .describe('Queue name to use for job execution (default: \"default\")'),\n }),\n },\n}\n"],"names":["z","toolSchemas","findResources","description","parameters","object","id","union","string","number","optional","describe","fallbackLocale","limit","int","min","max","default","locale","page","sort","where","createResource","data","draft","boolean","updateResource","depth","filePath","overrideLock","overwriteExistingFiles","deleteResource","createCollection","collectionDescription","collectionName","fields","array","any","hasUpload","findCollections","includeContent","includeCount","updateCollection","configUpdates","fieldModifications","fieldNamesToRemove","newContent","newFields","updateType","enum","deleteCollection","confirmDeletion","updateConfig","findConfig","includeMetadata","adminConfig","databaseConfig","generalConfig","pluginUpdates","auth","headers","login","collection","email","overrideAccess","password","showHiddenFields","verify","token","resetPassword","forgotPassword","disableEmail","unlock","createJob","inputSchema","record","jobData","jobName","regex","jobSlug","jobType","outputSchema","updateJob","configUpdate","handlerCode","taskSequence","runJob","delay","input","priority","queue"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,OAAO,MAAMC,cAAc;IACzBC,eAAe;QACbC,aAAa;QACbC,YAAYJ,EAAEK,MAAM,CAAC;YACnBC,IAAIN,EACDO,KAAK,CAAC;gBAACP,EAAEQ,MAAM;gBAAIR,EAAES,MAAM;aAAG,EAC9BC,QAAQ,GACRC,QAAQ,CACP;YAEJC,gBAAgBZ,EACbQ,MAAM,GACNE,QAAQ,GACRC,QAAQ,CAAC;YACZE,OAAOb,EACJS,MAAM,GACNK,GAAG,GACHC,GAAG,CAAC,GAAG,4BACPC,GAAG,CAAC,KAAK,2BACTN,QAAQ,GACRO,OAAO,CAAC,IACRN,QAAQ,CAAC;YACZO,QAAQlB,EACLQ,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AAEQ,MAAM,GAAGG,QAAQ,CAAC;YAC7B8E,UAAUzF,EACPS,MAAM,GACNK,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJN,QAAQ,GACRC,QAAQ,CAAC;YACZ+E,OAAO1F,EACJQ,MAAM,GACNE,QAAQ,GACRC,QAAQ,CAAC;QACd;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.65.0-internal.
|
|
3
|
+
"version": "3.65.0-internal.cebb1a8",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@payloadcms/eslint-config": "3.28.0",
|
|
48
|
-
"payload": "3.65.0-internal.
|
|
48
|
+
"payload": "3.65.0-internal.cebb1a8"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.65.0-internal.
|
|
51
|
+
"payload": "3.65.0-internal.cebb1a8"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
|
@@ -2,6 +2,8 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
|
2
2
|
import type { JSONSchema4 } from 'json-schema'
|
|
3
3
|
import type { PayloadRequest, TypedUser } from 'payload'
|
|
4
4
|
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
5
7
|
import type { PluginMCPServerConfig } from '../../../types.js'
|
|
6
8
|
|
|
7
9
|
import { toCamelCase } from '../../../utils/camelCase.js'
|
|
@@ -18,6 +20,9 @@ export const createResourceTool = (
|
|
|
18
20
|
) => {
|
|
19
21
|
const tool = async (
|
|
20
22
|
data: string,
|
|
23
|
+
draft: boolean,
|
|
24
|
+
locale?: string,
|
|
25
|
+
fallbackLocale?: string,
|
|
21
26
|
): Promise<{
|
|
22
27
|
content: Array<{
|
|
23
28
|
text: string
|
|
@@ -27,7 +32,9 @@ export const createResourceTool = (
|
|
|
27
32
|
const payload = req.payload
|
|
28
33
|
|
|
29
34
|
if (verboseLogs) {
|
|
30
|
-
payload.logger.info(
|
|
35
|
+
payload.logger.info(
|
|
36
|
+
`[payload-mcp] Creating resource in collection: ${collectionSlug}${locale ? ` with locale: ${locale}` : ''}`,
|
|
37
|
+
)
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
try {
|
|
@@ -51,9 +58,12 @@ export const createResourceTool = (
|
|
|
51
58
|
const result = await payload.create({
|
|
52
59
|
collection: collectionSlug,
|
|
53
60
|
data: parsedData,
|
|
61
|
+
draft,
|
|
54
62
|
overrideAccess: false,
|
|
55
63
|
req,
|
|
56
64
|
user,
|
|
65
|
+
...(locale && { locale }),
|
|
66
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
57
67
|
})
|
|
58
68
|
|
|
59
69
|
if (verboseLogs) {
|
|
@@ -109,13 +119,39 @@ ${JSON.stringify(result, null, 2)}
|
|
|
109
119
|
if (collections?.[collectionSlug]?.enabled) {
|
|
110
120
|
const convertedFields = convertCollectionSchemaToZod(schema)
|
|
111
121
|
|
|
122
|
+
// Create a new schema that combines the converted fields with create-specific parameters
|
|
123
|
+
const createResourceSchema = z.object({
|
|
124
|
+
...convertedFields.shape,
|
|
125
|
+
draft: z
|
|
126
|
+
.boolean()
|
|
127
|
+
.optional()
|
|
128
|
+
.default(false)
|
|
129
|
+
.describe('Whether to create the document as a draft'),
|
|
130
|
+
fallbackLocale: z
|
|
131
|
+
.string()
|
|
132
|
+
.optional()
|
|
133
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
134
|
+
locale: z
|
|
135
|
+
.string()
|
|
136
|
+
.optional()
|
|
137
|
+
.describe(
|
|
138
|
+
'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
139
|
+
),
|
|
140
|
+
})
|
|
141
|
+
|
|
112
142
|
server.tool(
|
|
113
143
|
`create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
|
|
114
144
|
`${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,
|
|
115
|
-
|
|
145
|
+
createResourceSchema.shape,
|
|
116
146
|
async (params: Record<string, unknown>) => {
|
|
117
|
-
const
|
|
118
|
-
|
|
147
|
+
const { draft, fallbackLocale, locale, ...fieldData } = params
|
|
148
|
+
const data = JSON.stringify(fieldData)
|
|
149
|
+
return await tool(
|
|
150
|
+
data,
|
|
151
|
+
draft as boolean,
|
|
152
|
+
locale as string | undefined,
|
|
153
|
+
fallbackLocale as string | undefined,
|
|
154
|
+
)
|
|
119
155
|
},
|
|
120
156
|
)
|
|
121
157
|
}
|
|
@@ -15,9 +15,11 @@ export const deleteResourceTool = (
|
|
|
15
15
|
collections: PluginMCPServerConfig['collections'],
|
|
16
16
|
) => {
|
|
17
17
|
const tool = async (
|
|
18
|
-
id?: string,
|
|
18
|
+
id?: number | string,
|
|
19
19
|
where?: string,
|
|
20
20
|
depth: number = 0,
|
|
21
|
+
locale?: string,
|
|
22
|
+
fallbackLocale?: string,
|
|
21
23
|
): Promise<{
|
|
22
24
|
content: Array<{
|
|
23
25
|
text: string
|
|
@@ -28,7 +30,7 @@ export const deleteResourceTool = (
|
|
|
28
30
|
|
|
29
31
|
if (verboseLogs) {
|
|
30
32
|
payload.logger.info(
|
|
31
|
-
`[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}`,
|
|
33
|
+
`[payload-mcp] Deleting resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,
|
|
32
34
|
)
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -80,6 +82,8 @@ export const deleteResourceTool = (
|
|
|
80
82
|
overrideAccess: false,
|
|
81
83
|
req,
|
|
82
84
|
user,
|
|
85
|
+
...(locale && { locale }),
|
|
86
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
// Delete by ID or where clause
|
|
@@ -204,8 +208,8 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
204
208
|
`delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
|
|
205
209
|
`${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,
|
|
206
210
|
toolSchemas.deleteResource.parameters.shape,
|
|
207
|
-
async ({ id, depth, where }) => {
|
|
208
|
-
return await tool(id, where, depth)
|
|
211
|
+
async ({ id, depth, fallbackLocale, locale, where }) => {
|
|
212
|
+
return await tool(id, where, depth, locale, fallbackLocale)
|
|
209
213
|
},
|
|
210
214
|
)
|
|
211
215
|
}
|
|
@@ -15,11 +15,13 @@ export const findResourceTool = (
|
|
|
15
15
|
collections: PluginMCPServerConfig['collections'],
|
|
16
16
|
) => {
|
|
17
17
|
const tool = async (
|
|
18
|
-
id?: string,
|
|
18
|
+
id?: number | string,
|
|
19
19
|
limit: number = 10,
|
|
20
20
|
page: number = 1,
|
|
21
21
|
sort?: string,
|
|
22
22
|
where?: string,
|
|
23
|
+
locale?: string,
|
|
24
|
+
fallbackLocale?: string,
|
|
23
25
|
): Promise<{
|
|
24
26
|
content: Array<{
|
|
25
27
|
text: string
|
|
@@ -30,7 +32,7 @@ export const findResourceTool = (
|
|
|
30
32
|
|
|
31
33
|
if (verboseLogs) {
|
|
32
34
|
payload.logger.info(
|
|
33
|
-
`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}`,
|
|
35
|
+
`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,
|
|
34
36
|
)
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -67,6 +69,8 @@ export const findResourceTool = (
|
|
|
67
69
|
overrideAccess: false,
|
|
68
70
|
req,
|
|
69
71
|
user,
|
|
72
|
+
...(locale && { locale }),
|
|
73
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
70
74
|
})
|
|
71
75
|
|
|
72
76
|
if (verboseLogs) {
|
|
@@ -120,6 +124,8 @@ ${JSON.stringify(doc, null, 2)}`,
|
|
|
120
124
|
page,
|
|
121
125
|
req,
|
|
122
126
|
user,
|
|
127
|
+
...(locale && { locale }),
|
|
128
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
if (sort) {
|
|
@@ -190,8 +196,8 @@ Page: ${result.page} of ${result.totalPages}
|
|
|
190
196
|
`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
|
|
191
197
|
`${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,
|
|
192
198
|
toolSchemas.findResources.parameters.shape,
|
|
193
|
-
async ({ id, limit, page, sort, where }) => {
|
|
194
|
-
return await tool(id, limit, page, sort, where)
|
|
199
|
+
async ({ id, fallbackLocale, limit, locale, page, sort, where }) => {
|
|
200
|
+
return await tool(id, limit, page, sort, where, locale, fallbackLocale)
|
|
195
201
|
},
|
|
196
202
|
)
|
|
197
203
|
}
|
|
@@ -20,13 +20,15 @@ export const updateResourceTool = (
|
|
|
20
20
|
) => {
|
|
21
21
|
const tool = async (
|
|
22
22
|
data: string,
|
|
23
|
-
id?: string,
|
|
23
|
+
id?: number | string,
|
|
24
24
|
where?: string,
|
|
25
25
|
draft: boolean = false,
|
|
26
26
|
depth: number = 0,
|
|
27
27
|
overrideLock: boolean = true,
|
|
28
28
|
filePath?: string,
|
|
29
29
|
overwriteExistingFiles: boolean = false,
|
|
30
|
+
locale?: string,
|
|
31
|
+
fallbackLocale?: string,
|
|
30
32
|
): Promise<{
|
|
31
33
|
content: Array<{
|
|
32
34
|
text: string
|
|
@@ -37,7 +39,7 @@ export const updateResourceTool = (
|
|
|
37
39
|
|
|
38
40
|
if (verboseLogs) {
|
|
39
41
|
payload.logger.info(
|
|
40
|
-
`[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}`,
|
|
42
|
+
`[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
41
43
|
)
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -120,6 +122,8 @@ export const updateResourceTool = (
|
|
|
120
122
|
user,
|
|
121
123
|
...(filePath && { filePath }),
|
|
122
124
|
...(overwriteExistingFiles && { overwriteExistingFiles }),
|
|
125
|
+
...(locale && { locale }),
|
|
126
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
if (verboseLogs) {
|
|
@@ -168,6 +172,8 @@ ${JSON.stringify(result, null, 2)}
|
|
|
168
172
|
where: whereClause,
|
|
169
173
|
...(filePath && { filePath }),
|
|
170
174
|
...(overwriteExistingFiles && { overwriteExistingFiles }),
|
|
175
|
+
...(locale && { locale }),
|
|
176
|
+
...(fallbackLocale && { fallbackLocale }),
|
|
171
177
|
}
|
|
172
178
|
|
|
173
179
|
if (verboseLogs) {
|
|
@@ -255,9 +261,10 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
255
261
|
const convertedFields = convertCollectionSchemaToZod(schema)
|
|
256
262
|
|
|
257
263
|
// Create a new schema that combines the converted fields with update-specific parameters
|
|
264
|
+
// Use .partial() to make all fields optional for partial updates
|
|
258
265
|
const updateResourceSchema = z.object({
|
|
259
|
-
...convertedFields.shape,
|
|
260
|
-
id: z.string().optional().describe('The ID of the document to update'),
|
|
266
|
+
...convertedFields.partial().shape,
|
|
267
|
+
id: z.union([z.string(), z.number()]).optional().describe('The ID of the document to update'),
|
|
261
268
|
depth: z
|
|
262
269
|
.number()
|
|
263
270
|
.optional()
|
|
@@ -268,7 +275,17 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
268
275
|
.optional()
|
|
269
276
|
.default(false)
|
|
270
277
|
.describe('Whether to update the document as a draft'),
|
|
278
|
+
fallbackLocale: z
|
|
279
|
+
.string()
|
|
280
|
+
.optional()
|
|
281
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
271
282
|
filePath: z.string().optional().describe('File path for file uploads'),
|
|
283
|
+
locale: z
|
|
284
|
+
.string()
|
|
285
|
+
.optional()
|
|
286
|
+
.describe(
|
|
287
|
+
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
288
|
+
),
|
|
272
289
|
overrideLock: z
|
|
273
290
|
.boolean()
|
|
274
291
|
.optional()
|
|
@@ -294,7 +311,9 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
294
311
|
id,
|
|
295
312
|
depth,
|
|
296
313
|
draft,
|
|
314
|
+
fallbackLocale,
|
|
297
315
|
filePath,
|
|
316
|
+
locale,
|
|
298
317
|
overrideLock,
|
|
299
318
|
overwriteExistingFiles,
|
|
300
319
|
where,
|
|
@@ -304,13 +323,15 @@ ${JSON.stringify(errors, null, 2)}
|
|
|
304
323
|
const data = JSON.stringify(fieldData)
|
|
305
324
|
return await tool(
|
|
306
325
|
data,
|
|
307
|
-
id as string | undefined,
|
|
326
|
+
id as number | string | undefined,
|
|
308
327
|
where as string | undefined,
|
|
309
328
|
draft as boolean,
|
|
310
329
|
depth as number,
|
|
311
330
|
overrideLock as boolean,
|
|
312
331
|
filePath as string | undefined,
|
|
313
332
|
overwriteExistingFiles as boolean,
|
|
333
|
+
locale as string | undefined,
|
|
334
|
+
fallbackLocale as string | undefined,
|
|
314
335
|
)
|
|
315
336
|
},
|
|
316
337
|
)
|
package/src/mcp/tools/schemas.ts
CHANGED
|
@@ -5,11 +5,15 @@ export const toolSchemas = {
|
|
|
5
5
|
description: 'Find documents in a collection by ID or where clause using Find or FindByID.',
|
|
6
6
|
parameters: z.object({
|
|
7
7
|
id: z
|
|
8
|
-
.string()
|
|
8
|
+
.union([z.string(), z.number()])
|
|
9
9
|
.optional()
|
|
10
10
|
.describe(
|
|
11
11
|
'Optional: specific document ID to retrieve. If not provided, returns all documents',
|
|
12
12
|
),
|
|
13
|
+
fallbackLocale: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
13
17
|
limit: z
|
|
14
18
|
.number()
|
|
15
19
|
.int()
|
|
@@ -18,6 +22,12 @@ export const toolSchemas = {
|
|
|
18
22
|
.optional()
|
|
19
23
|
.default(10)
|
|
20
24
|
.describe('Maximum number of documents to return (default: 10, max: 100)'),
|
|
25
|
+
locale: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe(
|
|
29
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
30
|
+
),
|
|
21
31
|
page: z
|
|
22
32
|
.number()
|
|
23
33
|
.int()
|
|
@@ -47,13 +57,26 @@ export const toolSchemas = {
|
|
|
47
57
|
.optional()
|
|
48
58
|
.default(false)
|
|
49
59
|
.describe('Whether to create the document as a draft'),
|
|
60
|
+
fallbackLocale: z
|
|
61
|
+
.string()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
64
|
+
locale: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe(
|
|
68
|
+
'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
69
|
+
),
|
|
50
70
|
}),
|
|
51
71
|
},
|
|
52
72
|
|
|
53
73
|
updateResource: {
|
|
54
74
|
description: 'Update documents in a collection by ID or where clause.',
|
|
55
75
|
parameters: z.object({
|
|
56
|
-
id: z
|
|
76
|
+
id: z
|
|
77
|
+
.union([z.string(), z.number()])
|
|
78
|
+
.optional()
|
|
79
|
+
.describe('Optional: specific document ID to update'),
|
|
57
80
|
data: z.string().describe('JSON string containing the data to update'),
|
|
58
81
|
depth: z
|
|
59
82
|
.number()
|
|
@@ -64,7 +87,17 @@ export const toolSchemas = {
|
|
|
64
87
|
.default(0)
|
|
65
88
|
.describe('Depth of population for relationships'),
|
|
66
89
|
draft: z.boolean().optional().default(false).describe('Whether to update as a draft'),
|
|
90
|
+
fallbackLocale: z
|
|
91
|
+
.string()
|
|
92
|
+
.optional()
|
|
93
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
67
94
|
filePath: z.string().optional().describe('Optional: absolute file path for file uploads'),
|
|
95
|
+
locale: z
|
|
96
|
+
.string()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe(
|
|
99
|
+
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
100
|
+
),
|
|
68
101
|
overrideLock: z
|
|
69
102
|
.boolean()
|
|
70
103
|
.optional()
|
|
@@ -85,7 +118,10 @@ export const toolSchemas = {
|
|
|
85
118
|
deleteResource: {
|
|
86
119
|
description: 'Delete documents in a collection by ID or where clause.',
|
|
87
120
|
parameters: z.object({
|
|
88
|
-
id: z
|
|
121
|
+
id: z
|
|
122
|
+
.union([z.string(), z.number()])
|
|
123
|
+
.optional()
|
|
124
|
+
.describe('Optional: specific document ID to delete'),
|
|
89
125
|
depth: z
|
|
90
126
|
.number()
|
|
91
127
|
.int()
|
|
@@ -94,6 +130,16 @@ export const toolSchemas = {
|
|
|
94
130
|
.optional()
|
|
95
131
|
.default(0)
|
|
96
132
|
.describe('Depth of population for relationships in response'),
|
|
133
|
+
fallbackLocale: z
|
|
134
|
+
.string()
|
|
135
|
+
.optional()
|
|
136
|
+
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
137
|
+
locale: z
|
|
138
|
+
.string()
|
|
139
|
+
.optional()
|
|
140
|
+
.describe(
|
|
141
|
+
'Optional: locale code for the operation (e.g., "en", "es"). Defaults to the default locale',
|
|
142
|
+
),
|
|
97
143
|
where: z
|
|
98
144
|
.string()
|
|
99
145
|
.optional()
|