@payloadcms/plugin-mcp 4.0.0-internal.a0ef1b8 → 4.0.0-internal.a2d053c
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/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +95 -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 +109 -16
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +39 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +94 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/endpoint/oauthLoginToken.d.ts +21 -0
- package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
- package/dist/endpoint/oauthLoginToken.js +79 -0
- package/dist/endpoint/oauthLoginToken.js.map +1 -0
- package/dist/endpoint/oauthServer.d.ts +12 -0
- package/dist/endpoint/oauthServer.d.ts.map +1 -0
- package/dist/endpoint/oauthServer.js +362 -0
- package/dist/endpoint/oauthServer.js.map +1 -0
- 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 +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -22
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +6 -6
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +146 -81
- 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 +123 -61
- 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 +63 -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 +60 -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 +114 -68
- 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 +55 -61
- 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 +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- 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 +88 -0
- package/dist/mcp/builtin/collections/fileInput.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 +77 -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 +62 -75
- 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 +74 -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 +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.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 +103 -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 +69 -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 +118 -137
- 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/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- 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 +69 -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 +60 -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 +27 -36
- 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 +68 -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 +78 -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 +81 -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 +70 -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 +44 -62
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +150 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +125 -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 +127 -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 +86 -47
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +205 -114
- 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/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/seal.d.ts +18 -0
- package/dist/utils/seal.d.ts.map +1 -0
- package/dist/utils/seal.js +27 -0
- package/dist/utils/seal.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.js.map +1 -1
- package/package.json +27 -37
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +99 -101
- package/src/endpoint/index.ts +95 -15
- package/src/endpoint/oauth.ts +92 -0
- package/src/endpoint/oauthLoginToken.ts +91 -0
- package/src/endpoint/oauthServer.ts +396 -0
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +52 -25
- package/src/mcp/buildMcpServer.ts +181 -116
- package/src/mcp/builtin/collections/authTools.ts +124 -77
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +115 -88
- package/src/mcp/builtin/collections/deleteTool.ts +49 -75
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +58 -111
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +106 -143
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +28 -58
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +52 -80
- package/src/mcp/builtinTools.ts +118 -41
- package/src/mcp/sanitizeMCPConfig.ts +121 -78
- package/src/stdio.ts +80 -47
- package/src/types.ts +223 -119
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/seal.ts +46 -0
- package/src/utils/toStandardSchema.ts +1 -1
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- 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 -60
- 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/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- 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/buildToolInput.d.ts +0 -29
- package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
- package/dist/utils/schemaConversion/buildToolInput.js +0 -51
- package/dist/utils/schemaConversion/buildToolInput.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/sanitizeEntitySchema.d.ts +0 -15
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/src/@types/assets.d.ts +0 -3
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -64
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/buildToolInput.ts +0 -68
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
- package/src/utils/transformPointDataToPayload.ts +0 -40
package/src/types.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CallToolResult,
|
|
3
3
|
ContentBlock,
|
|
4
|
+
Implementation,
|
|
4
5
|
JsonSchemaType,
|
|
5
|
-
|
|
6
|
+
McpServerOptions,
|
|
6
7
|
ResourceTemplate,
|
|
7
8
|
ServerContext,
|
|
8
9
|
StandardSchemaWithJSON,
|
|
10
|
+
ToolAnnotations,
|
|
9
11
|
} from '@modelcontextprotocol/server'
|
|
10
12
|
import type {
|
|
11
13
|
AuthCollectionSlug,
|
|
12
|
-
CollectionConfig,
|
|
13
14
|
CollectionSlug,
|
|
14
|
-
DefaultDocumentIDType,
|
|
15
15
|
GlobalSlug,
|
|
16
16
|
MaybePromise,
|
|
17
17
|
PayloadRequest,
|
|
18
|
-
|
|
18
|
+
SanitizedPermissions,
|
|
19
19
|
} from 'payload'
|
|
20
20
|
|
|
21
|
+
import type { GetAuthorizedMCPArgs } from './endpoint/access.js'
|
|
21
22
|
import type {
|
|
22
23
|
MCPCollectionAuthToolName,
|
|
23
24
|
MCPCollectionBuiltinName,
|
|
@@ -26,34 +27,16 @@ import type {
|
|
|
26
27
|
|
|
27
28
|
export type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }
|
|
28
29
|
|
|
29
|
-
/** Re-exported from `@modelcontextprotocol/server` —
|
|
30
|
-
export type { JsonSchemaType, StandardSchemaWithJSON }
|
|
30
|
+
/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */
|
|
31
|
+
export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
|
|
34
|
-
* JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
35
|
+
* JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
|
|
36
|
+
* Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
|
|
35
37
|
*/
|
|
36
38
|
export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON
|
|
37
39
|
|
|
38
|
-
/**
|
|
39
|
-
* Serializable mirror of `SanitizedMCPPluginConfig` for client components —
|
|
40
|
-
* the full sanitized config carries functions (tool handlers, etc.) that can't
|
|
41
|
-
* cross the server→client boundary. Built by `sanitizeClientPluginConfig` and
|
|
42
|
-
* passed to the `AccessField` component via `clientProps`.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export type ClientMCPPluginConfig = {
|
|
47
|
-
items: Array<{
|
|
48
|
-
collectionSlug?: string
|
|
49
|
-
description: string
|
|
50
|
-
globalSlug?: string
|
|
51
|
-
key: string
|
|
52
|
-
label: string
|
|
53
|
-
type: 'collectionTool' | 'globalTool' | 'prompt' | 'resource' | 'tool'
|
|
54
|
-
}>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
40
|
export type MCPToolResponse = {
|
|
58
41
|
content: ContentBlock[]
|
|
59
42
|
/**
|
|
@@ -70,6 +53,13 @@ export type MCPResponseOverride = (
|
|
|
70
53
|
req: PayloadRequest,
|
|
71
54
|
) => MCPToolResponse
|
|
72
55
|
|
|
56
|
+
export type MCPAfterToolCallHook = (args: {
|
|
57
|
+
input: unknown
|
|
58
|
+
req: PayloadRequest
|
|
59
|
+
response: MCPToolResponse
|
|
60
|
+
toolName: string
|
|
61
|
+
}) => MaybePromise<MCPToolResponse>
|
|
62
|
+
|
|
73
63
|
/**
|
|
74
64
|
* The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
|
|
75
65
|
* its inferred output; anything else falls back to `Record<string, unknown>`.
|
|
@@ -80,6 +70,19 @@ export type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON
|
|
|
80
70
|
: StandardSchemaWithJSON.InferOutput<TSchema>
|
|
81
71
|
: Record<string, unknown>
|
|
82
72
|
|
|
73
|
+
export type MCPAccessArgs = {
|
|
74
|
+
permissions?: SanitizedPermissions
|
|
75
|
+
req: PayloadRequest
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type CollectionMCPAccessArgs = {
|
|
79
|
+
slug: CollectionSlug
|
|
80
|
+
} & MCPAccessArgs
|
|
81
|
+
|
|
82
|
+
export type GlobalMCPAccessArgs = {
|
|
83
|
+
slug: GlobalSlug
|
|
84
|
+
} & MCPAccessArgs
|
|
85
|
+
|
|
83
86
|
export type ToolHandlerArgs<TSchema = undefined> = {
|
|
84
87
|
authorizedMCP: AuthorizedMCP
|
|
85
88
|
input: TypedInput<TSchema>
|
|
@@ -88,14 +91,21 @@ export type ToolHandlerArgs<TSchema = undefined> = {
|
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
export type CollectionToolHandlerArgs<TSchema = undefined> = {
|
|
91
|
-
|
|
94
|
+
slug: CollectionSlug
|
|
92
95
|
} & ToolHandlerArgs<TSchema>
|
|
93
96
|
|
|
94
97
|
export type GlobalToolHandlerArgs<TSchema = undefined> = {
|
|
95
|
-
|
|
98
|
+
slug: GlobalSlug
|
|
96
99
|
} & ToolHandlerArgs<TSchema>
|
|
97
100
|
|
|
98
101
|
export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
102
|
+
/**
|
|
103
|
+
* Runs while authorizing each MCP request, before the tool is advertised or called. Return
|
|
104
|
+
* `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
|
|
105
|
+
* is enabled.
|
|
106
|
+
*/
|
|
107
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
108
|
+
annotations?: ToolAnnotations
|
|
99
109
|
description: string
|
|
100
110
|
handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
|
|
101
111
|
input?: TSchema
|
|
@@ -105,30 +115,57 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
|
|
|
105
115
|
overrideResponse?: MCPResponseOverride
|
|
106
116
|
}
|
|
107
117
|
|
|
108
|
-
/**
|
|
109
|
-
* `TSchema` is the schema itself (Standard Schema, raw JSON Schema, or undefined).
|
|
110
|
-
* The function-form variant of `input` carries a concrete `{ collectionSchema: JsonSchemaType }`
|
|
111
|
-
* parameter type so callers can write `({ collectionSchema }) => …` without annotating it.
|
|
112
|
-
*/
|
|
113
118
|
export type CollectionTool<
|
|
114
119
|
TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,
|
|
115
120
|
> = {
|
|
121
|
+
/**
|
|
122
|
+
* Runs while authorizing each MCP request for this collection. Return `false` to reject calls
|
|
123
|
+
* to this tool for the collection. The shared tool is not advertised when no collections allow
|
|
124
|
+
* it, but can remain advertised when it is available for another collection. This is skipped
|
|
125
|
+
* when `overrideAccess` is enabled.
|
|
126
|
+
*/
|
|
127
|
+
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
|
|
116
128
|
handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
|
|
117
|
-
input?:
|
|
118
|
-
} & Pick<Tool, 'description' | 'overrideResponse'>
|
|
129
|
+
input?: TSchema
|
|
130
|
+
} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>
|
|
119
131
|
|
|
120
132
|
export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =
|
|
121
133
|
{
|
|
134
|
+
/**
|
|
135
|
+
* Runs while authorizing each MCP request for this global. Return `false` to reject calls to
|
|
136
|
+
* this tool for the global. The shared tool is not advertised when no globals allow it, but
|
|
137
|
+
* can remain advertised when it is available for another global. This is skipped when
|
|
138
|
+
* `overrideAccess` is enabled.
|
|
139
|
+
*/
|
|
140
|
+
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
|
|
122
141
|
handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
|
|
123
|
-
input?:
|
|
124
|
-
} & Pick<Tool, 'description' | 'overrideResponse'>
|
|
142
|
+
input?: TSchema
|
|
143
|
+
} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>
|
|
125
144
|
|
|
126
145
|
/**
|
|
127
146
|
* Configures (or disables) a built-in tool without replacing it.
|
|
128
147
|
* `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a
|
|
129
148
|
* required handler) from being silently accepted at a built-in key slot.
|
|
130
149
|
*/
|
|
131
|
-
export type
|
|
150
|
+
export type MCPBuiltInCollectionToolOverride = {
|
|
151
|
+
/**
|
|
152
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
153
|
+
* this collection. This is skipped when `overrideAccess` is enabled.
|
|
154
|
+
*/
|
|
155
|
+
access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
|
|
156
|
+
annotations?: ToolAnnotations
|
|
157
|
+
description?: string
|
|
158
|
+
handler?: never
|
|
159
|
+
overrideResponse?: MCPResponseOverride
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type MCPBuiltInGlobalToolOverride = {
|
|
163
|
+
/**
|
|
164
|
+
* Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
|
|
165
|
+
* this global. This is skipped when `overrideAccess` is enabled.
|
|
166
|
+
*/
|
|
167
|
+
access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
|
|
168
|
+
annotations?: ToolAnnotations
|
|
132
169
|
description?: string
|
|
133
170
|
handler?: never
|
|
134
171
|
overrideResponse?: MCPResponseOverride
|
|
@@ -142,13 +179,13 @@ export type MCPBuiltInToolOverride = {
|
|
|
142
179
|
export type MCPTopLevelToolEntry = Tool
|
|
143
180
|
|
|
144
181
|
export type MCPCollectionToolsMap = {
|
|
145
|
-
[customToolName: string]: boolean | CollectionTool |
|
|
182
|
+
[customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined
|
|
146
183
|
} & {
|
|
147
|
-
[K in MCPCollectionBuiltinName]?: false |
|
|
184
|
+
[K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride
|
|
148
185
|
}
|
|
149
186
|
|
|
150
187
|
export type MCPAuthCollectionToolsMap = {
|
|
151
|
-
[K in MCPCollectionAuthToolName]?:
|
|
188
|
+
[K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true
|
|
152
189
|
} & MCPCollectionToolsMap
|
|
153
190
|
|
|
154
191
|
/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */
|
|
@@ -157,9 +194,9 @@ export type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends
|
|
|
157
194
|
: MCPCollectionToolsMap
|
|
158
195
|
|
|
159
196
|
export type MCPGlobalToolsMap = {
|
|
160
|
-
[customToolName: string]: boolean | GlobalTool |
|
|
197
|
+
[customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined
|
|
161
198
|
} & {
|
|
162
|
-
[K in MCPGlobalBuiltinName]?: false |
|
|
199
|
+
[K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride
|
|
163
200
|
}
|
|
164
201
|
|
|
165
202
|
export type MCPTopLevelToolsMap = Record<string, Tool>
|
|
@@ -171,6 +208,12 @@ export type PromptHandlerArgs<TSchema = undefined> = {
|
|
|
171
208
|
}
|
|
172
209
|
|
|
173
210
|
export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
|
|
211
|
+
/**
|
|
212
|
+
* Runs while authorizing each MCP request, before the prompt is advertised or used. Return
|
|
213
|
+
* `false` to make the prompt unavailable for that request. This is skipped when
|
|
214
|
+
* `overrideAccess` is enabled.
|
|
215
|
+
*/
|
|
216
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
174
217
|
argsSchema: TSchema
|
|
175
218
|
description: string
|
|
176
219
|
handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{
|
|
@@ -188,6 +231,12 @@ export type ResourceHandlerArgs = {
|
|
|
188
231
|
}
|
|
189
232
|
|
|
190
233
|
export type Resource = {
|
|
234
|
+
/**
|
|
235
|
+
* Runs while authorizing each MCP request, before the resource is advertised or read. Return
|
|
236
|
+
* `false` to make the resource unavailable for that request. This is skipped when
|
|
237
|
+
* `overrideAccess` is enabled.
|
|
238
|
+
*/
|
|
239
|
+
access?: (args: MCPAccessArgs) => MaybePromise<boolean>
|
|
191
240
|
description: string
|
|
192
241
|
handler: (args: ResourceHandlerArgs) => MaybePromise<{
|
|
193
242
|
contents: Array<{ text: string; uri: string }>
|
|
@@ -221,106 +270,162 @@ export type MCPPluginConfig = {
|
|
|
221
270
|
collections?: {
|
|
222
271
|
[Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>
|
|
223
272
|
}
|
|
224
|
-
/** Skip MCP registration.
|
|
273
|
+
/** Skip MCP endpoint registration. */
|
|
225
274
|
disabled?: boolean
|
|
226
275
|
globals?: {
|
|
227
276
|
[Slug in GlobalSlug]?: MCPPluginGlobalConfig
|
|
228
277
|
}
|
|
278
|
+
hooks?: {
|
|
279
|
+
/** Transform a tool response after its handler returns */
|
|
280
|
+
afterToolCall?: MCPAfterToolCallHook[]
|
|
281
|
+
}
|
|
229
282
|
mcp?: {
|
|
283
|
+
/**
|
|
284
|
+
* Largest HTTP request body, in bytes, that the MCP endpoint accepts. Larger requests
|
|
285
|
+
* are answered with `413`. Base64 file uploads count toward this limit.
|
|
286
|
+
*
|
|
287
|
+
* @default 4194304 (4 MiB, the MCP SDK default)
|
|
288
|
+
*/
|
|
289
|
+
maxRequestBodySize?: number
|
|
230
290
|
serverOptions?: MCPServerOptions
|
|
231
291
|
verboseLogs?: boolean
|
|
232
292
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
293
|
+
/**
|
|
294
|
+
* How MCP clients sign in. MCP requests without an authenticated user get a `401` that points
|
|
295
|
+
* to the protected resource metadata (RFC 9728). Set to `false` to only accept API keys and
|
|
296
|
+
* anonymous requests.
|
|
297
|
+
*
|
|
298
|
+
* @default { type: 'builtin' }
|
|
299
|
+
*/
|
|
300
|
+
oauth?: false | MCPOAuthConfig
|
|
301
|
+
/**
|
|
302
|
+
* Replace the default MCP authorization resolver.
|
|
303
|
+
*
|
|
304
|
+
* This hook replaces the default authentication flow. It must set `req.user` to the
|
|
305
|
+
* authenticated Payload user, or to `null` for an anonymous caller, before returning.
|
|
306
|
+
*/
|
|
307
|
+
overrideGetAuthorizedMCP?: (
|
|
308
|
+
args: {
|
|
309
|
+
pluginConfig: SanitizedMCPPluginConfig
|
|
310
|
+
} & GetAuthorizedMCPArgs,
|
|
311
|
+
) => MaybePromise<AuthorizedMCP>
|
|
241
312
|
prompts?: Record<string, Prompt>
|
|
242
313
|
resources?: Record<string, Resource>
|
|
243
314
|
/** Cross-cutting tools (not scoped to any collection or global). */
|
|
244
315
|
tools?: MCPTopLevelToolsMap
|
|
245
|
-
userCollection?: CollectionSlug
|
|
246
316
|
}
|
|
247
317
|
|
|
248
|
-
export type
|
|
249
|
-
items: MCPItem[]
|
|
250
|
-
userCollection: CollectionSlug
|
|
251
|
-
} & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideApiKeyCollection' | 'overrideAuth'>
|
|
252
|
-
|
|
253
|
-
export type MCPServerOptions = {
|
|
254
|
-
options?: ConstructorParameters<typeof McpServer>[1]
|
|
255
|
-
serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>
|
|
256
|
-
}
|
|
318
|
+
export type MCPOAuthConfig = MCPBuiltinOAuthConfig | MCPExternalOAuthConfig
|
|
257
319
|
|
|
258
320
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* defaults (built-in CRUD is on, opt-in tools are off).
|
|
321
|
+
* This Payload app is the authorization server. Users sign in to the admin panel and allow the
|
|
322
|
+
* MCP client, which then gets an access token for them.
|
|
262
323
|
*/
|
|
263
|
-
export type
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
324
|
+
export type MCPBuiltinOAuthConfig = {
|
|
325
|
+
/**
|
|
326
|
+
* Creates the tokens the MCP client gets when the user clicks Allow. `req` is the user's own
|
|
327
|
+
* browser request, so `req.user` is the user who allowed it. Pass `authenticate` too if
|
|
328
|
+
* Payload's auth strategies don't accept the access token.
|
|
329
|
+
*
|
|
330
|
+
* @default a Payload login token for that user that only works for MCP, with a refresh token when
|
|
331
|
+
* the collection uses sessions
|
|
332
|
+
*/
|
|
333
|
+
issueToken?: (args: { req: PayloadRequest }) => MaybePromise<MCPOAuthTokens>
|
|
334
|
+
/**
|
|
335
|
+
* Trades a refresh token from `issueToken`, or from an earlier refresh, for new tokens. Return
|
|
336
|
+
* `null` when it's no longer valid, and the client sends the user through sign-in again. `req`
|
|
337
|
+
* is the MCP client's request, without a user. Only used together with `issueToken`.
|
|
338
|
+
*
|
|
339
|
+
* OAuth requires noticing copied refresh tokens: return a new refresh token every time, and
|
|
340
|
+
* revoke the tokens when an already used refresh token comes back.
|
|
341
|
+
*/
|
|
342
|
+
refreshToken?: (args: {
|
|
343
|
+
refreshToken: string
|
|
344
|
+
req: PayloadRequest
|
|
345
|
+
}) => MaybePromise<MCPOAuthTokens | null>
|
|
346
|
+
type: 'builtin'
|
|
347
|
+
} & MCPOAuthSharedConfig
|
|
348
|
+
|
|
349
|
+
export type MCPOAuthTokens = {
|
|
350
|
+
accessToken: string
|
|
351
|
+
/** Seconds until the access token expires. */
|
|
352
|
+
expiresIn?: number
|
|
353
|
+
/** Lets the client get new tokens without the user, through `refreshToken`. */
|
|
354
|
+
refreshToken?: string
|
|
283
355
|
}
|
|
284
356
|
|
|
285
|
-
/**
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
357
|
+
/** Another service, e.g. your identity provider, is the authorization server. */
|
|
358
|
+
export type MCPExternalOAuthConfig = {
|
|
359
|
+
/**
|
|
360
|
+
* The authorization servers that issue access tokens for MCP clients. Clients require each one
|
|
361
|
+
* to exactly match the `issuer` in that server's metadata, so pass a function when the exact
|
|
362
|
+
* value is only known at runtime, e.g. from the server's OpenID configuration or per host.
|
|
363
|
+
*/
|
|
364
|
+
authorizationServers: ((args: { req: PayloadRequest }) => MaybePromise<string[]>) | string[]
|
|
365
|
+
/**
|
|
366
|
+
* Scopes MCP clients should request, e.g. `['openid', 'email', 'profile']`. Without them,
|
|
367
|
+
* clients request none, which some authorization servers reject or answer with a token that
|
|
368
|
+
* doesn't identify the user.
|
|
369
|
+
*/
|
|
370
|
+
scopes?: string[]
|
|
371
|
+
type: 'external'
|
|
372
|
+
} & MCPOAuthSharedConfig
|
|
373
|
+
|
|
374
|
+
type MCPOAuthSharedConfig = {
|
|
375
|
+
/**
|
|
376
|
+
* Called on MCP requests with a bearer token that Payload's auth strategies didn't accept.
|
|
377
|
+
* Return the Payload user, including its `collection`, or `null` to answer with the OAuth challenge.
|
|
378
|
+
*/
|
|
379
|
+
authenticate?: (args: {
|
|
380
|
+
req: PayloadRequest
|
|
381
|
+
token: string
|
|
382
|
+
}) => MaybePromise<PayloadRequest['user']>
|
|
383
|
+
/**
|
|
384
|
+
* The URL clients call to reach the MCP endpoint.
|
|
385
|
+
*
|
|
386
|
+
* @default the absolute URL of `/api/mcp`, based on `serverURL` or the request URL
|
|
387
|
+
*/
|
|
388
|
+
resource?: string
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export type SanitizedMCPPluginConfig = {
|
|
392
|
+
items: MCPItem[]
|
|
393
|
+
/** `undefined` when OAuth is turned off. */
|
|
394
|
+
oauth?: MCPOAuthConfig
|
|
395
|
+
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
|
|
396
|
+
|
|
397
|
+
export type MCPServerOptions = {
|
|
398
|
+
options?: McpServerOptions
|
|
399
|
+
serverInfo?: Partial<Implementation>
|
|
293
400
|
}
|
|
294
401
|
|
|
295
402
|
/**
|
|
296
|
-
* One MCP primitive
|
|
297
|
-
*
|
|
298
|
-
* filtered by `getAuthorizedMCP`, registered by the MCP endpoint.
|
|
403
|
+
* One MCP primitive plus the metadata needed for config-driven filtering and
|
|
404
|
+
* registration.
|
|
299
405
|
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* registration time.
|
|
304
|
-
* - `label`: human-readable admin-UI display text for the checkbox.
|
|
305
|
-
* - `tool` / `prompt` / `resource`: the live primitive (its own
|
|
306
|
-
* `description` is what both MCP clients and the admin UI surface).
|
|
406
|
+
* - `configKey`: the config identifier, e.g. `find` or `echo`.
|
|
407
|
+
* - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.
|
|
408
|
+
* - `label`: human-readable display text.
|
|
307
409
|
*/
|
|
308
410
|
export type MCPItemBase = {
|
|
309
|
-
|
|
411
|
+
configKey: string
|
|
310
412
|
label: string
|
|
413
|
+
mcpName: string
|
|
311
414
|
}
|
|
312
415
|
|
|
416
|
+
export type CollectionMCPItem = {
|
|
417
|
+
collectionSlug: CollectionSlug
|
|
418
|
+
tool: CollectionTool
|
|
419
|
+
type: 'collectionTool'
|
|
420
|
+
} & MCPItemBase
|
|
421
|
+
|
|
422
|
+
export type GlobalMCPItem = {
|
|
423
|
+
globalSlug: GlobalSlug
|
|
424
|
+
tool: GlobalTool
|
|
425
|
+
type: 'globalTool'
|
|
426
|
+
} & MCPItemBase
|
|
427
|
+
|
|
313
428
|
export type MCPItem =
|
|
314
|
-
| ({
|
|
315
|
-
collectionSlug: CollectionSlug
|
|
316
|
-
tool: CollectionTool
|
|
317
|
-
type: 'collectionTool'
|
|
318
|
-
} & MCPItemBase)
|
|
319
|
-
| ({
|
|
320
|
-
globalSlug: GlobalSlug
|
|
321
|
-
tool: GlobalTool
|
|
322
|
-
type: 'globalTool'
|
|
323
|
-
} & MCPItemBase)
|
|
324
429
|
| ({
|
|
325
430
|
prompt: Prompt
|
|
326
431
|
type: 'prompt'
|
|
@@ -333,15 +438,14 @@ export type MCPItem =
|
|
|
333
438
|
tool: Tool
|
|
334
439
|
type: 'tool'
|
|
335
440
|
} & MCPItemBase)
|
|
441
|
+
| CollectionMCPItem
|
|
442
|
+
| GlobalMCPItem
|
|
336
443
|
|
|
337
444
|
/**
|
|
338
|
-
* The
|
|
339
|
-
*
|
|
340
|
-
* receive this via `args.authorizedMCP` so they can spread
|
|
341
|
-
* `localAPIDefaults(authorizedMCP)` into every local API call.
|
|
445
|
+
* The MCP items and access mode authorized for this request. The authenticated user is available
|
|
446
|
+
* as `req.user`.
|
|
342
447
|
*/
|
|
343
448
|
export type AuthorizedMCP = {
|
|
344
449
|
items: MCPItem[]
|
|
345
450
|
overrideAccess: boolean
|
|
346
|
-
user: null | TypedUser
|
|
347
451
|
}
|
|
@@ -5,7 +5,7 @@ import type { SanitizedMCPPluginConfig } from '../types.js'
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the sanitized plugin config — the form produced by
|
|
7
7
|
* `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.
|
|
8
|
-
* Callers downstream of plugin init can rely on `items
|
|
8
|
+
* Callers downstream of plugin init can rely on `items` and other defaults
|
|
9
9
|
* being fully resolved.
|
|
10
10
|
*/
|
|
11
11
|
export const getPluginConfig: (args: { config: SanitizedConfig }) => SanitizedMCPPluginConfig = ({
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encrypts data for the client to hold, so it doesn't need to be stored. `type` keeps one kind
|
|
5
|
+
* from being used as another, e.g. a client ID as an authorization code.
|
|
6
|
+
*/
|
|
7
|
+
export const seal = ({
|
|
8
|
+
type,
|
|
9
|
+
data,
|
|
10
|
+
expiresIn,
|
|
11
|
+
req,
|
|
12
|
+
}: {
|
|
13
|
+
data: object
|
|
14
|
+
/** Seconds */
|
|
15
|
+
expiresIn?: number
|
|
16
|
+
req: PayloadRequest
|
|
17
|
+
type: string
|
|
18
|
+
}): string =>
|
|
19
|
+
req.payload.encrypt(
|
|
20
|
+
JSON.stringify({ ...data, type, exp: expiresIn && Date.now() + expiresIn * 1000 }),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export const unseal = <T>({
|
|
24
|
+
type,
|
|
25
|
+
req,
|
|
26
|
+
value,
|
|
27
|
+
}: {
|
|
28
|
+
req: PayloadRequest
|
|
29
|
+
type: string
|
|
30
|
+
value: null | string
|
|
31
|
+
}): T | undefined => {
|
|
32
|
+
// Only the v1 format is authenticated. Older formats decrypt anything without an error.
|
|
33
|
+
if (!value?.startsWith('v1:')) {
|
|
34
|
+
return undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Previous secrets can be public, like a default secret from source code, so only client IDs
|
|
39
|
+
// accept them. Client IDs grant nothing, and this keeps clients registered when the secret changes.
|
|
40
|
+
const secret = type === 'client' ? undefined : req.payload.config.secret
|
|
41
|
+
const data = JSON.parse(req.payload.decrypt(value, { secret }))
|
|
42
|
+
return data.type === type && (!data.exp || data.exp > Date.now()) ? data : undefined
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -5,5 +5,5 @@ import type { ToolInputSchema } from '../types.js'
|
|
|
5
5
|
/** Normalize a tool/prompt input to a Standard Schema. Raw JSON Schema gets wrapped; Standard Schema instances pass through. */
|
|
6
6
|
export const toStandardSchema = (schema: ToolInputSchema): StandardSchemaWithJSON =>
|
|
7
7
|
typeof schema === 'object' && schema !== null && '~standard' in schema
|
|
8
|
-
?
|
|
8
|
+
? schema
|
|
9
9
|
: fromJsonSchema(schema)
|
package/dist/@types/assets.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/@types/assets.d.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { JSONField } from 'payload';
|
|
2
|
-
import type { SanitizedMCPPluginConfig } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Returns the API key collection's `access` field — a JSON field whose value
|
|
5
|
-
* is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
|
|
6
|
-
* a custom client component (`AccessField`) which renders a permissions
|
|
7
|
-
* matrix; the field's stored shape is just the runtime access tree.
|
|
8
|
-
*/
|
|
9
|
-
export declare const getAccessField: ({ pluginConfig, }: {
|
|
10
|
-
pluginConfig: SanitizedMCPPluginConfig;
|
|
11
|
-
}) => JSONField;
|
|
12
|
-
//# sourceMappingURL=getAccessField.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAccessField.d.ts","sourceRoot":"","sources":["../../src/collection/getAccessField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,KAAK,EAAkC,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,mBAE5B;IACD,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,SAqBH,CAAA"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the API key collection's `access` field — a JSON field whose value
|
|
3
|
-
* is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
|
|
4
|
-
* a custom client component (`AccessField`) which renders a permissions
|
|
5
|
-
* matrix; the field's stored shape is just the runtime access tree.
|
|
6
|
-
*/ export const getAccessField = ({ pluginConfig })=>{
|
|
7
|
-
const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig);
|
|
8
|
-
return {
|
|
9
|
-
name: 'access',
|
|
10
|
-
type: 'json',
|
|
11
|
-
admin: {
|
|
12
|
-
components: {
|
|
13
|
-
Field: {
|
|
14
|
-
clientProps: {
|
|
15
|
-
pluginConfig: clientPluginConfig
|
|
16
|
-
},
|
|
17
|
-
path: '@payloadcms/plugin-mcp/client#AccessField'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
// TODO: needs i18n once design is finalized
|
|
21
|
-
description: 'Access for this API key — uncheck to revoke individual tools.',
|
|
22
|
-
position: 'sidebar'
|
|
23
|
-
},
|
|
24
|
-
defaultValue: {},
|
|
25
|
-
// TODO: needs i18n once design is finalized
|
|
26
|
-
label: 'Access'
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,
|
|
31
|
-
* input/argsSchema functions, etc.) so the result is safe to thread to a
|
|
32
|
-
* client component via `clientProps`.
|
|
33
|
-
*/ const sanitizeClientPluginConfig = (pluginConfig)=>({
|
|
34
|
-
items: pluginConfig.items.map((item)=>({
|
|
35
|
-
...item.type === 'collectionTool' ? {
|
|
36
|
-
collectionSlug: item.collectionSlug
|
|
37
|
-
} : {},
|
|
38
|
-
...item.type === 'globalTool' ? {
|
|
39
|
-
globalSlug: item.globalSlug
|
|
40
|
-
} : {},
|
|
41
|
-
type: item.type,
|
|
42
|
-
description: itemDescription(item),
|
|
43
|
-
key: item.key,
|
|
44
|
-
label: item.label
|
|
45
|
-
}))
|
|
46
|
-
});
|
|
47
|
-
const itemDescription = (item)=>{
|
|
48
|
-
if (item.type === 'prompt') {
|
|
49
|
-
return item.prompt.description;
|
|
50
|
-
}
|
|
51
|
-
if (item.type === 'resource') {
|
|
52
|
-
return item.resource.description;
|
|
53
|
-
}
|
|
54
|
-
return item.tool.description;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
//# sourceMappingURL=getAccessField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collection/getAccessField.ts"],"sourcesContent":["import type { JSONField } from 'payload'\n\nimport type { ClientMCPPluginConfig, MCPItem, SanitizedMCPPluginConfig } from '../types.js'\n\n/**\n * Returns the API key collection's `access` field — a JSON field whose value\n * is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is\n * a custom client component (`AccessField`) which renders a permissions\n * matrix; the field's stored shape is just the runtime access tree.\n */\nexport const getAccessField = ({\n pluginConfig,\n}: {\n pluginConfig: SanitizedMCPPluginConfig\n}): JSONField => {\n const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig)\n\n return {\n name: 'access',\n type: 'json',\n admin: {\n components: {\n Field: {\n clientProps: { pluginConfig: clientPluginConfig },\n path: '@payloadcms/plugin-mcp/client#AccessField',\n },\n },\n // TODO: needs i18n once design is finalized\n description: 'Access for this API key — uncheck to revoke individual tools.',\n position: 'sidebar',\n },\n defaultValue: {},\n // TODO: needs i18n once design is finalized\n label: 'Access',\n }\n}\n\n/**\n * Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,\n * input/argsSchema functions, etc.) so the result is safe to thread to a\n * client component via `clientProps`.\n */\nconst sanitizeClientPluginConfig = (\n pluginConfig: SanitizedMCPPluginConfig,\n): ClientMCPPluginConfig => ({\n items: pluginConfig.items.map((item) => ({\n ...(item.type === 'collectionTool' ? { collectionSlug: item.collectionSlug } : {}),\n ...(item.type === 'globalTool' ? { globalSlug: item.globalSlug } : {}),\n type: item.type,\n description: itemDescription(item),\n key: item.key,\n label: item.label,\n })),\n})\n\nconst itemDescription = (item: MCPItem): string => {\n if (item.type === 'prompt') {\n return item.prompt.description\n }\n if (item.type === 'resource') {\n return item.resource.description\n }\n return item.tool.description\n}\n"],"names":["getAccessField","pluginConfig","clientPluginConfig","sanitizeClientPluginConfig","name","type","admin","components","Field","clientProps","path","description","position","defaultValue","label","items","map","item","collectionSlug","globalSlug","itemDescription","key","prompt","resource","tool"],"mappings":"AAIA;;;;;CAKC,GACD,OAAO,MAAMA,iBAAiB,CAAC,EAC7BC,YAAY,EAGb;IACC,MAAMC,qBAAqBC,2BAA2BF;IAEtD,OAAO;QACLG,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBAAER,cAAcC;oBAAmB;oBAChDQ,MAAM;gBACR;YACF;YACA,4CAA4C;YAC5CC,aAAa;YACbC,UAAU;QACZ;QACAC,cAAc,CAAC;QACf,4CAA4C;QAC5CC,OAAO;IACT;AACF,EAAC;AAED;;;;CAIC,GACD,MAAMX,6BAA6B,CACjCF,eAC2B,CAAA;QAC3Bc,OAAOd,aAAac,KAAK,CAACC,GAAG,CAAC,CAACC,OAAU,CAAA;gBACvC,GAAIA,KAAKZ,IAAI,KAAK,mBAAmB;oBAAEa,gBAAgBD,KAAKC,cAAc;gBAAC,IAAI,CAAC,CAAC;gBACjF,GAAID,KAAKZ,IAAI,KAAK,eAAe;oBAAEc,YAAYF,KAAKE,UAAU;gBAAC,IAAI,CAAC,CAAC;gBACrEd,MAAMY,KAAKZ,IAAI;gBACfM,aAAaS,gBAAgBH;gBAC7BI,KAAKJ,KAAKI,GAAG;gBACbP,OAAOG,KAAKH,KAAK;YACnB,CAAA;IACF,CAAA;AAEA,MAAMM,kBAAkB,CAACH;IACvB,IAAIA,KAAKZ,IAAI,KAAK,UAAU;QAC1B,OAAOY,KAAKK,MAAM,CAACX,WAAW;IAChC;IACA,IAAIM,KAAKZ,IAAI,KAAK,YAAY;QAC5B,OAAOY,KAAKM,QAAQ,CAACZ,WAAW;IAClC;IACA,OAAOM,KAAKO,IAAI,CAACb,WAAW;AAC9B"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload';
|
|
2
|
-
import type { SanitizedMCPPluginConfig } from '../types.js';
|
|
3
|
-
export declare const getAPIKeysCollection: ({ pluginConfig, }: {
|
|
4
|
-
pluginConfig: SanitizedMCPPluginConfig;
|
|
5
|
-
}) => CollectionConfig;
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,oBAAoB,GAAI,mBAElC;IACD,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAqDH,CAAA"}
|