@payloadcms/plugin-mcp 4.0.0-internal.e387174 → 4.0.0-internal.e7d4ebc

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.
Files changed (53) hide show
  1. package/dist/defaultAccess.d.ts.map +1 -1
  2. package/dist/defineTool.d.ts +8 -8
  3. package/dist/defineTool.d.ts.map +1 -1
  4. package/dist/endpoint/access.d.ts.map +1 -1
  5. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  6. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  7. package/dist/mcp/builtin/collections/createTool.js +12 -2
  8. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  9. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  10. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  11. package/dist/mcp/builtin/collections/fileInput.js +117 -0
  12. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  13. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  14. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  15. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  16. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  17. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  18. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +24 -2
  19. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  20. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  21. package/dist/mcp/builtin/collections/updateTool.js +13 -7
  22. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  23. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  24. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  25. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  26. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  27. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  28. package/dist/mcp/builtinTools.d.ts +6 -0
  29. package/dist/mcp/builtinTools.d.ts.map +1 -1
  30. package/dist/mcp/builtinTools.js +6 -0
  31. package/dist/mcp/builtinTools.js.map +1 -1
  32. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  33. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  34. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  35. package/dist/stdio.d.ts.map +1 -1
  36. package/dist/stdio.js +2 -1
  37. package/dist/stdio.js.map +1 -1
  38. package/dist/utils/camelCase.d.ts.map +1 -1
  39. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  40. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -1
  41. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  42. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  43. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  44. package/package.json +3 -3
  45. package/src/mcp/builtin/collections/createTool.ts +6 -2
  46. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  47. package/src/mcp/builtin/collections/fileInput.ts +154 -0
  48. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +18 -1
  49. package/src/mcp/builtin/collections/updateTool.ts +7 -5
  50. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  51. package/src/mcp/builtinTools.ts +7 -0
  52. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  53. package/src/stdio.ts +2 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType, Where } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents in any collection by passing the collection slug and data.'\n\nexport const updateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z\n .record(z.string(), z.unknown())\n .describe(\n 'The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.',\n ),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: \"published\" overrides true.',\n )\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n filePath: z.string().describe('File path for file uploads').optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\n publishAllLocales: z\n .boolean()\n .describe(\n 'For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n where: whereSchema\n .describe(\n 'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\n publishAllLocales,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n const validationError = validateCollectionData({\n collectionSlug,\n data: inputData,\n partial: true,\n req,\n })\n\n if (validationError) {\n return validationError\n }\n\n const parsedData = transformPointDataToPayload(inputData)\n\n const whereClause: Where = where ?? {}\n\n if (id) {\n const result = await payload.update({\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n where: whereClause,\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n const docs = result.docs || []\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n\n const errorSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n collectionSlug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\n }\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'updating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","formatCollectionError","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","data","record","unknown","depth","default","draft","boolean","fallbackLocale","filePath","locale","overrideLock","overwriteExistingFiles","publishAllLocales","select","where","handler","authorizedMCP","req","payload","logger","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","overrideAccess","undefined","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBV,qBAAqB;IACrDW,QAAQ,CAACC,OACPb,cAAca,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAO3B,EAAE4B,MAAM,CAAC;QACdC,IAAI7B,EAAE8B,KAAK,CAAC;YAAC9B,EAAE+B,MAAM;YAAI/B,EAAEgC,MAAM;SAAG,EAAEC,QAAQ,CAAC,oCAAoCC,QAAQ;QAC3FC,MAAMnC,EACHoC,MAAM,CAACpC,EAAE+B,MAAM,IAAI/B,EAAEqC,OAAO,IAC5BJ,QAAQ,CACP;QAEJK,OAAOtC,EACJgC,MAAM,GACNC,QAAQ,CAAC,kDACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOxC,EACJyC,OAAO,GACPR,QAAQ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BAAQC,MAAMiB;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D9B,OAAO2B,KAAK,CAAC,CAAC,2BAA2B,EAAE/D,eAAe,EAAE,EAAEgE,cAAc;QAC5E,OAAOxE,sBAAsB;YAAE2E,QAAQ;YAAYnE;YAAgB+D;YAAO7B;QAAI;IAChF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType, Where } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { fileInputSchema, resolveFile } from './fileInput.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents in any collection. Files can use a URL, base64, or an upload prepared by getUploadInstructions.'\n\nexport const updateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z\n .record(z.string(), z.unknown())\n .describe(\n 'The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.',\n ),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: \"published\" overrides true.',\n )\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n file: fileInputSchema.optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\n publishAllLocales: z\n .boolean()\n .describe(\n 'For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n where: whereSchema\n .describe(\n 'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n file: fileInput,\n locale,\n overrideLock,\n overwriteExistingFiles,\n publishAllLocales,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n const validationError = validateCollectionData({\n collectionSlug,\n data: inputData,\n partial: true,\n req,\n })\n\n if (validationError) {\n return validationError\n }\n\n const parsedData = transformPointDataToPayload(inputData)\n const file = await resolveFile({ collectionSlug, input: fileInput, req })\n\n const whereClause: Where = where ?? {}\n\n if (id) {\n const result = await payload.update({\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n where: whereClause,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n const docs = result.docs || []\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n\n const errorSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n collectionSlug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\n }\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'updating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","fileInputSchema","resolveFile","formatCollectionError","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","data","record","unknown","depth","default","draft","boolean","fallbackLocale","file","locale","overrideLock","overwriteExistingFiles","publishAllLocales","select","where","handler","authorizedMCP","req","payload","logger","fileInput","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","overrideAccess","undefined","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SA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,aAAa,EAAEwD,KAAKG,MAAM,CAAC,oBAAoB,EAAEF,OAAOE,MAAM,CAAC,KAAK,CAAC;QACpJ,IAAIH,KAAKG,MAAM,GAAG,GAAG;YACnBD,gBAAgB,CAAC,oCAAoC,EAAEL,KAAKC,SAAS,CAACE,MAAM,QAAQ,CAAC;QACvF;QACA,IAAIC,OAAOE,MAAM,GAAG,GAAG;YACrBD,gBAAgB,CAAC,yBAAyB,EAAEL,KAAKC,SAAS,CAACG,QAAQ,QAAQ,CAAC;YAE5E,MAAMG,cAAc1E,yBAAyB;gBAAEc;gBAAgBkC;YAAI;YAEnE,IAAI0B,aAAa;gBACfF,gBAAgB,CAAC,2CAA2C,EAAEL,KAAKC,SAAS,CAACM,aAAa,QAAQ,CAAC;YACrG;YAEA,OAAO;gBACLrB,SAAS;oBAAC;wBAAEC,MAAM;wBAAQC,MAAMiB;oBAAa;iBAAE;gBAC/CH,KAAK;oBAAEC;oBAAMC;gBAAO;gBACpBI,SAAS;gBACT,GAAID,cACA;oBACEE,mBAAmB;wBACjB9D;wBACAwD;wBACAC;wBACAM,QAAQH;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLrB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMiB;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D/B,OAAO4B,KAAK,CAAC,CAAC,2BAA2B,EAAEhE,eAAe,EAAE,EAAEiE,cAAc;QAC5E,OAAOzE,sBAAsB;YAAE4E,QAAQ;YAAYpE;YAAgBgE;YAAO9B;QAAI;IAChF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const getUploadInstructionsTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=uploadInstructionsTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadInstructionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,4CAyDpC,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal';
2
+ import { z } from 'zod';
3
+ import { defaultAccess } from '../../../defaultAccess.js';
4
+ import { defineCollectionTool } from '../../../defineTool.js';
5
+ export const getUploadInstructionsTool = defineCollectionTool({
6
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create || args.permissions?.collections?.[args.collectionSlug]?.update),
7
+ annotations: {
8
+ destructiveHint: false,
9
+ idempotentHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ title: 'Get Upload Instructions'
13
+ },
14
+ description: 'Prepare a file upload before createDocument or updateDocument. Pass file metadata only, without base64 or file contents.',
15
+ input: z.object({
16
+ docPrefix: z.string().describe('Optional document folder or prefix').optional(),
17
+ filename: z.string().describe('The original file name'),
18
+ filesize: z.number().int().nonnegative().describe('The file size in bytes'),
19
+ mimeType: z.string().describe('The file MIME type')
20
+ })
21
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
22
+ try {
23
+ const instructions = await getPayloadUploadInstructions({
24
+ ...input,
25
+ collectionSlug,
26
+ overrideAccess: authorizedMCP.overrideAccess,
27
+ req
28
+ });
29
+ const nextStep = instructions.type === 'http' ? 'Send the exact file bytes using request, then pass { source: "uploadReference", file } to createDocument or updateDocument.' : `Call the local MCP tool named "${instructions.name}" with the file and data, then pass { source: "uploadReference", file } to createDocument or updateDocument.`;
30
+ return {
31
+ content: [
32
+ {
33
+ type: 'text',
34
+ text: `Upload instructions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`
35
+ }
36
+ ],
37
+ structuredContent: {
38
+ instructions
39
+ }
40
+ };
41
+ } catch (error) {
42
+ const message = error instanceof Error ? error.message : 'Unknown error';
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: `Error getting upload instructions for collection "${collectionSlug}": ${message}`
48
+ }
49
+ ],
50
+ isError: true
51
+ };
52
+ }
53
+ });
54
+
55
+ //# sourceMappingURL=uploadInstructionsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/uploadInstructionsTool.ts"],"sourcesContent":["import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\n\nexport const getUploadInstructionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(\n args.permissions?.collections?.[args.collectionSlug]?.create ||\n args.permissions?.collections?.[args.collectionSlug]?.update,\n ),\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n readOnlyHint: false,\n title: 'Get Upload Instructions',\n },\n description:\n 'Prepare a file upload before createDocument or updateDocument. Pass file metadata only, without base64 or file contents.',\n input: z.object({\n docPrefix: z.string().describe('Optional document folder or prefix').optional(),\n filename: z.string().describe('The original file name'),\n filesize: z.number().int().nonnegative().describe('The file size in bytes'),\n mimeType: z.string().describe('The file MIME type'),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n try {\n const instructions = await getPayloadUploadInstructions({\n ...input,\n collectionSlug,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n })\n\n const nextStep =\n instructions.type === 'http'\n ? 'Send the exact file bytes using request, then pass { source: \"uploadReference\", file } to createDocument or updateDocument.'\n : `Call the local MCP tool named \"${instructions.name}\" with the file and data, then pass { source: \"uploadReference\", file } to createDocument or updateDocument.`\n\n return {\n content: [\n {\n type: 'text',\n text: `Upload instructions for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(instructions)}\\n\\`\\`\\`\\n${nextStep}`,\n },\n ],\n structuredContent: { instructions },\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error'\n return {\n content: [\n {\n type: 'text',\n text: `Error getting upload instructions for collection \"${collectionSlug}\": ${message}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["getUploadInstructions","getPayloadUploadInstructions","z","defaultAccess","defineCollectionTool","getUploadInstructionsTool","access","args","Boolean","permissions","collections","collectionSlug","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","docPrefix","string","describe","optional","filename","filesize","number","int","nonnegative","mimeType","handler","authorizedMCP","req","instructions","overrideAccess","nextStep","type","name","content","text","JSON","stringify","structuredContent","error","message","Error","isError"],"mappings":"AAAA,SAASA,yBAAyBC,4BAA4B,QAAQ,mBAAkB;AACxF,SAASC,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAE7D,OAAO,MAAMC,4BAA4BD,qBAAqB;IAC5DE,QAAQ,CAACC,OACPJ,cAAcI,SACdC,QACED,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC,UACpDL,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEE;IAE5DC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aACE;IACFC,OAAOnB,EAAEoB,MAAM,CAAC;QACdC,WAAWrB,EAAEsB,MAAM,GAAGC,QAAQ,CAAC,sCAAsCC,QAAQ;QAC7EC,UAAUzB,EAAEsB,MAAM,GAAGC,QAAQ,CAAC;QAC9BG,UAAU1B,EAAE2B,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGN,QAAQ,CAAC;QAClDO,UAAU9B,EAAEsB,MAAM,GAAGC,QAAQ,CAAC;IAChC;AACF,GAAGQ,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEvB,cAAc,EAAEU,KAAK,EAAEc,GAAG,EAAE;IAC7D,IAAI;QACF,MAAMC,eAAe,MAAMnC,6BAA6B;YACtD,GAAGoB,KAAK;YACRV;YACA0B,gBAAgBH,cAAcG,cAAc;YAC5CF;QACF;QAEA,MAAMG,WACJF,aAAaG,IAAI,KAAK,SAClB,gIACA,CAAC,+BAA+B,EAAEH,aAAaI,IAAI,CAAC,4GAA4G,CAAC;QAEvK,OAAO;YACLC,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,oCAAoC,EAAE/B,eAAe,gBAAgB,EAAEgC,KAAKC,SAAS,CAACR,cAAc,UAAU,EAAEE,UAAU;gBACnI;aACD;YACDO,mBAAmB;gBAAET;YAAa;QACpC;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAG;QACzD,OAAO;YACLN,SAAS;gBACP;oBACEF,MAAM;oBACNG,MAAM,CAAC,kDAAkD,EAAE/B,eAAe,GAAG,EAAEoC,SAAS;gBAC1F;aACD;YACDE,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateEntityData.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/validateEntityData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAA;AAI1F,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAuBrE,eAAO,MAAM,sBAAsB,GAAI,yCAKpC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA;AAEJ,eAAO,MAAM,kBAAkB,GAAI,4BAIhC;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA"}
1
+ {"version":3,"file":"validateEntityData.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/validateEntityData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAA;AAI1F,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAuBrE,eAAO,MAAM,sBAAsB,4CAKhC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA;AAEJ,eAAO,MAAM,kBAAkB,+BAI5B;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA"}
@@ -2,6 +2,7 @@ import type { CollectionTool, GlobalTool, Tool } from '../types.js';
2
2
  type CollectionBuiltin = {
3
3
  mcpName: string;
4
4
  requiresDuplicateEnabled?: boolean;
5
+ requiresUpload?: boolean;
5
6
  requiresVersions?: boolean;
6
7
  tool: CollectionTool;
7
8
  };
@@ -66,6 +67,11 @@ export declare const COLLECTION_BUILTINS: {
66
67
  mcpName: string;
67
68
  tool: CollectionTool;
68
69
  };
70
+ getUploadInstructions: {
71
+ mcpName: string;
72
+ requiresUpload: true;
73
+ tool: CollectionTool;
74
+ };
69
75
  restoreVersion: {
70
76
  mcpName: string;
71
77
  requiresVersions: true;
@@ -1 +1 @@
1
- {"version":3,"file":"builtinTools.d.ts","source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,OAAO;QAAY,IAAI;;;QACvB,OAAO;QAAY,IAAI;;CACkC,CAAA;AAErE;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;QAMlB,OAAO;QAAgB,IAAI;;;;;;;;;;;;;QAWhB,OAAO;QAAqB,IAAI;;;;;;;;QAMzC,OAAO;QAAkB,IAAI;;CACA,CAAA;AAEzC,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,mBAAmB,CAAA;AAEvE,MAAM,MAAM,yBAAyB,GAAG,MAAM,OAAO,wBAAwB,CAAA;AAE7E,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,eAAe,CAAA;AAE/D,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,aAAa,CAAA;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAoC,KAAK,CACxE,CAAC,sBAAsB,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,sBAAsB,CAAC,CAAC,CACzE,CAAA;AAED,eAAO,MAAM,0BAA0B,EAA0C,KAAK,CACpF,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAC9C,CAAA;AAED,eAAO,MAAM,+BAA+B,EAA+C,KAAK,CAC9F,CAAC,yBAAyB,EAAE,CAAC,OAAO,wBAAwB,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAC1F,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAsC,KAAK,CAC5E,CAAC,oBAAoB,EAAE,aAAa,CAAC,CACtC,CAAA"}
@@ -11,6 +11,7 @@ import { findVersionsTool } from './builtin/collections/findVersionsTool.js';
11
11
  import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js';
12
12
  import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js';
13
13
  import { updateDocumentTool } from './builtin/collections/updateTool.js';
14
+ import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js';
14
15
  import { getConfigInfoTool } from './builtin/getConfigInfoTool.js';
15
16
  import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js';
16
17
  import { findGlobalTool } from './builtin/globals/findTool.js';
@@ -74,6 +75,11 @@ export const TOOL_BUILTINS = {
74
75
  mcpName: 'getCollectionSchema',
75
76
  tool: getCollectionSchemaTool
76
77
  },
78
+ getUploadInstructions: {
79
+ mcpName: 'getUploadInstructions',
80
+ requiresUpload: true,
81
+ tool: getUploadInstructionsTool
82
+ },
77
83
  restoreVersion: {
78
84
  mcpName: 'restoreVersion',
79
85
  requiresVersions: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/builtinTools.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool, Tool } from '../types.js'\n\nimport {\n authCollectionTool,\n forgotPasswordCollectionTool,\n loginCollectionTool,\n resetPasswordCollectionTool,\n unlockCollectionTool,\n verifyCollectionTool,\n} from './builtin/collections/authTools.js'\nimport { countDocumentsTool } from './builtin/collections/countTool.js'\nimport { countVersionsTool } from './builtin/collections/countVersionsTool.js'\nimport { createDocumentTool } from './builtin/collections/createTool.js'\nimport { deleteDocumentsTool } from './builtin/collections/deleteTool.js'\nimport { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'\nimport { findDistinctTool } from './builtin/collections/findDistinctTool.js'\nimport { findDocumentsTool } from './builtin/collections/findTool.js'\nimport { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'\nimport { findVersionsTool } from './builtin/collections/findVersionsTool.js'\nimport { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'\nimport { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'\nimport { updateDocumentTool } from './builtin/collections/updateTool.js'\nimport { getConfigInfoTool } from './builtin/getConfigInfoTool.js'\nimport { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'\nimport { findGlobalTool } from './builtin/globals/findTool.js'\nimport { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'\nimport { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'\nimport { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'\nimport { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'\nimport { updateGlobalTool } from './builtin/globals/updateTool.js'\n\ntype CollectionBuiltin = {\n mcpName: string\n requiresDuplicateEnabled?: boolean\n requiresVersions?: boolean\n tool: CollectionTool\n}\n\ntype GlobalBuiltin = {\n mcpName: string\n requiresVersions?: boolean\n tool: GlobalTool\n}\n\nexport const TOOL_BUILTINS = {\n getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },\n} satisfies Record<string, { mcpName: string; tool: Tool }>\n\n/**\n * The static built-in collection CRUD tools. Keys here are the source of truth\n * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type\n * automatically.\n */\nexport const COLLECTION_BUILTINS = {\n count: { mcpName: 'countDocuments', tool: countDocumentsTool },\n countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },\n create: { mcpName: 'createDocument', tool: createDocumentTool },\n delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },\n duplicate: {\n mcpName: 'duplicateDocument',\n requiresDuplicateEnabled: true,\n tool: duplicateDocumentTool,\n },\n find: { mcpName: 'findDocuments', tool: findDocumentsTool },\n findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },\n findVersionByID: {\n mcpName: 'findVersionByID',\n requiresVersions: true,\n tool: findVersionByIDTool,\n },\n findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },\n getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },\n restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },\n update: { mcpName: 'updateDocument', tool: updateDocumentTool },\n} satisfies Record<string, CollectionBuiltin>\n\n/**\n * The static auth tools surfaced under auth-enabled collections. Keys are the\n * source of truth for `MCPCollectionAuthToolName`.\n */\nexport const COLLECTION_AUTH_BUILTINS = {\n auth: { mcpName: 'auth', tool: authCollectionTool },\n forgotPassword: {\n mcpName: 'forgotPassword',\n tool: forgotPasswordCollectionTool,\n },\n login: { mcpName: 'login', tool: loginCollectionTool },\n resetPassword: {\n mcpName: 'resetPassword',\n tool: resetPasswordCollectionTool,\n },\n unlock: { mcpName: 'unlock', tool: unlockCollectionTool },\n verify: { mcpName: 'verify', tool: verifyCollectionTool },\n} satisfies Record<string, { mcpName: string; tool: CollectionTool }>\n\n/**\n * The static built-in global tools. Keys are the source of truth for\n * `MCPGlobalBuiltinName`.\n */\nexport const GLOBAL_BUILTINS = {\n countGlobalVersions: {\n mcpName: 'countGlobalVersions',\n requiresVersions: true,\n tool: countGlobalVersionsTool,\n },\n find: { mcpName: 'findGlobal', tool: findGlobalTool },\n findGlobalVersionByID: {\n mcpName: 'findGlobalVersionByID',\n requiresVersions: true,\n tool: findGlobalVersionByIDTool,\n },\n findGlobalVersions: {\n mcpName: 'findGlobalVersions',\n requiresVersions: true,\n tool: findGlobalVersionsTool,\n },\n getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },\n restoreGlobalVersion: {\n mcpName: 'restoreGlobalVersion',\n requiresVersions: true,\n tool: restoreGlobalVersionTool,\n },\n update: { mcpName: 'updateGlobal', tool: updateGlobalTool },\n} satisfies Record<string, GlobalBuiltin>\n\nexport type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS\n\nexport type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS\n\nexport type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS\n\nexport type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS\n\n/**\n * Pre-typed `Object.entries` for each registry. The cast from `string` to the\n * literal key union lives here once so consumers can iterate without their own\n * cast — TypeScript's `Object.entries` always widens keys to `string`, which\n * defeats the narrow type lookups on `MCPCollectionToolsMap`.\n */\nexport const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<\n [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]\n>\n\nexport const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<\n [MCPCollectionBuiltinName, CollectionBuiltin]\n>\n\nexport const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<\n [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]\n>\n\nexport const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<\n [MCPGlobalBuiltinName, GlobalBuiltin]\n>\n"],"names":["authCollectionTool","forgotPasswordCollectionTool","loginCollectionTool","resetPasswordCollectionTool","unlockCollectionTool","verifyCollectionTool","countDocumentsTool","countVersionsTool","createDocumentTool","deleteDocumentsTool","duplicateDocumentTool","findDistinctTool","findDocumentsTool","findVersionByIDTool","findVersionsTool","getCollectionSchemaTool","restoreVersionTool","updateDocumentTool","getConfigInfoTool","countGlobalVersionsTool","findGlobalTool","findGlobalVersionByIDTool","findGlobalVersionsTool","getGlobalSchemaTool","restoreGlobalVersionTool","updateGlobalTool","TOOL_BUILTINS","getConfigInfo","mcpName","tool","COLLECTION_BUILTINS","count","countVersions","requiresVersions","create","delete","duplicate","requiresDuplicateEnabled","find","findDistinct","findVersionByID","findVersions","getCollectionSchema","restoreVersion","update","COLLECTION_AUTH_BUILTINS","auth","forgotPassword","login","resetPassword","unlock","verify","GLOBAL_BUILTINS","countGlobalVersions","findGlobalVersionByID","findGlobalVersions","getGlobalSchema","restoreGlobalVersion","TOOL_BUILTIN_ENTRIES","Object","entries","COLLECTION_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTIN_ENTRIES","GLOBAL_BUILTIN_ENTRIES"],"mappings":"AAEA,SACEA,kBAAkB,EAClBC,4BAA4B,EAC5BC,mBAAmB,EACnBC,2BAA2B,EAC3BC,oBAAoB,EACpBC,oBAAoB,QACf,qCAAoC;AAC3C,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,6CAA4C;A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BAExD;AAED,OAAO,MAAMgC,kCAAkCH,OAAOC,OAAO,CAACf,0BAE7D;AAED,OAAO,MAAMkB,yBAAyBJ,OAAOC,OAAO,CAACR,iBAEpD"}
1
+ {"version":3,"sources":["../../src/mcp/builtinTools.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool, Tool } from '../types.js'\n\nimport {\n authCollectionTool,\n forgotPasswordCollectionTool,\n loginCollectionTool,\n resetPasswordCollectionTool,\n unlockCollectionTool,\n verifyCollectionTool,\n} from './builtin/collections/authTools.js'\nimport { countDocumentsTool } from './builtin/collections/countTool.js'\nimport { countVersionsTool } from './builtin/collections/countVersionsTool.js'\nimport { createDocumentTool } from './builtin/collections/createTool.js'\nimport { deleteDocumentsTool } from './builtin/collections/deleteTool.js'\nimport { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'\nimport { findDistinctTool } from './builtin/collections/findDistinctTool.js'\nimport { findDocumentsTool } from './builtin/collections/findTool.js'\nimport { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'\nimport { findVersionsTool } from './builtin/collections/findVersionsTool.js'\nimport { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'\nimport { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'\nimport { updateDocumentTool } from './builtin/collections/updateTool.js'\nimport { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'\nimport { getConfigInfoTool } from './builtin/getConfigInfoTool.js'\nimport { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'\nimport { findGlobalTool } from './builtin/globals/findTool.js'\nimport { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'\nimport { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'\nimport { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'\nimport { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'\nimport { updateGlobalTool } from './builtin/globals/updateTool.js'\n\ntype CollectionBuiltin = {\n mcpName: string\n requiresDuplicateEnabled?: boolean\n requiresUpload?: boolean\n requiresVersions?: boolean\n tool: CollectionTool\n}\n\ntype GlobalBuiltin = {\n mcpName: string\n requiresVersions?: boolean\n tool: GlobalTool\n}\n\nexport const TOOL_BUILTINS = {\n getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },\n} satisfies Record<string, { mcpName: string; tool: Tool }>\n\n/**\n * The static built-in collection CRUD tools. Keys here are the source of truth\n * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type\n * automatically.\n */\nexport const COLLECTION_BUILTINS = {\n count: { mcpName: 'countDocuments', tool: countDocumentsTool },\n countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },\n create: { mcpName: 'createDocument', tool: createDocumentTool },\n delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },\n duplicate: {\n mcpName: 'duplicateDocument',\n requiresDuplicateEnabled: true,\n tool: duplicateDocumentTool,\n },\n find: { mcpName: 'findDocuments', tool: findDocumentsTool },\n findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },\n findVersionByID: {\n mcpName: 'findVersionByID',\n requiresVersions: true,\n tool: findVersionByIDTool,\n },\n findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },\n getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },\n getUploadInstructions: {\n mcpName: 'getUploadInstructions',\n requiresUpload: true,\n tool: getUploadInstructionsTool,\n },\n restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },\n update: { mcpName: 'updateDocument', tool: updateDocumentTool },\n} satisfies Record<string, CollectionBuiltin>\n\n/**\n * The static auth tools surfaced under auth-enabled collections. Keys are the\n * source of truth for `MCPCollectionAuthToolName`.\n */\nexport const COLLECTION_AUTH_BUILTINS = {\n auth: { mcpName: 'auth', tool: authCollectionTool },\n forgotPassword: {\n mcpName: 'forgotPassword',\n tool: forgotPasswordCollectionTool,\n },\n login: { mcpName: 'login', tool: loginCollectionTool },\n resetPassword: {\n mcpName: 'resetPassword',\n tool: resetPasswordCollectionTool,\n },\n unlock: { mcpName: 'unlock', tool: unlockCollectionTool },\n verify: { mcpName: 'verify', tool: verifyCollectionTool },\n} satisfies Record<string, { mcpName: string; tool: CollectionTool }>\n\n/**\n * The static built-in global tools. Keys are the source of truth for\n * `MCPGlobalBuiltinName`.\n */\nexport const GLOBAL_BUILTINS = {\n countGlobalVersions: {\n mcpName: 'countGlobalVersions',\n requiresVersions: true,\n tool: countGlobalVersionsTool,\n },\n find: { mcpName: 'findGlobal', tool: findGlobalTool },\n findGlobalVersionByID: {\n mcpName: 'findGlobalVersionByID',\n requiresVersions: true,\n tool: findGlobalVersionByIDTool,\n },\n findGlobalVersions: {\n mcpName: 'findGlobalVersions',\n requiresVersions: true,\n tool: findGlobalVersionsTool,\n },\n getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },\n restoreGlobalVersion: {\n mcpName: 'restoreGlobalVersion',\n requiresVersions: true,\n tool: restoreGlobalVersionTool,\n },\n update: { mcpName: 'updateGlobal', tool: updateGlobalTool },\n} satisfies Record<string, GlobalBuiltin>\n\nexport type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS\n\nexport type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS\n\nexport type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS\n\nexport type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS\n\n/**\n * Pre-typed `Object.entries` for each registry. The cast from `string` to the\n * literal key union lives here once so consumers can iterate without their own\n * cast — TypeScript's `Object.entries` always widens keys to `string`, which\n * defeats the narrow type lookups on `MCPCollectionToolsMap`.\n */\nexport const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<\n [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]\n>\n\nexport const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<\n [MCPCollectionBuiltinName, CollectionBuiltin]\n>\n\nexport const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<\n [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]\n>\n\nexport const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<\n [MCPGlobalBuiltinName, GlobalBuiltin]\n>\n"],"names":["authCollectionTool","forgotPasswordCollectionTool","loginCollectionTool","resetPasswordCollectionTool","unlockCollectionTool","verifyCollectionTool","countDocumentsTool","countVersionsTool","createDocumentTool","deleteDocumentsTool","duplicateDocumentTool","findDistinctTool","findDocumentsTool","findVersionByIDTool","findVersionsTool","getCollectionSchemaTool","restoreVersionTool","updateDocumentTool","getUploadInstructionsTool","getConfigInfoTool","countGlobalVersionsTool","findGlobalTool","findGlobalVersionByIDTool","findGlobalVersionsTool","getGlobalSchemaTool","restoreGlobalVersionTool","updateGlobalTool","TOOL_BUILTINS","getConfigInfo","mcpName","tool","COLLECTION_BUILTINS","count","countVersions","requiresVersions","create","delete","duplicate","requiresDuplicateEnabled","find","findDistinct","findVersionByID","findVersions","getCollectionSchema","getUploadInstructions","requiresUpload","restoreVersion","update","COLLECTION_AUTH_BUILTINS","auth","forgotPassword","login","resetPassword","unlock","verify","GLOBAL_BUILTINS","countGlobalVersions","findGlobalVersionByID","findGlobalVersions","getGlobalSchema","restoreGlobalVersion","TOOL_BUILTIN_ENTRIES","Object","entries","COLLECTION_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTIN_ENTRIES","GLOBAL_BUILTIN_ENTRIES"],"mappings":"AAEA,SACEA,kBAAkB,EAClBC,4BAA4B,EAC5BC,mBAAmB,EACnBC,2BAA2B,EAC3BC,oBAAoB,EACpBC,oBAAoB,QACf,qCAAoC;AAC3C,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,kBAAkB,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uBC,OAAOC,OAAO,CAACpC,eAElD;AAED,OAAO,MAAMqC,6BAA6BF,OAAOC,OAAO,CAAChC,qBAExD;AAED,OAAO,MAAMkC,kCAAkCH,OAAOC,OAAO,CAACf,0BAE7D;AAED,OAAO,MAAMkB,yBAAyBJ,OAAOC,OAAO,CAACR,iBAEpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeMCPConfig.d.ts","sourceRoot":"","sources":["../../src/mcp/sanitizeMCPConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EAGN,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAMV,eAAe,EACf,wBAAwB,EACzB,MAAM,aAAa,CAAA;AAcpB;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,2BAG/B;IACD,MAAM,EAAE,MAAM,GAAG,eAAe,CAAA;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B,KAAG,wBA6DH,CAAA"}
1
+ {"version":3,"file":"sanitizeMCPConfig.d.ts","sourceRoot":"","sources":["../../src/mcp/sanitizeMCPConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EAGN,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAMV,eAAe,EACf,wBAAwB,EACzB,MAAM,aAAa,CAAA;AAcpB;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,8BAG3B;IACD,MAAM,EAAE,MAAM,GAAG,eAAe,CAAA;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B,KAAG,wBA6DH,CAAA"}
@@ -89,13 +89,16 @@ const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
89
89
  * Payload disables duplicate for auth collections by default unless the
90
90
  * collection explicitly opts back in with `disableDuplicate: false`.
91
91
  */ const isDuplicateDisabled = collection.disableDuplicate === true || Boolean(collection.auth) && collection.disableDuplicate !== false;
92
- for (const [toolKey, { mcpName, requiresDuplicateEnabled, requiresVersions, tool }] of COLLECTION_BUILTIN_ENTRIES){
92
+ for (const [toolKey, { mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool }] of COLLECTION_BUILTIN_ENTRIES){
93
93
  if (requiresVersions && !collection.versions) {
94
94
  continue;
95
95
  }
96
96
  if (requiresDuplicateEnabled && isDuplicateDisabled) {
97
97
  continue;
98
98
  }
99
+ if (requiresUpload && !collection.upload) {
100
+ continue;
101
+ }
99
102
  const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey];
100
103
  if (matchedConfigEntry === false) {
101
104
  continue;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionMCPItem,\n CollectionTool,\n GlobalMCPItem,\n GlobalTool,\n MCPItem,\n MCPPluginConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport { defaultAccess } from '../defaultAccess.js'\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n TOOL_BUILTIN_ENTRIES,\n TOOL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {\n if (configKey in TOOL_BUILTINS) {\n continue\n }\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n configKey,\n label: prompt.title ?? configKey,\n mcpName: configKey,\n prompt: { ...prompt, access: prompt.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n configKey,\n label: resource.title ?? configKey,\n mcpName: configKey,\n resource: { ...resource, access: resource.access ?? defaultAccess },\n })\n }\n\n return {\n disabled: pluginConfig.disabled,\n hooks: pluginConfig.hooks,\n items,\n mcp: pluginConfig.mcp,\n overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): CollectionMCPItem[] => {\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: CollectionMCPItem[] = []\n /**\n * Payload disables duplicate for auth collections by default unless the\n * collection explicitly opts back in with `disableDuplicate: false`.\n */\n const isDuplicateDisabled =\n collection.disableDuplicate === true ||\n (Boolean(collection.auth) && collection.disableDuplicate !== false)\n\n for (const [\n toolKey,\n { mcpName, requiresDuplicateEnabled, requiresVersions, tool },\n ] of COLLECTION_BUILTIN_ENTRIES) {\n if (requiresVersions && !collection.versions) {\n continue\n }\n if (requiresDuplicateEnabled && isDuplicateDisabled) {\n continue\n }\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: toolKey,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: authToolKey,\n label: annotations.title ?? authToolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): GlobalMCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: GlobalMCPItem[] = []\n\n for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {\n if (requiresVersions && !global.versions) {\n continue\n }\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'globalTool',\n configKey: toolKey,\n globalSlug: slug,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n globalPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n configKey,\n globalSlug: slug,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n"],"names":["defaultAccess","COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","TOOL_BUILTIN_ENTRIES","TOOL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","configKey","mcpName","tool","type","label","annotations","title","access","Object","entries","tools","prompt","prompts","resource","resources","disabled","hooks","mcp","overrideGetAuthorizedMCP","slug","collectionPluginConfig","isDuplicateDisabled","disableDuplicate","Boolean","auth","toolKey","requiresDuplicateEnabled","requiresVersions","versions","matchedConfigEntry","override","undefined","collectionSlug","description","overrideResponse","authToolKey","customEntries","customTool","globalPluginConfig","globalSlug"],"mappings":"AAmBA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,SACEC,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,EACfC,oBAAoB,EACpBC,aAAa,QACR,oBAAmB;AAE1B;;;;;;;;CAQC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAMC,QAAmB,EAAE;IAE3B,KAAK,MAAMC,cAAcH,OAAOI,WAAW,IAAI,EAAE,CAAE;QACjDF,MAAMG,IAAI,IAAIC,yBAAyB;YAAEH;YAAYF;QAAa;IACpE;IAEA,KAAK,MAAMM,UAAUP,OAAOQ,OAAO,IAAI,EAAE,CAAE;QACzCN,MAAMG,IAAI,IAAII,qBAAqB;YAAEF;YAAQN;QAAa;IAC5D;IAEA,KAAK,MAAM,CAACS,WAAW,EAAEC,OAAO,EAAEC,IAAI,EAAE,CAAC,IAAIf,qBAAsB;QACjEK,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH;YACAI,OAAOF,KAAKG,WAAW,EAAEC,SAASN;YAClCC;YACAC,MAAM;gBAAE,GAAGA,IAAI;gBAAEK,QAAQL,KAAKK,MAAM,IAAI3B;YAAc;QACxD;IACF;IAEA,KAAK,MAAM,CAACoB,WAAWE,KAAK,IAAIM,OAAOC,OAAO,CAAClB,aAAamB,KAAK,IAAI,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AMC,WAAW,OAAOD,uBAAuB,WAAWA,qBAAqBE;QAC/E,MAAM1B,cAAc;YAAE,GAAGH,KAAKG,WAAW;YAAE,GAAGyB,UAAUzB,WAAW;QAAC;QACpEb,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH,WAAWyB;YACXc,YAAYpB;YACZf,OAAOC,YAAYC,KAAK,IAAImB;YAC5BxB;YACAC,MAAM;gBACJ,GAAGA,IAAI;gBACPK,QAAQuB,UAAUvB,UAAUL,KAAKK,MAAM,IAAI3B;gBAC3CyB;gBACA4B,aAAaH,UAAUG,eAAe/B,KAAK+B,WAAW;gBACtDC,kBACEJ,UAAUI,oBACVI,oBAAoBJ,oBACpBhC,KAAKgC,gBAAgB;YACzB;QACF;IACF;IAEA,MAAME,gBAAgB5B,OAAOC,OAAO,CAAC6B,oBAAoB5B,SAAS,CAAC;IAGnE,KAAK,MAAM,CAACV,WAAWqC,WAAW,IAAID,cAAe;QACnD,IAAIpC,aAAad,iBAAiB;YAChC;QACF;QACA,IAAI,CAACmD,YAAY;YACf;QACF;QACA7C,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH;YACAuC,YAAYpB;YACZf,OAAOiC,WAAWhC,WAAW,EAAEC,SAASN;YACxCC,SAASD;YACTE,MAAM;gBAAE,GAAGmC,UAAU;gBAAE9B,QAAQ8B,WAAW9B,MAAM,IAAI3B;YAAc;QACpE;IACF;IAEA,OAAOY;AACT"}
1
+ {"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionMCPItem,\n CollectionTool,\n GlobalMCPItem,\n GlobalTool,\n MCPItem,\n MCPPluginConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport { defaultAccess } from '../defaultAccess.js'\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n TOOL_BUILTIN_ENTRIES,\n TOOL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {\n if (configKey in TOOL_BUILTINS) {\n continue\n }\n items.push({\n type: 'tool',\n configKey,\n label: tool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...tool, access: tool.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n configKey,\n label: prompt.title ?? configKey,\n mcpName: configKey,\n prompt: { ...prompt, access: prompt.access ?? defaultAccess },\n })\n }\n\n for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n configKey,\n label: resource.title ?? configKey,\n mcpName: configKey,\n resource: { ...resource, access: resource.access ?? defaultAccess },\n })\n }\n\n return {\n disabled: pluginConfig.disabled,\n hooks: pluginConfig.hooks,\n items,\n mcp: pluginConfig.mcp,\n overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): CollectionMCPItem[] => {\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: CollectionMCPItem[] = []\n /**\n * Payload disables duplicate for auth collections by default unless the\n * collection explicitly opts back in with `disableDuplicate: false`.\n */\n const isDuplicateDisabled =\n collection.disableDuplicate === true ||\n (Boolean(collection.auth) && collection.disableDuplicate !== false)\n\n for (const [\n toolKey,\n { mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },\n ] of COLLECTION_BUILTIN_ENTRIES) {\n if (requiresVersions && !collection.versions) {\n continue\n }\n if (requiresDuplicateEnabled && isDuplicateDisabled) {\n continue\n }\n if (requiresUpload && !collection.upload) {\n continue\n }\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: toolKey,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: authToolKey,\n label: annotations.title ?? authToolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): GlobalMCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: GlobalMCPItem[] = []\n\n for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {\n if (requiresVersions && !global.versions) {\n continue\n }\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n const annotations = { ...tool.annotations, ...override?.annotations }\n items.push({\n type: 'globalTool',\n configKey: toolKey,\n globalSlug: slug,\n label: annotations.title ?? toolKey,\n mcpName,\n tool: {\n ...tool,\n access: override?.access ?? tool.access ?? defaultAccess,\n annotations,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n globalPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n configKey,\n globalSlug: slug,\n label: customTool.annotations?.title ?? configKey,\n mcpName: configKey,\n tool: { ...customTool, access: customTool.access ?? defaultAccess },\n })\n }\n\n return items\n}\n"],"names":["defaultAccess","COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","TOOL_BUILTIN_ENTRIES","TOOL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","configKey","mcpName","tool","type","label","annotations","title","access","Object","entries","tools","prompt","prompts","resource","resources","disabled","hooks","mcp","overrideGetAuthorizedMCP","slug","collectionPluginConfig","isDuplicateDisabled","disableDuplicate","Boolean","auth","toolKey","requiresDuplicateEnabled","requiresUpload","requiresVersions","versions","upload","matchedConfigEntry","override","undefined","collectionSlug","description","overrideResponse","authToolKey","customEntries","customTool","globalPluginConfig","globalSlug"],"mappings":"AAmBA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,SACEC,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,EACfC,oBAAoB,EACpBC,aAAa,QACR,oBAAmB;AAE1B;;;;;;;;CAQC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAMC,QAAmB,EAAE;IAE3B,KAAK,MAAMC,cAAc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AAItC,aAAad,iBAAiB;YAChC;QACF;QACA,IAAI,CAACqD,YAAY;YACf;QACF;QACA/C,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH;YACAyC,YAAYtB;YACZf,OAAOmC,WAAWlC,WAAW,EAAEC,SAASN;YACxCC,SAASD;YACTE,MAAM;gBAAE,GAAGqC,UAAU;gBAAEhC,QAAQgC,WAAWhC,MAAM,IAAI3B;YAAc;QACpE;IACF;IAEA,OAAOY;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA2GhD,CAAA"}
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA4GhD,CAAA"}
package/dist/stdio.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-console */ import { serveStdio } from '@modelcontextprotocol/server/stdio';
2
2
  import { fileURLToPath, pathToFileURL } from 'node:url';
3
3
  import { createLocalReq, getPayload } from 'payload';
4
- import { findConfig } from 'payload/node';
4
+ import { findConfig, loadEnv } from 'payload/node';
5
5
  import { getAuthorizedMCP } from './endpoint/access.js';
6
6
  import { buildMcpServer } from './mcp/buildMcpServer.js';
7
7
  import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
@@ -19,6 +19,7 @@ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
19
19
  if (projectRoot) {
20
20
  process.chdir(projectRoot);
21
21
  }
22
+ loadEnv();
22
23
  const configPath = findConfig();
23
24
  const configModule = await import(pathToFileURL(configPath).toString());
24
25
  const config = await (configModule.default ?? configModule);
package/dist/stdio.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { Config, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { serveStdio } from '@modelcontextprotocol/server/stdio'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { SanitizedMCPPluginConfig } from './types.js'\n\nimport { getAuthorizedMCP } from './endpoint/access.js'\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Starts Payload's MCP server over stdin and stdout.\n *\n * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,\n * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n // MCP clients may start this command from another folder. Move to the Payload\n // project so findConfig() can find the config.\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as SanitizedConfig\n\n /**\n * stdout is only for MCP messages. The spec says the server must not write\n * logs there and may write them to stderr instead.\n *\n * The 2.0 client library recovers from stray stdout logs, but that behavior is not\n * guaranteed. Move Payload logs to stderr so Payload does not add invalid data\n * to stdout. Keep options from configurable loggers. Replace pre-built loggers\n * because their output cannot be redirected.\n *\n * @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio\n */\n const loggerConfig: { logger?: Config['logger'] } = config\n if (\n loggerConfig.logger &&\n typeof loggerConfig.logger === 'object' &&\n 'options' in loggerConfig.logger\n ) {\n loggerConfig.logger.destination = process.stderr\n } else {\n loggerConfig.logger = { destination: process.stderr, options: {} }\n }\n\n const payload = await getPayload({ config, cron: false, disableOnInit: true })\n\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n // The command also works when mcpPlugin() is not in the Payload config.\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fallbackPlugin: Plugin = (config) => config\n Object.assign(fallbackPlugin, {\n slug: '@payloadcms/plugin-mcp',\n sanitizedOptions: pluginConfig,\n })\n payload.config.plugins ??= []\n payload.config.plugins.push(fallbackPlugin)\n }\n\n const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS\n let overrideAccess = false\n\n if (overrideAccessEnv === 'true') {\n overrideAccess = true\n } else if (overrideAccessEnv && overrideAccessEnv !== 'false') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be \"true\" or \"false\".')\n }\n\n if (overrideAccess && process.env.NODE_ENV !== 'development') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.')\n }\n\n const headers = new Headers()\n if (process.env.PAYLOAD_MCP_AUTHORIZATION) {\n headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)\n }\n\n const req = await createLocalReq({ req: { headers } }, payload)\n req.payloadAPI = 'MCP' as const\n const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })\n\n const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {\n onerror: (err) => {\n // MCP messages use stdout, so write SDK errors to stderr.\n console.error('[payload-mcp] error serving MCP over stdio:', err)\n },\n })\n\n // Close the MCP server and Payload when the client disconnects or the process stops.\n let isShuttingDown = false\n const shutdown = async () => {\n if (isShuttingDown) {\n return\n }\n isShuttingDown = true\n\n try {\n await stdioServer.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n\n process.exit(0)\n }\n\n process.once('SIGINT', () => void shutdown())\n process.once('SIGTERM', () => void shutdown())\n process.stdin.once('close', () => void shutdown())\n}\n"],"names":["serveStdio","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","getAuthorizedMCP","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","loggerConfig","logger","destination","stderr","options","payload","cron","disableOnInit","pluginConfig","fallbackPlugin","Object","assign","slug","sanitizedOptions","plugins","push","overrideAccessEnv","env","PAYLOAD_MCP_OVERRIDE_ACCESS","overrideAccess","Error","NODE_ENV","headers","Headers","PAYLOAD_MCP_AUTHORIZATION","set","req","payloadAPI","authorizedMCP","stdioServer","onerror","err","console","error","isShuttingDown","shutdown","close","destroy","exit","once","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD,SAASC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AACpD,SAASC,UAAU,QAAQ,eAAc;AAIzC,SAASC,gBAAgB,QAAQ,uBAAsB;AACvD,SAASC,cAAc,QAAQ,0BAAyB;AACxD,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,kBAAkB,QAAQ,gCAA+B;AAElE;;;;;CAKC,GACD,OAAO,MAAMC,cAAc;IACzB,8EAA8E;IAC9E,+CAA+C;IAC/C,MAAMC,cAAcF,mBAAmBT,cAAc,YAAYY,GAAG;IACpE,IAAID,aAAa;QACfE,QAAQC,KAAK,CAACH;IAChB;IAEA,MAAMI,aAAaX;IACnB,MAAMY,eAAe,MAAM,MAAM,CAACf,cAAcc,YAAYE,QAAQ;IACpE,MAAMC,SAAU,MAAOF,CAAAA,aAAaG,OAAO,IAAIH,YAAW;IAE1D;;;;;;;;;;GAUC,GACD,MAAMI,eAA8CF;IACpD,IACEE,aAAaC,MAAM,IACnB,OAAOD,aAAaC,MAAM,KAAK,YAC/B,aAAaD,aAAaC,MAAM,EAChC;QACAD,aAAaC,MAAM,CAACC,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MO,eAAe;YAAE0C;YAAepB;YAAckB;QAAI,IAAI;QACzFI,SAAS,CAACC;YACR,0DAA0D;YAC1DC,QAAQC,KAAK,CAAC,+CAA+CF;QAC/D;IACF;IAEA,qFAAqF;IACrF,IAAIG,iBAAiB;IACrB,MAAMC,WAAW;QACf,IAAID,gBAAgB;YAClB;QACF;QACAA,iBAAiB;QAEjB,IAAI;YACF,MAAML,YAAYO,KAAK;QACzB,EAAE,OAAOL,KAAK;YACZC,QAAQC,KAAK,CAAC,uCAAuCF;QACvD;QAEA,IAAI;YACF,MAAM1B,QAAQgC,OAAO;QACvB,EAAE,OAAON,KAAK;YACZC,QAAQC,KAAK,CAAC,2CAA2CF;QAC3D;QAEAtC,QAAQ6C,IAAI,CAAC;IACf;IAEA7C,QAAQ8C,IAAI,CAAC,UAAU,IAAM,KAAKJ;IAClC1C,QAAQ8C,IAAI,CAAC,WAAW,IAAM,KAAKJ;IACnC1C,QAAQ+C,KAAK,CAACD,IAAI,CAAC,SAAS,IAAM,KAAKJ;AACzC,EAAC"}
1
+ {"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { Config, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { serveStdio } from '@modelcontextprotocol/server/stdio'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig, loadEnv } from 'payload/node'\n\nimport type { SanitizedMCPPluginConfig } from './types.js'\n\nimport { getAuthorizedMCP } from './endpoint/access.js'\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Starts Payload's MCP server over stdin and stdout.\n *\n * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,\n * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n // MCP clients may start this command from another folder. Move to the Payload\n // project so findConfig() can find the config.\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n loadEnv()\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as SanitizedConfig\n\n /**\n * stdout is only for MCP messages. The spec says the server must not write\n * logs there and may write them to stderr instead.\n *\n * The 2.0 client library recovers from stray stdout logs, but that behavior is not\n * guaranteed. Move Payload logs to stderr so Payload does not add invalid data\n * to stdout. Keep options from configurable loggers. Replace pre-built loggers\n * because their output cannot be redirected.\n *\n * @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio\n */\n const loggerConfig: { logger?: Config['logger'] } = config\n if (\n loggerConfig.logger &&\n typeof loggerConfig.logger === 'object' &&\n 'options' in loggerConfig.logger\n ) {\n loggerConfig.logger.destination = process.stderr\n } else {\n loggerConfig.logger = { destination: process.stderr, options: {} }\n }\n\n const payload = await getPayload({ config, cron: false, disableOnInit: true })\n\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n // The command also works when mcpPlugin() is not in the Payload config.\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fallbackPlugin: Plugin = (config) => config\n Object.assign(fallbackPlugin, {\n slug: '@payloadcms/plugin-mcp',\n sanitizedOptions: pluginConfig,\n })\n payload.config.plugins ??= []\n payload.config.plugins.push(fallbackPlugin)\n }\n\n const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS\n let overrideAccess = false\n\n if (overrideAccessEnv === 'true') {\n overrideAccess = true\n } else if (overrideAccessEnv && overrideAccessEnv !== 'false') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be \"true\" or \"false\".')\n }\n\n if (overrideAccess && process.env.NODE_ENV !== 'development') {\n throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.')\n }\n\n const headers = new Headers()\n if (process.env.PAYLOAD_MCP_AUTHORIZATION) {\n headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)\n }\n\n const req = await createLocalReq({ req: { headers } }, payload)\n req.payloadAPI = 'MCP' as const\n const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })\n\n const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {\n onerror: (err) => {\n // MCP messages use stdout, so write SDK errors to stderr.\n console.error('[payload-mcp] error serving MCP over stdio:', err)\n },\n })\n\n // Close the MCP server and Payload when the client disconnects or the process stops.\n let isShuttingDown = false\n const shutdown = async () => {\n if (isShuttingDown) {\n return\n }\n isShuttingDown = true\n\n try {\n await stdioServer.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n\n process.exit(0)\n }\n\n process.once('SIGINT', () => void shutdown())\n process.once('SIGTERM', () => void shutdown())\n process.stdin.once('close', () => void shutdown())\n}\n"],"names":["serveStdio","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","loadEnv","getAuthorizedMCP","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","loggerConfig","logger","destination","stderr","options","payload","cron","disableOnInit","pluginConfig","fallbackPlugin","Object","assign","slug","sanitizedOptions","plugins","push","overrideAccessEnv","env","PAYLOAD_MCP_OVERRIDE_ACCESS","overrideAccess","Error","NODE_ENV","headers","Headers","PAYLOAD_MCP_AUTHORIZATION","set","req","payloadAPI","authorizedMCP","stdioServer","onerror","err","console","error","isShuttingDown","shutdown","close","destroy","exit","once","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD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C,IAAI,CAAC,UAAU,IAAM,KAAKJ;IAClC1C,QAAQ8C,IAAI,CAAC,WAAW,IAAM,KAAKJ;IACnC1C,QAAQ+C,KAAK,CAACD,IAAI,CAAC,SAAS,IAAM,KAAKJ;AACzC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/utils/camelCase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAIzC,CAAA"}
1
+ {"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/utils/camelCase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MAIzC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveProjectRoot.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProjectRoot.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,IAAI,GAAG,MAS5D,CAAA"}
1
+ {"version":3,"file":"resolveProjectRoot.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProjectRoot.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,aAAc,MAAM,KAAG,IAAI,GAAG,MAS5D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"filterFieldsByAccess.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AAEhB,KAAK,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAClD,KAAK,sBAAsB,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAAI,sDAKlC;IACD,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,WAAW,EAAE,4BAA4B,CAAA;IACzC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,sBAAsB,KAAK,OAAO,CAAA;CAC3E,KAAG,cAAc,EAoFjB,CAAA"}
1
+ {"version":3,"file":"filterFieldsByAccess.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AAEhB,KAAK,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAClD,KAAK,sBAAsB,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,yDAK9B;IACD,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,WAAW,EAAE,4BAA4B,CAAA;IACzC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,sBAAsB,KAAK,OAAO,CAAA;CAC3E,KAAG,cAAc,EAoFjB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,GAAI,uCAItC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,mCAIlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
1
+ {"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,0CAIlC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,sCAI9B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,cAAc,KAAG,cA0B7D,CAAA"}
1
+ {"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,WAAY,cAAc,KAAG,cA0B7D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"toStandardSchema.d.ts","sourceRoot":"","sources":["../../src/utils/toStandardSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,gIAAgI;AAChI,eAAO,MAAM,gBAAgB,GAAI,QAAQ,eAAe,KAAG,sBAG/B,CAAA"}
1
+ {"version":3,"file":"toStandardSchema.d.ts","sourceRoot":"","sources":["../../src/utils/toStandardSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,gIAAgI;AAChI,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,sBAG/B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-mcp",
3
- "version": "4.0.0-internal.e387174",
3
+ "version": "4.0.0-internal.e7d4ebc",
4
4
  "description": "MCP (Model Context Protocol) capabilities with Payload",
5
5
  "keywords": [
6
6
  "plugin",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@payloadcms/eslint-config": "3.28.0",
64
- "payload": "4.0.0-internal.e387174"
64
+ "payload": "4.0.0-internal.e7d4ebc"
65
65
  },
66
66
  "peerDependencies": {
67
- "payload": "4.0.0-internal.e387174"
67
+ "payload": "4.0.0-internal.e7d4ebc"
68
68
  },
69
69
  "//deps_notes": {
70
70
  "zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
@@ -11,10 +11,11 @@ import {
11
11
  } from '../../../utils/getVirtualFieldNames.js'
12
12
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
13
13
  import { validateCollectionData } from '../validateEntityData.js'
14
+ import { fileInputSchema, resolveFile } from './fileInput.js'
14
15
  import { formatCollectionError } from './formatCollectionError.js'
15
16
 
16
17
  const DEFAULT_DESCRIPTION =
17
- 'Create a document in any collection by passing the collection slug and data.'
18
+ 'Create a document in any collection. Files can use a URL, base64, or an upload prepared by getUploadInstructions.'
18
19
 
19
20
  export const createDocumentTool = defineCollectionTool({
20
21
  access: (args) =>
@@ -52,6 +53,7 @@ export const createDocumentTool = defineCollectionTool({
52
53
  .string()
53
54
  .describe('Optional: fallback locale code to use when requested locale is not available')
54
55
  .optional(),
56
+ file: fileInputSchema.optional(),
55
57
  locale: z
56
58
  .string()
57
59
  .describe(
@@ -69,7 +71,7 @@ export const createDocumentTool = defineCollectionTool({
69
71
  const payload = req.payload
70
72
  const logger = getLogger({ payload })
71
73
 
72
- const { data, depth, draft, fallbackLocale, locale, select } = input
74
+ const { data, depth, draft, fallbackLocale, file: fileInput, locale, select } = input
73
75
 
74
76
  logger.info(
75
77
  `Creating document in collection: ${collectionSlug}${locale ? ` with locale: ${locale}` : ''}`,
@@ -85,6 +87,7 @@ export const createDocumentTool = defineCollectionTool({
85
87
  }
86
88
 
87
89
  const parsedData = transformPointDataToPayload(inputData)
90
+ const file = await resolveFile({ collectionSlug, input: fileInput, req })
88
91
 
89
92
  const result = await payload.create({
90
93
  collection: collectionSlug,
@@ -93,6 +96,7 @@ export const createDocumentTool = defineCollectionTool({
93
96
  draft,
94
97
  overrideAccess: authorizedMCP.overrideAccess,
95
98
  req,
99
+ ...(file ? { file } : {}),
96
100
  ...(locale ? { locale } : {}),
97
101
  ...(fallbackLocale ? { fallbackLocale } : {}),
98
102
  ...(select ? { select: select as SelectType } : {}),