@payloadcms/plugin-mcp 4.0.0-canary.20 → 4.0.0-canary.20261117

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 (219) hide show
  1. package/bin.js +0 -7
  2. package/dist/endpoint/access.d.ts +20 -4
  3. package/dist/endpoint/access.d.ts.map +1 -1
  4. package/dist/endpoint/access.js +73 -11
  5. package/dist/endpoint/access.js.map +1 -1
  6. package/dist/endpoint/index.d.ts.map +1 -1
  7. package/dist/endpoint/index.js +58 -4
  8. package/dist/endpoint/index.js.map +1 -1
  9. package/dist/endpoint/oauth.d.ts +37 -0
  10. package/dist/endpoint/oauth.d.ts.map +1 -0
  11. package/dist/endpoint/oauth.js +105 -0
  12. package/dist/endpoint/oauth.js.map +1 -0
  13. package/dist/endpoint/oauthLoginToken.d.ts +27 -0
  14. package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
  15. package/dist/endpoint/oauthLoginToken.js +86 -0
  16. package/dist/endpoint/oauthLoginToken.js.map +1 -0
  17. package/dist/endpoint/oauthServer.d.ts +28 -0
  18. package/dist/endpoint/oauthServer.d.ts.map +1 -0
  19. package/dist/endpoint/oauthServer.js +455 -0
  20. package/dist/endpoint/oauthServer.js.map +1 -0
  21. package/dist/exports/client.d.ts +1 -1
  22. package/dist/exports/client.d.ts.map +1 -1
  23. package/dist/exports/client.js +1 -1
  24. package/dist/exports/client.js.map +1 -1
  25. package/dist/exports/rsc.d.ts +2 -0
  26. package/dist/exports/rsc.d.ts.map +1 -0
  27. package/dist/exports/rsc.js +3 -0
  28. package/dist/exports/rsc.js.map +1 -0
  29. package/dist/index.d.ts +10 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +34 -10
  32. package/dist/index.js.map +1 -1
  33. package/dist/mcp/buildMcpServer.d.ts +2 -2
  34. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  35. package/dist/mcp/buildMcpServer.js +36 -24
  36. package/dist/mcp/buildMcpServer.js.map +1 -1
  37. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  38. package/dist/mcp/builtin/collections/authTools.js +80 -56
  39. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  40. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  41. package/dist/mcp/builtin/collections/countTool.js +9 -14
  42. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  43. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  44. package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
  45. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  46. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  47. package/dist/mcp/builtin/collections/createTool.js +48 -49
  48. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  49. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/deleteTool.js +47 -44
  51. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  53. package/dist/mcp/builtin/collections/duplicateTool.js +31 -37
  54. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  55. package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
  56. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/fileInput.js +34 -70
  58. package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
  59. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  60. package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
  61. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  62. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  63. package/dist/mcp/builtin/collections/findTool.js +28 -46
  64. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  65. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  66. package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
  67. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  68. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  69. package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
  70. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  71. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  72. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +30 -14
  73. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  74. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  75. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  76. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  77. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  78. package/dist/mcp/builtin/collections/updateTool.js +55 -87
  79. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  80. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
  81. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
  82. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  83. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  84. package/dist/mcp/builtin/formatEntityError.js +55 -0
  85. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  86. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  87. package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
  88. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  89. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  90. package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
  91. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  92. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  93. package/dist/mcp/builtin/globals/findTool.js +10 -16
  94. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  95. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  96. package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
  97. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  98. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  99. package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
  100. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  101. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  102. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +29 -13
  103. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  104. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  105. package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
  106. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  107. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  108. package/dist/mcp/builtin/globals/updateTool.js +27 -36
  109. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  110. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  111. package/dist/mcp/sanitizeMCPConfig.js +4 -0
  112. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  113. package/dist/stdio.js +4 -3
  114. package/dist/stdio.js.map +1 -1
  115. package/dist/types.d.ts +131 -10
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/types.js.map +1 -1
  118. package/dist/utils/seal.d.ts +17 -0
  119. package/dist/utils/seal.d.ts.map +1 -0
  120. package/dist/utils/seal.js +24 -0
  121. package/dist/utils/seal.js.map +1 -0
  122. package/dist/utils/toStandardSchema.js.map +1 -1
  123. package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
  124. package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
  125. package/dist/views/Authorize/AllowButtons/index.js +88 -0
  126. package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
  127. package/dist/views/Authorize/index.css +19 -0
  128. package/dist/views/Authorize/index.d.ts +9 -0
  129. package/dist/views/Authorize/index.d.ts.map +1 -0
  130. package/dist/views/Authorize/index.js +98 -0
  131. package/dist/views/Authorize/index.js.map +1 -0
  132. package/package.json +30 -28
  133. package/src/endpoint/access.ts +81 -9
  134. package/src/endpoint/index.ts +50 -4
  135. package/src/endpoint/oauth.ts +108 -0
  136. package/src/endpoint/oauthLoginToken.ts +100 -0
  137. package/src/endpoint/oauthServer.ts +472 -0
  138. package/src/exports/client.ts +1 -1
  139. package/src/exports/rsc.ts +1 -0
  140. package/src/index.ts +53 -9
  141. package/src/mcp/buildMcpServer.ts +40 -30
  142. package/src/mcp/builtin/collections/authTools.ts +82 -71
  143. package/src/mcp/builtin/collections/countTool.ts +9 -21
  144. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  145. package/src/mcp/builtin/collections/createTool.ts +71 -96
  146. package/src/mcp/builtin/collections/deleteTool.ts +40 -66
  147. package/src/mcp/builtin/collections/duplicateTool.ts +36 -86
  148. package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
  149. package/src/mcp/builtin/collections/fileInput.ts +44 -81
  150. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  151. package/src/mcp/builtin/collections/findTool.ts +24 -106
  152. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  153. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  154. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +23 -12
  155. package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -57
  156. package/src/mcp/builtin/collections/updateTool.ts +55 -109
  157. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
  158. package/src/mcp/builtin/formatEntityError.ts +77 -0
  159. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  160. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  161. package/src/mcp/builtin/globals/findTool.ts +13 -52
  162. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  163. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  164. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +21 -11
  165. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  166. package/src/mcp/builtin/globals/updateTool.ts +38 -61
  167. package/src/mcp/sanitizeMCPConfig.ts +2 -0
  168. package/src/stdio.ts +2 -2
  169. package/src/types.ts +130 -10
  170. package/src/utils/seal.ts +46 -0
  171. package/src/utils/toStandardSchema.ts +1 -1
  172. package/src/views/Authorize/AllowButtons/index.tsx +97 -0
  173. package/src/views/Authorize/index.css +19 -0
  174. package/src/views/Authorize/index.tsx +100 -0
  175. package/dist/mcp/builtin/collections/fileInput.spec.js +0 -86
  176. package/dist/mcp/builtin/collections/fileInput.spec.js.map +0 -1
  177. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  178. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  179. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  180. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  181. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  182. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  183. package/dist/mcp/builtin/validateEntityData.js +0 -82
  184. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  185. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  186. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  187. package/dist/utils/getVirtualFieldNames.js +0 -35
  188. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  189. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  190. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  191. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  192. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  193. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  194. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  195. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  196. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  197. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  198. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  199. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  200. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  201. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  202. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  203. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  204. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  205. package/dist/utils/transformPointDataToPayload.js +0 -28
  206. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  207. package/dist/utils/whereSchema.d.ts +0 -9
  208. package/dist/utils/whereSchema.d.ts.map +0 -1
  209. package/dist/utils/whereSchema.js +0 -13
  210. package/dist/utils/whereSchema.js.map +0 -1
  211. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  212. package/src/mcp/builtin/validateEntityData.ts +0 -132
  213. package/src/utils/getVirtualFieldNames.ts +0 -53
  214. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  215. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  216. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  217. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  218. package/src/utils/transformPointDataToPayload.ts +0 -40
  219. package/src/utils/whereSchema.ts +0 -24
@@ -0,0 +1,97 @@
1
+ 'use client'
2
+
3
+ import { Button } from '@payloadcms/ui'
4
+ import React, { useEffect, useState, useSyncExternalStore } from 'react'
5
+
6
+ const baseClass = 'mcp-authorize'
7
+
8
+ /** How long the page must have been in front of the user before the buttons work, in ms. */
9
+ const enableDelay = 1000
10
+
11
+ // Whether the page is inside a frame never changes, so there's nothing to subscribe to
12
+ const subscribe = () => () => {}
13
+
14
+ /**
15
+ * The Allow and Deny buttons, protected against clicks the user didn't mean for this page:
16
+ *
17
+ * - Inside a frame they aren't shown, so other sites can't frame the page and trick users into
18
+ * clicking them. The server can't tell, so they're missing until the browser has checked.
19
+ * - They're disabled until the page has been visible and focused for a moment. Otherwise another
20
+ * site could open the page under the user's cursor while they double-click something else, so
21
+ * the second click lands on Allow. Leaving the page disables them again. Waiting works for every
22
+ * way of clicking, unlike requiring a mouse movement or key press first.
23
+ *
24
+ * @see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-17#section-7.11 for why the
25
+ * OAuth server must prevent clickjacking
26
+ * @see https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html#defending-against-doubleclickjacking
27
+ * for the double-click attack and its mitigation
28
+ */
29
+ export function AllowButtons() {
30
+ const isTopLevel = useSyncExternalStore(
31
+ subscribe,
32
+ () => window.top === window.self,
33
+ () => false,
34
+ )
35
+ const [isEnabled, setIsEnabled] = useState(false)
36
+
37
+ useEffect(() => {
38
+ let timeout: ReturnType<typeof setTimeout> | undefined
39
+
40
+ const enableAfterDelay = () => {
41
+ clearTimeout(timeout)
42
+ if (document.visibilityState === 'visible' && document.hasFocus()) {
43
+ timeout = setTimeout(() => setIsEnabled(true), enableDelay)
44
+ }
45
+ }
46
+ const disable = () => {
47
+ clearTimeout(timeout)
48
+ setIsEnabled(false)
49
+ }
50
+ const onVisibilityChange = () => {
51
+ if (document.visibilityState === 'visible') {
52
+ enableAfterDelay()
53
+ } else {
54
+ disable()
55
+ }
56
+ }
57
+
58
+ enableAfterDelay()
59
+ window.addEventListener('focus', enableAfterDelay)
60
+ window.addEventListener('blur', disable)
61
+ document.addEventListener('visibilitychange', onVisibilityChange)
62
+
63
+ return () => {
64
+ clearTimeout(timeout)
65
+ window.removeEventListener('focus', enableAfterDelay)
66
+ window.removeEventListener('blur', disable)
67
+ document.removeEventListener('visibilitychange', onVisibilityChange)
68
+ }
69
+ }, [])
70
+
71
+ if (!isTopLevel) {
72
+ return null
73
+ }
74
+
75
+ return (
76
+ <div className={`${baseClass}__actions`}>
77
+ <Button
78
+ buttonStyle="primary"
79
+ disabled={!isEnabled}
80
+ extraButtonProps={{ name: 'decision', value: 'allow' }}
81
+ margin={false}
82
+ type="submit"
83
+ >
84
+ Allow
85
+ </Button>
86
+ <Button
87
+ buttonStyle="secondary"
88
+ disabled={!isEnabled}
89
+ extraButtonProps={{ name: 'decision', value: 'deny' }}
90
+ margin={false}
91
+ type="submit"
92
+ >
93
+ Deny
94
+ </Button>
95
+ </div>
96
+ )
97
+ }
@@ -0,0 +1,19 @@
1
+ @layer payload-default {
2
+ .mcp-authorize {
3
+ overflow-wrap: anywhere;
4
+ }
5
+
6
+ .mcp-authorize__brand {
7
+ display: flex;
8
+ justify-content: center;
9
+ width: 100%;
10
+ margin-block-end: var(--spacer-5);
11
+ }
12
+
13
+ .mcp-authorize__actions {
14
+ display: flex;
15
+ flex-wrap: wrap;
16
+ justify-content: center;
17
+ gap: var(--spacer-2);
18
+ }
19
+ }
@@ -0,0 +1,100 @@
1
+ import type { AdminViewServerProps } from 'payload'
2
+
3
+ import { FormHeader, Logo, MinimalTemplate } from '@payloadcms/ui/rsc'
4
+ import { formatAdminURL } from 'payload/shared'
5
+ import React from 'react'
6
+
7
+ import type { AuthorizeViewError, Client, Consent } from '../../endpoint/oauthServer.js'
8
+
9
+ // eslint-disable-next-line payload/no-imports-from-exports-dir -- Server component must reference exports dir for proper client boundary
10
+ import { AllowButtons } from '../../exports/client.js'
11
+ import { unseal } from '../../utils/seal.js'
12
+ import './index.css'
13
+
14
+ const baseClass = 'mcp-authorize'
15
+
16
+ const restartSignIn = 'Start the sign-in again from your MCP client.'
17
+
18
+ const errorMessages: Record<AuthorizeViewError, { description: string; heading: string }> = {
19
+ expired: { description: restartSignIn, heading: 'This sign-in request expired' },
20
+ forbidden: {
21
+ description: 'Ask an admin of this app if you need access.',
22
+ heading: "Your account can't use MCP clients",
23
+ },
24
+ 'invalid-link': { description: restartSignIn, heading: 'This sign-in link is invalid' },
25
+ }
26
+
27
+ /**
28
+ * The admin page where users allow an MCP client to use their account, for the built-in OAuth
29
+ * server. Its authorize endpoint sends users here with the consent to show, or with an error.
30
+ */
31
+ export function MCPAuthorizeView({
32
+ initPageResult,
33
+ params,
34
+ searchParams,
35
+ server,
36
+ user,
37
+ }: AdminViewServerProps) {
38
+ const { locale, permissions, req } = initPageResult
39
+ const { i18n, payload } = req
40
+ const sealedConsent = getSearchParam(searchParams?.consent)
41
+ const consent = unseal<Consent>({ type: 'consent', req, value: sealedConsent })
42
+ const client = consent && unseal<Client>({ type: 'client', req, value: consent.clientID })
43
+ // The consent is only valid for the user it was made for
44
+ const isConsentValid =
45
+ client &&
46
+ consent &&
47
+ req.user?.id === consent.userID &&
48
+ req.user.collection === consent.collection
49
+ const errorParam = getSearchParam(searchParams?.error)
50
+ const error: AuthorizeViewError =
51
+ errorParam === 'forbidden' || errorParam === 'invalid-link' ? errorParam : 'expired'
52
+ const account = String(user?.email ?? consent?.userID)
53
+ const returnHost = consent && (new URL(consent.redirectURI).host || consent.redirectURI)
54
+
55
+ return (
56
+ <MinimalTemplate className={baseClass}>
57
+ <div className={`${baseClass}__brand`}>
58
+ <Logo
59
+ i18n={i18n}
60
+ locale={locale}
61
+ params={params}
62
+ payload={payload}
63
+ permissions={permissions}
64
+ searchParams={searchParams}
65
+ server={server}
66
+ user={user}
67
+ />
68
+ </div>
69
+ {/* Not translated yet, so screen readers in other admin languages read it as English */}
70
+ <div lang="en">
71
+ {isConsentValid ? (
72
+ <>
73
+ <FormHeader
74
+ description={`It will be able to use this app's MCP tools as ${account}, and you will return to ${returnHost}.`}
75
+ heading={`Allow ${client.name} to use your account?`}
76
+ />
77
+ <form
78
+ action={formatAdminURL({
79
+ apiRoute: payload.config.routes.api,
80
+ path: '/mcp/oauth/authorize',
81
+ })}
82
+ method="post"
83
+ >
84
+ <input name="consent" type="hidden" value={sealedConsent!} />
85
+ <AllowButtons />
86
+ </form>
87
+ </>
88
+ ) : (
89
+ <FormHeader
90
+ description={errorMessages[error].description}
91
+ heading={errorMessages[error].heading}
92
+ />
93
+ )}
94
+ </div>
95
+ </MinimalTemplate>
96
+ )
97
+ }
98
+
99
+ const getSearchParam = (value: string | string[] | undefined): null | string =>
100
+ typeof value === 'string' ? value : null
@@ -1,86 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { fileInputSchema, resolveFile } from './fileInput.js';
3
- describe('MCP file input', ()=>{
4
- it('should reject malformed MIME types', ()=>{
5
- const result = fileInputSchema.safeParse({
6
- data: 'aGVsbG8=',
7
- mimeType: 'text/plain\r\nx-test: value',
8
- name: 'hello.txt',
9
- source: 'base64'
10
- });
11
- expect(result.success).toBe(false);
12
- });
13
- it('should accept a prepared upload', ()=>{
14
- const result = fileInputSchema.safeParse({
15
- file: {
16
- filename: 'image.png',
17
- mimeType: 'image/png',
18
- size: 123,
19
- uploadReference: {
20
- uploadId: 'upload-id'
21
- }
22
- },
23
- source: 'uploadReference'
24
- });
25
- expect(result.success).toBe(true);
26
- });
27
- it('should reject oversized base64 files', async ()=>{
28
- const req = createRequest({
29
- maxFileSize: 4
30
- });
31
- await expect(resolveFile({
32
- collectionSlug: 'media',
33
- input: {
34
- data: Buffer.from('hello').toString('base64'),
35
- mimeType: 'text/plain',
36
- name: 'hello.txt',
37
- source: 'base64'
38
- },
39
- req
40
- })).rejects.toThrow('File exceeds the 4 byte upload limit.');
41
- });
42
- it('should reject URLs outside the collection allowlist', async ()=>{
43
- const req = createRequest({
44
- allowList: [
45
- {
46
- hostname: 'assets.example.com',
47
- protocol: 'https'
48
- }
49
- ]
50
- });
51
- await expect(resolveFile({
52
- collectionSlug: 'media',
53
- input: {
54
- source: 'externalURL',
55
- url: 'https://example.com/image.png'
56
- },
57
- req
58
- })).rejects.toThrow('The provided file URL is not allowed.');
59
- });
60
- });
61
- function createRequest({ allowList, maxFileSize }) {
62
- return {
63
- payload: {
64
- collections: {
65
- media: {
66
- config: {
67
- upload: allowList ? {
68
- pasteURL: {
69
- allowList
70
- }
71
- } : {}
72
- }
73
- }
74
- },
75
- config: {
76
- upload: {
77
- limits: {
78
- fileSize: maxFileSize
79
- }
80
- }
81
- }
82
- }
83
- };
84
- }
85
-
86
- //# sourceMappingURL=fileInput.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/fileInput.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { fileInputSchema, resolveFile } from './fileInput.js'\n\ndescribe('MCP file input', () => {\n it('should reject malformed MIME types', () => {\n const result = fileInputSchema.safeParse({\n data: 'aGVsbG8=',\n mimeType: 'text/plain\\r\\nx-test: value',\n name: 'hello.txt',\n source: 'base64',\n })\n\n expect(result.success).toBe(false)\n })\n\n it('should accept a prepared upload', () => {\n const result = fileInputSchema.safeParse({\n file: {\n filename: 'image.png',\n mimeType: 'image/png',\n size: 123,\n uploadReference: { uploadId: 'upload-id' },\n },\n source: 'uploadReference',\n })\n\n expect(result.success).toBe(true)\n })\n\n it('should reject oversized base64 files', async () => {\n const req = createRequest({ maxFileSize: 4 })\n\n await expect(\n resolveFile({\n collectionSlug: 'media',\n input: {\n data: Buffer.from('hello').toString('base64'),\n mimeType: 'text/plain',\n name: 'hello.txt',\n source: 'base64',\n },\n req,\n }),\n ).rejects.toThrow('File exceeds the 4 byte upload limit.')\n })\n\n it('should reject URLs outside the collection allowlist', async () => {\n const req = createRequest({\n allowList: [{ hostname: 'assets.example.com', protocol: 'https' }],\n })\n\n await expect(\n resolveFile({\n collectionSlug: 'media',\n input: {\n source: 'externalURL',\n url: 'https://example.com/image.png',\n },\n req,\n }),\n ).rejects.toThrow('The provided file URL is not allowed.')\n })\n})\n\nfunction createRequest({\n allowList,\n maxFileSize,\n}: {\n allowList?: Array<{ hostname: string; protocol: 'http' | 'https' }>\n maxFileSize?: number\n}): PayloadRequest {\n return {\n payload: {\n collections: {\n media: {\n config: {\n upload: allowList ? { pasteURL: { allowList } } : {},\n },\n },\n },\n config: {\n upload: {\n limits: {\n fileSize: maxFileSize,\n },\n },\n },\n },\n } as unknown as PayloadRequest\n}\n"],"names":["describe","expect","it","fileInputSchema","resolveFile","result","safeParse","data","mimeType","name","source","success","toBe","file","filename","size","uploadReference","uploadId","req","createRequest","maxFileSize","collectionSlug","input","Buffer","from","toString","rejects","toThrow","allowList","hostname","protocol","url","payload","collections","media","config","upload","pasteURL","limits","fileSize"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,eAAe,EAAEC,WAAW,QAAQ,iBAAgB;AAE7DJ,SAAS,kBAAkB;IACzBE,GAAG,sCAAsC;QACvC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCC,MAAM;YACNC,UAAU;YACVC,MAAM;YACNC,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,mCAAmC;QACpC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCO,MAAM;gBACJC,UAAU;gBACVN,UAAU;gBACVO,MAAM;gBACNC,iBAAiB;oBAAEC,UAAU;gBAAY;YAC3C;YACAP,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,wCAAwC;QACzC,MAAMgB,MAAMC,cAAc;YAAEC,aAAa;QAAE;QAE3C,MAAMnB,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLf,MAAMgB,OAAOC,IAAI,CAAC,SAASC,QAAQ,CAAC;gBACpCjB,UAAU;gBACVC,MAAM;gBACNC,QAAQ;YACV;YACAQ;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;IAEAzB,GAAG,uDAAuD;QACxD,MAAMgB,MAAMC,cAAc;YACxBS,WAAW;gBAAC;oBAAEC,UAAU;oBAAsBC,UAAU;gBAAQ;aAAE;QACpE;QAEA,MAAM7B,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLZ,QAAQ;gBACRqB,KAAK;YACP;YACAb;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;AACF;AAEA,SAASR,cAAc,EACrBS,SAAS,EACTR,WAAW,EAIZ;IACC,OAAO;QACLY,SAAS;YACPC,aAAa;gBACXC,OAAO;oBACLC,QAAQ;wBACNC,QAAQR,YAAY;4BAAES,UAAU;gCAAET;4BAAU;wBAAE,IAAI,CAAC;oBACrD;gBACF;YACF;YACAO,QAAQ;gBACNC,QAAQ;oBACNE,QAAQ;wBACNC,UAAUnB;oBACZ;gBACF;YACF;QACF;IACF;AACF"}
@@ -1,9 +0,0 @@
1
- import type { CollectionSlug, PayloadRequest } from 'payload';
2
- import type { MCPToolResponse } from '../../../types.js';
3
- export declare const formatCollectionError: ({ action, collectionSlug, error, req, }: {
4
- action: 'creating' | 'duplicating' | 'updating';
5
- collectionSlug: CollectionSlug;
6
- error: unknown;
7
- req: PayloadRequest;
8
- }) => MCPToolResponse;
9
- //# sourceMappingURL=formatCollectionError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,4CAK/B;IACD,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
@@ -1,60 +0,0 @@
1
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
2
- const getValidationErrors = (error)=>{
3
- if (!error || typeof error !== 'object') {
4
- return undefined;
5
- }
6
- const data = 'data' in error ? error.data : undefined;
7
- if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
8
- return undefined;
9
- }
10
- return data.errors;
11
- };
12
- const isSchemaError = (error, message)=>{
13
- if (getValidationErrors(error)) {
14
- return true;
15
- }
16
- const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined;
17
- return name === 'CastError' || name === 'ValidationError' || message.includes('Cast to ') || message.includes('validation failed');
18
- };
19
- export const formatCollectionError = ({ action, collectionSlug, error, req })=>{
20
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
21
- const errors = getValidationErrors(error) ?? [
22
- {
23
- message: errorMessage
24
- }
25
- ];
26
- if (!isSchemaError(error, errorMessage)) {
27
- return {
28
- content: [
29
- {
30
- type: 'text',
31
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`
32
- }
33
- ],
34
- isError: true
35
- };
36
- }
37
- const schema = getCollectionInputSchema({
38
- collectionSlug,
39
- req
40
- });
41
- const schemaText = schema ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\`` : '';
42
- return {
43
- content: [
44
- {
45
- type: 'text',
46
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`
47
- }
48
- ],
49
- isError: true,
50
- ...schema ? {
51
- structuredContent: {
52
- collectionSlug,
53
- errors,
54
- schema
55
- }
56
- } : {}
57
- };
58
- };
59
-
60
- //# sourceMappingURL=formatCollectionError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { MCPToolResponse } from '../../../types.js'\n\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nconst getValidationErrors = (error: unknown): undefined | unknown[] => {\n if (!error || typeof error !== 'object') {\n return undefined\n }\n\n const data = 'data' in error ? error.data : undefined\n if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {\n return undefined\n }\n\n return data.errors\n}\n\nconst isSchemaError = (error: unknown, message: string): boolean => {\n if (getValidationErrors(error)) {\n return true\n }\n\n const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined\n\n return (\n name === 'CastError' ||\n name === 'ValidationError' ||\n message.includes('Cast to ') ||\n message.includes('validation failed')\n )\n}\n\nexport const formatCollectionError = ({\n action,\n collectionSlug,\n error,\n req,\n}: {\n action: 'creating' | 'duplicating' | 'updating'\n collectionSlug: CollectionSlug\n error: unknown\n req: PayloadRequest\n}): MCPToolResponse => {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n const errors = getValidationErrors(error) ?? [{ message: errorMessage }]\n\n if (!isSchemaError(error, errorMessage)) {\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n\n const schema = getCollectionInputSchema({ collectionSlug, req })\n const schemaText = schema\n ? `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``\n : ''\n\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}${schemaText}`,\n },\n ],\n isError: true,\n ...(schema\n ? {\n structuredContent: {\n collectionSlug,\n errors,\n schema,\n },\n }\n : {}),\n }\n}\n"],"names":["getCollectionInputSchema","getValidationErrors","error","undefined","data","Array","isArray","errors","isSchemaError","message","name","includes","formatCollectionError","action","collectionSlug","req","errorMessage","Error","content","type","text","isError","schema","schemaText","JSON","stringify","structuredContent"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0DAAyD;AAElG,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,MAAMC,OAAO,UAAUF,QAAQA,MAAME,IAAI,GAAGD;IAC5C,IAAI,CAACC,QAAQ,OAAOA,SAAS,YAAY,CAAE,CAAA,YAAYA,IAAG,KAAM,CAACC,MAAMC,OAAO,CAACF,KAAKG,MAAM,GAAG;QAC3F,OAAOJ;IACT;IAEA,OAAOC,KAAKG,MAAM;AACpB;AAEA,MAAMC,gBAAgB,CAACN,OAAgBO;IACrC,IAAIR,oBAAoBC,QAAQ;QAC9B,OAAO;IACT;IAEA,MAAMQ,OAAOR,SAAS,OAAOA,UAAU,YAAY,UAAUA,QAAQA,MAAMQ,IAAI,GAAGP;IAElF,OACEO,SAAS,eACTA,SAAS,qBACTD,QAAQE,QAAQ,CAAC,eACjBF,QAAQE,QAAQ,CAAC;AAErB;AAEA,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,MAAM,EACNC,cAAc,EACdZ,KAAK,EACLa,GAAG,EAMJ;IACC,MAAMC,eAAed,iBAAiBe,QAAQf,MAAMO,OAAO,GAAG;IAC9D,MAAMF,SAASN,oBAAoBC,UAAU;QAAC;YAAEO,SAASO;QAAa;KAAE;IAExE,IAAI,CAACR,cAAcN,OAAOc,eAAe;QACvC,OAAO;YACLE,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,cAAc;gBACrF;aACD;YACDK,SAAS;QACX;IACF;IAEA,MAAMC,SAAStB,yBAAyB;QAAEc;QAAgBC;IAAI;IAC9D,MAAMQ,aAAaD,SACf,CAAC,2CAA2C,EAAEE,KAAKC,SAAS,CAACH,QAAQ,QAAQ,CAAC,GAC9E;IAEJ,OAAO;QACLJ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,eAAeO,YAAY;YAClG;SACD;QACDF,SAAS;QACT,GAAIC,SACA;YACEI,mBAAmB;gBACjBZ;gBACAP;gBACAe;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF,EAAC"}
@@ -1,14 +0,0 @@
1
- import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload';
2
- import type { MCPToolResponse } from '../../types.js';
3
- export declare const validateCollectionData: ({ collectionSlug, data, partial, req, }: {
4
- collectionSlug: CollectionSlug;
5
- data: Record<string, unknown>;
6
- partial?: boolean;
7
- req: PayloadRequest;
8
- }) => MCPToolResponse | null;
9
- export declare const validateGlobalData: ({ data, globalSlug, req, }: {
10
- data: Record<string, unknown>;
11
- globalSlug: GlobalSlug;
12
- req: PayloadRequest;
13
- }) => MCPToolResponse | null;
14
- //# sourceMappingURL=validateEntityData.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,82 +0,0 @@
1
- import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker';
2
- import { getCollectionInputSchema, getGlobalInputSchema } from '../../utils/schemaConversion/getEntityInputSchema.js';
3
- /**
4
- * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
5
- */ const validator = new CfWorkerJsonSchemaValidator({
6
- shortcircuit: true
7
- });
8
- /**
9
- * - Caches each entity's schema and validator, so both are only built on the first request.
10
- * - Keyed by payload config, then by entity type, slug, partial and language.
11
- */ const validatorCache = new WeakMap();
12
- export const validateCollectionData = ({ collectionSlug, data, partial, req })=>validateData({
13
- slug: collectionSlug,
14
- buildSchema: ()=>getCollectionInputSchema({
15
- collectionSlug,
16
- req
17
- }),
18
- data,
19
- entity: 'collection',
20
- partial,
21
- req
22
- });
23
- export const validateGlobalData = ({ data, globalSlug, req })=>validateData({
24
- slug: globalSlug,
25
- buildSchema: ()=>getGlobalInputSchema({
26
- globalSlug,
27
- req
28
- }),
29
- data,
30
- entity: 'global',
31
- partial: true,
32
- req
33
- });
34
- const validateData = ({ slug, buildSchema, data, entity, partial, req })=>{
35
- let cache = validatorCache.get(req.payload.config);
36
- if (!cache) {
37
- cache = new Map();
38
- validatorCache.set(req.payload.config, cache);
39
- }
40
- const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`;
41
- let entityValidator = cache.get(cacheKey);
42
- if (!entityValidator) {
43
- const schema = buildSchema();
44
- if (!schema) {
45
- return null;
46
- }
47
- entityValidator = {
48
- schema,
49
- validate: validator.getValidator(partial ? withoutRequired(schema) : schema)
50
- };
51
- cache.set(cacheKey, entityValidator);
52
- }
53
- const result = entityValidator.validate(data);
54
- if (result.valid) {
55
- return null;
56
- }
57
- const { schema } = entityValidator;
58
- return {
59
- content: [
60
- {
61
- type: 'text',
62
- text: `Invalid data for ${entity} "${slug}": ${result.errorMessage}\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
63
- }
64
- ],
65
- isError: true,
66
- structuredContent: {
67
- [`${entity}Slug`]: slug,
68
- errors: [
69
- {
70
- message: result.errorMessage
71
- }
72
- ],
73
- schema
74
- }
75
- };
76
- };
77
- /** Updates are partial — drop the schema's top-level `required` before validating. */ const withoutRequired = (schema)=>{
78
- const { required: _required, ...rest } = schema;
79
- return rest;
80
- };
81
-
82
- //# sourceMappingURL=validateEntityData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/mcp/builtin/validateEntityData.ts"],"sourcesContent":["import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'\n\nimport type { JsonSchemaType, MCPToolResponse } from '../../types.js'\n\nimport {\n getCollectionInputSchema,\n getGlobalInputSchema,\n} from '../../utils/schemaConversion/getEntityInputSchema.js'\n\n/**\n * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.\n */\nconst validator = new CfWorkerJsonSchemaValidator({ shortcircuit: true })\n\ntype EntityValidator = {\n schema: JsonSchemaType\n validate: ReturnType<(typeof validator)['getValidator']>\n}\n\n/**\n * - Caches each entity's schema and validator, so both are only built on the first request.\n * - Keyed by payload config, then by entity type, slug, partial and language.\n */\nconst validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()\n\nexport const validateCollectionData = ({\n collectionSlug,\n data,\n partial,\n req,\n}: {\n collectionSlug: CollectionSlug\n data: Record<string, unknown>\n partial?: boolean\n req: PayloadRequest\n}): MCPToolResponse | null =>\n validateData({\n slug: collectionSlug,\n buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),\n data,\n entity: 'collection',\n partial,\n req,\n })\n\nexport const validateGlobalData = ({\n data,\n globalSlug,\n req,\n}: {\n data: Record<string, unknown>\n globalSlug: GlobalSlug\n req: PayloadRequest\n}): MCPToolResponse | null =>\n validateData({\n slug: globalSlug,\n buildSchema: () => getGlobalInputSchema({ globalSlug, req }),\n data,\n entity: 'global',\n partial: true,\n req,\n })\n\nconst validateData = ({\n slug,\n buildSchema,\n data,\n entity,\n partial,\n req,\n}: {\n buildSchema: () => JsonSchemaType | null\n data: Record<string, unknown>\n entity: 'collection' | 'global'\n partial?: boolean\n req: PayloadRequest\n slug: string\n}): MCPToolResponse | null => {\n let cache = validatorCache.get(req.payload.config)\n if (!cache) {\n cache = new Map()\n validatorCache.set(req.payload.config, cache)\n }\n\n const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`\n let entityValidator = cache.get(cacheKey)\n\n if (!entityValidator) {\n const schema = buildSchema()\n\n if (!schema) {\n return null\n }\n\n entityValidator = {\n schema,\n validate: validator.getValidator(partial ? withoutRequired(schema) : schema),\n }\n cache.set(cacheKey, entityValidator)\n }\n\n const result = entityValidator.validate(data)\n\n if (result.valid) {\n return null\n }\n\n const { schema } = entityValidator\n\n return {\n content: [\n {\n type: 'text',\n text: `Invalid data for ${entity} \"${slug}\": ${result.errorMessage}\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``,\n },\n ],\n isError: true,\n structuredContent: {\n [`${entity}Slug`]: slug,\n errors: [{ message: result.errorMessage }],\n schema,\n },\n }\n}\n\n/** Updates are partial — drop the schema's top-level `required` before validating. */\nconst withoutRequired = (schema: JsonSchemaType): JsonSchemaType => {\n const { required: _required, ...rest } = schema\n return rest\n}\n"],"names":["CfWorkerJsonSchemaValidator","getCollectionInputSchema","getGlobalInputSchema","validator","shortcircuit","validatorCache","WeakMap","validateCollectionData","collectionSlug","data","partial","req","validateData","slug","buildSchema","entity","validateGlobalData","globalSlug","cache","get","payload","config","Map","set","cacheKey","i18n","language","entityValidator","schema","validate","getValidator","withoutRequired","result","valid","content","type","text","errorMessage","JSON","stringify","isError","structuredContent","errors","message","required","_required","rest"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,oDAAmD;AAI/F,SACEC,wBAAwB,EACxBC,oBAAoB,QACf,uDAAsD;AAE7D;;CAEC,GACD,MAAMC,YAAY,IAAIH,4BAA4B;IAAEI,cAAc;AAAK;AAOvE;;;CAGC,GACD,MAAMC,iBAAiB,IAAIC;AAE3B,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,cAAc,EACdC,IAAI,EACJC,OAAO,EACPC,GAAG,EAMJ,GACCC,aAAa;QACXC,MAAML;QACNM,aAAa,IAAMb,yBAAyB;gBAAEO;gBAAgBG;YAAI;QAClEF;QACAM,QAAQ;QACRL;QACAC;IACF,GAAE;AAEJ,OAAO,MAAMK,qBAAqB,CAAC,EACjCP,IAAI,EACJQ,UAAU,EACVN,GAAG,EAKJ,GACCC,aAAa;QACXC,MAAMI;QACNH,aAAa,IAAMZ,qBAAqB;gBAAEe;gBAAYN;YAAI;QAC1DF;QACAM,QAAQ;QACRL,SAAS;QACTC;IACF,GAAE;AAEJ,MAAMC,eAAe,CAAC,EACpBC,IAAI,EACJC,WAAW,EACXL,IAAI,EACJM,MAAM,EACNL,OAAO,EACPC,GAAG,EAQJ;IACC,IAAIO,QAAQb,eAAec,GAAG,CAACR,IAAIS,OAAO,CAACC,MAAM;IACjD,IAAI,CAACH,OAAO;QACVA,QAAQ,IAAII;QACZjB,eAAekB,GAAG,CAACZ,IAAIS,OAAO,CAACC,MAAM,EAAEH;IACzC;IAEA,MAAMM,WAAW,GAAGT,OAAO,CAAC,EAAEF,KAAK,CAAC,EAAEH,UAAU,YAAY,OAAO,CAAC,EAAEC,IAAIc,IAAI,CAACC,QAAQ,EAAE;IACzF,IAAIC,kBAAkBT,MAAMC,GAAG,CAACK;IAEhC,IAAI,CAACG,iBAAiB;QACpB,MAAMC,SAASd;QAEf,IAAI,CAACc,QAAQ;YACX,OAAO;QACT;QAEAD,kBAAkB;YAChBC;YACAC,UAAU1B,UAAU2B,YAAY,CAACpB,UAAUqB,gBAAgBH,UAAUA;QACvE;QACAV,MAAMK,GAAG,CAACC,UAAUG;IACtB;IAEA,MAAMK,SAASL,gBAAgBE,QAAQ,CAACpB;IAExC,IAAIuB,OAAOC,KAAK,EAAE;QAChB,OAAO;IACT;IAEA,MAAM,EAAEL,MAAM,EAAE,GAAGD;IAEnB,OAAO;QACLO,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,iBAAiB,EAAErB,OAAO,EAAE,EAAEF,KAAK,GAAG,EAAEmB,OAAOK,YAAY,CAAC,2CAA2C,EAAEC,KAAKC,SAAS,CAACX,QAAQ,QAAQ,CAAC;YAClJ;SACD;QACDY,SAAS;QACTC,mBAAmB;YACjB,CAAC,GAAG1B,OAAO,IAAI,CAAC,CAAC,EAAEF;YACnB6B,QAAQ;gBAAC;oBAAEC,SAASX,OAAOK,YAAY;gBAAC;aAAE;YAC1CT;QACF;IACF;AACF;AAEA,oFAAoF,GACpF,MAAMG,kBAAkB,CAACH;IACvB,MAAM,EAAEgB,UAAUC,SAAS,EAAE,GAAGC,MAAM,GAAGlB;IACzC,OAAOkB;AACT"}
@@ -1,14 +0,0 @@
1
- import type { SanitizedConfig } from 'payload';
2
- /**
3
- * Returns the names of all top-level virtual fields for a given collection slug.
4
- */
5
- export declare function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
6
- /**
7
- * Returns the names of all top-level virtual fields for a given global slug.
8
- */
9
- export declare function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
10
- /**
11
- * Strips virtual field values from a data object given a list of virtual field names.
12
- */
13
- export declare function stripVirtualFields(data: Record<string, unknown>, virtualFieldNames: string[]): Record<string, unknown>;
14
- //# sourceMappingURL=getVirtualFieldNames.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getVirtualFieldNames.d.ts","sourceRoot":"","sources":["../../src/utils/getVirtualFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU9F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU1F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
@@ -1,35 +0,0 @@
1
- import { fieldIsVirtual } from 'payload/shared';
2
- /**
3
- * Returns the names of all top-level virtual fields for a given collection slug.
4
- */ export function getCollectionVirtualFieldNames(config, slug) {
5
- const collection = config.collections.find((c)=>c.slug === slug);
6
- if (!collection) {
7
- return [];
8
- }
9
- return collection.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
10
- }
11
- /**
12
- * Returns the names of all top-level virtual fields for a given global slug.
13
- */ export function getGlobalVirtualFieldNames(config, slug) {
14
- const global = config.globals.find((g)=>g.slug === slug);
15
- if (!global) {
16
- return [];
17
- }
18
- return global.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
19
- }
20
- /**
21
- * Strips virtual field values from a data object given a list of virtual field names.
22
- */ export function stripVirtualFields(data, virtualFieldNames) {
23
- if (virtualFieldNames.length === 0) {
24
- return data;
25
- }
26
- const stripped = {
27
- ...data
28
- };
29
- for (const name of virtualFieldNames){
30
- delete stripped[name];
31
- }
32
- return stripped;
33
- }
34
-
35
- //# sourceMappingURL=getVirtualFieldNames.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/getVirtualFieldNames.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual } from 'payload/shared'\n\n/**\n * Returns the names of all top-level virtual fields for a given collection slug.\n */\nexport function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const collection = config.collections.find((c) => c.slug === slug)\n\n if (!collection) {\n return []\n }\n\n return collection.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Returns the names of all top-level virtual fields for a given global slug.\n */\nexport function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const global = config.globals.find((g) => g.slug === slug)\n\n if (!global) {\n return []\n }\n\n return global.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Strips virtual field values from a data object given a list of virtual field names.\n */\nexport function stripVirtualFields(\n data: Record<string, unknown>,\n virtualFieldNames: string[],\n): Record<string, unknown> {\n if (virtualFieldNames.length === 0) {\n return data\n }\n\n const stripped = { ...data }\n\n for (const name of virtualFieldNames) {\n delete stripped[name]\n }\n\n return stripped\n}\n"],"names":["fieldIsVirtual","getCollectionVirtualFieldNames","config","slug","collection","collections","find","c","flattenedFields","filter","field","map","name","getGlobalVirtualFieldNames","global","globals","g","stripVirtualFields","data","virtualFieldNames","length","stripped"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C;;CAEC,GACD,OAAO,SAASC,+BAA+BC,MAAuB,EAAEC,IAAY;IAClF,MAAMC,aAAaF,OAAOG,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEJ,IAAI,KAAKA;IAE7D,IAAI,CAACC,YAAY;QACf,OAAO,EAAE;IACX;IAEA,OAAOA,WAAWI,eAAe,CAC9BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASC,2BAA2BX,MAAuB,EAAEC,IAAY;IAC9E,MAAMW,SAASZ,OAAOa,OAAO,CAACT,IAAI,CAAC,CAACU,IAAMA,EAAEb,IAAI,KAAKA;IAErD,IAAI,CAACW,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,OAAOA,OAAON,eAAe,CAC1BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASK,mBACdC,IAA6B,EAC7BC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,MAAMG,WAAW;QAAE,GAAGH,IAAI;IAAC;IAE3B,KAAK,MAAMN,QAAQO,kBAAmB;QACpC,OAAOE,QAAQ,CAACT,KAAK;IACvB;IAEA,OAAOS;AACT"}
@@ -1,28 +0,0 @@
1
- import type { FlattenedBlock, FlattenedField, Operation, SanitizedDocumentPermissions } from 'payload';
2
- type FieldOperation = Exclude<Operation, 'delete'>;
3
- type AllowedFieldOperations = Record<FieldOperation, boolean>;
4
- /**
5
- * Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
6
- * operations allowed by the entity, field, and its parents and decides whether to remove the
7
- * field.
8
- *
9
- * Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
10
- * flattened by Payload, so their children are filtered at the containing level.
11
- *
12
- * @example Include fields writable through any collection operation the user can perform.
13
- * ```ts
14
- * filterFieldsByAccess({
15
- * fields,
16
- * permissions: collectionPermissions,
17
- * shouldExcludeField: ({ create, update }) => !create && !update,
18
- * })
19
- * ```
20
- */
21
- export declare const filterFieldsByAccess: ({ blocks, fields, permissions, shouldExcludeField, }: {
22
- blocks?: FlattenedBlock[];
23
- fields: FlattenedField[];
24
- permissions: SanitizedDocumentPermissions;
25
- shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean;
26
- }) => FlattenedField[];
27
- export {};
28
- //# sourceMappingURL=filterFieldsByAccess.d.ts.map
@@ -1 +0,0 @@
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"}