@payloadcms/plugin-mcp 3.65.0-internal.ef3958a → 3.66.0-canary.0
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/endpoints/mcp.js.map +1 -1
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +14 -3
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/dist/mcp/helpers/fileValidation.js +22 -22
- package/dist/mcp/helpers/fileValidation.js.map +1 -1
- 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/dist/types.d.ts +39 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/convertCollectionSchemaToZod.d.ts.map +1 -1
- package/dist/utils/convertCollectionSchemaToZod.js +1 -2
- package/dist/utils/convertCollectionSchemaToZod.js.map +1 -1
- package/package.json +3 -3
- package/src/endpoints/mcp.ts +1 -1
- package/src/mcp/getMcpHandler.ts +31 -4
- package/src/mcp/helpers/fileValidation.ts +22 -22
- 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
- package/src/types.ts +58 -9
- package/src/utils/convertCollectionSchemaToZod.ts +1 -2
|
@@ -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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AAM;4BACNC,MAAMiB;wBACR;qBACD;gBACH;gBAEA,OAAQ7B,aAAa,CAACD,eAAe,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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F,MAAMrB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,yCAAyC,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","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;QAOA,MAAMC,UAAUX,IAAIW,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEV,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,MAAM;QAErI;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIM,cAAc,CAAC;YACnB,IAAIJ,OAAO;gBACT,IAAI;oBACFI,cAAcC,KAAKC,KAAK,CAACN;oBACzB,IAAIR,aAAa;wBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEH,OAAO;oBAClE;gBACF,EAAE,OAAOO,aAAa;oBACpBN,QAAQC,MAAM,CAACM,IAAI,CAAC,CAAC,yCAAyC,EAAER,OAAO;oBACvE,MAAMS,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAsC;yBAAE;oBACnF;oBACA,OAAQlB,aAAa,CAACD,eAAe,EAAEoB,mBAAmBJ,UAAU,CAAC,GAAGnB,QACtEmB;gBAMJ;YACF;YAEA,kCAAkC;YAClC,IAAIb,IAAI;gBACN,IAAI;oBACF,MAAMkB,MAAM,MAAMb,QAAQc,QAAQ,CAAC;wBACjCnB;wBACAoB,YAAYvB;wBACZwB,gBAAgB;wBAChB3B;wBACAC;oBACF;oBAEA,IAAIC,aAAa;wBACfS,QAAQC,MAAM,CAACC,IAAI,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,"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,IA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,"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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AO,GACPJ,QAAQ,GACRG,OAAO,CAAC,OACRF,QAAQ,CAAC;YACZrC,UAAUnB,EAAEsD,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,y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OAAO,CAAC,MACRD,QAAQ,CAAC;YACZzC,wBAAwBpB,EACrB+D,OAAO,GACPH,QAAQ,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
|
},
|