@payloadcms/plugin-mcp 4.0.0-internal.bc5cf8c → 4.0.0-internal.bf4bcce
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.map +1 -1
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +2 -7
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +17 -14
- 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 +91 -16
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +27 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +61 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- 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 +68 -34
- 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 +80 -56
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +10 -16
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +10 -15
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- 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 +104 -54
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +45 -45
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +32 -39
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +88 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +12 -28
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +29 -48
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +18 -28
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +17 -32
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +68 -12
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +15 -28
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +67 -87
- 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.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +5 -7
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +10 -15
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +12 -18
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +14 -26
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +14 -31
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +46 -12
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +16 -24
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +28 -37
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +6 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +9 -3
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +6 -1
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -4
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +65 -45
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +94 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +9 -13
- package/src/endpoint/access.ts +14 -14
- package/src/endpoint/index.ts +79 -14
- package/src/endpoint/oauth.ts +72 -0
- package/src/index.ts +11 -4
- package/src/mcp/buildMcpServer.ts +80 -50
- package/src/mcp/builtin/collections/authTools.ts +80 -69
- package/src/mcp/builtin/collections/countTool.ts +10 -23
- package/src/mcp/builtin/collections/countVersionsTool.ts +10 -20
- package/src/mcp/builtin/collections/createTool.ts +110 -77
- package/src/mcp/builtin/collections/deleteTool.ts +36 -65
- package/src/mcp/builtin/collections/duplicateTool.ts +36 -87
- 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 +12 -65
- package/src/mcp/builtin/collections/findTool.ts +25 -108
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +16 -60
- package/src/mcp/builtin/collections/findVersionsTool.ts +15 -87
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +60 -15
- package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -58
- package/src/mcp/builtin/collections/updateTool.ts +63 -101
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +4 -5
- package/src/mcp/builtin/globals/countVersionsTool.ts +10 -19
- package/src/mcp/builtin/globals/findTool.ts +14 -53
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +14 -54
- package/src/mcp/builtin/globals/findVersionsTool.ts +15 -94
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -9
- package/src/mcp/builtin/globals/restoreVersionTool.ts +15 -47
- package/src/mcp/builtin/globals/updateTool.ts +39 -62
- package/src/mcp/builtinTools.ts +9 -2
- package/src/mcp/sanitizeMCPConfig.ts +6 -1
- package/src/stdio.ts +63 -45
- package/src/types.ts +95 -16
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- 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/getEntityInputSchema.d.ts +0 -11
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
- package/dist/utils/schemaConversion/getEntityInputSchema.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/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/@types/assets.d.ts +0 -3
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
- 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/utils/whereSchema.ts +0 -24
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-
|
|
3
|
+
Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultAccess.d.ts","sourceRoot":"","sources":["../src/defaultAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"defaultAccess.d.ts","sourceRoot":"","sources":["../src/defaultAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,eAAO,MAAM,aAAa,YAAa,aAAa,KAAG,OAA4B,CAAA"}
|
package/dist/defineTool.d.ts
CHANGED
|
@@ -11,16 +11,16 @@ import type { CollectionTool, GlobalTool, Prompt, Tool, ToolInputSchema } from '
|
|
|
11
11
|
* Config and handler signatures are derived from `Tool` / `CollectionTool` / `GlobalTool` /
|
|
12
12
|
* `Prompt` via `Omit` + indexed access so there's no duplication with `types.ts`.
|
|
13
13
|
*/
|
|
14
|
-
export declare const defineTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<Tool<TSchema>,
|
|
15
|
-
handler: (fn: Tool<TSchema>[
|
|
14
|
+
export declare const defineTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<Tool<TSchema>, 'handler'>) => {
|
|
15
|
+
handler: (fn: Tool<TSchema>['handler']) => Tool;
|
|
16
16
|
};
|
|
17
|
-
export declare const defineCollectionTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<CollectionTool<TSchema>,
|
|
18
|
-
handler: (fn: CollectionTool<TSchema>[
|
|
17
|
+
export declare const defineCollectionTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<CollectionTool<TSchema>, 'handler'>) => {
|
|
18
|
+
handler: (fn: CollectionTool<TSchema>['handler']) => CollectionTool;
|
|
19
19
|
};
|
|
20
|
-
export declare const defineGlobalTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<GlobalTool<TSchema>,
|
|
21
|
-
handler: (fn: GlobalTool<TSchema>[
|
|
20
|
+
export declare const defineGlobalTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<GlobalTool<TSchema>, 'handler'>) => {
|
|
21
|
+
handler: (fn: GlobalTool<TSchema>['handler']) => GlobalTool;
|
|
22
22
|
};
|
|
23
|
-
export declare const definePrompt: <TSchema extends ToolInputSchema = ToolInputSchema>(args: Omit<Prompt<TSchema>,
|
|
24
|
-
handler: (fn: Prompt<TSchema>[
|
|
23
|
+
export declare const definePrompt: <TSchema extends ToolInputSchema = ToolInputSchema>(args: Omit<Prompt<TSchema>, 'handler'>) => {
|
|
24
|
+
handler: (fn: Prompt<TSchema>['handler']) => Prompt;
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=defineTool.d.ts.map
|
package/dist/defineTool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineTool.d.ts","sourceRoot":"","sources":["../src/defineTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE3F;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"defineTool.d.ts","sourceRoot":"","sources":["../src/defineTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE3F;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,QAEnE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACnC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;CAElD,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,QAEnE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KAC7C;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,cAAc,CAAA;CAEtE,CAAA;AAEF,eAAO,MAAM,gBAAgB,GAC3B,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,QAEnE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACzC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,UAAU,CAAA;CAE9D,CAAA;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,eAAe,GAAG,eAAe,QACtE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACrC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,MAAM,CAAA;CAEtD,CAAA"}
|
|
@@ -5,13 +5,8 @@ export type GetAuthorizedMCPArgs = {
|
|
|
5
5
|
req: PayloadRequest;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Authorization has two layers:
|
|
11
|
-
* 1. Payload collection/global permissions determine whether built-in operation tools are shown.
|
|
12
|
-
* 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
|
|
13
|
-
*
|
|
14
|
-
* Like Payload core operations, `overrideAccess` skips both layers.
|
|
8
|
+
* Authenticates an MCP request and removes items the user cannot access.
|
|
9
|
+
* `overrideAccess` skips Payload and MCP item access checks.
|
|
15
10
|
*/
|
|
16
11
|
export declare const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP>;
|
|
17
12
|
export declare const filterMCPItems: ({ items, overrideAccess, req, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/endpoint/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAA;AAInE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIzD,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/endpoint/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAA;AAInE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIzD,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC,aAAa,CA0CnF,CAAA;AAED,eAAO,MAAM,cAAc,oCAIxB;IACD,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC,OAAO,EAAE,CAkBpB,CAAA"}
|
package/dist/endpoint/access.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { getAccessResults, UnauthorizedError } from 'payload';
|
|
2
2
|
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Authorization has two layers:
|
|
7
|
-
* 1. Payload collection/global permissions determine whether built-in operation tools are shown.
|
|
8
|
-
* 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
|
|
9
|
-
*
|
|
10
|
-
* Like Payload core operations, `overrideAccess` skips both layers.
|
|
4
|
+
* Authenticates an MCP request and removes items the user cannot access.
|
|
5
|
+
* `overrideAccess` skips Payload and MCP item access checks.
|
|
11
6
|
*/ export const getAuthorizedMCP = async ({ overrideAccess, req })=>{
|
|
12
7
|
const pluginConfig = getPluginConfig({
|
|
13
8
|
config: req.payload.config
|
|
@@ -27,7 +22,17 @@ import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
|
27
22
|
headers,
|
|
28
23
|
req
|
|
29
24
|
})).user;
|
|
30
|
-
|
|
25
|
+
// Only bearer tokens that no auth strategy accepted reach the hook, e.g. an OAuth access token.
|
|
26
|
+
// API keys use the `<collection> API-Key <key>` scheme instead of `Bearer`, so they never do.
|
|
27
|
+
const bearerToken = headers.get('Authorization')?.match(/^Bearer (.+)$/)?.[1];
|
|
28
|
+
if (!req.user && bearerToken && pluginConfig.oauth?.authenticate) {
|
|
29
|
+
req.user = await pluginConfig.oauth.authenticate({
|
|
30
|
+
req,
|
|
31
|
+
token: bearerToken
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// With OAuth, the endpoint answers with a challenge that starts the client's sign-in
|
|
35
|
+
if (hasAuthorization && !req.user && !pluginConfig.oauth) {
|
|
31
36
|
throw new UnauthorizedError(req.t);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -37,13 +42,11 @@ import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
|
37
42
|
overrideAccess,
|
|
38
43
|
req
|
|
39
44
|
}),
|
|
40
|
-
overrideAccess
|
|
41
|
-
user: req.user
|
|
45
|
+
overrideAccess
|
|
42
46
|
};
|
|
43
47
|
};
|
|
44
48
|
export const filterMCPItems = async ({ items, overrideAccess, req })=>{
|
|
45
|
-
// Match Payload core: overrideAccess bypasses access evaluation
|
|
46
|
-
// forcing each access function to return true.
|
|
49
|
+
// Match Payload core: overrideAccess bypasses access evaluation
|
|
47
50
|
if (overrideAccess) {
|
|
48
51
|
return items;
|
|
49
52
|
}
|
|
@@ -69,13 +72,13 @@ export const filterMCPItems = async ({ items, overrideAccess, req })=>{
|
|
|
69
72
|
switch(item.type){
|
|
70
73
|
case 'collectionTool':
|
|
71
74
|
return !item.tool.access || await item.tool.access({
|
|
72
|
-
|
|
75
|
+
slug: item.collectionSlug,
|
|
73
76
|
permissions,
|
|
74
77
|
req
|
|
75
78
|
});
|
|
76
79
|
case 'globalTool':
|
|
77
80
|
return !item.tool.access || await item.tool.access({
|
|
78
|
-
|
|
81
|
+
slug: item.globalSlug,
|
|
79
82
|
permissions,
|
|
80
83
|
req
|
|
81
84
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoint/access.ts"],"sourcesContent":["import type { PayloadRequest, SanitizedPermissions } from 'payload'\n\nimport { getAccessResults, UnauthorizedError } from 'payload'\n\nimport type { AuthorizedMCP, MCPItem } from '../types.js'\n\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\n\nexport type GetAuthorizedMCPArgs = {\n overrideAccess: boolean\n req: PayloadRequest\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/access.ts"],"sourcesContent":["import type { PayloadRequest, SanitizedPermissions } from 'payload'\n\nimport { getAccessResults, UnauthorizedError } from 'payload'\n\nimport type { AuthorizedMCP, MCPItem } from '../types.js'\n\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\n\nexport type GetAuthorizedMCPArgs = {\n overrideAccess: boolean\n req: PayloadRequest\n}\n\n/**\n * Authenticates an MCP request and removes items the user cannot access.\n * `overrideAccess` skips Payload and MCP item access checks.\n */\nexport const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({\n overrideAccess,\n req,\n}) => {\n const pluginConfig = getPluginConfig({ config: req.payload.config })\n\n if (pluginConfig.overrideGetAuthorizedMCP) {\n return await pluginConfig.overrideGetAuthorizedMCP({\n overrideAccess,\n pluginConfig,\n req,\n })\n }\n\n if (req.headers) {\n const headers = new Headers(req.headers)\n const hasAuthorization = headers.has('Authorization')\n\n headers.set('DisableAutologin', 'true')\n req.user = (await req.payload.auth({ headers, req })).user\n\n // Only bearer tokens that no auth strategy accepted reach the hook, e.g. an OAuth access token.\n // API keys use the `<collection> API-Key <key>` scheme instead of `Bearer`, so they never do.\n const bearerToken = headers.get('Authorization')?.match(/^Bearer (.+)$/)?.[1]\n if (!req.user && bearerToken && pluginConfig.oauth?.authenticate) {\n req.user = await pluginConfig.oauth.authenticate({ req, token: bearerToken })\n }\n\n // With OAuth, the endpoint answers with a challenge that starts the client's sign-in\n if (hasAuthorization && !req.user && !pluginConfig.oauth) {\n throw new UnauthorizedError(req.t)\n }\n }\n\n return {\n items: await filterMCPItems({\n items: pluginConfig.items,\n overrideAccess,\n req,\n }),\n overrideAccess,\n }\n}\n\nexport const filterMCPItems = async ({\n items,\n overrideAccess,\n req,\n}: {\n items: MCPItem[]\n overrideAccess: boolean\n req: PayloadRequest\n}): Promise<MCPItem[]> => {\n // Match Payload core: overrideAccess bypasses access evaluation\n if (overrideAccess) {\n return items\n }\n\n const authorizedItems: MCPItem[] = []\n\n const permissions = await getAccessResults({ req })\n\n for (const item of items) {\n if (!(await checkItemAccess({ item, permissions, req }))) {\n continue\n }\n authorizedItems.push(item)\n }\n\n return authorizedItems\n}\n\n/**\n * Runs MCP item access callbacks\n */\nconst checkItemAccess = async ({\n item,\n permissions,\n req,\n}: {\n item: MCPItem\n permissions?: SanitizedPermissions\n req: PayloadRequest\n}): Promise<boolean> => {\n switch (item.type) {\n case 'collectionTool':\n return (\n !item.tool.access ||\n (await item.tool.access({ slug: item.collectionSlug, permissions, req }))\n )\n case 'globalTool':\n return (\n !item.tool.access || (await item.tool.access({ slug: item.globalSlug, permissions, req }))\n )\n case 'prompt':\n return !item.prompt.access || (await item.prompt.access({ permissions, req }))\n case 'resource':\n return !item.resource.access || (await item.resource.access({ permissions, req }))\n case 'tool':\n return !item.tool.access || (await item.tool.access({ permissions, req }))\n }\n}\n"],"names":["getAccessResults","UnauthorizedError","getPluginConfig","getAuthorizedMCP","overrideAccess","req","pluginConfig","config","payload","overrideGetAuthorizedMCP","headers","Headers","hasAuthorization","has","set","user","auth","bearerToken","get","match","oauth","authenticate","token","t","items","filterMCPItems","authorizedItems","permissions","item","checkItemAccess","push","type","tool","access","slug","collectionSlug","globalSlug","prompt","resource"],"mappings":"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"}
|
package/dist/endpoint/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAe7D,eAAO,MAAM,WAAW,EAAE,cAwEzB,CAAA"}
|
package/dist/endpoint/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
|
|
1
|
+
import { createMcpHandler, isLegacyRequest, readRequestBody, WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
|
|
2
2
|
import { APIError } from 'payload';
|
|
3
3
|
import { buildMcpServer } from '../mcp/buildMcpServer.js';
|
|
4
4
|
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
5
5
|
import { getAuthorizedMCP } from './access.js';
|
|
6
|
+
import { oauthChallenge } from './oauth.js';
|
|
6
7
|
export const mcpEndpoint = async (req)=>{
|
|
7
8
|
if (!req.url) {
|
|
8
9
|
throw new APIError('Missing request URL', 400);
|
|
@@ -25,23 +26,97 @@ export const mcpEndpoint = async (req)=>{
|
|
|
25
26
|
overrideAccess,
|
|
26
27
|
req
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
if (pluginConfig.oauth && !req.user) {
|
|
30
|
+
return oauthChallenge({
|
|
31
|
+
req
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize;
|
|
35
|
+
// Payload augments the original web-standard Request in place.
|
|
36
|
+
const mcpRequest = req;
|
|
37
|
+
const parsedBody = await parseRequestBody({
|
|
38
|
+
maxRequestBodySize,
|
|
39
|
+
request: mcpRequest
|
|
36
40
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
42
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, {
|
|
43
|
+
maxRequestBodySize
|
|
44
|
+
})) {
|
|
45
|
+
const server = buildMcpServer({
|
|
46
|
+
authorizedMCP,
|
|
47
|
+
pluginConfig,
|
|
48
|
+
req
|
|
49
|
+
});
|
|
50
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
51
|
+
enableJsonResponse: true,
|
|
52
|
+
maxRequestBodySize,
|
|
53
|
+
sessionIdGenerator: undefined
|
|
54
|
+
});
|
|
55
|
+
transport.onerror = (err)=>{
|
|
56
|
+
req.payload.logger.error({
|
|
57
|
+
err,
|
|
58
|
+
msg: 'Error serving legacy MCP request'
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
await server.connect(transport);
|
|
63
|
+
return await transport.handleRequest(mcpRequest, {
|
|
64
|
+
parsedBody
|
|
65
|
+
});
|
|
66
|
+
} finally{
|
|
67
|
+
await server.close().catch((err)=>{
|
|
68
|
+
req.payload.logger.error({
|
|
69
|
+
err,
|
|
70
|
+
msg: 'Error closing MCP server'
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const handler = createMcpHandler(()=>buildMcpServer({
|
|
76
|
+
authorizedMCP,
|
|
77
|
+
pluginConfig,
|
|
78
|
+
req
|
|
79
|
+
}), {
|
|
80
|
+
legacy: 'reject',
|
|
81
|
+
maxRequestBodySize,
|
|
82
|
+
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
83
|
+
maxSubscriptions: 0,
|
|
84
|
+
onerror: (err)=>{
|
|
85
|
+
req.payload.logger.error({
|
|
86
|
+
err,
|
|
87
|
+
msg: 'Error serving modern MCP request'
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
responseMode: 'json'
|
|
43
91
|
});
|
|
44
|
-
|
|
92
|
+
try {
|
|
93
|
+
return await handler.fetch(mcpRequest, {
|
|
94
|
+
parsedBody
|
|
95
|
+
});
|
|
96
|
+
} finally{
|
|
97
|
+
await handler.close().catch((err)=>{
|
|
98
|
+
req.payload.logger.error({
|
|
99
|
+
err,
|
|
100
|
+
msg: 'Error closing modern MCP handler'
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
107
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
108
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
109
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
110
|
+
*/ const parseRequestBody = async ({ maxRequestBodySize, request })=>{
|
|
111
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize);
|
|
116
|
+
return body.tooLarge ? undefined : JSON.parse(body.text);
|
|
117
|
+
} catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
45
120
|
};
|
|
46
121
|
|
|
47
122
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoint/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/index.ts"],"sourcesContent":["import type { PayloadHandler, PayloadRequest } from 'payload'\n\nimport {\n createMcpHandler,\n isLegacyRequest,\n readRequestBody,\n WebStandardStreamableHTTPServerTransport,\n} from '@modelcontextprotocol/server'\nimport { APIError } from 'payload'\n\nimport { buildMcpServer } from '../mcp/buildMcpServer.js'\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\nimport { getAuthorizedMCP } from './access.js'\nimport { oauthChallenge } from './oauth.js'\n\nexport const mcpEndpoint: PayloadHandler = async (req) => {\n if (!req.url) {\n throw new APIError('Missing request URL', 400)\n }\n\n req.payloadAPI = 'MCP' as const\n\n const pluginConfig = getPluginConfig({ config: req.payload.config })\n const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')\n\n if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {\n throw new APIError('MCP overrideAccess is only available in development.', 400)\n }\n\n let overrideAccess = false\n if (overrideAccessParam === 'true') {\n overrideAccess = true\n } else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {\n throw new APIError('MCP overrideAccess must be \"true\" or \"false\".', 400)\n }\n\n const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })\n\n if (pluginConfig.oauth && !req.user) {\n return oauthChallenge({ req })\n }\n\n const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize\n // Payload augments the original web-standard Request in place.\n const mcpRequest = req as PayloadRequest & Request\n const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })\n\n // Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.\n if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n const transport = new WebStandardStreamableHTTPServerTransport({\n enableJsonResponse: true,\n maxRequestBodySize,\n sessionIdGenerator: undefined, // stateless mode\n })\n transport.onerror = (err) => {\n req.payload.logger.error({ err, msg: 'Error serving legacy MCP request' })\n }\n\n try {\n await server.connect(transport)\n return await transport.handleRequest(mcpRequest, { parsedBody })\n } finally {\n await server.close().catch((err) => {\n req.payload.logger.error({ err, msg: 'Error closing MCP server' })\n })\n }\n }\n\n const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {\n legacy: 'reject',\n maxRequestBodySize,\n // SDK subscriptions always use SSE, so disable them to keep every response JSON-only.\n maxSubscriptions: 0,\n onerror: (err) => {\n req.payload.logger.error({ err, msg: 'Error serving modern MCP request' })\n },\n responseMode: 'json',\n })\n\n try {\n return await handler.fetch(mcpRequest, { parsedBody })\n } finally {\n await handler.close().catch((err) => {\n req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })\n })\n }\n}\n\n/**\n * Parses a POST body once so the era check and the SDK handler can share it. The SDK\n * skips its size limit for a pre-parsed body, so this reads with the same limit. It reads\n * a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,\n * or not JSON), leaving the original request for the SDK to read and answer.\n */\nconst parseRequestBody = async ({\n maxRequestBodySize,\n request,\n}: {\n maxRequestBodySize?: number\n request: Request\n}): Promise<unknown> => {\n if (request.method.toUpperCase() !== 'POST') {\n return undefined\n }\n\n try {\n const body = await readRequestBody(request.clone(), maxRequestBodySize)\n return body.tooLarge ? undefined : JSON.parse(body.text)\n } catch {\n return undefined\n }\n}\n"],"names":["createMcpHandler","isLegacyRequest","readRequestBody","WebStandardStreamableHTTPServerTransport","APIError","buildMcpServer","getPluginConfig","getAuthorizedMCP","oauthChallenge","mcpEndpoint","req","url","payloadAPI","pluginConfig","config","payload","overrideAccessParam","URL","searchParams","get","process","env","NODE_ENV","overrideAccess","authorizedMCP","oauth","user","maxRequestBodySize","mcp","mcpRequest","parsedBody","parseRequestBody","request","server","transport","enableJsonResponse","sessionIdGenerator","undefined","onerror","err","logger","error","msg","connect","handleRequest","close","catch","handler","legacy","maxSubscriptions","responseMode","fetch","method","toUpperCase","body","clone","tooLarge","JSON","parse","text"],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PayloadHandler, PayloadRequest, SanitizedConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
4
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
5
|
+
*/
|
|
6
|
+
export declare const oauthProtectedResourceEndpoint: PayloadHandler;
|
|
7
|
+
/**
|
|
8
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
9
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
10
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import config from '@payload-config'
|
|
14
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
15
|
+
*
|
|
16
|
+
* export const GET = oauthProtectedResourceHandler(config)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const oauthProtectedResourceHandler: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request) => Promise<Response>;
|
|
20
|
+
/**
|
|
21
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
22
|
+
* metadata, which starts the client's OAuth flow.
|
|
23
|
+
*/
|
|
24
|
+
export declare const oauthChallenge: ({ req }: {
|
|
25
|
+
req: PayloadRequest;
|
|
26
|
+
}) => Response;
|
|
27
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/endpoint/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAU9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,cACuB,CAAA;AAEpE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,WAC/B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CACuB,CAAA;AAEnE;;;GAGG;AACH,eAAO,MAAM,cAAc,YAAa;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,KAAG,QAM/D,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { bearerAuthChallengeResponse, OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server';
|
|
2
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
3
|
+
/**
|
|
4
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
5
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
6
|
+
*/ export const oauthProtectedResourceEndpoint = (req)=>getMetadataResponse({
|
|
7
|
+
config: req.payload.config,
|
|
8
|
+
url: req.url
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
12
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
13
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import config from '@payload-config'
|
|
17
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
18
|
+
*
|
|
19
|
+
* export const GET = oauthProtectedResourceHandler(config)
|
|
20
|
+
* ```
|
|
21
|
+
*/ export const oauthProtectedResourceHandler = (config)=>async (request)=>getMetadataResponse({
|
|
22
|
+
config: await config,
|
|
23
|
+
url: request.url
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
27
|
+
* metadata, which starts the client's OAuth flow.
|
|
28
|
+
*/ export const oauthChallenge = ({ req })=>bearerAuthChallengeResponse(new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')), {
|
|
29
|
+
resourceMetadataUrl: `${getMCPURL({
|
|
30
|
+
config: req.payload.config,
|
|
31
|
+
url: req.url
|
|
32
|
+
})}/oauth-protected-resource`
|
|
33
|
+
});
|
|
34
|
+
const getMCPURL = ({ config, url })=>new URL(`${config.routes.api}/mcp`, config.serverURL || url).href;
|
|
35
|
+
const getMetadataResponse = ({ config, url })=>{
|
|
36
|
+
const pluginConfig = getPluginConfig({
|
|
37
|
+
config
|
|
38
|
+
});
|
|
39
|
+
if (!pluginConfig.oauth) {
|
|
40
|
+
return new Response(null, {
|
|
41
|
+
status: 404
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return Response.json({
|
|
45
|
+
authorization_servers: pluginConfig.oauth.authorizationServers,
|
|
46
|
+
bearer_methods_supported: [
|
|
47
|
+
'header'
|
|
48
|
+
],
|
|
49
|
+
resource: pluginConfig.oauth.resource ?? getMCPURL({
|
|
50
|
+
config,
|
|
51
|
+
url
|
|
52
|
+
})
|
|
53
|
+
}, // Public document, readable by browser-based MCP clients on any origin
|
|
54
|
+
{
|
|
55
|
+
headers: {
|
|
56
|
+
'Access-Control-Allow-Origin': '*'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/oauth.ts"],"sourcesContent":["import type { PayloadHandler, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport {\n bearerAuthChallengeResponse,\n OAuthError,\n OAuthErrorCode,\n} from '@modelcontextprotocol/server'\n\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\n\n/**\n * Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.\n * The OAuth challenge links here, so MCP clients find the authorization server without setup.\n */\nexport const oauthProtectedResourceEndpoint: PayloadHandler = (req) =>\n getMetadataResponse({ config: req.payload.config, url: req.url! })\n\n/**\n * Serves the same metadata for clients that ignore the challenge's link and only look at\n * `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at\n * `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:\n *\n * ```ts\n * import config from '@payload-config'\n * import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'\n *\n * export const GET = oauthProtectedResourceHandler(config)\n * ```\n */\nexport const oauthProtectedResourceHandler =\n (config: Promise<SanitizedConfig> | SanitizedConfig) =>\n async (request: Request): Promise<Response> =>\n getMetadataResponse({ config: await config, url: request.url })\n\n/**\n * Answers an unauthenticated MCP request with a challenge linking to the protected resource\n * metadata, which starts the client's OAuth flow.\n */\nexport const oauthChallenge = ({ req }: { req: PayloadRequest }): Response =>\n bearerAuthChallengeResponse(\n new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),\n {\n resourceMetadataUrl: `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth-protected-resource`,\n },\n )\n\nconst getMCPURL = ({ config, url }: { config: SanitizedConfig; url: string }): string =>\n new URL(`${config.routes.api}/mcp`, config.serverURL || url).href\n\nconst getMetadataResponse = ({\n config,\n url,\n}: {\n config: SanitizedConfig\n url: string\n}): Response => {\n const pluginConfig = getPluginConfig({ config })\n\n if (!pluginConfig.oauth) {\n return new Response(null, { status: 404 })\n }\n\n return Response.json(\n {\n authorization_servers: pluginConfig.oauth.authorizationServers,\n bearer_methods_supported: ['header'],\n resource: pluginConfig.oauth.resource ?? getMCPURL({ config, url }),\n },\n // Public document, readable by browser-based MCP clients on any origin\n { headers: { 'Access-Control-Allow-Origin': '*' } },\n )\n}\n"],"names":["bearerAuthChallengeResponse","OAuthError","OAuthErrorCode","getPluginConfig","oauthProtectedResourceEndpoint","req","getMetadataResponse","config","payload","url","oauthProtectedResourceHandler","request","oauthChallenge","InvalidToken","t","resourceMetadataUrl","getMCPURL","URL","routes","api","serverURL","href","pluginConfig","oauth","Response","status","json","authorization_servers","authorizationServers","bearer_methods_supported","resource","headers"],"mappings":"AAEA,SACEA,2BAA2B,EAC3BC,UAAU,EACVC,cAAc,QACT,+BAA8B;AAErC,SAASC,eAAe,QAAQ,8BAA6B;AAE7D;;;CAGC,GACD,OAAO,MAAMC,iCAAiD,CAACC,MAC7DC,oBAAoB;QAAEC,QAAQF,IAAIG,OAAO,CAACD,MAAM;QAAEE,KAAKJ,IAAII,GAAG;IAAE,GAAE;AAEpE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,gCACX,CAACH,SACD,OAAOI,UACLL,oBAAoB;YAAEC,QAAQ,MAAMA;YAAQE,KAAKE,QAAQF,GAAG;QAAC,GAAE;AAEnE;;;CAGC,GACD,OAAO,MAAMG,iBAAiB,CAAC,EAAEP,GAAG,EAA2B,GAC7DL,4BACE,IAAIC,WAAWC,eAAeW,YAAY,EAAER,IAAIS,CAAC,CAAC,wBAClD;QACEC,qBAAqB,GAAGC,UAAU;YAAET,QAAQF,IAAIG,OAAO,CAACD,MAAM;YAAEE,KAAKJ,IAAII,GAAG;QAAE,GAAG,yBAAyB,CAAC;IAC7G,GACD;AAEH,MAAMO,YAAY,CAAC,EAAET,MAAM,EAAEE,GAAG,EAA4C,GAC1E,IAAIQ,IAAI,GAAGV,OAAOW,MAAM,CAACC,GAAG,CAAC,IAAI,CAAC,EAAEZ,OAAOa,SAAS,IAAIX,KAAKY,IAAI;AAEnE,MAAMf,sBAAsB,CAAC,EAC3BC,MAAM,EACNE,GAAG,EAIJ;IACC,MAAMa,eAAenB,gBAAgB;QAAEI;IAAO;IAE9C,IAAI,CAACe,aAAaC,KAAK,EAAE;QACvB,OAAO,IAAIC,SAAS,MAAM;YAAEC,QAAQ;QAAI;IAC1C;IAEA,OAAOD,SAASE,IAAI,CAClB;QACEC,uBAAuBL,aAAaC,KAAK,CAACK,oBAAoB;QAC9DC,0BAA0B;YAAC;SAAS;QACpCC,UAAUR,aAAaC,KAAK,CAACO,QAAQ,IAAId,UAAU;YAAET;YAAQE;QAAI;IACnE,GACA,uEAAuE;IACvE;QAAEsB,SAAS;YAAE,+BAA+B;QAAI;IAAE;AAEtD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js';
|
|
2
2
|
declare module 'payload' {
|
|
3
|
-
interface
|
|
4
|
-
|
|
3
|
+
interface PayloadRequestAPI {
|
|
4
|
+
MCP: true;
|
|
5
5
|
}
|
|
6
6
|
interface RegisteredPlugins {
|
|
7
7
|
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
@@ -10,5 +10,6 @@ declare module 'payload' {
|
|
|
10
10
|
}
|
|
11
11
|
export type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig };
|
|
12
12
|
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js';
|
|
13
|
+
export { oauthProtectedResourceHandler } from './endpoint/oauth.js';
|
|
13
14
|
export declare const mcpPlugin: (options: MCPPluginConfig) => import("payload").Plugin;
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM1F,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,iBAAiB;QAChC,GAAG,EAAE,IAAI,CAAA;KACV;IACD,UAAU,iBAAiB;QACzB,uFAAuF;QACvF,wBAAwB,EAAE,eAAe,CAAA;KAC1C;CACF;AAED,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAA;AAExE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAClG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAA;AAEnE,eAAO,MAAM,SAAS,wDAsCpB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { definePlugin } from 'payload';
|
|
2
2
|
import { mcpEndpoint } from './endpoint/index.js';
|
|
3
|
+
import { oauthProtectedResourceEndpoint } from './endpoint/oauth.js';
|
|
3
4
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
|
|
4
5
|
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js';
|
|
6
|
+
export { oauthProtectedResourceHandler } from './endpoint/oauth.js';
|
|
5
7
|
export const mcpPlugin = definePlugin({
|
|
6
8
|
slug: '@payloadcms/plugin-mcp',
|
|
7
9
|
order: 10,
|
|
8
|
-
plugin: ({ config,
|
|
10
|
+
plugin: ({ config, options, plugins })=>{
|
|
9
11
|
const pluginConfig = sanitizeMCPConfig({
|
|
10
12
|
config,
|
|
11
|
-
pluginConfig:
|
|
13
|
+
pluginConfig: options
|
|
12
14
|
});
|
|
13
15
|
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
14
16
|
const registered = plugins['@payloadcms/plugin-mcp'];
|
|
@@ -40,6 +42,11 @@ export const mcpPlugin = definePlugin({
|
|
|
40
42
|
}),
|
|
41
43
|
method: 'get',
|
|
42
44
|
path: '/mcp'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
handler: oauthProtectedResourceEndpoint,
|
|
48
|
+
method: 'get',
|
|
49
|
+
path: '/mcp/oauth-protected-resource'
|
|
43
50
|
}
|
|
44
51
|
]
|
|
45
52
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { definePlugin } from 'payload'\n\nimport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'\n\nimport { mcpEndpoint } from './endpoint/index.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\n\ndeclare module 'payload' {\n export interface
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { definePlugin } from 'payload'\n\nimport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'\n\nimport { mcpEndpoint } from './endpoint/index.js'\nimport { oauthProtectedResourceEndpoint } from './endpoint/oauth.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\n\ndeclare module 'payload' {\n export interface PayloadRequestAPI {\n MCP: true\n }\n interface RegisteredPlugins {\n /** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */\n '@payloadcms/plugin-mcp': MCPPluginConfig\n }\n}\n\nexport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig }\n\nexport { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'\nexport { oauthProtectedResourceHandler } from './endpoint/oauth.js'\n\nexport const mcpPlugin = definePlugin<MCPPluginConfig>({\n slug: '@payloadcms/plugin-mcp',\n order: 10,\n plugin: ({ config, options, plugins }) => {\n const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: options })\n\n // Stash the sanitized config on plugin options so `getPluginConfig()` reads it.\n const registered = plugins['@payloadcms/plugin-mcp']\n if (registered) {\n // @ts-expect-error\n registered.sanitizedOptions = pluginConfig as unknown as typeof registered.options\n }\n\n if (pluginConfig.disabled) {\n return config\n }\n\n return {\n ...config,\n endpoints: [\n ...(config.endpoints ?? []),\n // Payload prefixes /api, so the full path is /api/mcp.\n { handler: mcpEndpoint, method: 'post', path: '/mcp' },\n // Streamable HTTP's optional server=>client GET stream. We don't offer\n // one, so answer 405 per spec-— clients then skip it cleanly\n {\n handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),\n method: 'get',\n path: '/mcp',\n },\n {\n handler: oauthProtectedResourceEndpoint,\n method: 'get',\n path: '/mcp/oauth-protected-resource',\n },\n ],\n }\n },\n})\n"],"names":["definePlugin","mcpEndpoint","oauthProtectedResourceEndpoint","sanitizeMCPConfig","defineCollectionTool","defineGlobalTool","definePrompt","defineTool","oauthProtectedResourceHandler","mcpPlugin","slug","order","plugin","config","options","plugins","pluginConfig","registered","sanitizedOptions","disabled","endpoints","handler","method","path","Response","headers","Allow","status"],"mappings":"AAAA,SAASA,YAAY,QAAQ,UAAS;AAItC,SAASC,WAAW,QAAQ,sBAAqB;AACjD,SAASC,8BAA8B,QAAQ,sBAAqB;AACpE,SAASC,iBAAiB,QAAQ,6BAA4B;AAc9D,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,UAAU,QAAQ,kBAAiB;AAClG,SAASC,6BAA6B,QAAQ,sBAAqB;AAEnE,OAAO,MAAMC,YAAYT,aAA8B;IACrDU,MAAM;IACNC,OAAO;IACPC,QAAQ,CAAC,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;QACnC,MAAMC,eAAeb,kBAAkB;YAAEU;YAAQG,cAAcF;QAAQ;QAEvE,gFAAgF;QAChF,MAAMG,aAAaF,OAAO,CAAC,yBAAyB;QACpD,IAAIE,YAAY;YACd,mBAAmB;YACnBA,WAAWC,gBAAgB,GAAGF;QAChC;QAEA,IAAIA,aAAaG,QAAQ,EAAE;YACzB,OAAON;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACTO,WAAW;mBACLP,OAAOO,SAAS,IAAI,EAAE;gBAC1B,uDAAuD;gBACvD;oBAAEC,SAASpB;oBAAaqB,QAAQ;oBAAQC,MAAM;gBAAO;gBACrD,uEAAuE;gBACvE,6DAA6D;gBAC7D;oBACEF,SAAS,IAAM,IAAIG,SAAS,MAAM;4BAAEC,SAAS;gCAAEC,OAAO;4BAAO;4BAAGC,QAAQ;wBAAI;oBAC5EL,QAAQ;oBACRC,MAAM;gBACR;gBACA;oBACEF,SAASnB;oBACToB,QAAQ;oBACRC,MAAM;gBACR;aACD;QACH;IACF;AACF,GAAE"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
1
2
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
-
import { type PayloadRequest } from 'payload';
|
|
3
3
|
import type { AuthorizedMCP, SanitizedMCPPluginConfig } from '../types.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* `McpServer` and returns it. The
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
|
|
6
|
+
* `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
|
|
7
|
+
* instances from this builder while they own the transport and protocol-era
|
|
8
|
+
* decision.
|
|
9
9
|
*
|
|
10
10
|
* `req` is the request context handlers see. For HTTP it's the live
|
|
11
11
|
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
12
|
-
* synthesized one built via `
|
|
12
|
+
* synthesized one built via `createPayloadRequest`.
|
|
13
13
|
*/
|
|
14
14
|
export declare const buildMcpServer: ({ authorizedMCP, pluginConfig, req, }: {
|
|
15
15
|
authorizedMCP: AuthorizedMCP;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildMcpServer.d.ts","sourceRoot":"","sources":["../../src/mcp/buildMcpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"buildMcpServer.d.ts","sourceRoot":"","sources":["../../src/mcp/buildMcpServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAsB,MAAM,8BAA8B,CAAA;AAG5E,OAAO,KAAK,EACV,aAAa,EAMb,wBAAwB,EAEzB,MAAM,aAAa,CAAA;AAKpB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,0CAIxB;IACD,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,wBAAwB,CAAA;IACtC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,SAgNH,CAAA"}
|