@payloadcms/plugin-mcp 4.0.0-canary.1 → 4.0.0-canary.10

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 (222) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +7 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/defineTool.d.ts +8 -8
  8. package/dist/defineTool.d.ts.map +1 -1
  9. package/dist/endpoint/access.d.ts +12 -5
  10. package/dist/endpoint/access.d.ts.map +1 -1
  11. package/dist/endpoint/access.js +75 -88
  12. package/dist/endpoint/access.js.map +1 -1
  13. package/dist/endpoint/index.d.ts +1 -1
  14. package/dist/endpoint/index.d.ts.map +1 -1
  15. package/dist/endpoint/index.js +68 -17
  16. package/dist/endpoint/index.js.map +1 -1
  17. package/dist/exports/client.d.ts +1 -1
  18. package/dist/exports/client.d.ts.map +1 -1
  19. package/dist/exports/client.js +1 -1
  20. package/dist/exports/client.js.map +1 -1
  21. package/dist/exports/internal.d.ts +2 -0
  22. package/dist/exports/internal.d.ts.map +1 -0
  23. package/dist/exports/internal.js +3 -0
  24. package/dist/exports/internal.js.map +1 -0
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +15 -20
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/buildMcpServer.d.ts +4 -4
  30. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  31. package/dist/mcp/buildMcpServer.js +34 -10
  32. package/dist/mcp/buildMcpServer.js.map +1 -1
  33. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  34. package/dist/mcp/builtin/collections/authTools.js +44 -6
  35. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  36. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  37. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  38. package/dist/mcp/builtin/collections/countTool.js +68 -0
  39. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  40. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  41. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/createTool.js +26 -24
  46. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  47. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/deleteTool.js +10 -2
  49. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  51. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  52. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  53. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  54. package/dist/mcp/builtin/collections/fileInput.d.ts +20 -0
  55. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  56. package/dist/mcp/builtin/collections/fileInput.js +100 -0
  57. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  58. package/dist/mcp/builtin/collections/fileInput.spec.js +72 -0
  59. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  60. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  61. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  62. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  63. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  64. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  65. package/dist/mcp/builtin/collections/findTool.js +46 -26
  66. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  67. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  68. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  70. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  71. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  74. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  76. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  77. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
  78. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  79. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +55 -4
  80. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  81. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  82. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  83. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  84. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  85. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  86. package/dist/mcp/builtin/collections/updateTool.js +37 -32
  87. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  88. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  89. package/dist/mcp/builtin/getConfigInfoTool.js +27 -8
  90. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  91. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  92. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  94. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  95. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  96. package/dist/mcp/builtin/globals/findTool.js +19 -22
  97. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  98. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  99. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  100. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  101. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  102. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  103. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  104. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  105. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  106. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  107. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +32 -2
  108. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  109. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  112. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/updateTool.js +14 -21
  114. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  115. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  116. package/dist/mcp/builtin/validateEntityData.js +1 -1
  117. package/dist/mcp/builtin/validateEntityData.js.map +1 -1
  118. package/dist/mcp/builtinTools.d.ts +69 -12
  119. package/dist/mcp/builtinTools.d.ts.map +1 -1
  120. package/dist/mcp/builtinTools.js +66 -10
  121. package/dist/mcp/builtinTools.js.map +1 -1
  122. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  123. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  124. package/dist/mcp/sanitizeMCPConfig.js +69 -27
  125. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  126. package/dist/stdio.d.ts +3 -3
  127. package/dist/stdio.d.ts.map +1 -1
  128. package/dist/stdio.js +82 -45
  129. package/dist/stdio.js.map +1 -1
  130. package/dist/types.d.ts +100 -87
  131. package/dist/types.d.ts.map +1 -1
  132. package/dist/types.js +2 -4
  133. package/dist/types.js.map +1 -1
  134. package/dist/utils/camelCase.d.ts.map +1 -1
  135. package/dist/utils/getPluginConfig.d.ts +1 -1
  136. package/dist/utils/getPluginConfig.js +1 -1
  137. package/dist/utils/getPluginConfig.js.map +1 -1
  138. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  139. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  140. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  141. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  142. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  143. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
  144. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  145. package/dist/utils/schemaConversion/getEntityInputSchema.js +44 -12
  146. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
  147. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  148. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  149. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  150. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  151. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  152. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  153. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  154. package/package.json +10 -15
  155. package/src/defaultAccess.ts +3 -0
  156. package/src/endpoint/access.ts +81 -101
  157. package/src/endpoint/index.ts +58 -16
  158. package/src/exports/client.ts +2 -1
  159. package/src/exports/internal.ts +1 -0
  160. package/src/index.ts +12 -20
  161. package/src/mcp/buildMcpServer.ts +48 -21
  162. package/src/mcp/builtin/collections/authTools.ts +45 -9
  163. package/src/mcp/builtin/collections/countTool.ts +73 -0
  164. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  165. package/src/mcp/builtin/collections/createTool.ts +27 -18
  166. package/src/mcp/builtin/collections/deleteTool.ts +11 -2
  167. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  168. package/src/mcp/builtin/collections/fileInput.spec.ts +79 -0
  169. package/src/mcp/builtin/collections/fileInput.ts +139 -0
  170. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  171. package/src/mcp/builtin/collections/findTool.ts +59 -20
  172. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  173. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  174. package/src/mcp/builtin/collections/formatCollectionError.ts +1 -1
  175. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +51 -3
  176. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  177. package/src/mcp/builtin/collections/updateTool.ts +39 -23
  178. package/src/mcp/builtin/getConfigInfoTool.ts +27 -4
  179. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  180. package/src/mcp/builtin/globals/findTool.ts +27 -18
  181. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  182. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  183. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +37 -2
  184. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  185. package/src/mcp/builtin/globals/updateTool.ts +16 -16
  186. package/src/mcp/builtin/validateEntityData.ts +1 -1
  187. package/src/mcp/builtinTools.ts +72 -16
  188. package/src/mcp/sanitizeMCPConfig.ts +48 -30
  189. package/src/stdio.ts +77 -45
  190. package/src/types.ts +108 -90
  191. package/src/utils/getPluginConfig.ts +1 -1
  192. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  193. package/src/utils/schemaConversion/getEntityInputSchema.ts +45 -27
  194. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  195. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  196. package/dist/collection/getAccessField.d.ts +0 -12
  197. package/dist/collection/getAccessField.d.ts.map +0 -1
  198. package/dist/collection/getAccessField.js +0 -57
  199. package/dist/collection/getAccessField.js.map +0 -1
  200. package/dist/collection/index.d.ts +0 -6
  201. package/dist/collection/index.d.ts.map +0 -1
  202. package/dist/collection/index.js +0 -60
  203. package/dist/collection/index.js.map +0 -1
  204. package/dist/components/AccessField/index.client.d.ts +0 -10
  205. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  206. package/dist/components/AccessField/index.client.js +0 -305
  207. package/dist/components/AccessField/index.client.js.map +0 -1
  208. package/dist/components/AccessField/index.css +0 -93
  209. package/dist/utils/localAPIDefaults.d.ts +0 -20
  210. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  211. package/dist/utils/localAPIDefaults.js +0 -19
  212. package/dist/utils/localAPIDefaults.js.map +0 -1
  213. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  214. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  215. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  216. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  217. package/src/collection/getAccessField.ts +0 -64
  218. package/src/collection/index.ts +0 -64
  219. package/src/components/AccessField/index.client.tsx +0 -347
  220. package/src/components/AccessField/index.css +0 -93
  221. package/src/utils/localAPIDefaults.ts +0 -22
  222. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -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 {\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 * - Applies the `userCollection` default\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, { label, mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {\n items.push({\n type: 'tool',\n configKey,\n label,\n mcpName,\n tool,\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: configKey,\n mcpName: configKey,\n tool,\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,\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,\n })\n }\n\n // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.\n const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,\n overrideAuth: pluginConfig.overrideAuth,\n userCollection:\n pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): CollectionMCPItem[] => {\n if (collection.slug === 'payload-mcp-api-keys') {\n return []\n }\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: CollectionMCPItem[] = []\n\n for (const [toolKey, { mcpName, tool }] of COLLECTION_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: toolKey,\n label: capitalize(toolKey),\n mcpName,\n tool: {\n ...tool,\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, { label, 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 items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: authToolKey,\n label,\n mcpName,\n tool: {\n ...tool,\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: configKey,\n mcpName: configKey,\n tool: customTool,\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, tool }] of GLOBAL_BUILTIN_ENTRIES) {\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'globalTool',\n configKey: toolKey,\n globalSlug: slug,\n label: capitalize(toolKey),\n mcpName,\n tool: {\n ...tool,\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: configKey,\n mcpName: configKey,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)\n"],"names":["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","label","mcpName","tool","type","Object","entries","tools","prompt","prompts","title","resource","resources","firstCollectionWithAuth","find","auth","Boolean","disabled","mcp","overrideApiKeyCollection","overrideAuth","userCollection","admin","user","slug","collectionPluginConfig","toolKey","matchedConfigEntry","override","undefined","collectionSlug","capitalize","description","overrideResponse","authToolKey","customEntries","customTool","globalPluginConfig","globalSlug","s","charAt","toUpperCase","slice"],"mappings":"AAmBA,SACEA,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,EACfC,oBAAoB,EACpBC,aAAa,QACR,oBAAmB;AAE1B;;;;;;;;;CASC,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,KAAK,EAAEC,OAAO,EAAEC,IAAI,EAAE,CAAC,IAAIhB,qBAAsB;QACxEK,MAAMG,IAAI,CAAC;YACTS,M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,OAAO5C;AACT;AAEA,MAAMuC,aAAa,CAACQ,IAAsBA,EAAEC,MAAM,CAAC,GAAGC,WAAW,KAAKF,EAAEG,KAAK,CAAC"}
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,CAAC,GAAI;QACxE,IAAIV,aAAaZ,eAAe;YAC9B;QACF;QACAI,MAAMG,IAAI,CAAC;YACTQ,MAAM;YACNH;YACAI,OAAOF,KAAKG,WAAW,EAAEC,SAASN;YAClCC,SAASD;YACTE,MAAM;gBAAE,GAAGA,IAAI;gBAAEK,QAAQL,KAAKK,MAAM,IAAI3B;YAAc;QACxD;IACF;IAEA,KAAK,MAAM,CAACoB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AGA,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"}
package/dist/stdio.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Stdio adapter for the Payload MCP server.
2
+ * Starts Payload's MCP server over stdin and stdout.
3
3
  *
4
- * Do not use in production. There's no auth; whoever can spawn the process gets
5
- * full access to your local data.
4
+ * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
5
+ * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
6
6
  */
7
7
  export declare const runMcpStdio: () => Promise<void>;
8
8
  //# sourceMappingURL=stdio.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA4EhD,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,CA2GhD,CAAA"}
package/dist/stdio.js CHANGED
@@ -1,76 +1,113 @@
1
- /* eslint-disable no-console */ import { StdioServerTransport } from '@modelcontextprotocol/server';
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
4
  import { findConfig } from 'payload/node';
5
+ import { getAuthorizedMCP } from './endpoint/access.js';
5
6
  import { buildMcpServer } from './mcp/buildMcpServer.js';
6
7
  import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
7
8
  import { getPluginConfig } from './utils/getPluginConfig.js';
8
9
  import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
9
10
  /**
10
- * Stdio adapter for the Payload MCP server.
11
+ * Starts Payload's MCP server over stdin and stdout.
11
12
  *
12
- * Do not use in production. There's no auth; whoever can spawn the process gets
13
- * full access to your local data.
13
+ * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
14
+ * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
14
15
  */ export const runMcpStdio = async ()=>{
15
- /**
16
- * If MCP clients spawn stdio servers from an arbitrary working directory,
17
- * Payload's cwd-anchored `findConfig()` can't locate the project on
18
- * its own. This module always lives inside the project's `node_modules`, so
19
- * we derive the project root from its own path and `chdir` into it.
20
- *
21
- * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
22
- * layouts (e.g. a monorepo where the package is hoisted above the app) can
23
- * fall back to it. See the implementation of findConfig for details.
24
- */ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url));
16
+ // MCP clients may start this command from another folder. Move to the Payload
17
+ // project so findConfig() can find the config.
18
+ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url));
25
19
  if (projectRoot) {
26
20
  process.chdir(projectRoot);
27
21
  }
28
22
  const configPath = findConfig();
29
23
  const configModule = await import(pathToFileURL(configPath).toString());
30
24
  const config = await (configModule.default ?? configModule);
25
+ /**
26
+ * stdout is only for MCP messages. The spec says the server must not write
27
+ * logs there and may write them to stderr instead.
28
+ *
29
+ * The 2.0 client library recovers from stray stdout logs, but that behavior is not
30
+ * guaranteed. Move Payload logs to stderr so Payload does not add invalid data
31
+ * to stdout. Keep options from configurable loggers. Replace pre-built loggers
32
+ * because their output cannot be redirected.
33
+ *
34
+ * @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio
35
+ */ const loggerConfig = config;
36
+ if (loggerConfig.logger && typeof loggerConfig.logger === 'object' && 'options' in loggerConfig.logger) {
37
+ loggerConfig.logger.destination = process.stderr;
38
+ } else {
39
+ loggerConfig.logger = {
40
+ destination: process.stderr,
41
+ options: {}
42
+ };
43
+ }
31
44
  const payload = await getPayload({
32
- config
45
+ config,
46
+ cron: false,
47
+ disableOnInit: true
33
48
  });
34
- /**
35
- * If the user added `mcpPlugin({...})` to their `plugins` array, read the
36
- * sanitized config they registered. Otherwise fall back to the defaults. That way,
37
- * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,
38
- * even if the plugin is not added to the plugins array.
39
- */ let pluginConfig;
49
+ let pluginConfig;
40
50
  try {
41
51
  pluginConfig = getPluginConfig({
42
52
  config: payload.config
43
53
  });
44
54
  } catch {
55
+ // The command also works when mcpPlugin() is not in the Payload config.
45
56
  pluginConfig = sanitizeMCPConfig({
46
57
  config: payload.config,
47
58
  pluginConfig: {}
48
59
  });
49
- const fakePluginFn = (config)=>config;
50
- fakePluginFn.slug = '@payloadcms/plugin-mcp';
51
- // @ts-expect-error
52
- fakePluginFn.sanitizedOptions = pluginConfig;
53
- (payload.config.plugins ??= []).push(fakePluginFn);
60
+ const fallbackPlugin = (config)=>config;
61
+ Object.assign(fallbackPlugin, {
62
+ slug: '@payloadcms/plugin-mcp',
63
+ sanitizedOptions: pluginConfig
64
+ });
65
+ payload.config.plugins ??= [];
66
+ payload.config.plugins.push(fallbackPlugin);
54
67
  }
55
- const authorizedMCP = {
56
- items: pluginConfig.items,
57
- overrideAccess: true,
58
- user: null
59
- };
60
- const req = await createLocalReq({}, payload);
68
+ const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS;
69
+ let overrideAccess = false;
70
+ if (overrideAccessEnv === 'true') {
71
+ overrideAccess = true;
72
+ } else if (overrideAccessEnv && overrideAccessEnv !== 'false') {
73
+ throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be "true" or "false".');
74
+ }
75
+ if (overrideAccess && process.env.NODE_ENV !== 'development') {
76
+ throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.');
77
+ }
78
+ const headers = new Headers();
79
+ if (process.env.PAYLOAD_MCP_AUTHORIZATION) {
80
+ headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION);
81
+ }
82
+ const req = await createLocalReq({
83
+ req: {
84
+ headers
85
+ }
86
+ }, payload);
61
87
  req.payloadAPI = 'MCP';
62
- const server = buildMcpServer({
63
- authorizedMCP,
64
- pluginConfig,
88
+ const authorizedMCP = await getAuthorizedMCP({
89
+ overrideAccess,
65
90
  req
66
91
  });
67
- const transport = new StdioServerTransport();
68
- await server.connect(transport);
69
- // Process now lives until stdin closes. Wire graceful shutdown so DB
70
- // connections (and any other Payload-managed resources) get released.
71
- const shutdown = async (code = 0)=>{
92
+ const stdioServer = serveStdio(()=>buildMcpServer({
93
+ authorizedMCP,
94
+ pluginConfig,
95
+ req
96
+ }), {
97
+ onerror: (err)=>{
98
+ // MCP messages use stdout, so write SDK errors to stderr.
99
+ console.error('[payload-mcp] error serving MCP over stdio:', err);
100
+ }
101
+ });
102
+ // Close the MCP server and Payload when the client disconnects or the process stops.
103
+ let isShuttingDown = false;
104
+ const shutdown = async ()=>{
105
+ if (isShuttingDown) {
106
+ return;
107
+ }
108
+ isShuttingDown = true;
72
109
  try {
73
- await server.close();
110
+ await stdioServer.close();
74
111
  } catch (err) {
75
112
  console.error('[payload-mcp] error closing server:', err);
76
113
  }
@@ -79,11 +116,11 @@ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
79
116
  } catch (err) {
80
117
  console.error('[payload-mcp] error destroying payload:', err);
81
118
  }
82
- process.exit(code);
119
+ process.exit(0);
83
120
  };
84
- process.on('SIGINT', ()=>void shutdown(0));
85
- process.on('SIGTERM', ()=>void shutdown(0));
86
- process.stdin.on('close', ()=>void shutdown(0));
121
+ process.once('SIGINT', ()=>void shutdown());
122
+ process.once('SIGTERM', ()=>void shutdown());
123
+ process.stdin.once('close', ()=>void shutdown());
87
124
  };
88
125
 
89
126
  //# sourceMappingURL=stdio.js.map
package/dist/stdio.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { AuthorizedMCP, SanitizedMCPPluginConfig } from './types.js'\n\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 * Stdio adapter for the Payload MCP server.\n *\n * Do not use in production. There's no auth; whoever can spawn the process gets\n * full access to your local data.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n /**\n * If MCP clients spawn stdio servers from an arbitrary working directory,\n * Payload's cwd-anchored `findConfig()` can't locate the project on\n * its own. This module always lives inside the project's `node_modules`, so\n * we derive the project root from its own path and `chdir` into it.\n *\n * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual\n * layouts (e.g. a monorepo where the package is hoisted above the app) can\n * fall back to it. See the implementation of findConfig for details.\n */\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 MaybePromise<SanitizedConfig>\n\n const payload = await getPayload({ config })\n\n /**\n * If the user added `mcpPlugin({...})` to their `plugins` array, read the\n * sanitized config they registered. Otherwise fall back to the defaults. That way,\n * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,\n * even if the plugin is not added to the plugins array.\n */\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fakePluginFn: Plugin = (config) => config\n fakePluginFn.slug = '@payloadcms/plugin-mcp'\n // @ts-expect-error\n fakePluginFn.sanitizedOptions = pluginConfig\n\n // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work\n ;(payload.config.plugins ??= []).push(fakePluginFn)\n }\n\n const authorizedMCP: AuthorizedMCP = {\n items: pluginConfig.items,\n overrideAccess: true,\n user: null,\n }\n\n const req = await createLocalReq({}, payload)\n req.payloadAPI = 'MCP' as const\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // Process now lives until stdin closes. Wire graceful shutdown so DB\n // connections (and any other Payload-managed resources) get released.\n const shutdown = async (code = 0) => {\n try {\n await server.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n process.exit(code)\n }\n\n process.on('SIGINT', () => void shutdown(0))\n process.on('SIGTERM', () => void shutdown(0))\n process.stdin.on('close', () => void shutdown(0))\n}\n"],"names":["StdioServerTransport","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","payload","pluginConfig","fakePluginFn","slug","sanitizedOptions","plugins","push","authorizedMCP","items","overrideAccess","user","req","payloadAPI","server","transport","connect","shutdown","code","close","err","console","error","destroy","exit","on","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD,SAASC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AACpD,SAASC,UAAU,QAAQ,eAAc;AAIzC,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;;;;;;;;;GASC,GACD,MAAMC,cAAcF,mBAAmBR,cAAc,YAAYW,GAAG;IACpE,IAAID,aAAa;QACfE,QAAQC,KAAK,CAACH;IAChB;IAEA,MAAMI,aAAaV;IACnB,MAAMW,eAAe,MAAM,MAAM,CAACd,cAAca,YAAYE,QAAQ;IACpE,MAAMC,SAAU,MAAOF,CAAAA,aAAaG,OAAO,IAAIH,YAAW;IAE1D,MAAMI,UAAU,MAAMhB,WAAW;QAAEc;IAAO;IAE1C;;;;;GAKC,GACD,IAAIG;IACJ,IAAI;QACFA,eAAeb,gBAAgB;YAAEU,QAAQE,QAAQF,MAAM;QAAC;IAC1D,EAAE,OAAM;QACNG,eAAed,kBAAkB;YAAEW,QAAQE,QAAQF,MAAM;YAAEG,cAAc,CAAC;QAAE;QAE5E,MAAMC,eAAuB,CAACJ,SAAWA;QACzCI,aAAaC,IAAI,GAAG;QACpB,mBAAmB;QACnBD,aAAaE,gBAAgB,GAAGH;QAG9BD,CAAAA,QAAQF,MAAM,CAACO,OAAO,KAAK,EAAE,AAAD,EAAGC,IAAI,CAACJ;IACxC;IAEA,MAAMK,gBAA+B;QACnCC,OAAOP,aAAaO,KAAK;QACzBC,gBAAgB;QAChBC,MAAM;IACR;IAEA,MAAMC,MAAM,MAAM5B,eAAe,CAAC,GAAGiB;IACrCW,IAAIC,UAAU,GAAG;IAEjB,MAAMC,SAAS3B,eAAe;QAAEqB;QAAeN;QAAcU;IAAI;IAEjE,MAAMG,YAAY,IAAIlC;IACtB,MAAMiC,OAAOE,OAAO,CAACD;IAErB,qEAAqE;IACrE,sEAAsE;IACtE,MAAME,WAAW,OAAOC,OAAO,CAAC;QAC9B,IAAI;YACF,MAAMJ,OAAOK,KAAK;QACpB,EAAE,OAAOC,KAAK;YACZC,QAAQC,KAAK,CAAC,uCAAuCF;QACvD;QACA,IAAI;YACF,MAAMnB,QAAQsB,OAAO;QACvB,EAAE,OAAOH,KAAK;YACZC,QAAQC,KAAK,CAAC,2CAA2CF;QAC3D;QACA1B,QAAQ8B,IAAI,CAACN;IACf;IAEAxB,QAAQ+B,EAAE,CAAC,UAAU,IAAM,KAAKR,SAAS;IACzCvB,QAAQ+B,EAAE,CAAC,WAAW,IAAM,KAAKR,SAAS;IAC1CvB,QAAQgC,KAAK,CAACD,EAAE,CAAC,SAAS,IAAM,KAAKR,SAAS;AAChD,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 } 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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,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"}
package/dist/types.d.ts CHANGED
@@ -1,32 +1,16 @@
1
- import type { CallToolResult, ContentBlock, JsonSchemaType, McpServer, ResourceTemplate, ServerContext, StandardSchemaWithJSON } from '@modelcontextprotocol/server';
2
- import type { AuthCollectionSlug, CollectionConfig, CollectionSlug, DefaultDocumentIDType, GlobalSlug, MaybePromise, PayloadRequest, TypedUser } from 'payload';
1
+ import type { CallToolResult, ContentBlock, JsonSchemaType, McpServer, ResourceTemplate, ServerContext, StandardSchemaWithJSON, ToolAnnotations } from '@modelcontextprotocol/server';
2
+ import type { AuthCollectionSlug, CollectionSlug, GlobalSlug, MaybePromise, PayloadRequest, SanitizedPermissions } from 'payload';
3
+ import type { GetAuthorizedMCPArgs } from './endpoint/access.js';
3
4
  import type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName } from './mcp/builtinTools.js';
4
5
  export type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName };
5
- /** Re-exported from `@modelcontextprotocol/server` — the JSON Schema shape the MCP runtime validates against. */
6
- export type { JsonSchemaType, StandardSchemaWithJSON };
6
+ /** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */
7
+ export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations };
7
8
  /**
8
9
  * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
9
- * JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
10
+ * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
11
+ * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
10
12
  */
11
13
  export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON;
12
- /**
13
- * Serializable mirror of `SanitizedMCPPluginConfig` for client components —
14
- * the full sanitized config carries functions (tool handlers, etc.) that can't
15
- * cross the server→client boundary. Built by `sanitizeClientPluginConfig` and
16
- * passed to the `AccessField` component via `clientProps`.
17
- *
18
- * @internal
19
- */
20
- export type ClientMCPPluginConfig = {
21
- items: Array<{
22
- collectionSlug?: string;
23
- configKey: string;
24
- description: string;
25
- globalSlug?: string;
26
- label: string;
27
- type: 'collectionTool' | 'globalTool' | 'prompt' | 'resource' | 'tool';
28
- }>;
29
- };
30
14
  export type MCPToolResponse = {
31
15
  content: ContentBlock[];
32
16
  /**
@@ -37,11 +21,27 @@ export type MCPToolResponse = {
37
21
  doc?: Record<string, unknown>;
38
22
  } & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>;
39
23
  export type MCPResponseOverride = (response: MCPToolResponse, doc: Record<string, unknown>, req: PayloadRequest) => MCPToolResponse;
24
+ export type MCPAfterToolCallHook = (args: {
25
+ input: unknown;
26
+ req: PayloadRequest;
27
+ response: MCPToolResponse;
28
+ toolName: string;
29
+ }) => MaybePromise<MCPToolResponse>;
40
30
  /**
41
31
  * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
42
32
  * its inferred output; anything else falls back to `Record<string, unknown>`.
43
33
  */
44
34
  export type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON ? StandardSchemaWithJSON extends TSchema ? Record<string, unknown> : StandardSchemaWithJSON.InferOutput<TSchema> : Record<string, unknown>;
35
+ export type MCPAccessArgs = {
36
+ permissions?: SanitizedPermissions;
37
+ req: PayloadRequest;
38
+ };
39
+ export type CollectionMCPAccessArgs = {
40
+ collectionSlug: CollectionSlug;
41
+ } & MCPAccessArgs;
42
+ export type GlobalMCPAccessArgs = {
43
+ globalSlug: GlobalSlug;
44
+ } & MCPAccessArgs;
45
45
  export type ToolHandlerArgs<TSchema = undefined> = {
46
46
  authorizedMCP: AuthorizedMCP;
47
47
  input: TypedInput<TSchema>;
@@ -55,6 +55,13 @@ export type GlobalToolHandlerArgs<TSchema = undefined> = {
55
55
  globalSlug: GlobalSlug;
56
56
  } & ToolHandlerArgs<TSchema>;
57
57
  export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
58
+ /**
59
+ * Runs while authorizing each MCP request, before the tool is advertised or called. Return
60
+ * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
61
+ * is enabled.
62
+ */
63
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
64
+ annotations?: ToolAnnotations;
58
65
  description: string;
59
66
  handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
60
67
  input?: TSchema;
@@ -64,19 +71,50 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
64
71
  overrideResponse?: MCPResponseOverride;
65
72
  };
66
73
  export type CollectionTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
74
+ /**
75
+ * Runs while authorizing each MCP request for this collection. Return `false` to reject calls
76
+ * to this tool for the collection. The shared tool is not advertised when no collections allow
77
+ * it, but can remain advertised when it is available for another collection. This is skipped
78
+ * when `overrideAccess` is enabled.
79
+ */
80
+ access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
67
81
  handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
68
82
  input?: TSchema;
69
- } & Pick<Tool, 'description' | 'overrideResponse'>;
83
+ } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>;
70
84
  export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
85
+ /**
86
+ * Runs while authorizing each MCP request for this global. Return `false` to reject calls to
87
+ * this tool for the global. The shared tool is not advertised when no globals allow it, but
88
+ * can remain advertised when it is available for another global. This is skipped when
89
+ * `overrideAccess` is enabled.
90
+ */
91
+ access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
71
92
  handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
72
93
  input?: TSchema;
73
- } & Pick<Tool, 'description' | 'overrideResponse'>;
94
+ } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>;
74
95
  /**
75
96
  * Configures (or disables) a built-in tool without replacing it.
76
97
  * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a
77
98
  * required handler) from being silently accepted at a built-in key slot.
78
99
  */
79
- export type MCPBuiltInToolOverride = {
100
+ export type MCPBuiltInCollectionToolOverride = {
101
+ /**
102
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
103
+ * this collection. This is skipped when `overrideAccess` is enabled.
104
+ */
105
+ access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
106
+ annotations?: ToolAnnotations;
107
+ description?: string;
108
+ handler?: never;
109
+ overrideResponse?: MCPResponseOverride;
110
+ };
111
+ export type MCPBuiltInGlobalToolOverride = {
112
+ /**
113
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
114
+ * this global. This is skipped when `overrideAccess` is enabled.
115
+ */
116
+ access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
117
+ annotations?: ToolAnnotations;
80
118
  description?: string;
81
119
  handler?: never;
82
120
  overrideResponse?: MCPResponseOverride;
@@ -88,19 +126,19 @@ export type MCPBuiltInToolOverride = {
88
126
  */
89
127
  export type MCPTopLevelToolEntry = Tool;
90
128
  export type MCPCollectionToolsMap = {
91
- [customToolName: string]: boolean | CollectionTool | MCPBuiltInToolOverride | undefined;
129
+ [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined;
92
130
  } & {
93
- [K in MCPCollectionBuiltinName]?: false | MCPBuiltInToolOverride;
131
+ [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride;
94
132
  };
95
133
  export type MCPAuthCollectionToolsMap = {
96
- [K in MCPCollectionAuthToolName]?: MCPBuiltInToolOverride | true;
134
+ [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true;
97
135
  } & MCPCollectionToolsMap;
98
136
  /** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */
99
137
  export type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug ? MCPAuthCollectionToolsMap : MCPCollectionToolsMap;
100
138
  export type MCPGlobalToolsMap = {
101
- [customToolName: string]: boolean | GlobalTool | MCPBuiltInToolOverride | undefined;
139
+ [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined;
102
140
  } & {
103
- [K in MCPGlobalBuiltinName]?: false | MCPBuiltInToolOverride;
141
+ [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride;
104
142
  };
105
143
  export type MCPTopLevelToolsMap = Record<string, Tool>;
106
144
  export type PromptHandlerArgs<TSchema = undefined> = {
@@ -109,6 +147,12 @@ export type PromptHandlerArgs<TSchema = undefined> = {
109
147
  serverContext: ServerContext;
110
148
  };
111
149
  export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
150
+ /**
151
+ * Runs while authorizing each MCP request, before the prompt is advertised or used. Return
152
+ * `false` to make the prompt unavailable for that request. This is skipped when
153
+ * `overrideAccess` is enabled.
154
+ */
155
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
112
156
  argsSchema: TSchema;
113
157
  description: string;
114
158
  handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{
@@ -130,6 +174,12 @@ export type ResourceHandlerArgs = {
130
174
  uri: URL;
131
175
  };
132
176
  export type Resource = {
177
+ /**
178
+ * Runs while authorizing each MCP request, before the resource is advertised or read. Return
179
+ * `false` to make the resource unavailable for that request. This is skipped when
180
+ * `overrideAccess` is enabled.
181
+ */
182
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
133
183
  description: string;
134
184
  handler: (args: ResourceHandlerArgs) => MaybePromise<{
135
185
  contents: Array<{
@@ -163,81 +213,47 @@ export type MCPPluginConfig = {
163
213
  collections?: {
164
214
  [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>;
165
215
  };
166
- /** Skip MCP registration. The API key collection is still added (so DB / types stay stable). */
216
+ /** Skip MCP endpoint registration. */
167
217
  disabled?: boolean;
168
218
  globals?: {
169
219
  [Slug in GlobalSlug]?: MCPPluginGlobalConfig;
170
220
  };
221
+ hooks?: {
222
+ /** Transform a tool response after its handler returns */
223
+ afterToolCall?: MCPAfterToolCallHook[];
224
+ };
171
225
  mcp?: {
172
226
  serverOptions?: MCPServerOptions;
173
227
  verboseLogs?: boolean;
174
228
  };
175
- overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig;
176
- /** Replace the default API-key auth with a custom resolver. */
177
- overrideAuth?: (args: {
178
- getAPIKeyDoc: (overrideApiKey?: string) => Promise<MCPAPIKeysDoc>;
179
- getAuthorizedMCP: (args: {
180
- apiKeyDoc: MCPAPIKeysDoc;
181
- }) => AuthorizedMCP;
229
+ /**
230
+ * Replace the default MCP authorization resolver.
231
+ *
232
+ * This hook replaces the default authentication flow. It must set `req.user` to the
233
+ * authenticated Payload user, or to `null` for an anonymous caller, before returning.
234
+ */
235
+ overrideGetAuthorizedMCP?: (args: {
182
236
  pluginConfig: SanitizedMCPPluginConfig;
183
- req: PayloadRequest;
184
- }) => MaybePromise<AuthorizedMCP>;
237
+ } & GetAuthorizedMCPArgs) => MaybePromise<AuthorizedMCP>;
185
238
  prompts?: Record<string, Prompt>;
186
239
  resources?: Record<string, Resource>;
187
240
  /** Cross-cutting tools (not scoped to any collection or global). */
188
241
  tools?: MCPTopLevelToolsMap;
189
- userCollection?: CollectionSlug;
190
242
  };
191
243
  export type SanitizedMCPPluginConfig = {
192
244
  items: MCPItem[];
193
- userCollection: CollectionSlug;
194
- } & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideApiKeyCollection' | 'overrideAuth'>;
245
+ } & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>;
195
246
  export type MCPServerOptions = {
196
247
  options?: ConstructorParameters<typeof McpServer>[1];
197
248
  serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>;
198
249
  };
199
250
  /**
200
- * Nested access tree as stored in the collection.
201
- * A `false` leaf disables that tool; missing keys defer to
202
- * defaults (built-in CRUD is on, opt-in tools are off).
203
- */
204
- export type MCPAPIKeysDocAccessTree = {
205
- collections?: {
206
- [CollectionSlug: CollectionSlug]: {
207
- [ToolKey: string]: boolean;
208
- };
209
- };
210
- globals?: {
211
- [GlobalSlug: GlobalSlug]: {
212
- [ToolKey: string]: boolean;
213
- };
214
- };
215
- prompts?: {
216
- [PromptKey: string]: boolean;
217
- };
218
- resources?: {
219
- [ResourceKey: string]: boolean;
220
- };
221
- tools?: {
222
- [ToolKey: string]: boolean;
223
- };
224
- };
225
- /**
226
- * Stored on `payload-mcp-api-keys` docs
227
- */
228
- export type MCPAPIKeysDoc = {
229
- access: MCPAPIKeysDocAccessTree;
230
- id: DefaultDocumentIDType;
231
- overrideAccess?: boolean;
232
- user: null | TypedUser;
233
- };
234
- /**
235
- * One MCP primitive plus the metadata needed for access checks, admin UI, and
251
+ * One MCP primitive plus the metadata needed for config-driven filtering and
236
252
  * registration.
237
253
  *
238
- * - `configKey`: the config/API-key identifier, e.g. `find` or `echo`.
254
+ * - `configKey`: the config identifier, e.g. `find` or `echo`.
239
255
  * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.
240
- * - `label`: human-readable admin checkbox text.
256
+ * - `label`: human-readable display text.
241
257
  */
242
258
  export type MCPItemBase = {
243
259
  configKey: string;
@@ -265,14 +281,11 @@ export type MCPItem = ({
265
281
  type: 'tool';
266
282
  } & MCPItemBase) | CollectionMCPItem | GlobalMCPItem;
267
283
  /**
268
- * The caller's identity + the MCP items they can use for this request. Returned
269
- * by `getAuthorizedMCP`; denied items are simply absent from `items`. Handlers
270
- * receive this via `args.authorizedMCP` so they can spread
271
- * `localAPIDefaults(authorizedMCP)` into every local API call.
284
+ * The MCP items and access mode authorized for this request. The authenticated user is available
285
+ * as `req.user`.
272
286
  */
273
287
  export type AuthorizedMCP = {
274
288
  items: MCPItem[];
275
289
  overrideAccess: boolean;
276
- user: null | TypedUser;
277
290
  };
278
291
  //# sourceMappingURL=types.d.ts.map