@payloadcms/plugin-mcp 4.0.0-internal.5f0cd13 → 4.0.0-internal.63f8536
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/LICENSE.md +1 -1
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/endpoint/access.d.ts +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +75 -88
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +68 -17
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -20
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +4 -4
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +133 -73
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +44 -6
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +68 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +39 -40
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +15 -22
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +51 -46
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +88 -84
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +20 -23
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +33 -38
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +144 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +119 -20
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +121 -58
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -3
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +82 -45
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +112 -110
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.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 +13 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +11 -16
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +81 -101
- package/src/endpoint/index.ts +58 -16
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +12 -20
- package/src/mcp/buildMcpServer.ts +169 -109
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- package/src/mcp/builtin/collections/countTool.ts +73 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/collections/createTool.ts +56 -61
- package/src/mcp/builtin/collections/deleteTool.ts +20 -18
- package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +65 -36
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
- package/src/mcp/builtin/collections/updateTool.ts +112 -107
- package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
- package/src/mcp/builtin/globals/findTool.ts +28 -19
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
- package/src/mcp/builtin/globals/updateTool.ts +52 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +117 -78
- package/src/stdio.ts +77 -45
- package/src/types.ts +128 -115
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -57
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -59
- package/dist/collection/index.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -305
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -93
- 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/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -57
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -63
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
- package/src/utils/schemaConversion/transformPointFields.ts +0 -56
package/dist/types.d.ts
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
import type { CallToolResult, ContentBlock, JsonSchemaType, McpServer, ResourceTemplate, ServerContext, StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
2
|
-
import type { AuthCollectionSlug,
|
|
1
|
+
import type { CallToolResult, ContentBlock, JsonSchemaType, McpServer, ResourceTemplate, ServerContext, StandardSchemaWithJSON, ToolAnnotations } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { AuthCollectionSlug, CollectionSlug, GlobalSlug, MaybePromise, PayloadRequest, SanitizedPermissions } from 'payload';
|
|
3
|
+
import type { GetAuthorizedMCPArgs } from './endpoint/access.js';
|
|
3
4
|
import type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName } from './mcp/builtinTools.js';
|
|
4
5
|
export type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName };
|
|
5
|
-
/** Re-exported from `@modelcontextprotocol/server` —
|
|
6
|
-
export type { JsonSchemaType, StandardSchemaWithJSON };
|
|
6
|
+
/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */
|
|
7
|
+
export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations };
|
|
7
8
|
/**
|
|
8
9
|
* What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
|
|
9
|
-
* JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
10
|
+
* JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
11
|
+
* Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
|
|
10
12
|
*/
|
|
11
13
|
export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON;
|
|
12
|
-
/**
|
|
13
|
-
* Serializable mirror of `SanitizedMCPPluginConfig` for client components —
|
|
14
|
-
* the full sanitized config carries functions (tool handlers, etc.) that can't
|
|
15
|
-
* cross the server→client boundary. Built by `sanitizeClientPluginConfig` and
|
|
16
|
-
* passed to the `AccessField` component via `clientProps`.
|
|
17
|
-
*
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export type ClientMCPPluginConfig = {
|
|
21
|
-
items: Array<{
|
|
22
|
-
collectionSlug?: string;
|
|
23
|
-
description: string;
|
|
24
|
-
globalSlug?: string;
|
|
25
|
-
key: string;
|
|
26
|
-
label: string;
|
|
27
|
-
type: 'collectionTool' | 'globalTool' | 'prompt' | 'resource' | 'tool';
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
14
|
export type MCPToolResponse = {
|
|
31
15
|
content: ContentBlock[];
|
|
32
16
|
/**
|
|
@@ -37,11 +21,27 @@ export type MCPToolResponse = {
|
|
|
37
21
|
doc?: Record<string, unknown>;
|
|
38
22
|
} & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>;
|
|
39
23
|
export type MCPResponseOverride = (response: MCPToolResponse, doc: Record<string, unknown>, req: PayloadRequest) => MCPToolResponse;
|
|
24
|
+
export type MCPAfterToolCallHook = (args: {
|
|
25
|
+
input: unknown;
|
|
26
|
+
req: PayloadRequest;
|
|
27
|
+
response: MCPToolResponse;
|
|
28
|
+
toolName: string;
|
|
29
|
+
}) => MaybePromise<MCPToolResponse>;
|
|
40
30
|
/**
|
|
41
31
|
* The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
|
|
42
32
|
* its inferred output; anything else falls back to `Record<string, unknown>`.
|
|
43
33
|
*/
|
|
44
34
|
export type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON ? StandardSchemaWithJSON extends TSchema ? Record<string, unknown> : StandardSchemaWithJSON.InferOutput<TSchema> : Record<string, unknown>;
|
|
35
|
+
export type MCPAccessArgs = {
|
|
36
|
+
permissions?: SanitizedPermissions;
|
|
37
|
+
req: PayloadRequest;
|
|
38
|
+
};
|
|
39
|
+
export type CollectionMCPAccessArgs = {
|
|
40
|
+
collectionSlug: CollectionSlug;
|
|
41
|
+
} & MCPAccessArgs;
|
|
42
|
+
export type GlobalMCPAccessArgs = {
|
|
43
|
+
globalSlug: GlobalSlug;
|
|
44
|
+
} & MCPAccessArgs;
|
|
45
45
|
export type ToolHandlerArgs<TSchema = undefined> = {
|
|
46
46
|
authorizedMCP: AuthorizedMCP;
|
|
47
47
|
input: TypedInput<TSchema>;
|
|
@@ -55,6 +55,13 @@ export type GlobalToolHandlerArgs<TSchema = undefined> = {
|
|
|
55
55
|
globalSlug: GlobalSlug;
|
|
56
56
|
} & ToolHandlerArgs<TSchema>;
|
|
57
57
|
export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
58
|
+
/**
|
|
59
|
+
* Runs while authorizing each MCP request, before the tool is advertised or called. Return
|
|
60
|
+
* `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
|
|
61
|
+
* is enabled.
|
|
62
|
+
*/
|
|
63
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
64
|
+
annotations?: ToolAnnotations;
|
|
58
65
|
description: string;
|
|
59
66
|
handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
|
|
60
67
|
input?: TSchema;
|
|
@@ -63,29 +70,51 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
|
|
|
63
70
|
*/
|
|
64
71
|
overrideResponse?: MCPResponseOverride;
|
|
65
72
|
};
|
|
66
|
-
/**
|
|
67
|
-
* `TSchema` is the schema itself (Standard Schema, raw JSON Schema, or undefined).
|
|
68
|
-
* The function-form variant of `input` carries a concrete `{ collectionSchema: JsonSchemaType }`
|
|
69
|
-
* parameter type so callers can write `({ collectionSchema }) => …` without annotating it.
|
|
70
|
-
*/
|
|
71
73
|
export type CollectionTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
74
|
+
/**
|
|
75
|
+
* Runs while authorizing each MCP request for this collection. Return `false` to reject calls
|
|
76
|
+
* to this tool for the collection. The shared tool is not advertised when no collections allow
|
|
77
|
+
* it, but can remain advertised when it is available for another collection. This is skipped
|
|
78
|
+
* when `overrideAccess` is enabled.
|
|
79
|
+
*/
|
|
80
|
+
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
|
|
72
81
|
handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
|
|
73
|
-
input?:
|
|
74
|
-
|
|
75
|
-
}) => TSchema) | TSchema;
|
|
76
|
-
} & Pick<Tool, 'description' | 'overrideResponse'>;
|
|
82
|
+
input?: TSchema;
|
|
83
|
+
} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>;
|
|
77
84
|
export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
85
|
+
/**
|
|
86
|
+
* Runs while authorizing each MCP request for this global. Return `false` to reject calls to
|
|
87
|
+
* this tool for the global. The shared tool is not advertised when no globals allow it, but
|
|
88
|
+
* can remain advertised when it is available for another global. This is skipped when
|
|
89
|
+
* `overrideAccess` is enabled.
|
|
90
|
+
*/
|
|
91
|
+
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
|
|
78
92
|
handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>;
|
|
79
|
-
input?:
|
|
80
|
-
|
|
81
|
-
}) => TSchema) | TSchema;
|
|
82
|
-
} & Pick<Tool, 'description' | 'overrideResponse'>;
|
|
93
|
+
input?: TSchema;
|
|
94
|
+
} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>;
|
|
83
95
|
/**
|
|
84
96
|
* Configures (or disables) a built-in tool without replacing it.
|
|
85
97
|
* `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a
|
|
86
98
|
* required handler) from being silently accepted at a built-in key slot.
|
|
87
99
|
*/
|
|
88
|
-
export type
|
|
100
|
+
export type MCPBuiltInCollectionToolOverride = {
|
|
101
|
+
/**
|
|
102
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
103
|
+
* this collection. This is skipped when `overrideAccess` is enabled.
|
|
104
|
+
*/
|
|
105
|
+
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>;
|
|
106
|
+
annotations?: ToolAnnotations;
|
|
107
|
+
description?: string;
|
|
108
|
+
handler?: never;
|
|
109
|
+
overrideResponse?: MCPResponseOverride;
|
|
110
|
+
};
|
|
111
|
+
export type MCPBuiltInGlobalToolOverride = {
|
|
112
|
+
/**
|
|
113
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
114
|
+
* this global. This is skipped when `overrideAccess` is enabled.
|
|
115
|
+
*/
|
|
116
|
+
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>;
|
|
117
|
+
annotations?: ToolAnnotations;
|
|
89
118
|
description?: string;
|
|
90
119
|
handler?: never;
|
|
91
120
|
overrideResponse?: MCPResponseOverride;
|
|
@@ -97,19 +126,19 @@ export type MCPBuiltInToolOverride = {
|
|
|
97
126
|
*/
|
|
98
127
|
export type MCPTopLevelToolEntry = Tool;
|
|
99
128
|
export type MCPCollectionToolsMap = {
|
|
100
|
-
[customToolName: string]: boolean | CollectionTool |
|
|
129
|
+
[customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined;
|
|
101
130
|
} & {
|
|
102
|
-
[K in MCPCollectionBuiltinName]?: false |
|
|
131
|
+
[K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride;
|
|
103
132
|
};
|
|
104
133
|
export type MCPAuthCollectionToolsMap = {
|
|
105
|
-
[K in MCPCollectionAuthToolName]?:
|
|
134
|
+
[K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true;
|
|
106
135
|
} & MCPCollectionToolsMap;
|
|
107
136
|
/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */
|
|
108
137
|
export type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug ? MCPAuthCollectionToolsMap : MCPCollectionToolsMap;
|
|
109
138
|
export type MCPGlobalToolsMap = {
|
|
110
|
-
[customToolName: string]: boolean | GlobalTool |
|
|
139
|
+
[customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined;
|
|
111
140
|
} & {
|
|
112
|
-
[K in MCPGlobalBuiltinName]?: false |
|
|
141
|
+
[K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride;
|
|
113
142
|
};
|
|
114
143
|
export type MCPTopLevelToolsMap = Record<string, Tool>;
|
|
115
144
|
export type PromptHandlerArgs<TSchema = undefined> = {
|
|
@@ -118,6 +147,12 @@ export type PromptHandlerArgs<TSchema = undefined> = {
|
|
|
118
147
|
serverContext: ServerContext;
|
|
119
148
|
};
|
|
120
149
|
export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
|
|
150
|
+
/**
|
|
151
|
+
* Runs while authorizing each MCP request, before the prompt is advertised or used. Return
|
|
152
|
+
* `false` to make the prompt unavailable for that request. This is skipped when
|
|
153
|
+
* `overrideAccess` is enabled.
|
|
154
|
+
*/
|
|
155
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
121
156
|
argsSchema: TSchema;
|
|
122
157
|
description: string;
|
|
123
158
|
handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{
|
|
@@ -139,6 +174,12 @@ export type ResourceHandlerArgs = {
|
|
|
139
174
|
uri: URL;
|
|
140
175
|
};
|
|
141
176
|
export type Resource = {
|
|
177
|
+
/**
|
|
178
|
+
* Runs while authorizing each MCP request, before the resource is advertised or read. Return
|
|
179
|
+
* `false` to make the resource unavailable for that request. This is skipped when
|
|
180
|
+
* `overrideAccess` is enabled.
|
|
181
|
+
*/
|
|
182
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>;
|
|
142
183
|
description: string;
|
|
143
184
|
handler: (args: ResourceHandlerArgs) => MaybePromise<{
|
|
144
185
|
contents: Array<{
|
|
@@ -172,100 +213,64 @@ export type MCPPluginConfig = {
|
|
|
172
213
|
collections?: {
|
|
173
214
|
[Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>;
|
|
174
215
|
};
|
|
175
|
-
/** Skip MCP registration.
|
|
216
|
+
/** Skip MCP endpoint registration. */
|
|
176
217
|
disabled?: boolean;
|
|
177
218
|
globals?: {
|
|
178
219
|
[Slug in GlobalSlug]?: MCPPluginGlobalConfig;
|
|
179
220
|
};
|
|
221
|
+
hooks?: {
|
|
222
|
+
/** Transform a tool response after its handler returns */
|
|
223
|
+
afterToolCall?: MCPAfterToolCallHook[];
|
|
224
|
+
};
|
|
180
225
|
mcp?: {
|
|
181
226
|
serverOptions?: MCPServerOptions;
|
|
182
227
|
verboseLogs?: boolean;
|
|
183
228
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Replace the default MCP authorization resolver.
|
|
231
|
+
*
|
|
232
|
+
* This hook replaces the default authentication flow. It must set `req.user` to the
|
|
233
|
+
* authenticated Payload user, or to `null` for an anonymous caller, before returning.
|
|
234
|
+
*/
|
|
235
|
+
overrideGetAuthorizedMCP?: (args: {
|
|
191
236
|
pluginConfig: SanitizedMCPPluginConfig;
|
|
192
|
-
|
|
193
|
-
}) => MaybePromise<AuthorizedMCP>;
|
|
237
|
+
} & GetAuthorizedMCPArgs) => MaybePromise<AuthorizedMCP>;
|
|
194
238
|
prompts?: Record<string, Prompt>;
|
|
195
239
|
resources?: Record<string, Resource>;
|
|
196
240
|
/** Cross-cutting tools (not scoped to any collection or global). */
|
|
197
241
|
tools?: MCPTopLevelToolsMap;
|
|
198
|
-
userCollection?: CollectionSlug;
|
|
199
242
|
};
|
|
200
243
|
export type SanitizedMCPPluginConfig = {
|
|
201
244
|
items: MCPItem[];
|
|
202
|
-
|
|
203
|
-
} & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideApiKeyCollection' | 'overrideAuth'>;
|
|
245
|
+
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>;
|
|
204
246
|
export type MCPServerOptions = {
|
|
205
247
|
options?: ConstructorParameters<typeof McpServer>[1];
|
|
206
248
|
serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>;
|
|
207
249
|
};
|
|
208
250
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* defaults (built-in CRUD is on, opt-in tools are off).
|
|
212
|
-
*/
|
|
213
|
-
export type MCPAPIKeysDocAccessTree = {
|
|
214
|
-
collections?: {
|
|
215
|
-
[CollectionSlug: CollectionSlug]: {
|
|
216
|
-
[ToolKey: string]: boolean;
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
globals?: {
|
|
220
|
-
[GlobalSlug: GlobalSlug]: {
|
|
221
|
-
[ToolKey: string]: boolean;
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
prompts?: {
|
|
225
|
-
[PromptKey: string]: boolean;
|
|
226
|
-
};
|
|
227
|
-
resources?: {
|
|
228
|
-
[ResourceKey: string]: boolean;
|
|
229
|
-
};
|
|
230
|
-
tools?: {
|
|
231
|
-
[ToolKey: string]: boolean;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* Stored on `payload-mcp-api-keys` docs
|
|
236
|
-
*/
|
|
237
|
-
export type MCPAPIKeysDoc = {
|
|
238
|
-
access: MCPAPIKeysDocAccessTree;
|
|
239
|
-
id: DefaultDocumentIDType;
|
|
240
|
-
overrideAccess?: boolean;
|
|
241
|
-
user: null | TypedUser;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* One MCP primitive — tool, prompt, or resource — paired with the metadata both
|
|
245
|
-
* the endpoint and the API key collection need. Built by `sanitizeMCPConfig`,
|
|
246
|
-
* filtered by `getAuthorizedMCP`, registered by the MCP endpoint.
|
|
251
|
+
* One MCP primitive plus the metadata needed for config-driven filtering and
|
|
252
|
+
* registration.
|
|
247
253
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* registration time.
|
|
252
|
-
* - `label`: human-readable admin-UI display text for the checkbox.
|
|
253
|
-
* - `tool` / `prompt` / `resource`: the live primitive (its own
|
|
254
|
-
* `description` is what both MCP clients and the admin UI surface).
|
|
254
|
+
* - `configKey`: the config identifier, e.g. `find` or `echo`.
|
|
255
|
+
* - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.
|
|
256
|
+
* - `label`: human-readable display text.
|
|
255
257
|
*/
|
|
256
258
|
export type MCPItemBase = {
|
|
257
|
-
|
|
259
|
+
configKey: string;
|
|
258
260
|
label: string;
|
|
261
|
+
mcpName: string;
|
|
259
262
|
};
|
|
260
|
-
export type
|
|
263
|
+
export type CollectionMCPItem = {
|
|
261
264
|
collectionSlug: CollectionSlug;
|
|
262
265
|
tool: CollectionTool;
|
|
263
266
|
type: 'collectionTool';
|
|
264
|
-
} & MCPItemBase
|
|
267
|
+
} & MCPItemBase;
|
|
268
|
+
export type GlobalMCPItem = {
|
|
265
269
|
globalSlug: GlobalSlug;
|
|
266
270
|
tool: GlobalTool;
|
|
267
271
|
type: 'globalTool';
|
|
268
|
-
} & MCPItemBase
|
|
272
|
+
} & MCPItemBase;
|
|
273
|
+
export type MCPItem = ({
|
|
269
274
|
prompt: Prompt;
|
|
270
275
|
type: 'prompt';
|
|
271
276
|
} & MCPItemBase) | ({
|
|
@@ -274,16 +279,13 @@ export type MCPItem = ({
|
|
|
274
279
|
} & MCPItemBase) | ({
|
|
275
280
|
tool: Tool;
|
|
276
281
|
type: 'tool';
|
|
277
|
-
} & MCPItemBase);
|
|
282
|
+
} & MCPItemBase) | CollectionMCPItem | GlobalMCPItem;
|
|
278
283
|
/**
|
|
279
|
-
* The
|
|
280
|
-
*
|
|
281
|
-
* receive this via `args.authorizedMCP` so they can spread
|
|
282
|
-
* `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`.
|
|
283
286
|
*/
|
|
284
287
|
export type AuthorizedMCP = {
|
|
285
288
|
items: MCPItem[];
|
|
286
289
|
overrideAccess: boolean;
|
|
287
|
-
user: null | TypedUser;
|
|
288
290
|
};
|
|
289
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,
|
|
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;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AAC,CAAC,CAAC,CAAC,CAAA;CACjE,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,gBAAgB,CAAA;CACvB,GAAG,WAAW,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
|
-
* receive this via `args.authorizedMCP` so they can spread
|
|
5
|
-
* `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} from '@modelcontextprotocol/server'\nimport type {\n AuthCollectionSlug,\n CollectionConfig,\n CollectionSlug,\n DefaultDocumentIDType,\n GlobalSlug,\n MaybePromise,\n PayloadRequest,\n TypedUser,\n} from 'payload'\n\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` — the JSON Schema shape the MCP runtime validates against. */\nexport type { JsonSchemaType, StandardSchemaWithJSON }\n\n/**\n * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw\n * JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).\n */\nexport type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON\n\n/**\n * Serializable mirror of `SanitizedMCPPluginConfig` for client components —\n * the full sanitized config carries functions (tool handlers, etc.) that can't\n * cross the server→client boundary. Built by `sanitizeClientPluginConfig` and\n * passed to the `AccessField` component via `clientProps`.\n *\n * @internal\n */\nexport type ClientMCPPluginConfig = {\n items: Array<{\n collectionSlug?: string\n description: string\n globalSlug?: string\n key: string\n label: string\n type: 'collectionTool' | 'globalTool' | 'prompt' | 'resource' | 'tool'\n }>\n}\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\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 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 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\n/**\n * `TSchema` is the schema itself (Standard Schema, raw JSON Schema, or undefined).\n * The function-form variant of `input` carries a concrete `{ collectionSchema: JsonSchemaType }`\n * parameter type so callers can write `({ collectionSchema }) => …` without annotating it.\n */\nexport type CollectionTool<\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n> = {\n handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: ((args: { collectionSchema: JsonSchemaType }) => TSchema) | TSchema\n} & Pick<Tool, 'description' | 'overrideResponse'>\n\nexport type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =\n {\n handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: ((args: { globalSchema: JsonSchemaType }) => TSchema) | TSchema\n } & Pick<Tool, '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 MCPBuiltInToolOverride = {\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 | MCPBuiltInToolOverride | undefined\n} & {\n [K in MCPCollectionBuiltinName]?: false | MCPBuiltInToolOverride\n}\n\nexport type MCPAuthCollectionToolsMap = {\n [K in MCPCollectionAuthToolName]?: MCPBuiltInToolOverride | 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 | MCPBuiltInToolOverride | undefined\n} & {\n [K in MCPGlobalBuiltinName]?: false | MCPBuiltInToolOverride\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 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 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 registration. The API key collection is still added (so DB / types stay stable). */\n disabled?: boolean\n globals?: {\n [Slug in GlobalSlug]?: MCPPluginGlobalConfig\n }\n mcp?: {\n serverOptions?: MCPServerOptions\n verboseLogs?: boolean\n }\n overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig\n /** Replace the default API-key auth with a custom resolver. */\n overrideAuth?: (args: {\n getAPIKeyDoc: (overrideApiKey?: string) => Promise<MCPAPIKeysDoc>\n getAuthorizedMCP: (args: { apiKeyDoc: MCPAPIKeysDoc }) => AuthorizedMCP\n pluginConfig: SanitizedMCPPluginConfig\n req: PayloadRequest\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 userCollection?: CollectionSlug\n}\n\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n userCollection: CollectionSlug\n} & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideApiKeyCollection' | 'overrideAuth'>\n\nexport type MCPServerOptions = {\n options?: ConstructorParameters<typeof McpServer>[1]\n serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>\n}\n\n/**\n * Nested access tree as stored in the collection.\n * A `false` leaf disables that tool; missing keys defer to\n * defaults (built-in CRUD is on, opt-in tools are off).\n */\nexport type MCPAPIKeysDocAccessTree = {\n collections?: {\n [CollectionSlug: CollectionSlug]: {\n [ToolKey: string]: boolean\n }\n }\n globals?: {\n [GlobalSlug: GlobalSlug]: {\n [ToolKey: string]: boolean\n }\n }\n prompts?: {\n [PromptKey: string]: boolean\n }\n resources?: {\n [ResourceKey: string]: boolean\n }\n tools?: {\n [ToolKey: string]: boolean\n }\n}\n\n/**\n * Stored on `payload-mcp-api-keys` docs\n */\nexport type MCPAPIKeysDoc = {\n access: MCPAPIKeysDocAccessTree\n id: DefaultDocumentIDType\n overrideAccess?: boolean\n user: null | TypedUser\n}\n\n/**\n * One MCP primitive — tool, prompt, or resource — paired with the metadata both\n * the endpoint and the API key collection need. Built by `sanitizeMCPConfig`,\n * filtered by `getAuthorizedMCP`, registered by the MCP endpoint.\n *\n * - `key`: the config identifier (`find`, `echo`). Used for the API-key deny\n * lookup and as the admin checkbox field name. For collection/global tools,\n * the MCP wire name (`findPosts`) is derived from `key + slug` at\n * registration time.\n * - `label`: human-readable admin-UI display text for the checkbox.\n * - `tool` / `prompt` / `resource`: the live primitive (its own\n * `description` is what both MCP clients and the admin UI surface).\n */\nexport type MCPItemBase = {\n key: string\n label: string\n}\n\nexport type MCPItem =\n | ({\n collectionSlug: CollectionSlug\n tool: CollectionTool\n type: 'collectionTool'\n } & MCPItemBase)\n | ({\n globalSlug: GlobalSlug\n tool: GlobalTool\n type: 'globalTool'\n } & MCPItemBase)\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\n/**\n * The caller's identity + the MCP items they can use for this request. Returned\n * by `getAuthorizedMCP`; denied items are simply absent from `items`. Handlers\n * receive this via `args.authorizedMCP` so they can spread\n * `localAPIDefaults(authorizedMCP)` into every local API call.\n */\nexport type AuthorizedMCP = {\n items: MCPItem[]\n overrideAccess: boolean\n user: null | TypedUser\n}\n"],"names":[],"mappings":"AAgVA;;;;;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"}
|
|
@@ -3,7 +3,7 @@ import type { SanitizedMCPPluginConfig } from '../types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the sanitized plugin config — the form produced by
|
|
5
5
|
* `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.
|
|
6
|
-
* Callers downstream of plugin init can rely on `items
|
|
6
|
+
* Callers downstream of plugin init can rely on `items` and other defaults
|
|
7
7
|
* being fully resolved.
|
|
8
8
|
*/
|
|
9
9
|
export declare const getPluginConfig: (args: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the sanitized plugin config — the form produced by
|
|
3
3
|
* `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.
|
|
4
|
-
* Callers downstream of plugin init can rely on `items
|
|
4
|
+
* Callers downstream of plugin init can rely on `items` and other defaults
|
|
5
5
|
* being fully resolved.
|
|
6
6
|
*/ export const getPluginConfig = ({ config })=>{
|
|
7
7
|
const plugin = config.plugins?.find((plugin)=>plugin.slug === '@payloadcms/plugin-mcp');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/getPluginConfig.ts"],"sourcesContent":["import type { PluginsMap, SanitizedConfig } from 'payload'\n\nimport type { SanitizedMCPPluginConfig } from '../types.js'\n\n/**\n * Returns the sanitized plugin config — the form produced by\n * `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.\n * Callers downstream of plugin init can rely on `items
|
|
1
|
+
{"version":3,"sources":["../../src/utils/getPluginConfig.ts"],"sourcesContent":["import type { PluginsMap, SanitizedConfig } from 'payload'\n\nimport type { SanitizedMCPPluginConfig } from '../types.js'\n\n/**\n * Returns the sanitized plugin config — the form produced by\n * `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.\n * Callers downstream of plugin init can rely on `items` and other defaults\n * being fully resolved.\n */\nexport const getPluginConfig: (args: { config: SanitizedConfig }) => SanitizedMCPPluginConfig = ({\n config,\n}) => {\n const plugin = config.plugins?.find(\n (plugin) => plugin.slug === '@payloadcms/plugin-mcp',\n ) as PluginsMap['@payloadcms/plugin-mcp']\n\n if (!plugin) {\n throw new Error('MCP Plugin not found in config.plugins.')\n }\n\n // @ts-expect-error\n return plugin.sanitizedOptions\n}\n"],"names":["getPluginConfig","config","plugin","plugins","find","slug","Error","sanitizedOptions"],"mappings":"AAIA;;;;;CAKC,GACD,OAAO,MAAMA,kBAAmF,CAAC,EAC/FC,MAAM,EACP;IACC,MAAMC,SAASD,OAAOE,OAAO,EAAEC,KAC7B,CAACF,SAAWA,OAAOG,IAAI,KAAK;IAG9B,IAAI,CAACH,QAAQ;QACX,MAAM,IAAII,MAAM;IAClB;IAEA,mBAAmB;IACnB,OAAOJ,OAAOK,gBAAgB;AAChC,EAAC"}
|
|
@@ -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,GAAI,sDAKlC;IACD,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,WAAW,EAAE,4BAA4B,CAAA;IACzC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,sBAAsB,KAAK,OAAO,CAAA;CAC3E,KAAG,cAAc,EAoFjB,CAAA"}
|
|
@@ -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,IAA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ectionPermission, type SanitizedGlobalPermission } from 'payload';
|
|
2
|
+
import type { JsonSchemaType } from '../../types.js';
|
|
3
|
+
export declare const getCollectionInputSchema: ({ collectionSlug, permissions, req, }: {
|
|
4
|
+
collectionSlug: CollectionSlug;
|
|
5
|
+
permissions?: SanitizedCollectionPermission;
|
|
6
|
+
req: PayloadRequest;
|
|
7
|
+
}) => JsonSchemaType | null;
|
|
8
|
+
export declare const getGlobalInputSchema: ({ globalSlug, permissions, req, }: {
|
|
9
|
+
globalSlug: GlobalSlug;
|
|
10
|
+
permissions?: SanitizedGlobalPermission;
|
|
11
|
+
req: PayloadRequest;
|
|
12
|
+
}) => JsonSchemaType | null;
|
|
13
|
+
//# sourceMappingURL=getEntityInputSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,GAAI,uCAItC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,mCAIlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
|