@payloadcms/plugin-mcp 4.0.0-internal.811e0a4 → 4.0.0-internal.8867dba
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +7 -0
- package/dist/defaultAccess.d.ts.map +1 -1
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +2 -7
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +4 -11
- package/dist/endpoint/access.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +1 -2
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +1 -2
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +15 -6
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +1 -2
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +117 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +3 -4
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +1 -2
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +1 -2
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +45 -5
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +1 -2
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +24 -12
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +1 -2
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +2 -2
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +1 -2
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +1 -2
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +21 -3
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +1 -2
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +2 -2
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtinTools.d.ts +6 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +6 -0
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +4 -1
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/types.d.ts +44 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +40 -6
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +2 -2
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/endpoint/access.ts +3 -10
- package/src/mcp/builtin/collections/countTool.ts +1 -2
- package/src/mcp/builtin/collections/countVersionsTool.ts +2 -6
- package/src/mcp/builtin/collections/createTool.ts +15 -6
- package/src/mcp/builtin/collections/deleteTool.ts +1 -2
- package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +154 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +3 -3
- package/src/mcp/builtin/collections/findTool.ts +3 -4
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +43 -9
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/collections/updateTool.ts +26 -10
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
- package/src/mcp/builtin/globals/countVersionsTool.ts +2 -6
- package/src/mcp/builtin/globals/findTool.ts +2 -2
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
- package/src/mcp/builtin/globals/restoreVersionTool.ts +3 -3
- package/src/mcp/builtin/globals/updateTool.ts +2 -2
- package/src/mcp/builtinTools.ts +7 -0
- package/src/mcp/sanitizeMCPConfig.ts +4 -1
- package/src/types.ts +43 -7
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +47 -13
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +2 -2
- package/dist/utils/localAPIDefaults.d.ts +0 -20
- package/dist/utils/localAPIDefaults.d.ts.map +0 -1
- package/dist/utils/localAPIDefaults.js +0 -19
- package/dist/utils/localAPIDefaults.js.map +0 -1
- package/src/utils/localAPIDefaults.ts +0 -22
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CallToolResult, ContentBlock, JsonSchemaType, McpServer, ResourceTemplate, ServerContext, StandardSchemaWithJSON, ToolAnnotations } from '@modelcontextprotocol/server';
|
|
2
|
-
import type { AuthCollectionSlug, CollectionSlug, GlobalSlug, MaybePromise, PayloadRequest, SanitizedPermissions
|
|
2
|
+
import type { AuthCollectionSlug, CollectionSlug, GlobalSlug, MaybePromise, PayloadRequest, SanitizedPermissions } from 'payload';
|
|
3
3
|
import type { GetAuthorizedMCPArgs } from './endpoint/access.js';
|
|
4
4
|
import type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName } from './mcp/builtinTools.js';
|
|
5
5
|
export type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName };
|
|
@@ -55,6 +55,11 @@ 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
|
+
*/
|
|
58
63
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
59
64
|
annotations?: ToolAnnotations;
|
|
60
65
|
description: string;
|
|
@@ -66,11 +71,23 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
|
|
|
66
71
|
overrideResponse?: MCPResponseOverride;
|
|
67
72
|
};
|
|
68
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
|
+
*/
|
|
69
80
|
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
|
|
70
81
|
handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
|
|
71
82
|
input?: TSchema;
|
|
72
83
|
} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>;
|
|
73
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
|
+
*/
|
|
74
91
|
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
|
|
75
92
|
handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
|
|
76
93
|
input?: TSchema;
|
|
@@ -81,6 +98,10 @@ export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSc
|
|
|
81
98
|
* required handler) from being silently accepted at a built-in key slot.
|
|
82
99
|
*/
|
|
83
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
|
+
*/
|
|
84
105
|
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
|
|
85
106
|
annotations?: ToolAnnotations;
|
|
86
107
|
description?: string;
|
|
@@ -88,6 +109,10 @@ export type MCPBuiltInCollectionToolOverride = {
|
|
|
88
109
|
overrideResponse?: MCPResponseOverride;
|
|
89
110
|
};
|
|
90
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
|
+
*/
|
|
91
116
|
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
|
|
92
117
|
annotations?: ToolAnnotations;
|
|
93
118
|
description?: string;
|
|
@@ -122,6 +147,11 @@ export type PromptHandlerArgs<TSchema = undefined> = {
|
|
|
122
147
|
serverContext: ServerContext;
|
|
123
148
|
};
|
|
124
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
|
+
*/
|
|
125
155
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
126
156
|
argsSchema: TSchema;
|
|
127
157
|
description: string;
|
|
@@ -144,6 +174,11 @@ export type ResourceHandlerArgs = {
|
|
|
144
174
|
uri: URL;
|
|
145
175
|
};
|
|
146
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
|
+
*/
|
|
147
182
|
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
148
183
|
description: string;
|
|
149
184
|
handler: (args: ResourceHandlerArgs) => MaybePromise<{
|
|
@@ -191,7 +226,12 @@ export type MCPPluginConfig = {
|
|
|
191
226
|
serverOptions?: MCPServerOptions;
|
|
192
227
|
verboseLogs?: boolean;
|
|
193
228
|
};
|
|
194
|
-
/**
|
|
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
|
+
*/
|
|
195
235
|
overrideGetAuthorizedMCP?: (args: {
|
|
196
236
|
pluginConfig: SanitizedMCPPluginConfig;
|
|
197
237
|
} & GetAuthorizedMCPArgs) => MaybePromise<AuthorizedMCP>;
|
|
@@ -241,14 +281,11 @@ export type MCPItem = ({
|
|
|
241
281
|
type: 'tool';
|
|
242
282
|
} & MCPItemBase) | CollectionMCPItem | GlobalMCPItem;
|
|
243
283
|
/**
|
|
244
|
-
* The
|
|
245
|
-
*
|
|
246
|
-
* absent from `items`. Tool handlers receive this via `args.authorizedMCP` so
|
|
247
|
-
* they can spread `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`.
|
|
248
286
|
*/
|
|
249
287
|
export type AuthorizedMCP = {
|
|
250
288
|
items: MCPItem[];
|
|
251
289
|
overrideAccess: boolean;
|
|
252
|
-
user: null | User;
|
|
253
290
|
};
|
|
254
291
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,CAAA;AAEzF,gGAAgG;AAChG,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,CAAA;AAEvE;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,sBAAsB,CAAA;AAErE,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,GAAG,IAAI,CAAC,cAAc,EA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,CAAA;AAEf,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,YAAY,CAAA;CACnB,GAAG,WAAW,CAAA;AAEf,MAAM,MAAM,OAAO,GACf,CAAC;IACC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,QAAQ,CAAA;CACf,GAAG,WAAW,CAAC,GAChB,CAAC;IACC,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,UAAU,CAAA;CACjB,GAAG,WAAW,CAAC,GAChB,CAAC;IACC,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,WAAW,CAAC,GAChB,iBAAiB,GACjB,aAAa,CAAA;AAEjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA"}
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
* absent from `items`. Tool handlers receive this via `args.authorizedMCP` so
|
|
5
|
-
* they can spread `localAPIDefaults(authorizedMCP)` into every local API call.
|
|
2
|
+
* The MCP items and access mode authorized for this request. The authenticated user is available
|
|
3
|
+
* as `req.user`.
|
|
6
4
|
*/ export { };
|
|
7
5
|
|
|
8
6
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CallToolResult,\n ContentBlock,\n JsonSchemaType,\n McpServer,\n ResourceTemplate,\n ServerContext,\n StandardSchemaWithJSON,\n ToolAnnotations,\n} from '@modelcontextprotocol/server'\nimport type {\n AuthCollectionSlug,\n CollectionSlug,\n GlobalSlug,\n MaybePromise,\n PayloadRequest,\n SanitizedPermissions,\n User,\n} from 'payload'\n\nimport type { GetAuthorizedMCPArgs } from './endpoint/access.js'\nimport type {\n MCPCollectionAuthToolName,\n MCPCollectionBuiltinName,\n MCPGlobalBuiltinName,\n} from './mcp/builtinTools.js'\n\nexport type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }\n\n/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */\nexport type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }\n\n/**\n * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw\n * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).\n * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.\n */\nexport type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON\n\nexport type MCPToolResponse = {\n content: ContentBlock[]\n /**\n * If available, return the document fetched within the\n * mcp tool. This is threaded as an additional argument to\n * overrideResponse functions and stripped before going on the wire.\n */\n doc?: Record<string, unknown>\n} & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>\n\nexport type MCPResponseOverride = (\n response: MCPToolResponse,\n doc: Record<string, unknown>,\n req: PayloadRequest,\n) => MCPToolResponse\n\nexport type MCPAfterToolCallHook = (args: {\n input: unknown\n req: PayloadRequest\n response: MCPToolResponse\n toolName: string\n}) => MaybePromise<MCPToolResponse>\n\n/**\n * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets\n * its inferred output; anything else falls back to `Record<string, unknown>`.\n */\nexport type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON\n ? StandardSchemaWithJSON extends TSchema\n ? Record<string, unknown>\n : StandardSchemaWithJSON.InferOutput<TSchema>\n : Record<string, unknown>\n\nexport type MCPAccessArgs = {\n permissions?: SanitizedPermissions\n req: PayloadRequest\n}\n\nexport type CollectionMCPAccessArgs = {\n collectionSlug: CollectionSlug\n} & MCPAccessArgs\n\nexport type GlobalMCPAccessArgs = {\n globalSlug: GlobalSlug\n} & MCPAccessArgs\n\nexport type ToolHandlerArgs<TSchema = undefined> = {\n authorizedMCP: AuthorizedMCP\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type CollectionToolHandlerArgs<TSchema = undefined> = {\n collectionSlug: CollectionSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type GlobalToolHandlerArgs<TSchema = undefined> = {\n globalSlug: GlobalSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description: string\n handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n /**\n * Override the return value of the tool handler\n */\n overrideResponse?: MCPResponseOverride\n}\n\nexport type CollectionTool<\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n> = {\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\nexport type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =\n {\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\n/**\n * Configures (or disables) a built-in tool without replacing it.\n * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a\n * required handler) from being silently accepted at a built-in key slot.\n */\nexport type MCPBuiltInCollectionToolOverride = {\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\nexport type MCPBuiltInGlobalToolOverride = {\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\n/**\n * Value at a custom (non-built-in) tool key. Either the tool itself, or `false`\n * to disable it (useful when one plugin defines a custom tool and another\n * wants to opt out per-collection).\n */\nexport type MCPTopLevelToolEntry = Tool\n\nexport type MCPCollectionToolsMap = {\n [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined\n} & {\n [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride\n}\n\nexport type MCPAuthCollectionToolsMap = {\n [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true\n} & MCPCollectionToolsMap\n\n/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */\nexport type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug\n ? MCPAuthCollectionToolsMap\n : MCPCollectionToolsMap\n\nexport type MCPGlobalToolsMap = {\n [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined\n} & {\n [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride\n}\n\nexport type MCPTopLevelToolsMap = Record<string, Tool>\n\nexport type PromptHandlerArgs<TSchema = undefined> = {\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n argsSchema: TSchema\n description: string\n handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{\n messages: Array<{ content: { text: string; type: 'text' }; role: 'assistant' | 'user' }>\n }>\n title: string\n}\n\nexport type ResourceHandlerArgs = {\n /** Variables extracted from a `ResourceTemplate` URI. Empty for static-URI resources. */\n params: Record<string, string>\n req: PayloadRequest\n serverContext: ServerContext\n uri: URL\n}\n\nexport type Resource = {\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n description: string\n handler: (args: ResourceHandlerArgs) => MaybePromise<{\n contents: Array<{ text: string; uri: string }>\n }>\n mimeType: string\n title: string\n uri: ResourceTemplate | string\n}\n\nexport type MCPPluginCollectionConfig<TSlug extends CollectionSlug> = {\n description?: string\n /** Fallback for built-in tools that don't set their own `overrideResponse`. */\n overrideResponse?: MCPResponseOverride\n tools?: MCPToolsMapForCollection<TSlug>\n}\n\nexport type MCPPluginGlobalConfig = {\n description?: string\n overrideResponse?: MCPResponseOverride\n tools?: MCPGlobalToolsMap\n}\n\n/**\n * The user-facing config shape passed to `mcpPlugin({ ... })`. Tools, prompts,\n * resources, and per-collection/global tool maps live in their own nested\n * fields. `sanitizeMCPConfig` flattens those into `items` and applies defaults\n * to produce a `SanitizedMCPPluginConfig` — the form every internal consumer\n * actually works with.\n */\nexport type MCPPluginConfig = {\n collections?: {\n [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>\n }\n /** Skip MCP endpoint registration. */\n disabled?: boolean\n globals?: {\n [Slug in GlobalSlug]?: MCPPluginGlobalConfig\n }\n hooks?: {\n /** Transform a tool response after its handler returns */\n afterToolCall?: MCPAfterToolCallHook[]\n }\n mcp?: {\n serverOptions?: MCPServerOptions\n verboseLogs?: boolean\n }\n /** Replace the default MCP authorization resolver. */\n overrideGetAuthorizedMCP?: (\n args: {\n pluginConfig: SanitizedMCPPluginConfig\n } & GetAuthorizedMCPArgs,\n ) => MaybePromise<AuthorizedMCP>\n prompts?: Record<string, Prompt>\n resources?: Record<string, Resource>\n /** Cross-cutting tools (not scoped to any collection or global). */\n tools?: MCPTopLevelToolsMap\n}\n\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>\n\nexport type MCPServerOptions = {\n options?: ConstructorParameters<typeof McpServer>[1]\n serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>\n}\n\n/**\n * One MCP primitive plus the metadata needed for config-driven filtering and\n * registration.\n *\n * - `configKey`: the config identifier, e.g. `find` or `echo`.\n * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.\n * - `label`: human-readable display text.\n */\nexport type MCPItemBase = {\n configKey: string\n label: string\n mcpName: string\n}\n\nexport type CollectionMCPItem = {\n collectionSlug: CollectionSlug\n tool: CollectionTool\n type: 'collectionTool'\n} & MCPItemBase\n\nexport type GlobalMCPItem = {\n globalSlug: GlobalSlug\n tool: GlobalTool\n type: 'globalTool'\n} & MCPItemBase\n\nexport type MCPItem =\n | ({\n prompt: Prompt\n type: 'prompt'\n } & MCPItemBase)\n | ({\n resource: Resource\n type: 'resource'\n } & MCPItemBase)\n | ({\n tool: Tool\n type: 'tool'\n } & MCPItemBase)\n | CollectionMCPItem\n | GlobalMCPItem\n\n/**\n * The caller's identity + the MCP items authorized for this request. Disabled\n * items and items blocked by access callbacks or Payload operation access are\n * absent from `items`. Tool handlers receive this via `args.authorizedMCP` so\n * they can spread `localAPIDefaults(authorizedMCP)` into every local API call.\n */\nexport type AuthorizedMCP = {\n items: MCPItem[]\n overrideAccess: boolean\n user: null | User\n}\n"],"names":[],"mappings":"AAyTA;;;;;CAKC,GACD,WAIC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CallToolResult,\n ContentBlock,\n JsonSchemaType,\n McpServer,\n ResourceTemplate,\n ServerContext,\n StandardSchemaWithJSON,\n ToolAnnotations,\n} from '@modelcontextprotocol/server'\nimport type {\n AuthCollectionSlug,\n CollectionSlug,\n GlobalSlug,\n MaybePromise,\n PayloadRequest,\n SanitizedPermissions,\n} from 'payload'\n\nimport type { GetAuthorizedMCPArgs } from './endpoint/access.js'\nimport type {\n MCPCollectionAuthToolName,\n MCPCollectionBuiltinName,\n MCPGlobalBuiltinName,\n} from './mcp/builtinTools.js'\n\nexport type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }\n\n/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */\nexport type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }\n\n/**\n * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw\n * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).\n * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.\n */\nexport type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON\n\nexport type MCPToolResponse = {\n content: ContentBlock[]\n /**\n * If available, return the document fetched within the\n * mcp tool. This is threaded as an additional argument to\n * overrideResponse functions and stripped before going on the wire.\n */\n doc?: Record<string, unknown>\n} & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>\n\nexport type MCPResponseOverride = (\n response: MCPToolResponse,\n doc: Record<string, unknown>,\n req: PayloadRequest,\n) => MCPToolResponse\n\nexport type MCPAfterToolCallHook = (args: {\n input: unknown\n req: PayloadRequest\n response: MCPToolResponse\n toolName: string\n}) => MaybePromise<MCPToolResponse>\n\n/**\n * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets\n * its inferred output; anything else falls back to `Record<string, unknown>`.\n */\nexport type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON\n ? StandardSchemaWithJSON extends TSchema\n ? Record<string, unknown>\n : StandardSchemaWithJSON.InferOutput<TSchema>\n : Record<string, unknown>\n\nexport type MCPAccessArgs = {\n permissions?: SanitizedPermissions\n req: PayloadRequest\n}\n\nexport type CollectionMCPAccessArgs = {\n collectionSlug: CollectionSlug\n} & MCPAccessArgs\n\nexport type GlobalMCPAccessArgs = {\n globalSlug: GlobalSlug\n} & MCPAccessArgs\n\nexport type ToolHandlerArgs<TSchema = undefined> = {\n authorizedMCP: AuthorizedMCP\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type CollectionToolHandlerArgs<TSchema = undefined> = {\n collectionSlug: CollectionSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type GlobalToolHandlerArgs<TSchema = undefined> = {\n globalSlug: GlobalSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {\n /**\n * Runs while authorizing each MCP request, before the tool is advertised or called. Return\n * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`\n * is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description: string\n handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n /**\n * Override the return value of the tool handler\n */\n overrideResponse?: MCPResponseOverride\n}\n\nexport type CollectionTool<\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n> = {\n /**\n * Runs while authorizing each MCP request for this collection. Return `false` to reject calls\n * to this tool for the collection. The shared tool is not advertised when no collections allow\n * it, but can remain advertised when it is available for another collection. This is skipped\n * when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\nexport type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =\n {\n /**\n * Runs while authorizing each MCP request for this global. Return `false` to reject calls to\n * this tool for the global. The shared tool is not advertised when no globals allow it, but\n * can remain advertised when it is available for another global. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\n/**\n * Configures (or disables) a built-in tool without replacing it.\n * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a\n * required handler) from being silently accepted at a built-in key slot.\n */\nexport type MCPBuiltInCollectionToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this collection. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\nexport type MCPBuiltInGlobalToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this global. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\n/**\n * Value at a custom (non-built-in) tool key. Either the tool itself, or `false`\n * to disable it (useful when one plugin defines a custom tool and another\n * wants to opt out per-collection).\n */\nexport type MCPTopLevelToolEntry = Tool\n\nexport type MCPCollectionToolsMap = {\n [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined\n} & {\n [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride\n}\n\nexport type MCPAuthCollectionToolsMap = {\n [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true\n} & MCPCollectionToolsMap\n\n/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */\nexport type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug\n ? MCPAuthCollectionToolsMap\n : MCPCollectionToolsMap\n\nexport type MCPGlobalToolsMap = {\n [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined\n} & {\n [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride\n}\n\nexport type MCPTopLevelToolsMap = Record<string, Tool>\n\nexport type PromptHandlerArgs<TSchema = undefined> = {\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {\n /**\n * Runs while authorizing each MCP request, before the prompt is advertised or used. Return\n * `false` to make the prompt unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n argsSchema: TSchema\n description: string\n handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{\n messages: Array<{ content: { text: string; type: 'text' }; role: 'assistant' | 'user' }>\n }>\n title: string\n}\n\nexport type ResourceHandlerArgs = {\n /** Variables extracted from a `ResourceTemplate` URI. Empty for static-URI resources. */\n params: Record<string, string>\n req: PayloadRequest\n serverContext: ServerContext\n uri: URL\n}\n\nexport type Resource = {\n /**\n * Runs while authorizing each MCP request, before the resource is advertised or read. Return\n * `false` to make the resource unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n description: string\n handler: (args: ResourceHandlerArgs) => MaybePromise<{\n contents: Array<{ text: string; uri: string }>\n }>\n mimeType: string\n title: string\n uri: ResourceTemplate | string\n}\n\nexport type MCPPluginCollectionConfig<TSlug extends CollectionSlug> = {\n description?: string\n /** Fallback for built-in tools that don't set their own `overrideResponse`. */\n overrideResponse?: MCPResponseOverride\n tools?: MCPToolsMapForCollection<TSlug>\n}\n\nexport type MCPPluginGlobalConfig = {\n description?: string\n overrideResponse?: MCPResponseOverride\n tools?: MCPGlobalToolsMap\n}\n\n/**\n * The user-facing config shape passed to `mcpPlugin({ ... })`. Tools, prompts,\n * resources, and per-collection/global tool maps live in their own nested\n * fields. `sanitizeMCPConfig` flattens those into `items` and applies defaults\n * to produce a `SanitizedMCPPluginConfig` — the form every internal consumer\n * actually works with.\n */\nexport type MCPPluginConfig = {\n collections?: {\n [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>\n }\n /** Skip MCP endpoint registration. */\n disabled?: boolean\n globals?: {\n [Slug in GlobalSlug]?: MCPPluginGlobalConfig\n }\n hooks?: {\n /** Transform a tool response after its handler returns */\n afterToolCall?: MCPAfterToolCallHook[]\n }\n mcp?: {\n serverOptions?: MCPServerOptions\n verboseLogs?: boolean\n }\n /**\n * Replace the default MCP authorization resolver.\n *\n * This hook replaces the default authentication flow. It must set `req.user` to the\n * authenticated Payload user, or to `null` for an anonymous caller, before returning.\n */\n overrideGetAuthorizedMCP?: (\n args: {\n pluginConfig: SanitizedMCPPluginConfig\n } & GetAuthorizedMCPArgs,\n ) => MaybePromise<AuthorizedMCP>\n prompts?: Record<string, Prompt>\n resources?: Record<string, Resource>\n /** Cross-cutting tools (not scoped to any collection or global). */\n tools?: MCPTopLevelToolsMap\n}\n\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>\n\nexport type MCPServerOptions = {\n options?: ConstructorParameters<typeof McpServer>[1]\n serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>\n}\n\n/**\n * One MCP primitive plus the metadata needed for config-driven filtering and\n * registration.\n *\n * - `configKey`: the config identifier, e.g. `find` or `echo`.\n * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.\n * - `label`: human-readable display text.\n */\nexport type MCPItemBase = {\n configKey: string\n label: string\n mcpName: string\n}\n\nexport type CollectionMCPItem = {\n collectionSlug: CollectionSlug\n tool: CollectionTool\n type: 'collectionTool'\n} & MCPItemBase\n\nexport type GlobalMCPItem = {\n globalSlug: GlobalSlug\n tool: GlobalTool\n type: 'globalTool'\n} & MCPItemBase\n\nexport type MCPItem =\n | ({\n prompt: Prompt\n type: 'prompt'\n } & MCPItemBase)\n | ({\n resource: Resource\n type: 'resource'\n } & MCPItemBase)\n | ({\n tool: Tool\n type: 'tool'\n } & MCPItemBase)\n | CollectionMCPItem\n | GlobalMCPItem\n\n/**\n * The MCP items and access mode authorized for this request. The authenticated user is available\n * as `req.user`.\n */\nexport type AuthorizedMCP = {\n items: MCPItem[]\n overrideAccess: boolean\n}\n"],"names":[],"mappings":"AAgWA;;;CAGC,GACD,WAGC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/utils/camelCase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/utils/camelCase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MAIzC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProjectRoot.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProjectRoot.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"resolveProjectRoot.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProjectRoot.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,aAAc,MAAM,KAAG,IAAI,GAAG,MAS5D,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterFieldsByAccess.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AAEhB,KAAK,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAClD,KAAK,sBAAsB,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
|
|
3
|
+
* operations allowed by the entity, field, and its parents and decides whether to remove the
|
|
4
|
+
* field.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
|
|
7
|
+
* flattened by Payload, so their children are filtered at the containing level.
|
|
8
|
+
*
|
|
9
|
+
* @example Include fields writable through any collection operation the user can perform.
|
|
10
|
+
* ```ts
|
|
11
|
+
* filterFieldsByAccess({
|
|
12
|
+
* fields,
|
|
13
|
+
* permissions: collectionPermissions,
|
|
14
|
+
* shouldExcludeField: ({ create, update }) => !create && !update,
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/ export const filterFieldsByAccess = ({ blocks, fields, permissions, shouldExcludeField })=>{
|
|
18
|
+
const filterFields = (nestedFields, nestedPermissions, parentAllowedOperations)=>{
|
|
19
|
+
const accessibleFields = [];
|
|
20
|
+
for (const field of nestedFields){
|
|
21
|
+
const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name];
|
|
22
|
+
const isOperationAllowed = (operation)=>parentAllowedOperations[operation] && (fieldPermissions === true || fieldPermissions?.[operation] === true);
|
|
23
|
+
const allowedOperations = {
|
|
24
|
+
create: isOperationAllowed('create'),
|
|
25
|
+
read: isOperationAllowed('read'),
|
|
26
|
+
update: isOperationAllowed('update')
|
|
27
|
+
};
|
|
28
|
+
if (shouldExcludeField(allowedOperations)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (field.type === 'blocks') {
|
|
32
|
+
const accessibleBlocks = [];
|
|
33
|
+
for (const blockOrReference of field.blocks){
|
|
34
|
+
const block = typeof blockOrReference === 'string' ? blocks?.find(({ slug })=>slug === blockOrReference) : blockOrReference;
|
|
35
|
+
if (!block) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const blockPermissions = fieldPermissions === true ? true : fieldPermissions?.blocks === true ? true : fieldPermissions?.blocks?.[block.slug];
|
|
39
|
+
accessibleBlocks.push({
|
|
40
|
+
...block,
|
|
41
|
+
flattenedFields: filterFields(block.flattenedFields, blockPermissions === true ? true : blockPermissions?.fields, allowedOperations)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (accessibleBlocks.length === 0) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
accessibleFields.push({
|
|
48
|
+
...field,
|
|
49
|
+
blocks: accessibleBlocks
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {
|
|
54
|
+
accessibleFields.push({
|
|
55
|
+
...field,
|
|
56
|
+
flattenedFields: filterFields(field.flattenedFields, fieldPermissions === true ? true : fieldPermissions?.fields, allowedOperations)
|
|
57
|
+
});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
accessibleFields.push(field);
|
|
61
|
+
}
|
|
62
|
+
return accessibleFields;
|
|
63
|
+
};
|
|
64
|
+
return filterFields(fields, permissions.fields, {
|
|
65
|
+
create: 'create' in permissions && permissions.create === true,
|
|
66
|
+
read: permissions.read === true,
|
|
67
|
+
update: permissions.update === true
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=filterFieldsByAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedField,\n Operation,\n SanitizedDocumentPermissions,\n SanitizedFieldsPermissions,\n} from 'payload'\n\ntype FieldOperation = Exclude<Operation, 'delete'>\ntype AllowedFieldOperations = Record<FieldOperation, boolean>\n\n/**\n * Filters fields using the access results in `permissions`. `shouldExcludeField` receives the\n * operations allowed by the entity, field, and its parents and decides whether to remove the\n * field.\n *\n * Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are\n * flattened by Payload, so their children are filtered at the containing level.\n *\n * @example Include fields writable through any collection operation the user can perform.\n * ```ts\n * filterFieldsByAccess({\n * fields,\n * permissions: collectionPermissions,\n * shouldExcludeField: ({ create, update }) => !create && !update,\n * })\n * ```\n */\nexport const filterFieldsByAccess = ({\n blocks,\n fields,\n permissions,\n shouldExcludeField,\n}: {\n blocks?: FlattenedBlock[]\n fields: FlattenedField[]\n permissions: SanitizedDocumentPermissions\n shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean\n}): FlattenedField[] => {\n const filterFields = (\n nestedFields: FlattenedField[],\n nestedPermissions: SanitizedFieldsPermissions | undefined,\n parentAllowedOperations: AllowedFieldOperations,\n ): FlattenedField[] => {\n const accessibleFields: FlattenedField[] = []\n\n for (const field of nestedFields) {\n const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name]\n const isOperationAllowed = (operation: FieldOperation): boolean =>\n parentAllowedOperations[operation] &&\n (fieldPermissions === true || fieldPermissions?.[operation] === true)\n const allowedOperations: AllowedFieldOperations = {\n create: isOperationAllowed('create'),\n read: isOperationAllowed('read'),\n update: isOperationAllowed('update'),\n }\n\n if (shouldExcludeField(allowedOperations)) {\n continue\n }\n\n if (field.type === 'blocks') {\n const accessibleBlocks: (FlattenedBlock | string)[] = []\n\n for (const blockOrReference of field.blocks) {\n const block =\n typeof blockOrReference === 'string'\n ? blocks?.find(({ slug }) => slug === blockOrReference)\n : blockOrReference\n\n if (!block) {\n continue\n }\n\n const blockPermissions =\n fieldPermissions === true\n ? true\n : fieldPermissions?.blocks === true\n ? true\n : fieldPermissions?.blocks?.[block.slug]\n\n accessibleBlocks.push({\n ...block,\n flattenedFields: filterFields(\n block.flattenedFields,\n blockPermissions === true ? true : blockPermissions?.fields,\n allowedOperations,\n ),\n })\n }\n\n if (accessibleBlocks.length === 0) {\n continue\n }\n\n accessibleFields.push({ ...field, blocks: accessibleBlocks })\n continue\n }\n\n if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {\n accessibleFields.push({\n ...field,\n flattenedFields: filterFields(\n field.flattenedFields,\n fieldPermissions === true ? true : fieldPermissions?.fields,\n allowedOperations,\n ),\n })\n continue\n }\n\n accessibleFields.push(field)\n }\n\n return accessibleFields\n }\n\n return filterFields(fields, permissions.fields, {\n create: 'create' in permissions && permissions.create === true,\n read: permissions.read === true,\n update: permissions.update === true,\n })\n}\n"],"names":["filterFieldsByAccess","blocks","fields","permissions","shouldExcludeField","filterFields","nestedFields","nestedPermissions","parentAllowedOperations","accessibleFields","field","fieldPermissions","name","isOperationAllowed","operation","allowedOperations","create","read","update","type","accessibleBlocks","blockOrReference","block","find","slug","blockPermissions","push","flattenedFields","length"],"mappings":"AAWA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMA,uBAAuB,CAAC,EACnCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,kBAAkB,EAMnB;IACC,MAAMC,eAAe,CACnBC,cACAC,mBACAC;QAEA,MAAMC,mBAAqC,EAAE;QAE7C,KAAK,MAAMC,SAASJ,aAAc;YAChC,MAAMK,mBAAmBJ,sBAAsB,OAAO,OAAOA,mBAAmB,CAACG,MAAME,IAAI,CAAC;YAC5F,MAAMC,qBAAqB,CAACC,YAC1BN,uBAAuB,CAACM,UAAU,IACjCH,CAAAA,qBAAqB,QAAQA,kBAAkB,CAACG,UAAU,KAAK,IAAG;YACrE,MAAMC,oBAA4C;gBAChDC,QAAQH,mBAAmB;gBAC3BI,MAAMJ,mBAAmB;gBACzBK,QAAQL,mBAAmB;YAC7B;YAEA,IAAIT,mBAAmBW,oBAAoB;gBACzC;YACF;YAEA,IAAIL,MAAMS,IAAI,KAAK,UAAU;gBAC3B,MAAMC,mBAAgD,EAAE;gBAExD,KAAK,MAAMC,oBAAoBX,MAAMT,MAAM,CAAE;oBAC3C,MAAMqB,QACJ,OAAOD,qBAAqB,WACxBpB,QAAQsB,KAAK,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASH,oBACpCA;oBAEN,IAAI,CAACC,OAAO;wBACV;oBACF;oBAEA,MAAMG,mBACJd,qBAAqB,OACjB,OACAA,kBAAkBV,WAAW,OAC3B,OACAU,kBAAkBV,QAAQ,CAACqB,MAAME,IAAI,CAAC;oBAE9CJ,iBAAiBM,IAAI,CAAC;wBACpB,GAAGJ,KAAK;wBACRK,iBAAiBtB,aACfiB,MAAMK,eAAe,EACrBF,qBAAqB,OAAO,OAAOA,kBAAkBvB,QACrDa;oBAEJ;gBACF;gBAEA,IAAIK,iBAAiBQ,MAAM,KAAK,GAAG;oBACjC;gBACF;gBAEAnB,iBAAiBiB,IAAI,CAAC;oBAAE,GAAGhB,KAAK;oBAAET,QAAQmB;gBAAiB;gBAC3D;YACF;YAEA,IAAIV,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,OAAO;gBAC5EV,iBAAiBiB,IAAI,CAAC;oBACpB,GAAGhB,KAAK;oBACRiB,iBAAiBtB,aACfK,MAAMiB,eAAe,EACrBhB,qBAAqB,OAAO,OAAOA,kBAAkBT,QACrDa;gBAEJ;gBACA;YACF;YAEAN,iBAAiBiB,IAAI,CAAChB;QACxB;QAEA,OAAOD;IACT;IAEA,OAAOJ,aAAaH,QAAQC,YAAYD,MAAM,EAAE;QAC9Cc,QAAQ,YAAYb,eAAeA,YAAYa,MAAM,KAAK;QAC1DC,MAAMd,YAAYc,IAAI,KAAK;QAC3BC,QAAQf,YAAYe,MAAM,KAAK;IACjC;AACF,EAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { type CollectionSlug, type GlobalSlug, type PayloadRequest } from 'payload';
|
|
1
|
+
import { type CollectionSlug, type GlobalSlug, type PayloadRequest, type SanitizedCollectionPermission, type SanitizedGlobalPermission } from 'payload';
|
|
2
2
|
import type { JsonSchemaType } from '../../types.js';
|
|
3
|
-
export declare const getCollectionInputSchema: ({ collectionSlug, req, }: {
|
|
3
|
+
export declare const getCollectionInputSchema: ({ collectionSlug, permissions, req, }: {
|
|
4
4
|
collectionSlug: CollectionSlug;
|
|
5
|
+
permissions?: SanitizedCollectionPermission;
|
|
5
6
|
req: PayloadRequest;
|
|
6
7
|
}) => JsonSchemaType | null;
|
|
7
|
-
export declare const getGlobalInputSchema: ({ globalSlug, req, }: {
|
|
8
|
+
export declare const getGlobalInputSchema: ({ globalSlug, permissions, req, }: {
|
|
8
9
|
globalSlug: GlobalSlug;
|
|
10
|
+
permissions?: SanitizedGlobalPermission;
|
|
9
11
|
req: PayloadRequest;
|
|
10
12
|
}) => JsonSchemaType | null;
|
|
11
13
|
//# sourceMappingURL=getEntityInputSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,0CAIlC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,sCAI9B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
|
|
@@ -1,32 +1,66 @@
|
|
|
1
1
|
import { entityToStandaloneJSONSchema } from 'payload';
|
|
2
|
+
import { filterFieldsByAccess } from './filterFieldsByAccess.js';
|
|
2
3
|
import { sanitizeEntitySchema } from './sanitizeEntitySchema.js';
|
|
3
|
-
export const getCollectionInputSchema = ({ collectionSlug, req })=>{
|
|
4
|
+
export const getCollectionInputSchema = ({ collectionSlug, permissions, req })=>{
|
|
4
5
|
const collection = req.payload.collections[collectionSlug]?.config;
|
|
5
6
|
if (!collection) {
|
|
6
7
|
return null;
|
|
7
8
|
}
|
|
9
|
+
if (!permissions) {
|
|
10
|
+
return buildEntityInputSchema({
|
|
11
|
+
entity: collection,
|
|
12
|
+
req
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
16
|
+
blocks: req.payload.config.blocks,
|
|
17
|
+
fields: collection.flattenedFields,
|
|
18
|
+
permissions,
|
|
19
|
+
shouldExcludeField: ({ create, update })=>!create && !update
|
|
20
|
+
});
|
|
8
21
|
return buildEntityInputSchema({
|
|
9
22
|
entity: collection,
|
|
23
|
+
fields: fieldsAllowedByAccess,
|
|
10
24
|
req
|
|
11
25
|
});
|
|
12
26
|
};
|
|
13
|
-
export const getGlobalInputSchema = ({ globalSlug, req })=>{
|
|
27
|
+
export const getGlobalInputSchema = ({ globalSlug, permissions, req })=>{
|
|
14
28
|
const global = req.payload.config.globals.find((globalConfig)=>globalConfig.slug === globalSlug);
|
|
15
29
|
if (!global) {
|
|
16
30
|
return null;
|
|
17
31
|
}
|
|
32
|
+
if (!permissions) {
|
|
33
|
+
return buildEntityInputSchema({
|
|
34
|
+
entity: global,
|
|
35
|
+
req
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
39
|
+
blocks: req.payload.config.blocks,
|
|
40
|
+
fields: global.flattenedFields,
|
|
41
|
+
permissions,
|
|
42
|
+
shouldExcludeField: ({ create, update })=>!create && !update
|
|
43
|
+
});
|
|
18
44
|
return buildEntityInputSchema({
|
|
19
45
|
entity: global,
|
|
46
|
+
fields: fieldsAllowedByAccess,
|
|
20
47
|
req
|
|
21
48
|
});
|
|
22
49
|
};
|
|
23
|
-
const buildEntityInputSchema = ({ entity, req })
|
|
24
|
-
|
|
50
|
+
const buildEntityInputSchema = ({ entity, fields = entity.flattenedFields, req })=>{
|
|
51
|
+
// The core schema generator reads flattenedFields from the entity and has no fields argument.
|
|
52
|
+
const entityForSchema = {
|
|
53
|
+
...entity,
|
|
54
|
+
flattenedFields: fields
|
|
55
|
+
};
|
|
56
|
+
const schema = entityToStandaloneJSONSchema({
|
|
25
57
|
config: req.payload.config,
|
|
26
58
|
defaultIDType: req.payload.db.defaultIDType,
|
|
27
|
-
entity,
|
|
59
|
+
entity: entityForSchema,
|
|
28
60
|
i18n: req.i18n,
|
|
29
61
|
variant: 'input'
|
|
30
|
-
})
|
|
62
|
+
});
|
|
63
|
+
return sanitizeEntitySchema(schema);
|
|
64
|
+
};
|
|
31
65
|
|
|
32
66
|
//# sourceMappingURL=getEntityInputSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedGlobalConfig,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n req,\n}: {\n collectionSlug: CollectionSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n return buildEntityInputSchema({ entity: collection, req })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n req,\n}: {\n globalSlug: GlobalSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n return buildEntityInputSchema({ entity: global, req })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n req,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n req: PayloadRequest\n}): JsonSchemaType
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type FlattenedField,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedCollectionPermission,\n type SanitizedGlobalConfig,\n type SanitizedGlobalPermission,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { filterFieldsByAccess } from './filterFieldsByAccess.js'\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n permissions,\n req,\n}: {\n collectionSlug: CollectionSlug\n permissions?: SanitizedCollectionPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: collection, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: collection.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: collection, fields: fieldsAllowedByAccess, req })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n permissions,\n req,\n}: {\n globalSlug: GlobalSlug\n permissions?: SanitizedGlobalPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: global, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: global.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: global, fields: fieldsAllowedByAccess, req })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n fields = entity.flattenedFields,\n req,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n fields?: FlattenedField[]\n req: PayloadRequest\n}): JsonSchemaType => {\n // The core schema generator reads flattenedFields from the entity and has no fields argument.\n const entityForSchema = { ...entity, flattenedFields: fields }\n const schema = entityToStandaloneJSONSchema({\n config: req.payload.config,\n defaultIDType: req.payload.db.defaultIDType,\n entity: entityForSchema,\n i18n: req.i18n,\n variant: 'input',\n }) as unknown as JsonSchemaType\n\n return sanitizeEntitySchema(schema)\n}\n"],"names":["entityToStandaloneJSONSchema","filterFieldsByAccess","sanitizeEntitySchema","getCollectionInputSchema","collectionSlug","permissions","req","collection","payload","collections","config","buildEntityInputSchema","entity","fieldsAllowedByAccess","blocks","fields","flattenedFields","shouldExcludeField","create","update","getGlobalInputSchema","globalSlug","global","globals","find","globalConfig","slug","entityForSchema","schema","defaultIDType","db","i18n","variant"],"mappings":"AAAA,SAEEA,4BAA4B,QAQvB,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,cAAc,EACdC,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACL,eAAe,EAAEM;IAE5D,IAAI,CAACH,YAAY;QACf,OAAO;IACT;IAEA,IAAI,CAACF,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQL;YAAYD;QAAI;IAC1D;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQR,WAAWS,eAAe;QAClCX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQL;QAAYQ,QAAQF;QAAuBP;IAAI;AACzF,EAAC;AAED,OAAO,MAAMc,uBAAuB,CAAC,EACnCC,UAAU,EACVhB,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMgB,SAAShB,IAAIE,OAAO,CAACE,MAAM,CAACa,OAAO,CAACC,IAAI,CAAC,CAACC,eAAiBA,aAAaC,IAAI,KAAKL;IAEvF,IAAI,CAACC,QAAQ;QACX,OAAO;IACT;IAEA,IAAI,CAACjB,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQU;YAAQhB;QAAI;IACtD;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQO,OAAON,eAAe;QAC9BX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQU;QAAQP,QAAQF;QAAuBP;IAAI;AACrF,EAAC;AAED,MAAMK,yBAAyB,CAAC,EAC9BC,MAAM,EACNG,SAASH,OAAOI,eAAe,EAC/BV,GAAG,EAKJ;IACC,8FAA8F;IAC9F,MAAMqB,kBAAkB;QAAE,GAAGf,MAAM;QAAEI,iBAAiBD;IAAO;IAC7D,MAAMa,SAAS5B,6BAA6B;QAC1CU,QAAQJ,IAAIE,OAAO,CAACE,MAAM;QAC1BmB,eAAevB,IAAIE,OAAO,CAACsB,EAAE,CAACD,aAAa;QAC3CjB,QAAQe;QACRI,MAAMzB,IAAIyB,IAAI;QACdC,SAAS;IACX;IAEA,OAAO9B,qBAAqB0B;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,WAAY,cAAc,KAAG,cA0B7D,CAAA"}
|
|
@@ -104,8 +104,8 @@ describe('sanitizeEntitySchema', ()=>{
|
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
properties: {
|
|
107
|
-
// Managed
|
|
108
|
-
//
|
|
107
|
+
// Managed timestamps are excluded upstream by the `input` variant. `id` stays because it's
|
|
108
|
+
// a valid optional input (a client may supply a custom ID).
|
|
109
109
|
id: {
|
|
110
110
|
type: 'string'
|
|
111
111
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\ndescribe('sanitizeEntitySchema', () => {\n it('renames the Lexical node-union definition to a short name and keeps it a strict oneOf', () => {\n // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field\n // (Payload's `input` variant): a `$defs` node union (a `oneOf` of node shapes). The input variant\n // already types the relationship node's `value` as a bare ID - there is no populated-doc `$ref` to\n // reduce here (the variant did that upstream), so sanitize leaves the value untouched.\n const standalone: JsonSchemaType = {\n type: 'object',\n $defs: {\n LexicalNodes_ABCDEF12: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n value: { type: 'string', description: 'The related document ID.' },\n },\n required: ['type'],\n },\n ],\n },\n },\n properties: {\n id: { type: 'string' },\n content: {\n type: 'object',\n properties: {\n root: {\n type: 'object',\n properties: {\n children: { type: 'array', items: { $ref: '#/$defs/LexicalNodes_ABCDEF12' } },\n },\n },\n },\n },\n },\n }\n\n expect(sanitizeEntitySchema(standalone)).toStrictEqual({\n type: 'object',\n $defs: {\n // The node union is renamed to a short, readable `node`, and stays a strict discriminated\n // `oneOf` - not loosened to `anyOf`.\n node: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n // The value is already ID-only from the input variant - left as-is.\n value: { type: 'string', description: 'The related document ID.' },\n },\n required: ['type'],\n },\n ],\n },\n },\n properties: {\n // Managed
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\ndescribe('sanitizeEntitySchema', () => {\n it('renames the Lexical node-union definition to a short name and keeps it a strict oneOf', () => {\n // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field\n // (Payload's `input` variant): a `$defs` node union (a `oneOf` of node shapes). The input variant\n // already types the relationship node's `value` as a bare ID - there is no populated-doc `$ref` to\n // reduce here (the variant did that upstream), so sanitize leaves the value untouched.\n const standalone: JsonSchemaType = {\n type: 'object',\n $defs: {\n LexicalNodes_ABCDEF12: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n value: { type: 'string', description: 'The related document ID.' },\n },\n required: ['type'],\n },\n ],\n },\n },\n properties: {\n id: { type: 'string' },\n content: {\n type: 'object',\n properties: {\n root: {\n type: 'object',\n properties: {\n children: { type: 'array', items: { $ref: '#/$defs/LexicalNodes_ABCDEF12' } },\n },\n },\n },\n },\n },\n }\n\n expect(sanitizeEntitySchema(standalone)).toStrictEqual({\n type: 'object',\n $defs: {\n // The node union is renamed to a short, readable `node`, and stays a strict discriminated\n // `oneOf` - not loosened to `anyOf`.\n node: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: { type: { const: 'paragraph' } },\n required: ['type'],\n },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { const: 'relationship' },\n // The value is already ID-only from the input variant - left as-is.\n value: { type: 'string', description: 'The related document ID.' },\n },\n required: ['type'],\n },\n ],\n },\n },\n properties: {\n // Managed timestamps are excluded upstream by the `input` variant. `id` stays because it's\n // a valid optional input (a client may supply a custom ID).\n id: { type: 'string' },\n content: {\n type: 'object',\n properties: {\n root: {\n type: 'object',\n properties: {\n children: { type: 'array', items: { $ref: '#/$defs/node' } },\n },\n },\n },\n },\n },\n })\n })\n})\n"],"names":["describe","expect","it","sanitizeEntitySchema","standalone","type","$defs","LexicalNodes_ABCDEF12","oneOf","additionalProperties","properties","const","required","value","description","id","content","root","children","items","$ref","toStrictEqual","node"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAI7C,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhEH,SAAS,wBAAwB;IAC/BE,GAAG,yFAAyF;QAC1F,gGAAgG;QAChG,kGAAkG;QAClG,mGAAmG;QACnG,uFAAuF;QACvF,MAAME,aAA6B;YACjCC,MAAM;YACNC,OAAO;gBACLC,uBAAuB;oBACrBC,OAAO;wBACL;4BACEH,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCAAEL,MAAM;oCAAEM,OAAO;gCAAY;4BAAE;4BAC3CC,UAAU;gCAAC;6BAAO;wBACpB;wBACA;4BACEP,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCACVL,MAAM;oCAAEM,OAAO;gCAAe;gCAC9BE,OAAO;oCAAER,MAAM;oCAAUS,aAAa;gCAA2B;4BACnE;4BACAF,UAAU;gCAAC;6BAAO;wBACpB;qBACD;gBACH;YACF;YACAF,YAAY;gBACVK,IAAI;oBAAEV,MAAM;gBAAS;gBACrBW,SAAS;oBACPX,MAAM;oBACNK,YAAY;wBACVO,MAAM;4BACJZ,MAAM;4BACNK,YAAY;gCACVQ,UAAU;oCAAEb,MAAM;oCAASc,OAAO;wCAAEC,MAAM;oCAAgC;gCAAE;4BAC9E;wBACF;oBACF;gBACF;YACF;QACF;QAEAnB,OAAOE,qBAAqBC,aAAaiB,aAAa,CAAC;YACrDhB,MAAM;YACNC,OAAO;gBACL,0FAA0F;gBAC1F,qCAAqC;gBACrCgB,MAAM;oBACJd,OAAO;wBACL;4BACEH,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCAAEL,MAAM;oCAAEM,OAAO;gCAAY;4BAAE;4BAC3CC,UAAU;gCAAC;6BAAO;wBACpB;wBACA;4BACEP,MAAM;4BACNI,sBAAsB;4BACtBC,YAAY;gCACVL,MAAM;oCAAEM,OAAO;gCAAe;gCAC9B,oEAAoE;gCACpEE,OAAO;oCAAER,MAAM;oCAAUS,aAAa;gCAA2B;4BACnE;4BACAF,UAAU;gCAAC;6BAAO;wBACpB;qBACD;gBACH;YACF;YACAF,YAAY;gBACV,2FAA2F;gBAC3F,4DAA4D;gBAC5DK,IAAI;oBAAEV,MAAM;gBAAS;gBACrBW,SAAS;oBACPX,MAAM;oBACNK,YAAY;wBACVO,MAAM;4BACJZ,MAAM;4BACNK,YAAY;gCACVQ,UAAU;oCAAEb,MAAM;oCAASc,OAAO;wCAAEC,MAAM;oCAAe;gCAAE;4BAC7D;wBACF;oBACF;gBACF;YACF;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toStandardSchema.d.ts","sourceRoot":"","sources":["../../src/utils/toStandardSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,gIAAgI;AAChI,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"toStandardSchema.d.ts","sourceRoot":"","sources":["../../src/utils/toStandardSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,gIAAgI;AAChI,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,sBAG/B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.8867dba",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"bin.js"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@modelcontextprotocol/server": "2.0.0-beta.
|
|
58
|
+
"@modelcontextprotocol/server": "2.0.0-beta.3",
|
|
59
59
|
"tsx": "4.22.4",
|
|
60
60
|
"zod": "^4.2.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@payloadcms/eslint-config": "3.28.0",
|
|
64
|
-
"payload": "4.0.0-internal.
|
|
64
|
+
"payload": "4.0.0-internal.8867dba"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"payload": "4.0.0-internal.
|
|
67
|
+
"payload": "4.0.0-internal.8867dba"
|
|
68
68
|
},
|
|
69
69
|
"//deps_notes": {
|
|
70
70
|
"zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
|
package/src/endpoint/access.ts
CHANGED
|
@@ -12,13 +12,8 @@ export type GetAuthorizedMCPArgs = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Authorization has two layers:
|
|
18
|
-
* 1. Payload collection/global permissions determine whether built-in operation tools are shown.
|
|
19
|
-
* 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
|
|
20
|
-
*
|
|
21
|
-
* Like Payload core operations, `overrideAccess` skips both layers.
|
|
15
|
+
* Authenticates an MCP request and removes items the user cannot access.
|
|
16
|
+
* `overrideAccess` skips Payload and MCP item access checks.
|
|
22
17
|
*/
|
|
23
18
|
export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
|
|
24
19
|
overrideAccess,
|
|
@@ -53,7 +48,6 @@ export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<Authorize
|
|
|
53
48
|
req,
|
|
54
49
|
}),
|
|
55
50
|
overrideAccess,
|
|
56
|
-
user: req.user,
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
|
|
@@ -66,8 +60,7 @@ export const filterMCPItems = async ({
|
|
|
66
60
|
overrideAccess: boolean
|
|
67
61
|
req: PayloadRequest
|
|
68
62
|
}): Promise<MCPItem[]> => {
|
|
69
|
-
// Match Payload core: overrideAccess bypasses access evaluation
|
|
70
|
-
// forcing each access function to return true.
|
|
63
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
71
64
|
if (overrideAccess) {
|
|
72
65
|
return items
|
|
73
66
|
}
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -42,8 +41,8 @@ export const countDocumentsTool = defineCollectionTool({
|
|
|
42
41
|
try {
|
|
43
42
|
const result = await payload.count({
|
|
44
43
|
collection: collectionSlug,
|
|
44
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
45
45
|
req,
|
|
46
|
-
...localAPIDefaults(authorizedMCP),
|
|
47
46
|
...(locale ? { locale } : {}),
|
|
48
47
|
...(trash !== undefined ? { trash } : {}),
|
|
49
48
|
...(where ? { where } : {}),
|