@payloadcms/plugin-mcp 3.82.1 → 3.83.0-canary.1
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/auth/auth.js +1 -1
- package/dist/mcp/tools/auth/auth.js.map +1 -1
- package/dist/mcp/tools/auth/forgotPassword.js +1 -1
- package/dist/mcp/tools/auth/forgotPassword.js.map +1 -1
- package/dist/mcp/tools/auth/login.js +1 -1
- package/dist/mcp/tools/auth/login.js.map +1 -1
- package/dist/mcp/tools/auth/resetPassword.js +1 -1
- package/dist/mcp/tools/auth/resetPassword.js.map +1 -1
- package/dist/mcp/tools/auth/unlock.js +1 -1
- package/dist/mcp/tools/auth/unlock.js.map +1 -1
- package/dist/mcp/tools/global/find.js +1 -1
- package/dist/mcp/tools/global/find.js.map +1 -1
- package/dist/mcp/tools/global/update.js +1 -1
- package/dist/mcp/tools/global/update.js.map +1 -1
- package/dist/mcp/tools/job/run.js +2 -2
- package/dist/mcp/tools/job/run.js.map +1 -1
- package/dist/mcp/tools/resource/create.js +1 -1
- package/dist/mcp/tools/resource/create.js.map +1 -1
- package/dist/mcp/tools/resource/delete.js +3 -3
- package/dist/mcp/tools/resource/delete.js.map +1 -1
- package/dist/mcp/tools/resource/find.js +2 -2
- package/dist/mcp/tools/resource/find.js.map +1 -1
- package/dist/mcp/tools/resource/update.js +3 -3
- package/dist/mcp/tools/resource/update.js.map +1 -1
- package/package.json +4 -4
- package/src/mcp/tools/auth/auth.ts +1 -1
- package/src/mcp/tools/auth/forgotPassword.ts +1 -1
- package/src/mcp/tools/auth/login.ts +1 -1
- package/src/mcp/tools/auth/resetPassword.ts +1 -1
- package/src/mcp/tools/auth/unlock.ts +1 -1
- package/src/mcp/tools/global/find.ts +1 -1
- package/src/mcp/tools/global/update.ts +1 -1
- package/src/mcp/tools/job/run.ts +2 -2
- package/src/mcp/tools/resource/create.ts +1 -1
- package/src/mcp/tools/resource/delete.ts +3 -3
- package/src/mcp/tools/resource/find.ts +2 -2
- package/src/mcp/tools/resource/update.ts +3 -3
|
@@ -29,7 +29,7 @@ export const authTool = (server, req, verboseLogs)=>{
|
|
|
29
29
|
content: [
|
|
30
30
|
{
|
|
31
31
|
type: 'text',
|
|
32
|
-
text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result
|
|
32
|
+
text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
33
33
|
}
|
|
34
34
|
]
|
|
35
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/auth/auth.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const authTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (headers?: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Checking authentication status')\n }\n\n try {\n // Parse custom headers if provided, otherwise use empty headers\n let authHeaders = new Headers()\n\n if (headers) {\n try {\n const parsedHeaders = JSON.parse(headers)\n authHeaders = new Headers(parsedHeaders)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom headers: ${headers}`)\n }\n } catch (_ignore) {\n payload.logger.warn(`[payload-mcp] Invalid headers JSON: ${headers}, using empty headers`)\n }\n }\n\n const result = await payload.auth({\n headers: authHeaders,\n })\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Authentication check completed successfully')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Authentication Status\\n\\n\\`\\`\\`json\\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/auth/auth.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const authTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (headers?: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Checking authentication status')\n }\n\n try {\n // Parse custom headers if provided, otherwise use empty headers\n let authHeaders = new Headers()\n\n if (headers) {\n try {\n const parsedHeaders = JSON.parse(headers)\n authHeaders = new Headers(parsedHeaders)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom headers: ${headers}`)\n }\n } catch (_ignore) {\n payload.logger.warn(`[payload-mcp] Invalid headers JSON: ${headers}, using empty headers`)\n }\n }\n\n const result = await payload.auth({\n headers: authHeaders,\n })\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Authentication check completed successfully')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Authentication Status\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error checking authentication: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error checking authentication**: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'auth',\n {\n description: toolSchemas.auth.description,\n inputSchema: toolSchemas.auth.parameters.shape,\n },\n async ({ headers }) => {\n return await tool(headers)\n },\n )\n}\n"],"names":["toolSchemas","authTool","server","req","verboseLogs","tool","headers","payload","logger","info","authHeaders","Headers","parsedHeaders","JSON","parse","_ignore","warn","result","auth","content","type","text","stringify","error","errorMessage","Error","message","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,WAAW,CAACC,QAAmBC,KAAqBC;IAC/D,MAAMC,OAAO,OAAOC;QAClB,MAAMC,UAAUJ,IAAII,OAAO;QAE3B,IAAIH,aAAa;YACfG,QAAQC,MAAM,CAACC,IAAI,CAAC;QACtB;QAEA,IAAI;YACF,gEAAgE;YAChE,IAAIC,cAAc,IAAIC;YAEtB,IAAIL,SAAS;gBACX,IAAI;oBACF,MAAMM,gBAAgBC,KAAKC,KAAK,CAACR;oBACjCI,cAAc,IAAIC,QAAQC;oBAC1B,IAAIR,aAAa;wBACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,oCAAoC,EAAEH,SAAS;oBACtE;gBACF,EAAE,OAAOS,SAAS;oBAChBR,QAAQC,MAAM,CAACQ,IAAI,CAAC,CAAC,oCAAoC,EAAEV,QAAQ,qBAAqB,CAAC;gBAC3F;YACF;YAEA,MAAMW,SAAS,MAAMV,QAAQW,IAAI,CAAC;gBAChCZ,SAASI;YACX;YAEA,IAAIN,aAAa;gBACfG,QAAQC,MAAM,CAACC,IAAI,CAAC;YACtB;YAEA,OAAO;gBACLU,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,uCAAuC,EAAER,KAAKS,SAAS,CAACL,QAAQ,QAAQ,CAAC;oBAClF;iBACD;YACH;QACF,EAAE,OAAOM,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9DnB,QAAQC,MAAM,CAACe,KAAK,CAAC,CAAC,6CAA6C,EAAEC,cAAc;YAEnF,OAAO;gBACLL,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,qCAAqC,EAAEG,cAAc;oBAC9D;iBACD;YACH;QACF;IACF;IAEAtB,OAAOyB,YAAY,CACjB,QACA;QACEC,aAAa5B,YAAYkB,IAAI,CAACU,WAAW;QACzCC,aAAa7B,YAAYkB,IAAI,CAACY,UAAU,CAACC,KAAK;IAChD,GACA,OAAO,EAAEzB,OAAO,EAAE;QAChB,OAAO,MAAMD,KAAKC;IACpB;AAEJ,EAAC"}
|
|
@@ -20,7 +20,7 @@ export const forgotPasswordTool = (server, req, verboseLogs)=>{
|
|
|
20
20
|
content: [
|
|
21
21
|
{
|
|
22
22
|
type: 'text',
|
|
23
|
-
text: `# Password Reset Email Sent\n\n**User:** ${email}\n**Collection:** ${collection}\n**Email Disabled:** ${disableEmail}\n\n\`\`\`json\n${JSON.stringify(result
|
|
23
|
+
text: `# Password Reset Email Sent\n\n**User:** ${email}\n**Collection:** ${collection}\n**Email Disabled:** ${disableEmail}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
24
24
|
}
|
|
25
25
|
]
|
|
26
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/auth/forgotPassword.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const forgotPasswordTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n) => {\n const tool = async (collection: string, email: string, disableEmail: boolean = false) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Sending password reset email for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.forgotPassword({\n collection,\n data: {\n email,\n },\n disableEmail,\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Password reset email sent successfully for user: ${email}`,\n )\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Password Reset Email Sent\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n**Email Disabled:** ${disableEmail}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/auth/forgotPassword.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const forgotPasswordTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n) => {\n const tool = async (collection: string, email: string, disableEmail: boolean = false) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Sending password reset email for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.forgotPassword({\n collection,\n data: {\n email,\n },\n disableEmail,\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Password reset email sent successfully for user: ${email}`,\n )\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Password Reset Email Sent\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n**Email Disabled:** ${disableEmail}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error sending password reset email for user ${email}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error sending password reset email for user \"${email}\"**: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'forgotPassword',\n {\n description: toolSchemas.forgotPassword.description,\n inputSchema: toolSchemas.forgotPassword.parameters.shape,\n },\n async ({ collection, disableEmail, email }) => {\n return await tool(collection, email, disableEmail)\n },\n )\n}\n"],"names":["toolSchemas","forgotPasswordTool","server","req","verboseLogs","tool","collection","email","disableEmail","payload","logger","info","result","forgotPassword","data","content","type","text","JSON","stringify","error","errorMessage","Error","message","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC;IAEA,MAAMC,OAAO,OAAOC,YAAoBC,OAAeC,eAAwB,KAAK;QAClF,MAAMC,UAAUN,IAAIM,OAAO;QAE3B,IAAIL,aAAa;YACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,qDAAqD,EAAEJ,MAAM,gBAAgB,EAAED,YAAY;QAEhG;QAEA,IAAI;YACF,MAAMM,SAAS,MAAMH,QAAQI,cAAc,CAAC;gBAC1CP;gBACAQ,MAAM;oBACJP;gBACF;gBACAC;YACF;YAEA,IAAIJ,aAAa;gBACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+DAA+D,EAAEJ,OAAO;YAE7E;YAEA,OAAO;gBACLQ,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,yCAAyC,EAAEV,MAAM,kBAAkB,EAAED,WAAW,sBAAsB,EAAEE,aAAa,gBAAgB,EAAEU,KAAKC,SAAS,CAACP,QAAQ,QAAQ,CAAC;oBAChL;iBACD;YACH;QACF,EAAE,OAAOQ,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9Dd,QAAQC,MAAM,CAACU,KAAK,CAClB,CAAC,0DAA0D,EAAEb,MAAM,EAAE,EAAEc,cAAc;YAGvF,OAAO;gBACLN,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,iDAAiD,EAAEV,MAAM,KAAK,EAAEc,cAAc;oBACvF;iBACD;YACH;QACF;IACF;IAEAnB,OAAOsB,YAAY,CACjB,kBACA;QACEC,aAAazB,YAAYa,cAAc,CAACY,WAAW;QACnDC,aAAa1B,YAAYa,cAAc,CAACc,UAAU,CAACC,KAAK;IAC1D,GACA,OAAO,EAAEtB,UAAU,EAAEE,YAAY,EAAED,KAAK,EAAE;QACxC,OAAO,MAAMF,KAAKC,YAAYC,OAAOC;IACvC;AAEJ,EAAC"}
|
|
@@ -23,7 +23,7 @@ export const loginTool = (server, req, verboseLogs)=>{
|
|
|
23
23
|
content: [
|
|
24
24
|
{
|
|
25
25
|
type: 'text',
|
|
26
|
-
text: `# Login Successful\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result
|
|
26
|
+
text: `# Login Successful\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/auth/login.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const loginTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (\n collection: string,\n email: string,\n password: string,\n depth: number = 0,\n overrideAccess: boolean = false,\n showHiddenFields: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Attempting login for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.login({\n collection,\n data: {\n email,\n password,\n },\n depth,\n overrideAccess,\n showHiddenFields,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Login successful for user: ${email}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Login Successful\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/auth/login.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const loginTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (\n collection: string,\n email: string,\n password: string,\n depth: number = 0,\n overrideAccess: boolean = false,\n showHiddenFields: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Attempting login for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.login({\n collection,\n data: {\n email,\n password,\n },\n depth,\n overrideAccess,\n showHiddenFields,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Login successful for user: ${email}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Login Successful\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Login failed for user ${email}: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Login failed for user \"${email}\"**: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'login',\n {\n description: toolSchemas.login.description,\n inputSchema: toolSchemas.login.parameters.shape,\n },\n async ({ collection, depth, email, overrideAccess, password, showHiddenFields }) => {\n return await tool(collection, email, password, depth, overrideAccess, showHiddenFields)\n },\n )\n}\n"],"names":["toolSchemas","loginTool","server","req","verboseLogs","tool","collection","email","password","depth","overrideAccess","showHiddenFields","payload","logger","info","result","login","data","content","type","text","JSON","stringify","error","errorMessage","Error","message","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,YAAY,CAACC,QAAmBC,KAAqBC;IAChE,MAAMC,OAAO,OACXC,YACAC,OACAC,UACAC,QAAgB,CAAC,EACjBC,iBAA0B,KAAK,EAC/BC,mBAA4B,KAAK;QAEjC,MAAMC,UAAUT,IAAIS,OAAO;QAE3B,IAAIR,aAAa;YACfQ,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,yCAAyC,EAAEP,MAAM,gBAAgB,EAAED,YAAY;QAEpF;QAEA,IAAI;YACF,MAAMS,SAAS,MAAMH,QAAQI,KAAK,CAAC;gBACjCV;gBACAW,MAAM;oBACJV;oBACAC;gBACF;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIP,aAAa;gBACfQ,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,yCAAyC,EAAEP,OAAO;YACzE;YAEA,OAAO;gBACLW,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,gCAAgC,EAAEb,MAAM,kBAAkB,EAAED,WAAW,gBAAgB,EAAEe,KAAKC,SAAS,CAACP,QAAQ,QAAQ,CAAC;oBAClI;iBACD;YACH;QACF,EAAE,OAAOQ,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9Dd,QAAQC,MAAM,CAACU,KAAK,CAAC,CAAC,oCAAoC,EAAEhB,MAAM,EAAE,EAAEiB,cAAc;YAEpF,OAAO;gBACLN,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEb,MAAM,KAAK,EAAEiB,cAAc;oBACjE;iBACD;YACH;QACF;IACF;IAEAtB,OAAOyB,YAAY,CACjB,SACA;QACEC,aAAa5B,YAAYgB,KAAK,CAACY,WAAW;QAC1CC,aAAa7B,YAAYgB,KAAK,CAACc,UAAU,CAACC,KAAK;IACjD,GACA,OAAO,EAAEzB,UAAU,EAAEG,KAAK,EAAEF,KAAK,EAAEG,cAAc,EAAEF,QAAQ,EAAEG,gBAAgB,EAAE;QAC7E,OAAO,MAAMN,KAAKC,YAAYC,OAAOC,UAAUC,OAAOC,gBAAgBC;IACxE;AAEJ,EAAC"}
|
|
@@ -21,7 +21,7 @@ export const resetPasswordTool = (server, req, verboseLogs)=>{
|
|
|
21
21
|
content: [
|
|
22
22
|
{
|
|
23
23
|
type: 'text',
|
|
24
|
-
text: `# Password Reset Successful\n\n**Collection:** ${collection}\n**Token:** ${token}\n\n\`\`\`json\n${JSON.stringify(result
|
|
24
|
+
text: `# Password Reset Successful\n\n**Collection:** ${collection}\n**Token:** ${token}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
25
25
|
}
|
|
26
26
|
]
|
|
27
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/auth/resetPassword.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const resetPasswordTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (collection: string, token: string, password: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Resetting password for user in collection: ${collection}`)\n }\n\n try {\n const result = await payload.resetPassword({\n collection,\n data: {\n password,\n token,\n },\n overrideAccess: true,\n })\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Password reset completed successfully')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Password Reset Successful\\n\\n**Collection:** ${collection}\\n**Token:** ${token}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/auth/resetPassword.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const resetPasswordTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (collection: string, token: string, password: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Resetting password for user in collection: ${collection}`)\n }\n\n try {\n const result = await payload.resetPassword({\n collection,\n data: {\n password,\n token,\n },\n overrideAccess: true,\n })\n\n if (verboseLogs) {\n payload.logger.info('[payload-mcp] Password reset completed successfully')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Password Reset Successful\\n\\n**Collection:** ${collection}\\n**Token:** ${token}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error resetting password: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error resetting password**: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'resetPassword',\n {\n description: toolSchemas.resetPassword.description,\n inputSchema: toolSchemas.resetPassword.parameters.shape,\n },\n async ({ collection, password, token }) => {\n return await tool(collection, token, password)\n },\n )\n}\n"],"names":["toolSchemas","resetPasswordTool","server","req","verboseLogs","tool","collection","token","password","payload","logger","info","result","resetPassword","data","overrideAccess","content","type","text","JSON","stringify","error","errorMessage","Error","message","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,oBAAoB,CAACC,QAAmBC,KAAqBC;IACxE,MAAMC,OAAO,OAAOC,YAAoBC,OAAeC;QACrD,MAAMC,UAAUN,IAAIM,OAAO;QAE3B,IAAIL,aAAa;YACfK,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,yDAAyD,EAAEL,YAAY;QAC9F;QAEA,IAAI;YACF,MAAMM,SAAS,MAAMH,QAAQI,aAAa,CAAC;gBACzCP;gBACAQ,MAAM;oBACJN;oBACAD;gBACF;gBACAQ,gBAAgB;YAClB;YAEA,IAAIX,aAAa;gBACfK,QAAQC,MAAM,CAACC,IAAI,CAAC;YACtB;YAEA,OAAO;gBACLK,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,+CAA+C,EAAEZ,WAAW,aAAa,EAAEC,MAAM,gBAAgB,EAAEY,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;oBAC5I;iBACD;YACH;QACF,EAAE,OAAOS,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9Df,QAAQC,MAAM,CAACW,KAAK,CAAC,CAAC,wCAAwC,EAAEC,cAAc;YAE9E,OAAO;gBACLN,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,gCAAgC,EAAEI,cAAc;oBACzD;iBACD;YACH;QACF;IACF;IAEApB,OAAOuB,YAAY,CACjB,iBACA;QACEC,aAAa1B,YAAYa,aAAa,CAACa,WAAW;QAClDC,aAAa3B,YAAYa,aAAa,CAACe,UAAU,CAACC,KAAK;IACzD,GACA,OAAO,EAAEvB,UAAU,EAAEE,QAAQ,EAAED,KAAK,EAAE;QACpC,OAAO,MAAMF,KAAKC,YAAYC,OAAOC;IACvC;AAEJ,EAAC"}
|
|
@@ -20,7 +20,7 @@ export const unlockTool = (server, req, verboseLogs)=>{
|
|
|
20
20
|
content: [
|
|
21
21
|
{
|
|
22
22
|
type: 'text',
|
|
23
|
-
text: `# User Account Unlocked\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result
|
|
23
|
+
text: `# User Account Unlocked\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
24
24
|
}
|
|
25
25
|
]
|
|
26
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/auth/unlock.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const unlockTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (collection: string, email: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Unlocking user account for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.unlock({\n collection,\n data: {\n email,\n },\n overrideAccess: true,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] User account unlocked successfully for user: ${email}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# User Account Unlocked\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/auth/unlock.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const unlockTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n const tool = async (collection: string, email: string) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Unlocking user account for user: ${email} in collection: ${collection}`,\n )\n }\n\n try {\n const result = await payload.unlock({\n collection,\n data: {\n email,\n },\n overrideAccess: true,\n })\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] User account unlocked successfully for user: ${email}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# User Account Unlocked\\n\\n**User:** ${email}\\n**Collection:** ${collection}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error unlocking user account for user ${email}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error unlocking user account for user \"${email}\"**: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'unlock',\n {\n description: toolSchemas.unlock.description,\n inputSchema: toolSchemas.unlock.parameters.shape,\n },\n async ({ collection, email }) => {\n return await tool(collection, email)\n },\n )\n}\n"],"names":["toolSchemas","unlockTool","server","req","verboseLogs","tool","collection","email","payload","logger","info","result","unlock","data","overrideAccess","content","type","text","JSON","stringify","error","errorMessage","Error","message","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,aAAa,CAACC,QAAmBC,KAAqBC;IACjE,MAAMC,OAAO,OAAOC,YAAoBC;QACtC,MAAMC,UAAUL,IAAIK,OAAO;QAE3B,IAAIJ,aAAa;YACfI,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEH,MAAM,gBAAgB,EAAED,YAAY;QAE1F;QAEA,IAAI;YACF,MAAMK,SAAS,MAAMH,QAAQI,MAAM,CAAC;gBAClCN;gBACAO,MAAM;oBACJN;gBACF;gBACAO,gBAAgB;YAClB;YAEA,IAAIV,aAAa;gBACfI,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,2DAA2D,EAAEH,OAAO;YAC3F;YAEA,OAAO;gBACLQ,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,qCAAqC,EAAEV,MAAM,kBAAkB,EAAED,WAAW,gBAAgB,EAAEY,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;oBACvI;iBACD;YACH;QACF,EAAE,OAAOS,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9Df,QAAQC,MAAM,CAACW,KAAK,CAClB,CAAC,oDAAoD,EAAEb,MAAM,EAAE,EAAEc,cAAc;YAGjF,OAAO;gBACLN,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2CAA2C,EAAEV,MAAM,KAAK,EAAEc,cAAc;oBACjF;iBACD;YACH;QACF;IACF;IAEAnB,OAAOsB,YAAY,CACjB,UACA;QACEC,aAAazB,YAAYY,MAAM,CAACa,WAAW;QAC3CC,aAAa1B,YAAYY,MAAM,CAACe,UAAU,CAACC,KAAK;IAClD,GACA,OAAO,EAAEtB,UAAU,EAAEC,KAAK,EAAE;QAC1B,OAAO,MAAMF,KAAKC,YAAYC;IAChC;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/global/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, SelectType, 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 findGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n) => {\n const tool = async (\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n select?: 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 global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n user,\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Add locale parameters if provided\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\n }\n\n const result = await payload.findGlobal(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\":\n\\`\\`\\`json\n${JSON.stringify(result
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/global/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest, SelectType, 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 findGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n) => {\n const tool = async (\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n select?: 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 global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n }\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n user,\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n // Add locale parameters if provided\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\n }\n\n const result = await payload.findGlobal(findOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\":\n\\`\\`\\`json\n${JSON.stringify(result)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, result, req) || 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(`[payload-mcp] Error reading global ${globalSlug}: ${errorMessage}`)\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (globals?.[globalSlug]?.enabled) {\n server.registerTool(\n `find${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.findGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: toolSchemas.findGlobal.parameters.shape,\n },\n async ({ depth, fallbackLocale, locale, select }) => {\n return await tool(depth, locale, fallbackLocale, select)\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findGlobalTool","server","req","user","verboseLogs","globalSlug","globals","tool","depth","locale","fallbackLocale","select","payload","logger","info","findOptions","slug","selectClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","result","findGlobal","stringify","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","parameters","shape"],"mappings":"AAKA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,iBAAiB,CAC5BC,QACAC,KACAC,MACAC,aACAC,YACAC;IAEA,MAAMC,OAAO,OACXC,QAAgB,CAAC,EACjBC,QACAC,gBACAC;QAOA,MAAMC,UAAUV,IAAIU,OAAO;QAE3B,IAAIR,aAAa;YACfQ,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAET,WAAW,SAAS,EAAEG,QAAQC,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAExG;QAEA,IAAI;YACF,MAAMM,cAAwD;gBAC5DC,MAAMX;gBACNG;gBACAL;YACF;YAEA,IAAIc;YACJ,IAAIN,QAAQ;gBACV,IAAI;oBACFM,eAAeC,KAAKC,KAAK,CAACR;gBAC5B,EAAE,OAAOS,aAAa;oBACpBR,QAAQC,MAAM,CAACQ,IAAI,CAAC,CAAC,qDAAqD,EAAEV,QAAQ;oBACpF,MAAMW,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAuC;yBAAE;oBACpF;oBACA,OAAQnB,SAAS,CAACD,WAAW,EAAEqB,mBAAmBJ,UAAU,CAAC,GAAGpB,QAAQoB;gBAM1E;YACF;YAEA,oCAAoC;YACpC,IAAIb,QAAQ;gBACVM,YAAYN,MAAM,GAAGA;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CAACC,KAAK;QACtD,GACA,OAAO,EAAEnC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE;YAC9C,OAAO,MAAMJ,KAAKC,OAAOC,QAAQC,gBAAgBC;QACnD;IAEJ;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/global/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n draft: boolean = false,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n select?: 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 global: ${globalSlug}, 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\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${globalSlug}: ${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 (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {\n slug: globalSlug,\n data: parsedData,\n depth,\n draft,\n user,\n }\n\n // Add locale parameters if provided\n if (locale) {\n updateOptions.locale = locale\n }\n if (fallbackLocale) {\n updateOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n updateOptions.select = selectClause\n }\n\n const result = await payload.updateGlobal(updateOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\" updated successfully!\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, result, req) || 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(`[payload-mcp] Error updating global ${globalSlug}: ${errorMessage}`)\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating global \"${globalSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (globals?.[globalSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Make all fields optional for partial updates (PATCH-style)\n const optionalFields = Object.fromEntries(\n Object.entries(convertedFields.shape).map(([key, value]) => [key, (value as any).optional()]),\n )\n\n const updateGlobalSchema = z.object({\n ...optionalFields,\n depth: z.number().optional().describe('Optional: Depth of relationships to populate'),\n draft: z.boolean().optional().describe('Optional: Whether to save as draft (default: false)'),\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 update data in (e.g., \"en\", \"es\"). Use \"all\" to update all locales for localized fields',\n ),\n select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n ),\n })\n\n server.registerTool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: updateGlobalSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...rest } = params\n const data = JSON.stringify(rest)\n return await tool(\n data,\n draft as boolean,\n depth as number,\n locale as string,\n fallbackLocale as string,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getGlobalVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","selectClause","warn","updateOptions","slug","result","updateGlobal","errorMessage","Error","message","enabled","convertedFields","optionalFields","Object","fromEntries","entries","shape","map","key","value","optional","updateGlobalSchema","object","number","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","params","rest"],"mappings":"AAIA,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ACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/global/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateGlobalTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n globalSlug: string,\n globals: PluginMCPServerConfig['globals'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n draft: boolean = false,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n select?: 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 global: ${globalSlug}, 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\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${globalSlug}: ${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 (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON for global: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],\n }\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {\n slug: globalSlug,\n data: parsedData,\n depth,\n draft,\n user,\n }\n\n // Add locale parameters if provided\n if (locale) {\n updateOptions.locale = locale\n }\n if (fallbackLocale) {\n updateOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n updateOptions.select = selectClause\n }\n\n const result = await payload.updateGlobal(updateOptions)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated global: ${globalSlug}`)\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Global \"${globalSlug}\" updated successfully!\n\\`\\`\\`json\n${JSON.stringify(result)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, result, req) || 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(`[payload-mcp] Error updating global ${globalSlug}: ${errorMessage}`)\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error updating global \"${globalSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (globals?.[globalSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (globals?.[globalSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n // Make all fields optional for partial updates (PATCH-style)\n const optionalFields = Object.fromEntries(\n Object.entries(convertedFields.shape).map(([key, value]) => [key, (value as any).optional()]),\n )\n\n const updateGlobalSchema = z.object({\n ...optionalFields,\n depth: z.number().optional().describe('Optional: Depth of relationships to populate'),\n draft: z.boolean().optional().describe('Optional: Whether to save as draft (default: false)'),\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 update data in (e.g., \"en\", \"es\"). Use \"all\" to update all locales for localized fields',\n ),\n select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n ),\n })\n\n server.registerTool(\n `update${globalSlug.charAt(0).toUpperCase() + toCamelCase(globalSlug).slice(1)}`,\n {\n description: `${toolSchemas.updateGlobal.description.trim()}\\n\\n${globals?.[globalSlug]?.description || ''}`,\n inputSchema: updateGlobalSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...rest } = params\n const data = JSON.stringify(rest)\n return await tool(\n data,\n draft as boolean,\n depth as number,\n locale as string,\n fallbackLocale as string,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getGlobalVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","toolSchemas","updateGlobalTool","server","req","user","verboseLogs","globalSlug","globals","schema","tool","data","draft","depth","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","selectClause","warn","updateOptions","slug","result","updateGlobal","errorMessage","Error","message","enabled","convertedFields","optionalFields","Object","fromEntries","entries","shape","map","key","value","optional","updateGlobalSchema","object","number","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","trim","inputSchema","params","rest"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,0BAA0B,EAC1BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,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
${JSON.stringify(input
|
|
56
|
+
${JSON.stringify(input)}
|
|
57
57
|
\`\`\`
|
|
58
58
|
|
|
59
59
|
## Job Status
|
|
@@ -94,7 +94,7 @@ console.log('Job result:', result)
|
|
|
94
94
|
|
|
95
95
|
## Input Data Provided:
|
|
96
96
|
\`\`\`json
|
|
97
|
-
${JSON.stringify(input
|
|
97
|
+
${JSON.stringify(input)}
|
|
98
98
|
\`\`\`
|
|
99
99
|
|
|
100
100
|
## Next Steps:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/job/run.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Reusable function for running jobs\nexport const runJob = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n jobSlug: string,\n input: Record<string, unknown>,\n queue?: string,\n priority?: number,\n delay?: number,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Running job: ${jobSlug}`)\n }\n\n try {\n // Actually run the job using Payload's job queue\n const jobQueueOptions: Record<string, unknown> = {\n input,\n task: jobSlug,\n }\n\n if (queue && queue !== 'default') {\n jobQueueOptions.queue = queue\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom queue: ${queue}`)\n }\n }\n\n if (priority && priority > 0) {\n jobQueueOptions.priority = priority\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job priority: ${priority}`)\n }\n }\n\n if (delay && delay > 0) {\n jobQueueOptions.waitUntil = new Date(Date.now() + delay)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job delay: ${delay}ms`)\n }\n }\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Queuing job with options: ${JSON.stringify(jobQueueOptions)}`,\n )\n }\n\n const job = await payload.jobs.queue(\n jobQueueOptions as Parameters<typeof payload.jobs.queue>[0],\n )\n\n const jobId = (job as { id?: string })?.id || 'unknown'\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Job created successfully: ${jobId}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Job Queued Successfully: ${jobSlug}\n\n## Job Details\n- **Job ID**: ${jobId}\n- **Job Slug**: ${jobSlug}\n- **Queue**: ${queue || 'default'}\n- **Priority**: ${priority || 'default'}\n- **Delay**: ${delay ? `${delay}ms` : 'none'}\n- **Status**: Queued and Running\n\n## Input Data\n\\`\\`\\`json\n${JSON.stringify(input
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/job/run.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Reusable function for running jobs\nexport const runJob = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n jobSlug: string,\n input: Record<string, unknown>,\n queue?: string,\n priority?: number,\n delay?: number,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Running job: ${jobSlug}`)\n }\n\n try {\n // Actually run the job using Payload's job queue\n const jobQueueOptions: Record<string, unknown> = {\n input,\n task: jobSlug,\n }\n\n if (queue && queue !== 'default') {\n jobQueueOptions.queue = queue\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Using custom queue: ${queue}`)\n }\n }\n\n if (priority && priority > 0) {\n jobQueueOptions.priority = priority\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job priority: ${priority}`)\n }\n }\n\n if (delay && delay > 0) {\n jobQueueOptions.waitUntil = new Date(Date.now() + delay)\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Setting job delay: ${delay}ms`)\n }\n }\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Queuing job with options: ${JSON.stringify(jobQueueOptions)}`,\n )\n }\n\n const job = await payload.jobs.queue(\n jobQueueOptions as Parameters<typeof payload.jobs.queue>[0],\n )\n\n const jobId = (job as { id?: string })?.id || 'unknown'\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Job created successfully: ${jobId}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `# Job Queued Successfully: ${jobSlug}\n\n## Job Details\n- **Job ID**: ${jobId}\n- **Job Slug**: ${jobSlug}\n- **Queue**: ${queue || 'default'}\n- **Priority**: ${priority || 'default'}\n- **Delay**: ${delay ? `${delay}ms` : 'none'}\n- **Status**: Queued and Running\n\n## Input Data\n\\`\\`\\`json\n${JSON.stringify(input)}\n\\`\\`\\`\n\n## Job Status\nThe job has been successfully queued and will be processed according to the queue settings.\n\n## Monitoring the Job\nYou can monitor the job status using:\n\n\\`\\`\\`typescript\n// Check job status\nconst jobStatus = await payload.jobs.status('${jobId}')\nconsole.log('Job status:', jobStatus)\n\n// Wait for completion\nconst result = await payload.jobs.wait('${jobId}')\nconsole.log('Job result:', result)\n\\`\\`\\`\n\n✅ Job successfully queued with ID: ${jobId}`,\n },\n ],\n }\n } catch (error) {\n const errorMsg = (error as Error).message\n payload.logger.error(`[payload-mcp] Error running job \"${jobSlug}\": ${errorMsg}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ Error running job \"${jobSlug}\": ${errorMsg}\n\n## Common Issues:\n1. **Job not found**: The job \"${jobSlug}\" may not be registered in your Payload configuration\n2. **Invalid input format**: Ensure the input matches the job's input schema\n3. **Queue not configured**: The queue \"${queue || 'default'}\" may not be properly set up\n4. **Permission issues**: Ensure proper access rights for job execution\n5. **Job handler error**: The job implementation may have errors\n\n## Input Data Provided:\n\\`\\`\\`json\n${JSON.stringify(input)}\n\\`\\`\\`\n\n## Next Steps:\n1. **Verify job exists**: Check that the job \"${jobSlug}\" is properly registered\n2. **Check input format**: Ensure the input data matches the expected schema\n3. **Review job configuration**: Verify the job is properly configured in your Payload setup\n4. **Check permissions**: Ensure you have the necessary permissions to run jobs\n5. **Review error logs**: Check the server logs for more detailed error information\n\n## Troubleshooting:\n- **Job not found**: Verify the job slug and check your jobs configuration\n- **Schema mismatch**: Ensure input data matches the job's input schema\n- **Queue issues**: Check that the specified queue is properly configured\n- **Permission errors**: Verify user permissions for job execution`,\n },\n ],\n }\n }\n}\n\nexport const runJobTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {\n server.registerTool(\n 'runJob',\n {\n description: 'Runs a Payload job with specified input data and queue options',\n inputSchema: toolSchemas.runJob.parameters.shape,\n },\n async ({ delay, input, jobSlug, priority, queue }) => {\n if (verboseLogs) {\n req.payload.logger.info(`[payload-mcp] Run Job Tool called with: ${jobSlug}`)\n }\n return runJob(\n req,\n verboseLogs,\n jobSlug,\n input as Record<string, unknown>,\n queue,\n priority,\n delay,\n )\n },\n )\n}\n"],"names":["toolSchemas","runJob","req","verboseLogs","jobSlug","input","queue","priority","delay","payload","logger","info","jobQueueOptions","task","waitUntil","Date","now","JSON","stringify","job","jobs","jobId","id","content","type","text","error","errorMsg","message","runJobTool","server","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,QAAQ,gBAAe;AAE3C,qCAAqC;AACrC,OAAO,MAAMC,SAAS,OACpBC,KACAC,aACAC,SACAC,OACAC,OACAC,UACAC;IAEA,MAAMC,UAAUP,IAAIO,OAAO;IAE3B,IAAIN,aAAa;QACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEP,SAAS;IAC7D;IAEA,IAAI;QACF,iDAAiD;QACjD,MAAMQ,kBAA2C;YAC/CP;YACAQ,MAAMT;QACR;QAEA,IAAIE,SAASA,UAAU,WAAW;YAChCM,gBAAgBN,KAAK,GAAGA;YACxB,IAAIH,aAAa;gBACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEL,OAAO;YAClE;QACF;QAEA,IAAIC,YAAYA,WAAW,GAAG;YAC5BK,gBAAgBL,QAAQ,GAAGA;YAC3B,IAAIJ,aAAa;gBACfM,QAAQC,MAAM,CAACC,IAAI,CAA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AAEE,SAAS,UAAU;;;;;;AAM7D,EAAEW,KAAKC,SAAS,CAACb,OAAO;;;;8CAIsB,EAAED,QAAQ;;;;;;;;;;kEAUU,CAAC;gBAC3D;aACD;QACH;IACF;AACF,EAAC;AAED,OAAO,MAAMyB,aAAa,CAACC,QAAmB5B,KAAqBC;IACjE2B,OAAOC,YAAY,CACjB,UACA;QACEC,aAAa;QACbC,aAAajC,YAAYC,MAAM,CAACiC,UAAU,CAACC,KAAK;IAClD,GACA,OAAO,EAAE3B,KAAK,EAAEH,KAAK,EAAED,OAAO,EAAEG,QAAQ,EAAED,KAAK,EAAE;QAC/C,IAAIH,aAAa;YACfD,IAAIO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,wCAAwC,EAAEP,SAAS;QAC9E;QACA,OAAOH,OACLC,KACAC,aACAC,SACAC,OACAC,OACAC,UACAC;IAEJ;AAEJ,EAAC"}
|
|
@@ -79,7 +79,7 @@ export const createResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
79
79
|
text: `Resource created successfully in collection "${collectionSlug}"!
|
|
80
80
|
Created resource:
|
|
81
81
|
\`\`\`json
|
|
82
|
-
${JSON.stringify(result
|
|
82
|
+
${JSON.stringify(result)}
|
|
83
83
|
\`\`\``
|
|
84
84
|
}
|
|
85
85
|
]
|
|
@@ -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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.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 depth: number = 0,\n draft: boolean,\n locale?: string,\n fallbackLocale?: string,\n select?: 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(selectClause && { select: selectClause }),\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 depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships in response'),\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to create (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n })\n\n server.registerTool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n inputSchema: createResourceSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...fieldData } = params\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n depth as number,\n draft as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","depth","draft","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","content","type","text","selectClause","warn","response","overrideResponse","result","create","collection","overrideAccess","id","errorMessage","Error","message","enabled","convertedFields","createResourceSchema","object","shape","number","int","min","max","optional","default","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","createResource","trim","inputSchema","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,QAAgB,CAAC,EACjBC,OACAC,QACAC,gBACAC;QAOA,MAAMC,UAAUb,IAAIa,OAAO;QAE3B,IAAIX,aAAa;YACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEZ,iBAAiBO,SAAS,CAAC,cAAc,EAAEA,QAAQ,GAAG,IAAI;QAEhH;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACX;gBAExB,2DAA2D;gBAC3D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AY,CACjB,CAAC,MAAM,EAAElD,eAAemD,MAAM,CAAC,GAAGC,WAAW,KAAK/D,YAAYW,gBAAgBqD,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGrD,aAAa,CAACD,eAAe,EAAEsD,eAAe5D,YAAY6D,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAanB,qBAAqBE,KAAK;QACzC,GACA,OAAOkB;YACL,MAAM,EAAErD,KAAK,EAAEC,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEE,MAAM,EAAE,GAAGkD,WAAW,GAAGD;YACvE,MAAMtD,OAAOU,KAAKI,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.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 depth: number = 0,\n draft: boolean,\n locale?: string,\n fallbackLocale?: string,\n select?: 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(selectClause && { select: selectClause }),\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)}\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 depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .optional()\n .default(0)\n .describe('How many levels deep to populate relationships in response'),\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to create (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n })\n\n server.registerTool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n inputSchema: createResourceSchema.shape,\n },\n async (params: Record<string, unknown>) => {\n const { depth, draft, fallbackLocale, locale, select, ...fieldData } = params\n const data = JSON.stringify(fieldData)\n return await tool(\n data,\n depth as number,\n draft as boolean,\n locale as string | undefined,\n fallbackLocale as string | undefined,\n select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","depth","draft","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","content","type","text","selectClause","warn","response","overrideResponse","result","create","collection","overrideAccess","id","errorMessage","Error","message","enabled","convertedFields","createResourceSchema","object","shape","number","int","min","max","optional","default","describe","boolean","string","registerTool","charAt","toUpperCase","slice","description","createResource","trim","inputSchema","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC,MACAC,QAAgB,CAAC,EACjBC,OACAC,QACAC,gBACAC;QAOA,MAAMC,UAAUb,IAAIa,OAAO;QAE3B,IAAIX,aAAa;YACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEZ,iBAAiBO,SAAS,CAAC,cAAc,EAAEA,QAAQ,GAAG,IAAI;QAEhH;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACX;gBAExB,2DAA2D;gBAC3DS,aAAapB,4BAA4BoB;gBAEzC,MAAMG,oBAAoB1B,+BAA+BoB,QAAQO,MAAM,EAAEjB;gBACzEa,aAAatB,mBAAmBsB,YAAYG;gBAE5C,IAAIjB,aAAa;oBACfW,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEZ,eAAe,EAAE,EAAEc,KAAKI,SAAS,CAACL,aAAa;gBAEpF;YACF,EAAE,OAAOM,aAAa;gBACpBT,QAAQC,MAAM,CAACS,KAAK,CAAC,CAAC,0CAA0C,EAAEhB,MAAM;g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,GAAGD;YACvE,MAAMtD,OAAOU,KAAKI,SAAS,CAACyC;YAC5B,OAAO,MAAMxD,KACXC,MACAC,OACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
@@ -81,7 +81,7 @@ export const deleteResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
81
81
|
text: `Document deleted successfully from collection "${collectionSlug}"!
|
|
82
82
|
Deleted document:
|
|
83
83
|
\`\`\`json
|
|
84
|
-
${JSON.stringify(result
|
|
84
|
+
${JSON.stringify(result)}
|
|
85
85
|
\`\`\``
|
|
86
86
|
}
|
|
87
87
|
]
|
|
@@ -102,13 +102,13 @@ Errors: ${errors.length}
|
|
|
102
102
|
if (docs.length > 0) {
|
|
103
103
|
responseText += `\n\nDeleted documents:
|
|
104
104
|
\`\`\`json
|
|
105
|
-
${JSON.stringify(docs
|
|
105
|
+
${JSON.stringify(docs)}
|
|
106
106
|
\`\`\``;
|
|
107
107
|
}
|
|
108
108
|
if (errors.length > 0) {
|
|
109
109
|
responseText += `\n\nErrors:
|
|
110
110
|
\`\`\`json
|
|
111
|
-
${JSON.stringify(errors
|
|
111
|
+
${JSON.stringify(errors)}
|
|
112
112
|
\`\`\``;
|
|
113
113
|
}
|
|
114
114
|
const response = {
|
|
@@ -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?: 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.registerTool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n inputSchema: toolSchemas.deleteResource.parameters.shape,\n },\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","registerTool","charAt","toUpperCase","slice","description","deleteResource","trim","inputSchema","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,KAAK,CAACf;oBACzB,IAAIL,aAAa;wBACfS,QAAQC,MAAM,CAAC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AEA,OAAQhC,aAAa,CAACD,eAAe,EAAEgB,mBAAmBJ,UAAU,CAAC,GAAGf,QAAQe;QAMlF;IACF;IAEA,IAAIX,aAAa,CAACD,eAAe,EAAEoC,SAAS;QAC1CxC,OAAOyC,YAAY,CACjB,CAAC,MAAM,EAAErC,eAAesC,MAAM,CAAC,GAAGC,WAAW,KAAK9C,YAAYO,gBAAgBwC,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAGxC,aAAa,CAACD,eAAe,EAAEyC,eAAe/C,YAAYgD,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalD,YAAYgD,cAAc,CAACG,UAAU,CAACC,KAAK;QAC1D,GACA,OAAO,EAAE3C,EAAE,EAAEE,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEF,KAAK,EAAE;YACjD,OAAO,MAAMF,KAAKC,IAAIC,OAAOC,OAAOC,QAAQC;QAC9C;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)}\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)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors)}\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.registerTool(\n `delete${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.deleteResource.description.trim()}`,\n inputSchema: toolSchemas.deleteResource.parameters.shape,\n },\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","registerTool","charAt","toUpperCase","slice","description","deleteResource","trim","inputSchema","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,KAAK,CAACf;oBACzB,IAAIL,aAAa;wBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEN,OAAO;oBAClE;gBACF,EAAE,OAAOgB,aAAa;oBACpBZ,QAAQC,MAAM,CAACY,IAAI,CAAC,CAAC,yCAAyC,EAAEjB,OAAO;oBACvE,MAAMQ,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAsC;yBAAE;o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AAa,GAAGxC,aAAa,CAACD,eAAe,EAAEyC,eAAe/C,YAAYgD,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalD,YAAYgD,cAAc,CAACG,UAAU,CAACC,KAAK;QAC1D,GACA,OAAO,EAAE3C,EAAE,EAAEE,KAAK,EAAEE,cAAc,EAAED,MAAM,EAAEF,KAAK,EAAE;YACjD,OAAO,MAAMF,KAAKC,IAAIC,OAAOC,OAAOC,QAAQC;QAC9C;IAEJ;AACF,EAAC"}
|
|
@@ -77,7 +77,7 @@ export const findResourceTool = (server, req, user, verboseLogs, collectionSlug,
|
|
|
77
77
|
{
|
|
78
78
|
type: 'text',
|
|
79
79
|
text: `Resource from collection "${collectionSlug}":
|
|
80
|
-
${JSON.stringify(doc
|
|
80
|
+
${JSON.stringify(doc)}`
|
|
81
81
|
}
|
|
82
82
|
]
|
|
83
83
|
};
|
|
@@ -132,7 +132,7 @@ Total: ${result.totalDocs} documents
|
|
|
132
132
|
Page: ${result.page} of ${result.totalPages}
|
|
133
133
|
`;
|
|
134
134
|
for (const doc of result.docs){
|
|
135
|
-
responseText += `\n\`\`\`json\n${JSON.stringify(doc
|
|
135
|
+
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
|
|
136
136
|
}
|
|
137
137
|
const response = {
|
|
138
138
|
content: [
|
|
@@ -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, SelectType, 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 select?: string,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n draft?: boolean,\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 // Parse select clause if provided\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 depth,\n ...(selectClause && { select: selectClause }),\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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 depth,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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.registerTool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n inputSchema: toolSchemas.findResources.parameters.shape,\n },\n async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {\n return await tool(\n id,\n limit,\n page,\n sort,\n where,\n select,\n depth,\n locale,\n fallbackLocale,\n draft,\n )\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","select","depth","locale","fallbackLocale","draft","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","selectClause","doc","findByID","collection","overrideAccess","undefined","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","findResources","trim","inputSchema","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,QAAgB,CAAC,EACjBC,QACAC,gBACAC;QAOA,MAAMC,UAAUhB,IAAIgB,OAAO;QAE3B,IAAId,aAAa;YACfc,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEf,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,OAAOK,SAAS,CAAC,UAAU,EAAE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,eAAe,EAAEqD,eAAe3D,YAAY4D,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI;YAC5GC,aAAa9D,YAAY4D,aAAa,CAACG,UAAU,CAACC,KAAK;QACzD,GACA,OAAO,EAAEvD,EAAE,EAAEM,KAAK,EAAEG,KAAK,EAAED,cAAc,EAAEP,KAAK,EAAEM,MAAM,EAAEL,IAAI,EAAEG,MAAM,EAAEF,IAAI,EAAEC,KAAK,EAAE;YACnF,OAAO,MAAML,KACXC,IACAC,OACAC,MACAC,MACAC,OACAC,QACAC,OACAC,QACAC,gBACAC;QAEJ;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, SelectType, 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 select?: string,\n depth: number = 0,\n locale?: string,\n fallbackLocale?: string,\n draft?: boolean,\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 // Parse select clause if provided\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 depth,\n ...(selectClause && { select: selectClause }),\n overrideAccess: false,\n req,\n user,\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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)}`,\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 depth,\n limit,\n overrideAccess: false,\n page,\n req,\n user,\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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)}\\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.registerTool(\n `find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,\n inputSchema: toolSchemas.findResources.parameters.shape,\n },\n async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {\n return await tool(\n id,\n limit,\n page,\n sort,\n where,\n select,\n depth,\n locale,\n fallbackLocale,\n draft,\n )\n },\n )\n }\n}\n"],"names":["toCamelCase","toolSchemas","findResourceTool","server","req","user","verboseLogs","collectionSlug","collections","tool","id","limit","page","sort","where","select","depth","locale","fallbackLocale","draft","payload","logger","info","whereClause","JSON","parse","_parseError","warn","response","content","type","text","overrideResponse","selectClause","doc","findByID","collection","overrideAccess","undefined","stringify","_findError","findOptions","Object","keys","length","result","find","docs","responseText","totalDocs","totalPages","error","errorMessage","Error","message","enabled","registerTool","charAt","toUpperCase","slice","description","findResources","trim","inputSchema","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,QAAgB,CAAC,EACjBC,QACAC,gBACAC;QAOA,MAAMC,UAAUhB,IAAIgB,OAAO;QAE3B,IAAId,aAAa;YACfc,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,gDAAgD,EAAEf,iBAAiBG,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEC,MAAM,QAAQ,EAAEC,OAAOK,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE3K;QAEA,IAAI;YACF,iCAAiC;YACjC,IAAIM,cAAc,CAAC;YACnB,IAAIT,OAAO;gBACT,IAAI;oBACFS,cAAcC,KAAKC,KAAK,CAACX;oBACzB,IAAIR,aAAa;wBACfc,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAER,OAAO;oBAClE;gBACF,EAAE,OAAOY,aAAa;oBACpBN,QAAQC,MAAM,CAACM,IAAI,CAAC,CAAC,yCAAyC,EAAEb,OAAO;oBACvE,MAAMc,WAAW;wBACfC,SAAS;4BAAC;gCAAEC,MAAM;gCAAiBC,MAAM;4BAAsC;yBAAE;oBACnF;oBACA,OAAQvB,aAAa,CAACD,eAAe,EAAEyB,mBAAmBJ,UAAU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;wBACNC,MAAMiB;oBACR;iBACD;YACH;YAEA,OAAQxC,aAAa,CAACD,eAAe,EAAEyB,mBAAmBJ,UAAUiB,QAAQzC,QAC1EwB;QAMJ,EAAE,OAAOuB,OAAO;YACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;YAC9DlC,QAAQC,MAAM,CAAC8B,KAAK,CAClB,CAAC,sDAAsD,EAAE5C,eAAe,EAAE,EAAE6C,cAAc;YAE5F,MAAMxB,WAAW;gBACfC,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,6CAA6C,EAAExB,eAAe,KAAK,EAAE6C,cAAc;oBAC5F;iBACD;YACH;YACA,OAAQ5C,aAAa,CAACD,eAAe,EAAEyB,mBAAmBJ,UAAU,CAAC,GAAGxB,QAAQwB;QAMlF;IACF;IAEA,IAAIpB,aAAa,CAACD,eAAe,EAAEgD,SAAS;QAC1CpD,OAAOqD,YAAY,CACjB,CAAC,IAAI,EAAEjD,eAAekD,MAAM,CAAC,GAAGC,WAAW,KAAK1D,YAAYO,gBAAgBoD,KAAK,CAAC,IAAI,EACtF;YACEC,aAAa,GAAGpD,aAAa,CAACD,eAAe,EAAEqD,eAAe3D,YAAY4D,aAAa,CAACD,WAAW,CAACE,IAAI,IAAI;YAC5GC,aAAa9D,YAAY4D,aAAa,CAACG,UAAU,CAACC,KAAK;QACzD,GACA,OAAO,EAAEvD,EAAE,EAAEM,KAAK,EAAEG,KAAK,EAAED,cAAc,EAAEP,KAAK,EAAEM,MAAM,EAAEL,IAAI,EAAEG,MAAM,EAAEF,IAAI,EAAEC,KAAK,EAAE;YACnF,OAAO,MAAML,KACXC,IACAC,OACAC,MACAC,MACAC,OACAC,QACAC,OACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
|
|
@@ -131,7 +131,7 @@ export const updateResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
131
131
|
text: `Document updated successfully in collection "${collectionSlug}"!
|
|
132
132
|
Updated document:
|
|
133
133
|
\`\`\`json
|
|
134
|
-
${JSON.stringify(result
|
|
134
|
+
${JSON.stringify(result)}
|
|
135
135
|
\`\`\``
|
|
136
136
|
}
|
|
137
137
|
]
|
|
@@ -185,13 +185,13 @@ Errors: ${errors.length}
|
|
|
185
185
|
if (docs.length > 0) {
|
|
186
186
|
responseText += `\n\nUpdated documents:
|
|
187
187
|
\`\`\`json
|
|
188
|
-
${JSON.stringify(docs
|
|
188
|
+
${JSON.stringify(docs)}
|
|
189
189
|
\`\`\``;
|
|
190
190
|
}
|
|
191
191
|
if (errors.length > 0) {
|
|
192
192
|
responseText += `\n\nErrors:
|
|
193
193
|
\`\`\`json
|
|
194
|
-
${JSON.stringify(errors
|
|
194
|
+
${JSON.stringify(errors)}
|
|
195
195
|
\`\`\``;
|
|
196
196
|
}
|
|
197
197
|
const response = {
|
|
@@ -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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.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 select?: 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 ...(selectClause && { select: selectClause }),\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 ...(selectClause && { select: selectClause }),\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.registerTool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n inputSchema: updateResourceSchema.shape,\n },\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 select,\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 select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","selectClause","warn","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","registerTool","charAt","toUpperCase","slice","description","updateResource","trim","inputSchema","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,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,gBACAC;QAOA,MAAMC,UAAUlB,IAAIkB,OAAO;QAE3B,IAAIhB,aAAa;YACfgB,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEjB,iBAAiBK,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,qBAAqB,SAAS,EAAEE,QAAQK,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE7K;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAAChB;gBAExB,2DAA2D;gBAC3Dc,aAAazB,4BAA4ByB;gBAEzC,MAAMG,oBAAoB/B,+BAA+ByB,QAAQO,MAAM,EAAEtB;gBACzEkB,aAAa3B,mBAAmB2B,YAAYG;gBAE5C,IAAItB,aAAa;oBACfgB,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEjB,eAAe,EAAE,EAAEmB,KAAKI,SAAS,CAACL,aAAa;gBAEpF;YACF,EAAE,OAAOM,aAAa;gBACpBT,Q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C;YACZ9C,wBAAwBvB,EACrBuE,OAAO,GACPH,QAAQ,GACRE,OAAO,CAAC,OACRD,QAAQ,CAAC;YACZ3C,QAAQ1B,EACLkE,MAAM,GACNE,QAAQ,GACRC,QAAQ,CACP;YAEJnD,OAAOlB,EACJkE,MAAM,GACNE,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEA7D,OAAOgE,YAAY,CACjB,CAAC,MAAM,EAAE5D,eAAe6D,MAAM,CAAC,GAAGC,WAAW,KAAKzE,YAAYW,gBAAgB+D,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAG/D,aAAa,CAACD,eAAe,EAAEgE,eAAetE,YAAYuE,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalB,qBAAqBG,KAAK;QACzC,GACA,OAAOgB;YACL,MAAM,EACJ/D,EAAE,EACFG,KAAK,EACLD,KAAK,EACLM,cAAc,EACdH,QAAQ,EACRE,MAAM,EACNH,YAAY,EACZE,sBAAsB,EACtBG,MAAM,EACNR,KAAK,EACL,GAAG+D,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMhE,OAAOe,KAAKI,SAAS,CAAC8C;YAC5B,OAAO,MAAMlE,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC,wBACAC,QACAC,gBACAC;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, SelectType, TypedUser } from 'payload'\n\nimport { z } from 'zod'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.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 select?: 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\n // Transform point fields from object format to tuple array\n parsedData = transformPointDataToPayload(parsedData)\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch (_parseError) {\n payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)\n const response = {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select 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 ...(selectClause && { select: selectClause }),\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)}\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 ...(selectClause && { select: selectClause }),\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)}\n\\`\\`\\``\n }\n\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\n\\`\\`\\`json\n${JSON.stringify(errors)}\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 select: z\n .string()\n .optional()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n ),\n where: z\n .string()\n .optional()\n .describe('JSON string for where clause to update multiple documents'),\n })\n\n server.registerTool(\n `update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n {\n description: `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,\n inputSchema: updateResourceSchema.shape,\n },\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 select,\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 select as string | undefined,\n )\n },\n )\n }\n}\n"],"names":["z","toCamelCase","getCollectionVirtualFieldNames","stripVirtualFields","convertCollectionSchemaToZod","transformPointDataToPayload","toolSchemas","updateResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","id","where","draft","depth","overrideLock","filePath","overwriteExistingFiles","locale","fallbackLocale","select","payload","logger","info","parsedData","JSON","parse","virtualFieldNames","config","stringify","_parseError","error","response","content","type","text","overrideResponse","whereClause","selectClause","warn","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","registerTool","charAt","toUpperCase","slice","description","updateResource","trim","inputSchema","params","fieldData"],"mappings":"AAIA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,4BAA4B,QAAQ,kEAAiE;AAC9G,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,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,gBACAC;QAOA,MAAMC,UAAUlB,IAAIkB,OAAO;QAE3B,IAAIhB,aAAa;YACfgB,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,+CAA+C,EAAEjB,iBAAiBK,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,qBAAqB,SAAS,EAAEE,QAAQK,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;QAE7K;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIM;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAAChB;gBAExB,2DAA2D;gBAC3Dc,aAAazB,4BAA4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AAQ,GACRC,QAAQ,CAAC;YACZ/C,UAAUtB,EAAEkE,MAAM,GAAGE,QAAQ,GAAGC,QAAQ,CAAC;YACzC7C,QAAQxB,EACLkE,MAAM,GACNE,QAAQ,GACRC,QAAQ,CACP;YAEJhD,cAAcrB,EACXuE,OAAO,GACPH,QAAQ,GACRE,OAAO,CAAC,MACRD,QAAQ,CAAC;YACZ9C,wBAAwBvB,EACrBuE,OAAO,GACPH,QAAQ,GACRE,OAAO,CAAC,OACRD,QAAQ,CAAC;YACZ3C,QAAQ1B,EACLkE,MAAM,GACNE,QAAQ,GACRC,QAAQ,CACP;YAEJnD,OAAOlB,EACJkE,MAAM,GACNE,QAAQ,GACRC,QAAQ,CAAC;QACd;QAEA7D,OAAOgE,YAAY,CACjB,CAAC,MAAM,EAAE5D,eAAe6D,MAAM,CAAC,GAAGC,WAAW,KAAKzE,YAAYW,gBAAgB+D,KAAK,CAAC,IAAI,EACxF;YACEC,aAAa,GAAG/D,aAAa,CAACD,eAAe,EAAEgE,eAAetE,YAAYuE,cAAc,CAACD,WAAW,CAACE,IAAI,IAAI;YAC7GC,aAAalB,qBAAqBG,KAAK;QACzC,GACA,OAAOgB;YACL,MAAM,EACJ/D,EAAE,EACFG,KAAK,EACLD,KAAK,EACLM,cAAc,EACdH,QAAQ,EACRE,MAAM,EACNH,YAAY,EACZE,sBAAsB,EACtBG,MAAM,EACNR,KAAK,EACL,GAAG+D,WACJ,GAAGD;YACJ,qEAAqE;YACrE,MAAMhE,OAAOe,KAAKI,SAAS,CAAC8C;YAC5B,OAAO,MAAMlE,KACXC,MACAC,IACAC,OACAC,OACAC,OACAC,cACAC,UACAC,wBACAC,QACAC,gBACAC;QAEJ;IAEJ;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.83.0-canary.1",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"zod": "^3.25.50"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"payload": "3.83.0-canary.1",
|
|
48
|
+
"@payloadcms/eslint-config": "3.28.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.
|
|
51
|
+
"payload": "3.83.0-canary.1"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
|
@@ -39,7 +39,7 @@ export const authTool = (server: McpServer, req: PayloadRequest, verboseLogs: bo
|
|
|
39
39
|
content: [
|
|
40
40
|
{
|
|
41
41
|
type: 'text' as const,
|
|
42
|
-
text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result
|
|
42
|
+
text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
45
|
}
|
|
@@ -36,7 +36,7 @@ export const forgotPasswordTool = (
|
|
|
36
36
|
content: [
|
|
37
37
|
{
|
|
38
38
|
type: 'text' as const,
|
|
39
|
-
text: `# Password Reset Email Sent\n\n**User:** ${email}\n**Collection:** ${collection}\n**Email Disabled:** ${disableEmail}\n\n\`\`\`json\n${JSON.stringify(result
|
|
39
|
+
text: `# Password Reset Email Sent\n\n**User:** ${email}\n**Collection:** ${collection}\n**Email Disabled:** ${disableEmail}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
42
|
}
|
|
@@ -40,7 +40,7 @@ export const loginTool = (server: McpServer, req: PayloadRequest, verboseLogs: b
|
|
|
40
40
|
content: [
|
|
41
41
|
{
|
|
42
42
|
type: 'text' as const,
|
|
43
|
-
text: `# Login Successful\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result
|
|
43
|
+
text: `# Login Successful\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
44
44
|
},
|
|
45
45
|
],
|
|
46
46
|
}
|
|
@@ -29,7 +29,7 @@ export const resetPasswordTool = (server: McpServer, req: PayloadRequest, verbos
|
|
|
29
29
|
content: [
|
|
30
30
|
{
|
|
31
31
|
type: 'text' as const,
|
|
32
|
-
text: `# Password Reset Successful\n\n**Collection:** ${collection}\n**Token:** ${token}\n\n\`\`\`json\n${JSON.stringify(result
|
|
32
|
+
text: `# Password Reset Successful\n\n**Collection:** ${collection}\n**Token:** ${token}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
33
33
|
},
|
|
34
34
|
],
|
|
35
35
|
}
|
|
@@ -30,7 +30,7 @@ export const unlockTool = (server: McpServer, req: PayloadRequest, verboseLogs:
|
|
|
30
30
|
content: [
|
|
31
31
|
{
|
|
32
32
|
type: 'text' as const,
|
|
33
|
-
text: `# User Account Unlocked\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result
|
|
33
|
+
text: `# User Account Unlocked\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
36
|
}
|
package/src/mcp/tools/job/run.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const runJob = async (
|
|
|
79
79
|
|
|
80
80
|
## Input Data
|
|
81
81
|
\`\`\`json
|
|
82
|
-
${JSON.stringify(input
|
|
82
|
+
${JSON.stringify(input)}
|
|
83
83
|
\`\`\`
|
|
84
84
|
|
|
85
85
|
## Job Status
|
|
@@ -121,7 +121,7 @@ console.log('Job result:', result)
|
|
|
121
121
|
|
|
122
122
|
## Input Data Provided:
|
|
123
123
|
\`\`\`json
|
|
124
|
-
${JSON.stringify(input
|
|
124
|
+
${JSON.stringify(input)}
|
|
125
125
|
\`\`\`
|
|
126
126
|
|
|
127
127
|
## Next Steps:
|
|
@@ -115,7 +115,7 @@ export const deleteResourceTool = (
|
|
|
115
115
|
text: `Document deleted successfully from collection "${collectionSlug}"!
|
|
116
116
|
Deleted document:
|
|
117
117
|
\`\`\`json
|
|
118
|
-
${JSON.stringify(result
|
|
118
|
+
${JSON.stringify(result)}
|
|
119
119
|
\`\`\``,
|
|
120
120
|
},
|
|
121
121
|
],
|
|
@@ -148,14 +148,14 @@ Errors: ${errors.length}
|
|
|
148
148
|
if (docs.length > 0) {
|
|
149
149
|
responseText += `\n\nDeleted documents:
|
|
150
150
|
\`\`\`json
|
|
151
|
-
${JSON.stringify(docs
|
|
151
|
+
${JSON.stringify(docs)}
|
|
152
152
|
\`\`\``
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (errors.length > 0) {
|
|
156
156
|
responseText += `\n\nErrors:
|
|
157
157
|
\`\`\`json
|
|
158
|
-
${JSON.stringify(errors
|
|
158
|
+
${JSON.stringify(errors)}
|
|
159
159
|
\`\`\``
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -108,7 +108,7 @@ export const findResourceTool = (
|
|
|
108
108
|
{
|
|
109
109
|
type: 'text' as const,
|
|
110
110
|
text: `Resource from collection "${collectionSlug}":
|
|
111
|
-
${JSON.stringify(doc
|
|
111
|
+
${JSON.stringify(doc)}`,
|
|
112
112
|
},
|
|
113
113
|
],
|
|
114
114
|
}
|
|
@@ -179,7 +179,7 @@ Page: ${result.page} of ${result.totalPages}
|
|
|
179
179
|
`
|
|
180
180
|
|
|
181
181
|
for (const doc of result.docs) {
|
|
182
|
-
responseText += `\n\`\`\`json\n${JSON.stringify(doc
|
|
182
|
+
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
const response = {
|
|
@@ -178,7 +178,7 @@ export const updateResourceTool = (
|
|
|
178
178
|
text: `Document updated successfully in collection "${collectionSlug}"!
|
|
179
179
|
Updated document:
|
|
180
180
|
\`\`\`json
|
|
181
|
-
${JSON.stringify(result
|
|
181
|
+
${JSON.stringify(result)}
|
|
182
182
|
\`\`\``,
|
|
183
183
|
},
|
|
184
184
|
],
|
|
@@ -236,14 +236,14 @@ Errors: ${errors.length}
|
|
|
236
236
|
if (docs.length > 0) {
|
|
237
237
|
responseText += `\n\nUpdated documents:
|
|
238
238
|
\`\`\`json
|
|
239
|
-
${JSON.stringify(docs
|
|
239
|
+
${JSON.stringify(docs)}
|
|
240
240
|
\`\`\``
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
if (errors.length > 0) {
|
|
244
244
|
responseText += `\n\nErrors:
|
|
245
245
|
\`\`\`json
|
|
246
|
-
${JSON.stringify(errors
|
|
246
|
+
${JSON.stringify(errors)}
|
|
247
247
|
\`\`\``
|
|
248
248
|
}
|
|
249
249
|
|