@payloadcms/plugin-mcp 4.0.0-internal.f11981a → 4.0.0-internal.f2a04f7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +0 -7
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +17 -5
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +46 -4
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +35 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +87 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +2 -2
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +36 -24
- 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 +9 -14
- 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 +9 -13
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +48 -49
- 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 +44 -43
- 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 +31 -37
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.js +34 -70
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
- 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 +27 -45
- 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 +17 -26
- 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 +16 -30
- 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 +30 -14
- 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 +14 -26
- 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 +55 -87
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
- 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 +3 -2
- 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 +9 -13
- 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 +10 -16
- 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 +13 -24
- 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 +13 -29
- 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 +29 -13
- 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 +15 -22
- 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 +27 -36
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +1 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.js +4 -3
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +51 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +23 -25
- package/src/endpoint/access.ts +14 -6
- package/src/endpoint/index.ts +41 -3
- package/src/endpoint/oauth.ts +90 -0
- package/src/index.ts +19 -2
- package/src/mcp/buildMcpServer.ts +40 -30
- package/src/mcp/builtin/collections/authTools.ts +80 -69
- package/src/mcp/builtin/collections/countTool.ts +9 -21
- package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
- package/src/mcp/builtin/collections/createTool.ts +73 -96
- package/src/mcp/builtin/collections/deleteTool.ts +36 -64
- package/src/mcp/builtin/collections/duplicateTool.ts +35 -85
- package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
- package/src/mcp/builtin/collections/fileInput.ts +44 -81
- package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
- package/src/mcp/builtin/collections/findTool.ts +23 -105
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
- package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +23 -12
- package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
- package/src/mcp/builtin/collections/updateTool.ts +55 -109
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
- package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
- package/src/mcp/builtin/globals/findTool.ts +12 -51
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +21 -11
- package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
- package/src/mcp/builtin/globals/updateTool.ts +37 -60
- package/src/mcp/sanitizeMCPConfig.ts +1 -0
- package/src/stdio.ts +2 -2
- package/src/types.ts +50 -8
- package/dist/mcp/builtin/collections/fileInput.spec.js +0 -86
- package/dist/mcp/builtin/collections/fileInput.spec.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/schemaConversion/filterFieldsByAccess.d.ts +0 -28
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
- 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/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/schemaConversion/filterFieldsByAccess.ts +0 -123
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CallToolResult, ContentBlock, JsonSchemaType,
|
|
1
|
+
import type { CallToolResult, ContentBlock, Implementation, JsonSchemaType, McpServerOptions, ResourceTemplate, ServerContext, StandardSchemaWithJSON, ToolAnnotations } from '@modelcontextprotocol/server';
|
|
2
2
|
import type { AuthCollectionSlug, CollectionSlug, GlobalSlug, MaybePromise, PayloadRequest, SanitizedPermissions } from 'payload';
|
|
3
3
|
import type { GetAuthorizedMCPArgs } from './endpoint/access.js';
|
|
4
4
|
import type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName } from './mcp/builtinTools.js';
|
|
@@ -37,10 +37,10 @@ export type MCPAccessArgs = {
|
|
|
37
37
|
req: PayloadRequest;
|
|
38
38
|
};
|
|
39
39
|
export type CollectionMCPAccessArgs = {
|
|
40
|
-
|
|
40
|
+
slug: CollectionSlug;
|
|
41
41
|
} & MCPAccessArgs;
|
|
42
42
|
export type GlobalMCPAccessArgs = {
|
|
43
|
-
|
|
43
|
+
slug: GlobalSlug;
|
|
44
44
|
} & MCPAccessArgs;
|
|
45
45
|
export type ToolHandlerArgs<TSchema = undefined> = {
|
|
46
46
|
authorizedMCP: AuthorizedMCP;
|
|
@@ -49,10 +49,10 @@ export type ToolHandlerArgs<TSchema = undefined> = {
|
|
|
49
49
|
serverContext: ServerContext;
|
|
50
50
|
};
|
|
51
51
|
export type CollectionToolHandlerArgs<TSchema = undefined> = {
|
|
52
|
-
|
|
52
|
+
slug: CollectionSlug;
|
|
53
53
|
} & ToolHandlerArgs<TSchema>;
|
|
54
54
|
export type GlobalToolHandlerArgs<TSchema = undefined> = {
|
|
55
|
-
|
|
55
|
+
slug: GlobalSlug;
|
|
56
56
|
} & ToolHandlerArgs<TSchema>;
|
|
57
57
|
export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
58
58
|
/**
|
|
@@ -223,9 +223,52 @@ export type MCPPluginConfig = {
|
|
|
223
223
|
afterToolCall?: MCPAfterToolCallHook[];
|
|
224
224
|
};
|
|
225
225
|
mcp?: {
|
|
226
|
+
/**
|
|
227
|
+
* Largest HTTP request body, in bytes, that the MCP endpoint accepts. Larger requests
|
|
228
|
+
* are answered with `413`. Base64 file uploads count toward this limit.
|
|
229
|
+
*
|
|
230
|
+
* @default 4194304 (4 MiB, the MCP SDK default)
|
|
231
|
+
*/
|
|
232
|
+
maxRequestBodySize?: number;
|
|
226
233
|
serverOptions?: MCPServerOptions;
|
|
227
234
|
verboseLogs?: boolean;
|
|
228
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* Lets MCP clients sign in through an OAuth authorization server. MCP requests without an
|
|
238
|
+
* authenticated user get a `401` that points to the protected resource metadata (RFC 9728),
|
|
239
|
+
* served by `oauthProtectedResourceHandler`. Payload's auth strategies must accept the
|
|
240
|
+
* issued access tokens.
|
|
241
|
+
*/
|
|
242
|
+
oauth?: {
|
|
243
|
+
/**
|
|
244
|
+
* Called on MCP requests with a bearer token that Payload's auth strategies didn't accept.
|
|
245
|
+
* Return the Payload user, including its `collection`, or `null` to answer with the OAuth challenge.
|
|
246
|
+
*/
|
|
247
|
+
authenticate?: (args: {
|
|
248
|
+
req: PayloadRequest;
|
|
249
|
+
token: string;
|
|
250
|
+
}) => MaybePromise<PayloadRequest['user']>;
|
|
251
|
+
/**
|
|
252
|
+
* The authorization servers that issue access tokens for MCP clients. Clients require each one
|
|
253
|
+
* to exactly match the `issuer` in that server's metadata, so pass a function when the exact
|
|
254
|
+
* value is only known at runtime, e.g. from the server's OpenID configuration or per host.
|
|
255
|
+
*/
|
|
256
|
+
authorizationServers: ((args: {
|
|
257
|
+
req: PayloadRequest;
|
|
258
|
+
}) => MaybePromise<string[]>) | string[];
|
|
259
|
+
/**
|
|
260
|
+
* The URL clients call to reach the MCP endpoint.
|
|
261
|
+
*
|
|
262
|
+
* @default the absolute URL of `/api/mcp`, based on `serverURL` or the request URL
|
|
263
|
+
*/
|
|
264
|
+
resource?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Scopes MCP clients should request, e.g. `['openid', 'email', 'profile']`. Without them,
|
|
267
|
+
* clients request none, which some authorization servers reject or answer with a token that
|
|
268
|
+
* doesn't identify the user.
|
|
269
|
+
*/
|
|
270
|
+
scopes?: string[];
|
|
271
|
+
};
|
|
229
272
|
/**
|
|
230
273
|
* Replace the default MCP authorization resolver.
|
|
231
274
|
*
|
|
@@ -242,10 +285,10 @@ export type MCPPluginConfig = {
|
|
|
242
285
|
};
|
|
243
286
|
export type SanitizedMCPPluginConfig = {
|
|
244
287
|
items: MCPItem[];
|
|
245
|
-
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>;
|
|
288
|
+
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'oauth' | 'overrideGetAuthorizedMCP'>;
|
|
246
289
|
export type MCPServerOptions = {
|
|
247
|
-
options?:
|
|
248
|
-
serverInfo?: Partial<
|
|
290
|
+
options?: McpServerOptions;
|
|
291
|
+
serverInfo?: Partial<Implementation>;
|
|
249
292
|
};
|
|
250
293
|
/**
|
|
251
294
|
* One MCP primitive plus the metadata needed for config-driven filtering and
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,CAAA;AAEzF,gGAAgG;AAChG,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,CAAA;AAEvE;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,sBAAsB,CAAA;AAErE,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,GAAG,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,SAAS,GAAG,mBAAmB,CAAC,CAAA;AAEnE,MAAM,MAAM,mBAAmB,GAAG,CACh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AAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CACrC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,gBAAgB,CAAA;CACvB,GAAG,WAAW,CAAA;AAEf,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,YAAY,CAAA;CACnB,GAAG,WAAW,CAAA;AAEf,MAAM,MAAM,OAAO,GACf,CAAC;IACC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,QAAQ,CAAA;CACf,GAAG,WAAW,CAAC,GAChB,CAAC;IACC,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,UAAU,CAAA;CACjB,GAAG,WAAW,CAAC,GAChB,CAAC;IACC,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,WAAW,CAAC,GAChB,iBAAiB,GACjB,aAAa,CAAA;AAEjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CallToolResult,\n ContentBlock,\n JsonSchemaType,\n McpServer,\n ResourceTemplate,\n ServerContext,\n StandardSchemaWithJSON,\n ToolAnnotations,\n} from '@modelcontextprotocol/server'\nimport type {\n AuthCollectionSlug,\n CollectionSlug,\n GlobalSlug,\n MaybePromise,\n PayloadRequest,\n SanitizedPermissions,\n} from 'payload'\n\nimport type { GetAuthorizedMCPArgs } from './endpoint/access.js'\nimport type {\n MCPCollectionAuthToolName,\n MCPCollectionBuiltinName,\n MCPGlobalBuiltinName,\n} from './mcp/builtinTools.js'\n\nexport type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }\n\n/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */\nexport type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }\n\n/**\n * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw\n * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).\n * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.\n */\nexport type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON\n\nexport type MCPToolResponse = {\n content: ContentBlock[]\n /**\n * If available, return the document fetched within the\n * mcp tool. This is threaded as an additional argument to\n * overrideResponse functions and stripped before going on the wire.\n */\n doc?: Record<string, unknown>\n} & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>\n\nexport type MCPResponseOverride = (\n response: MCPToolResponse,\n doc: Record<string, unknown>,\n req: PayloadRequest,\n) => MCPToolResponse\n\nexport type MCPAfterToolCallHook = (args: {\n input: unknown\n req: PayloadRequest\n response: MCPToolResponse\n toolName: string\n}) => MaybePromise<MCPToolResponse>\n\n/**\n * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets\n * its inferred output; anything else falls back to `Record<string, unknown>`.\n */\nexport type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON\n ? StandardSchemaWithJSON extends TSchema\n ? Record<string, unknown>\n : StandardSchemaWithJSON.InferOutput<TSchema>\n : Record<string, unknown>\n\nexport type MCPAccessArgs = {\n permissions?: SanitizedPermissions\n req: PayloadRequest\n}\n\nexport type CollectionMCPAccessArgs = {\n collectionSlug: CollectionSlug\n} & MCPAccessArgs\n\nexport type GlobalMCPAccessArgs = {\n globalSlug: GlobalSlug\n} & MCPAccessArgs\n\nexport type ToolHandlerArgs<TSchema = undefined> = {\n authorizedMCP: AuthorizedMCP\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type CollectionToolHandlerArgs<TSchema = undefined> = {\n collectionSlug: CollectionSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type GlobalToolHandlerArgs<TSchema = undefined> = {\n globalSlug: GlobalSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {\n /**\n * Runs while authorizing each MCP request, before the tool is advertised or called. Return\n * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`\n * is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description: string\n handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n /**\n * Override the return value of the tool handler\n */\n overrideResponse?: MCPResponseOverride\n}\n\nexport type CollectionTool<\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n> = {\n /**\n * Runs while authorizing each MCP request for this collection. Return `false` to reject calls\n * to this tool for the collection. The shared tool is not advertised when no collections allow\n * it, but can remain advertised when it is available for another collection. This is skipped\n * when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\nexport type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =\n {\n /**\n * Runs while authorizing each MCP request for this global. Return `false` to reject calls to\n * this tool for the global. The shared tool is not advertised when no globals allow it, but\n * can remain advertised when it is available for another global. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\n/**\n * Configures (or disables) a built-in tool without replacing it.\n * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a\n * required handler) from being silently accepted at a built-in key slot.\n */\nexport type MCPBuiltInCollectionToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this collection. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\nexport type MCPBuiltInGlobalToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this global. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\n/**\n * Value at a custom (non-built-in) tool key. Either the tool itself, or `false`\n * to disable it (useful when one plugin defines a custom tool and another\n * wants to opt out per-collection).\n */\nexport type MCPTopLevelToolEntry = Tool\n\nexport type MCPCollectionToolsMap = {\n [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined\n} & {\n [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride\n}\n\nexport type MCPAuthCollectionToolsMap = {\n [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true\n} & MCPCollectionToolsMap\n\n/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */\nexport type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug\n ? MCPAuthCollectionToolsMap\n : MCPCollectionToolsMap\n\nexport type MCPGlobalToolsMap = {\n [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined\n} & {\n [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride\n}\n\nexport type MCPTopLevelToolsMap = Record<string, Tool>\n\nexport type PromptHandlerArgs<TSchema = undefined> = {\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {\n /**\n * Runs while authorizing each MCP request, before the prompt is advertised or used. Return\n * `false` to make the prompt unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n argsSchema: TSchema\n description: string\n handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{\n messages: Array<{ content: { text: string; type: 'text' }; role: 'assistant' | 'user' }>\n }>\n title: string\n}\n\nexport type ResourceHandlerArgs = {\n /** Variables extracted from a `ResourceTemplate` URI. Empty for static-URI resources. */\n params: Record<string, string>\n req: PayloadRequest\n serverContext: ServerContext\n uri: URL\n}\n\nexport type Resource = {\n /**\n * Runs while authorizing each MCP request, before the resource is advertised or read. Return\n * `false` to make the resource unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n description: string\n handler: (args: ResourceHandlerArgs) => MaybePromise<{\n contents: Array<{ text: string; uri: string }>\n }>\n mimeType: string\n title: string\n uri: ResourceTemplate | string\n}\n\nexport type MCPPluginCollectionConfig<TSlug extends CollectionSlug> = {\n description?: string\n /** Fallback for built-in tools that don't set their own `overrideResponse`. */\n overrideResponse?: MCPResponseOverride\n tools?: MCPToolsMapForCollection<TSlug>\n}\n\nexport type MCPPluginGlobalConfig = {\n description?: string\n overrideResponse?: MCPResponseOverride\n tools?: MCPGlobalToolsMap\n}\n\n/**\n * The user-facing config shape passed to `mcpPlugin({ ... })`. Tools, prompts,\n * resources, and per-collection/global tool maps live in their own nested\n * fields. `sanitizeMCPConfig` flattens those into `items` and applies defaults\n * to produce a `SanitizedMCPPluginConfig` — the form every internal consumer\n * actually works with.\n */\nexport type MCPPluginConfig = {\n collections?: {\n [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>\n }\n /** Skip MCP endpoint registration. */\n disabled?: boolean\n globals?: {\n [Slug in GlobalSlug]?: MCPPluginGlobalConfig\n }\n hooks?: {\n /** Transform a tool response after its handler returns */\n afterToolCall?: MCPAfterToolCallHook[]\n }\n mcp?: {\n serverOptions?: MCPServerOptions\n verboseLogs?: boolean\n }\n /**\n * Replace the default MCP authorization resolver.\n *\n * This hook replaces the default authentication flow. It must set `req.user` to the\n * authenticated Payload user, or to `null` for an anonymous caller, before returning.\n */\n overrideGetAuthorizedMCP?: (\n args: {\n pluginConfig: SanitizedMCPPluginConfig\n } & GetAuthorizedMCPArgs,\n ) => MaybePromise<AuthorizedMCP>\n prompts?: Record<string, Prompt>\n resources?: Record<string, Resource>\n /** Cross-cutting tools (not scoped to any collection or global). */\n tools?: MCPTopLevelToolsMap\n}\n\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>\n\nexport type MCPServerOptions = {\n options?: ConstructorParameters<typeof McpServer>[1]\n serverInfo?: Partial<ConstructorParameters<typeof McpServer>[0]>\n}\n\n/**\n * One MCP primitive plus the metadata needed for config-driven filtering and\n * registration.\n *\n * - `configKey`: the config identifier, e.g. `find` or `echo`.\n * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.\n * - `label`: human-readable display text.\n */\nexport type MCPItemBase = {\n configKey: string\n label: string\n mcpName: string\n}\n\nexport type CollectionMCPItem = {\n collectionSlug: CollectionSlug\n tool: CollectionTool\n type: 'collectionTool'\n} & MCPItemBase\n\nexport type GlobalMCPItem = {\n globalSlug: GlobalSlug\n tool: GlobalTool\n type: 'globalTool'\n} & MCPItemBase\n\nexport type MCPItem =\n | ({\n prompt: Prompt\n type: 'prompt'\n } & MCPItemBase)\n | ({\n resource: Resource\n type: 'resource'\n } & MCPItemBase)\n | ({\n tool: Tool\n type: 'tool'\n } & MCPItemBase)\n | CollectionMCPItem\n | GlobalMCPItem\n\n/**\n * The MCP items and access mode authorized for this request. The authenticated user is available\n * as `req.user`.\n */\nexport type AuthorizedMCP = {\n items: MCPItem[]\n overrideAccess: boolean\n}\n"],"names":[],"mappings":"AAgWA;;;CAGC,GACD,WAGC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CallToolResult,\n ContentBlock,\n Implementation,\n JsonSchemaType,\n McpServerOptions,\n ResourceTemplate,\n ServerContext,\n StandardSchemaWithJSON,\n ToolAnnotations,\n} from '@modelcontextprotocol/server'\nimport type {\n AuthCollectionSlug,\n CollectionSlug,\n GlobalSlug,\n MaybePromise,\n PayloadRequest,\n SanitizedPermissions,\n} from 'payload'\n\nimport type { GetAuthorizedMCPArgs } from './endpoint/access.js'\nimport type {\n MCPCollectionAuthToolName,\n MCPCollectionBuiltinName,\n MCPGlobalBuiltinName,\n} from './mcp/builtinTools.js'\n\nexport type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }\n\n/** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */\nexport type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }\n\n/**\n * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw\n * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).\n * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.\n */\nexport type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON\n\nexport type MCPToolResponse = {\n content: ContentBlock[]\n /**\n * If available, return the document fetched within the\n * mcp tool. This is threaded as an additional argument to\n * overrideResponse functions and stripped before going on the wire.\n */\n doc?: Record<string, unknown>\n} & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>\n\nexport type MCPResponseOverride = (\n response: MCPToolResponse,\n doc: Record<string, unknown>,\n req: PayloadRequest,\n) => MCPToolResponse\n\nexport type MCPAfterToolCallHook = (args: {\n input: unknown\n req: PayloadRequest\n response: MCPToolResponse\n toolName: string\n}) => MaybePromise<MCPToolResponse>\n\n/**\n * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets\n * its inferred output; anything else falls back to `Record<string, unknown>`.\n */\nexport type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON\n ? StandardSchemaWithJSON extends TSchema\n ? Record<string, unknown>\n : StandardSchemaWithJSON.InferOutput<TSchema>\n : Record<string, unknown>\n\nexport type MCPAccessArgs = {\n permissions?: SanitizedPermissions\n req: PayloadRequest\n}\n\nexport type CollectionMCPAccessArgs = {\n slug: CollectionSlug\n} & MCPAccessArgs\n\nexport type GlobalMCPAccessArgs = {\n slug: GlobalSlug\n} & MCPAccessArgs\n\nexport type ToolHandlerArgs<TSchema = undefined> = {\n authorizedMCP: AuthorizedMCP\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type CollectionToolHandlerArgs<TSchema = undefined> = {\n slug: CollectionSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type GlobalToolHandlerArgs<TSchema = undefined> = {\n slug: GlobalSlug\n} & ToolHandlerArgs<TSchema>\n\nexport type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {\n /**\n * Runs while authorizing each MCP request, before the tool is advertised or called. Return\n * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`\n * is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description: string\n handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n /**\n * Override the return value of the tool handler\n */\n overrideResponse?: MCPResponseOverride\n}\n\nexport type CollectionTool<\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n> = {\n /**\n * Runs while authorizing each MCP request for this collection. Return `false` to reject calls\n * to this tool for the collection. The shared tool is not advertised when no collections allow\n * it, but can remain advertised when it is available for another collection. This is skipped\n * when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n} & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\nexport type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =\n {\n /**\n * Runs while authorizing each MCP request for this global. Return `false` to reject calls to\n * this tool for the global. The shared tool is not advertised when no globals allow it, but\n * can remain advertised when it is available for another global. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>\n input?: TSchema\n } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>\n\n/**\n * Configures (or disables) a built-in tool without replacing it.\n * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a\n * required handler) from being silently accepted at a built-in key slot.\n */\nexport type MCPBuiltInCollectionToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this collection. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\nexport type MCPBuiltInGlobalToolOverride = {\n /**\n * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for\n * this global. This is skipped when `overrideAccess` is enabled.\n */\n access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>\n annotations?: ToolAnnotations\n description?: string\n handler?: never\n overrideResponse?: MCPResponseOverride\n}\n\n/**\n * Value at a custom (non-built-in) tool key. Either the tool itself, or `false`\n * to disable it (useful when one plugin defines a custom tool and another\n * wants to opt out per-collection).\n */\nexport type MCPTopLevelToolEntry = Tool\n\nexport type MCPCollectionToolsMap = {\n [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined\n} & {\n [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride\n}\n\nexport type MCPAuthCollectionToolsMap = {\n [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true\n} & MCPCollectionToolsMap\n\n/** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */\nexport type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug\n ? MCPAuthCollectionToolsMap\n : MCPCollectionToolsMap\n\nexport type MCPGlobalToolsMap = {\n [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined\n} & {\n [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride\n}\n\nexport type MCPTopLevelToolsMap = Record<string, Tool>\n\nexport type PromptHandlerArgs<TSchema = undefined> = {\n input: TypedInput<TSchema>\n req: PayloadRequest\n serverContext: ServerContext\n}\n\nexport type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {\n /**\n * Runs while authorizing each MCP request, before the prompt is advertised or used. Return\n * `false` to make the prompt unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n argsSchema: TSchema\n description: string\n handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{\n messages: Array<{ content: { text: string; type: 'text' }; role: 'assistant' | 'user' }>\n }>\n title: string\n}\n\nexport type ResourceHandlerArgs = {\n /** Variables extracted from a `ResourceTemplate` URI. Empty for static-URI resources. */\n params: Record<string, string>\n req: PayloadRequest\n serverContext: ServerContext\n uri: URL\n}\n\nexport type Resource = {\n /**\n * Runs while authorizing each MCP request, before the resource is advertised or read. Return\n * `false` to make the resource unavailable for that request. This is skipped when\n * `overrideAccess` is enabled.\n */\n access?: (args: MCPAccessArgs) => MaybePromise<boolean>\n description: string\n handler: (args: ResourceHandlerArgs) => MaybePromise<{\n contents: Array<{ text: string; uri: string }>\n }>\n mimeType: string\n title: string\n uri: ResourceTemplate | string\n}\n\nexport type MCPPluginCollectionConfig<TSlug extends CollectionSlug> = {\n description?: string\n /** Fallback for built-in tools that don't set their own `overrideResponse`. */\n overrideResponse?: MCPResponseOverride\n tools?: MCPToolsMapForCollection<TSlug>\n}\n\nexport type MCPPluginGlobalConfig = {\n description?: string\n overrideResponse?: MCPResponseOverride\n tools?: MCPGlobalToolsMap\n}\n\n/**\n * The user-facing config shape passed to `mcpPlugin({ ... })`. Tools, prompts,\n * resources, and per-collection/global tool maps live in their own nested\n * fields. `sanitizeMCPConfig` flattens those into `items` and applies defaults\n * to produce a `SanitizedMCPPluginConfig` — the form every internal consumer\n * actually works with.\n */\nexport type MCPPluginConfig = {\n collections?: {\n [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>\n }\n /** Skip MCP endpoint registration. */\n disabled?: boolean\n globals?: {\n [Slug in GlobalSlug]?: MCPPluginGlobalConfig\n }\n hooks?: {\n /** Transform a tool response after its handler returns */\n afterToolCall?: MCPAfterToolCallHook[]\n }\n mcp?: {\n /**\n * Largest HTTP request body, in bytes, that the MCP endpoint accepts. Larger requests\n * are answered with `413`. Base64 file uploads count toward this limit.\n *\n * @default 4194304 (4 MiB, the MCP SDK default)\n */\n maxRequestBodySize?: number\n serverOptions?: MCPServerOptions\n verboseLogs?: boolean\n }\n /**\n * Lets MCP clients sign in through an OAuth authorization server. MCP requests without an\n * authenticated user get a `401` that points to the protected resource metadata (RFC 9728),\n * served by `oauthProtectedResourceHandler`. Payload's auth strategies must accept the\n * issued access tokens.\n */\n oauth?: {\n /**\n * Called on MCP requests with a bearer token that Payload's auth strategies didn't accept.\n * Return the Payload user, including its `collection`, or `null` to answer with the OAuth challenge.\n */\n authenticate?: (args: {\n req: PayloadRequest\n token: string\n }) => MaybePromise<PayloadRequest['user']>\n /**\n * The authorization servers that issue access tokens for MCP clients. Clients require each one\n * to exactly match the `issuer` in that server's metadata, so pass a function when the exact\n * value is only known at runtime, e.g. from the server's OpenID configuration or per host.\n */\n authorizationServers: ((args: { req: PayloadRequest }) => MaybePromise<string[]>) | string[]\n /**\n * The URL clients call to reach the MCP endpoint.\n *\n * @default the absolute URL of `/api/mcp`, based on `serverURL` or the request URL\n */\n resource?: string\n /**\n * Scopes MCP clients should request, e.g. `['openid', 'email', 'profile']`. Without them,\n * clients request none, which some authorization servers reject or answer with a token that\n * doesn't identify the user.\n */\n scopes?: string[]\n }\n /**\n * Replace the default MCP authorization resolver.\n *\n * This hook replaces the default authentication flow. It must set `req.user` to the\n * authenticated Payload user, or to `null` for an anonymous caller, before returning.\n */\n overrideGetAuthorizedMCP?: (\n args: {\n pluginConfig: SanitizedMCPPluginConfig\n } & GetAuthorizedMCPArgs,\n ) => MaybePromise<AuthorizedMCP>\n prompts?: Record<string, Prompt>\n resources?: Record<string, Resource>\n /** Cross-cutting tools (not scoped to any collection or global). */\n tools?: MCPTopLevelToolsMap\n}\n\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'oauth' | 'overrideGetAuthorizedMCP'>\n\nexport type MCPServerOptions = {\n options?: McpServerOptions\n serverInfo?: Partial<Implementation>\n}\n\n/**\n * One MCP primitive plus the metadata needed for config-driven filtering and\n * registration.\n *\n * - `configKey`: the config identifier, e.g. `find` or `echo`.\n * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.\n * - `label`: human-readable display text.\n */\nexport type MCPItemBase = {\n configKey: string\n label: string\n mcpName: string\n}\n\nexport type CollectionMCPItem = {\n collectionSlug: CollectionSlug\n tool: CollectionTool\n type: 'collectionTool'\n} & MCPItemBase\n\nexport type GlobalMCPItem = {\n globalSlug: GlobalSlug\n tool: GlobalTool\n type: 'globalTool'\n} & MCPItemBase\n\nexport type MCPItem =\n | ({\n prompt: Prompt\n type: 'prompt'\n } & MCPItemBase)\n | ({\n resource: Resource\n type: 'resource'\n } & MCPItemBase)\n | ({\n tool: Tool\n type: 'tool'\n } & MCPItemBase)\n | CollectionMCPItem\n | GlobalMCPItem\n\n/**\n * The MCP items and access mode authorized for this request. The authenticated user is available\n * as `req.user`.\n */\nexport type AuthorizedMCP = {\n items: MCPItem[]\n overrideAccess: boolean\n}\n"],"names":[],"mappings":"AA0YA;;;CAGC,GACD,WAGC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.f2a04f7",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"plugin",
|
|
7
6
|
"mcp",
|
|
8
|
-
"model context protocol"
|
|
7
|
+
"model context protocol",
|
|
8
|
+
"plugin"
|
|
9
9
|
],
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
13
|
-
"directory": "packages/plugin-mcp"
|
|
14
|
-
},
|
|
15
10
|
"license": "MIT",
|
|
16
11
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
17
12
|
"maintainers": [
|
|
@@ -21,7 +16,22 @@
|
|
|
21
16
|
"url": "https://payloadcms.com"
|
|
22
17
|
}
|
|
23
18
|
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
22
|
+
"directory": "packages/plugin-mcp"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"payload-mcp": "./bin.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src",
|
|
29
|
+
"dist",
|
|
30
|
+
"bin.js"
|
|
31
|
+
],
|
|
24
32
|
"type": "module",
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
25
35
|
"exports": {
|
|
26
36
|
".": {
|
|
27
37
|
"import": "./dist/index.js",
|
|
@@ -44,30 +54,18 @@
|
|
|
44
54
|
"default": "./dist/exports/internal.js"
|
|
45
55
|
}
|
|
46
56
|
},
|
|
47
|
-
"main": "./dist/index.js",
|
|
48
|
-
"types": "./dist/index.d.ts",
|
|
49
|
-
"bin": {
|
|
50
|
-
"payload-mcp": "./bin.js"
|
|
51
|
-
},
|
|
52
|
-
"files": [
|
|
53
|
-
"src",
|
|
54
|
-
"dist",
|
|
55
|
-
"bin.js"
|
|
56
|
-
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@modelcontextprotocol/server": "2.
|
|
59
|
-
"tsx": "4.
|
|
60
|
-
"zod": "^4.2.0"
|
|
58
|
+
"@modelcontextprotocol/server": "2.3.1",
|
|
59
|
+
"tsx": "4.23.15"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
62
|
"@payloadcms/eslint-config": "3.28.0",
|
|
64
|
-
"payload": "4.0.0-internal.
|
|
63
|
+
"payload": "4.0.0-internal.f2a04f7"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
|
-
"payload": "4.0.0-internal.
|
|
66
|
+
"payload": "4.0.0-internal.f2a04f7"
|
|
68
67
|
},
|
|
69
68
|
"//deps_notes": {
|
|
70
|
-
"zod": "zod is a hard dependency of @modelcontextprotocol/server, thus we can safely use it without it impacting bundle size. Make extra sure the zod version here matches exactly what's defined in the dependencies of @modelcontextprotocol/server to avoid duplicate versions being installed.",
|
|
71
69
|
"tsx": "Required by the `bin.js` stdio mcp. Keep the version pinned to whatever `payload` ships to avoid duplicate installs."
|
|
72
70
|
},
|
|
73
71
|
"homepage:": "https://payloadcms.com",
|
|
@@ -77,7 +75,7 @@
|
|
|
77
75
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
78
76
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
79
77
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
80
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
78
|
+
"copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
81
79
|
"lint": "eslint .",
|
|
82
80
|
"lint:fix": "eslint . --fix",
|
|
83
81
|
"pack:plugin": "pnpm build && pnpm pack"
|
package/src/endpoint/access.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PayloadRequest, SanitizedPermissions } from 'payload'
|
|
2
2
|
|
|
3
|
-
import { getAccessResults, UnauthorizedError } from 'payload'
|
|
3
|
+
import { executeAuthStrategies, getAccessResults, UnauthorizedError } from 'payload'
|
|
4
4
|
|
|
5
5
|
import type { AuthorizedMCP, MCPItem } from '../types.js'
|
|
6
6
|
|
|
@@ -34,9 +34,18 @@ export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<Authorize
|
|
|
34
34
|
const hasAuthorization = headers.has('Authorization')
|
|
35
35
|
|
|
36
36
|
headers.set('DisableAutologin', 'true')
|
|
37
|
-
|
|
37
|
+
// Not `payload.auth()`, which also computes permissions that filterMCPItems computes anyway
|
|
38
|
+
req.user = (await executeAuthStrategies({ headers, payload: req.payload, req })).user
|
|
39
|
+
|
|
40
|
+
// Only bearer tokens that no auth strategy accepted reach the hook, e.g. an OAuth access token.
|
|
41
|
+
// API keys use the `<collection> API-Key <key>` scheme instead of `Bearer`, so they never do.
|
|
42
|
+
const bearerToken = headers.get('Authorization')?.match(/^Bearer (.+)$/)?.[1]
|
|
43
|
+
if (!req.user && bearerToken && pluginConfig.oauth?.authenticate) {
|
|
44
|
+
req.user = await pluginConfig.oauth.authenticate({ req, token: bearerToken })
|
|
45
|
+
}
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
// With OAuth, the endpoint answers with a challenge that starts the client's sign-in
|
|
48
|
+
if (hasAuthorization && !req.user && !pluginConfig.oauth) {
|
|
40
49
|
throw new UnauthorizedError(req.t)
|
|
41
50
|
}
|
|
42
51
|
}
|
|
@@ -95,12 +104,11 @@ const checkItemAccess = async ({
|
|
|
95
104
|
case 'collectionTool':
|
|
96
105
|
return (
|
|
97
106
|
!item.tool.access ||
|
|
98
|
-
(await item.tool.access({
|
|
107
|
+
(await item.tool.access({ slug: item.collectionSlug, permissions, req }))
|
|
99
108
|
)
|
|
100
109
|
case 'globalTool':
|
|
101
110
|
return (
|
|
102
|
-
!item.tool.access ||
|
|
103
|
-
(await item.tool.access({ globalSlug: item.globalSlug, permissions, req }))
|
|
111
|
+
!item.tool.access || (await item.tool.access({ slug: item.globalSlug, permissions, req }))
|
|
104
112
|
)
|
|
105
113
|
case 'prompt':
|
|
106
114
|
return !item.prompt.access || (await item.prompt.access({ permissions, req }))
|
package/src/endpoint/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { PayloadHandler, PayloadRequest } from 'payload'
|
|
|
3
3
|
import {
|
|
4
4
|
createMcpHandler,
|
|
5
5
|
isLegacyRequest,
|
|
6
|
+
readRequestBody,
|
|
6
7
|
WebStandardStreamableHTTPServerTransport,
|
|
7
8
|
} from '@modelcontextprotocol/server'
|
|
8
9
|
import { APIError } from 'payload'
|
|
@@ -10,6 +11,7 @@ import { APIError } from 'payload'
|
|
|
10
11
|
import { buildMcpServer } from '../mcp/buildMcpServer.js'
|
|
11
12
|
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
12
13
|
import { getAuthorizedMCP } from './access.js'
|
|
14
|
+
import { getMCPResource, oauthChallenge } from './oauth.js'
|
|
13
15
|
|
|
14
16
|
export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
15
17
|
if (!req.url) {
|
|
@@ -17,6 +19,8 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
req.payloadAPI = 'MCP' as const
|
|
22
|
+
// Lets auth strategies check that an OAuth access token was issued for this MCP server
|
|
23
|
+
req.context.mcp = { resource: getMCPResource({ config: req.payload.config, url: req.url }) }
|
|
20
24
|
|
|
21
25
|
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
22
26
|
const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
|
|
@@ -33,14 +37,22 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
40
|
+
|
|
41
|
+
if (pluginConfig.oauth && !req.user) {
|
|
42
|
+
return oauthChallenge({ req })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
|
|
36
46
|
// Payload augments the original web-standard Request in place.
|
|
37
47
|
const mcpRequest = req as PayloadRequest & Request
|
|
48
|
+
const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })
|
|
38
49
|
|
|
39
50
|
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
40
|
-
if (await isLegacyRequest(mcpRequest)) {
|
|
51
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {
|
|
41
52
|
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
42
53
|
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
43
54
|
enableJsonResponse: true,
|
|
55
|
+
maxRequestBodySize,
|
|
44
56
|
sessionIdGenerator: undefined, // stateless mode
|
|
45
57
|
})
|
|
46
58
|
transport.onerror = (err) => {
|
|
@@ -49,7 +61,7 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
49
61
|
|
|
50
62
|
try {
|
|
51
63
|
await server.connect(transport)
|
|
52
|
-
return await transport.handleRequest(mcpRequest)
|
|
64
|
+
return await transport.handleRequest(mcpRequest, { parsedBody })
|
|
53
65
|
} finally {
|
|
54
66
|
await server.close().catch((err) => {
|
|
55
67
|
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
@@ -59,6 +71,7 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
59
71
|
|
|
60
72
|
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
61
73
|
legacy: 'reject',
|
|
74
|
+
maxRequestBodySize,
|
|
62
75
|
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
63
76
|
maxSubscriptions: 0,
|
|
64
77
|
onerror: (err) => {
|
|
@@ -68,10 +81,35 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
68
81
|
})
|
|
69
82
|
|
|
70
83
|
try {
|
|
71
|
-
return await handler.fetch(mcpRequest)
|
|
84
|
+
return await handler.fetch(mcpRequest, { parsedBody })
|
|
72
85
|
} finally {
|
|
73
86
|
await handler.close().catch((err) => {
|
|
74
87
|
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
75
88
|
})
|
|
76
89
|
}
|
|
77
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
94
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
95
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
96
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
97
|
+
*/
|
|
98
|
+
const parseRequestBody = async ({
|
|
99
|
+
maxRequestBodySize,
|
|
100
|
+
request,
|
|
101
|
+
}: {
|
|
102
|
+
maxRequestBodySize?: number
|
|
103
|
+
request: Request
|
|
104
|
+
}): Promise<unknown> => {
|
|
105
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize)
|
|
111
|
+
return body.tooLarge ? undefined : JSON.parse(body.text)
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { OAuthProtectedResourceMetadata } from '@modelcontextprotocol/server'
|
|
2
|
+
import type { PayloadHandler, PayloadRequest, SanitizedConfig } from 'payload'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
bearerAuthChallengeResponse,
|
|
6
|
+
OAuthError,
|
|
7
|
+
OAuthErrorCode,
|
|
8
|
+
} from '@modelcontextprotocol/server'
|
|
9
|
+
import { createPayloadRequest, getPayload } from 'payload'
|
|
10
|
+
|
|
11
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
15
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
16
|
+
*/
|
|
17
|
+
export const oauthProtectedResourceEndpoint: PayloadHandler = (req) => getMetadataResponse({ req })
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
21
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
22
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import config from '@payload-config'
|
|
26
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
27
|
+
*
|
|
28
|
+
* export const GET = oauthProtectedResourceHandler(config)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const oauthProtectedResourceHandler =
|
|
32
|
+
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
|
33
|
+
async (request: Request): Promise<Response> =>
|
|
34
|
+
getMetadataResponse({
|
|
35
|
+
req: await createPayloadRequest({ payload: await getPayload({ config }), req: request }),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
40
|
+
* metadata, which starts the client's OAuth flow.
|
|
41
|
+
*/
|
|
42
|
+
export const oauthChallenge = ({ req }: { req: PayloadRequest }): Response => {
|
|
43
|
+
const response = bearerAuthChallengeResponse(
|
|
44
|
+
new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),
|
|
45
|
+
{
|
|
46
|
+
requiredScopes: getPluginConfig({ config: req.payload.config }).oauth?.scopes,
|
|
47
|
+
resourceMetadataUrl: `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth-protected-resource`,
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// Lets browser-based MCP clients read the challenge, when Payload's `cors` setting allows them
|
|
52
|
+
response.headers.set('Access-Control-Expose-Headers', 'WWW-Authenticate')
|
|
53
|
+
|
|
54
|
+
return response
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The MCP endpoint's address, as advertised in the metadata's `resource`. Clients send it when
|
|
59
|
+
* they sign in, and authorization servers that support it put it in the access token's audience.
|
|
60
|
+
*/
|
|
61
|
+
export const getMCPResource = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
62
|
+
getPluginConfig({ config }).oauth?.resource ?? getMCPURL({ config, url })
|
|
63
|
+
|
|
64
|
+
const getMCPURL = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
65
|
+
new URL(`${config.routes.api}/mcp`, config.serverURL || url).href
|
|
66
|
+
|
|
67
|
+
const getMetadataResponse = async ({ req }: { req: PayloadRequest }): Promise<Response> => {
|
|
68
|
+
const { config } = req.payload
|
|
69
|
+
const pluginConfig = getPluginConfig({ config })
|
|
70
|
+
|
|
71
|
+
if (!pluginConfig.oauth) {
|
|
72
|
+
return new Response(null, { status: 404 })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const { authorizationServers, scopes } = pluginConfig.oauth
|
|
76
|
+
|
|
77
|
+
return Response.json(
|
|
78
|
+
{
|
|
79
|
+
authorization_servers:
|
|
80
|
+
typeof authorizationServers === 'function'
|
|
81
|
+
? await authorizationServers({ req })
|
|
82
|
+
: authorizationServers,
|
|
83
|
+
bearer_methods_supported: ['header'],
|
|
84
|
+
resource: getMCPResource({ config, url: req.url! }),
|
|
85
|
+
scopes_supported: scopes,
|
|
86
|
+
} satisfies OAuthProtectedResourceMetadata,
|
|
87
|
+
// Public document, readable by browser-based MCP clients on any origin
|
|
88
|
+
{ headers: { 'Access-Control-Allow-Origin': '*' } },
|
|
89
|
+
)
|
|
90
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { definePlugin } from 'payload'
|
|
|
3
3
|
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
4
4
|
|
|
5
5
|
import { mcpEndpoint } from './endpoint/index.js'
|
|
6
|
+
import { oauthProtectedResourceEndpoint } from './endpoint/oauth.js'
|
|
6
7
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
7
8
|
|
|
8
9
|
declare module 'payload' {
|
|
@@ -13,11 +14,19 @@ declare module 'payload' {
|
|
|
13
14
|
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
14
15
|
'@payloadcms/plugin-mcp': MCPPluginConfig
|
|
15
16
|
}
|
|
17
|
+
export interface RequestContext {
|
|
18
|
+
/** Set on MCP requests before they're authenticated. */
|
|
19
|
+
mcp?: {
|
|
20
|
+
/** The MCP endpoint's address, which OAuth access tokens for MCP are issued for. */
|
|
21
|
+
resource: string
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
export type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig }
|
|
19
27
|
|
|
20
28
|
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'
|
|
29
|
+
export { oauthProtectedResourceHandler } from './endpoint/oauth.js'
|
|
21
30
|
|
|
22
31
|
export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
23
32
|
slug: '@payloadcms/plugin-mcp',
|
|
@@ -40,15 +49,23 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
40
49
|
...config,
|
|
41
50
|
endpoints: [
|
|
42
51
|
...(config.endpoints ?? []),
|
|
43
|
-
// Payload prefixes /api, so the full path is /api/mcp.
|
|
44
|
-
|
|
52
|
+
// Payload prefixes /api, so the full path is /api/mcp. getAuthorizedMCP authenticates the
|
|
53
|
+
// request with dev auto-login turned off, so Payload doesn't authenticate it first.
|
|
54
|
+
{ disableAuth: true, handler: mcpEndpoint, method: 'post', path: '/mcp' },
|
|
45
55
|
// Streamable HTTP's optional server=>client GET stream. We don't offer
|
|
46
56
|
// one, so answer 405 per spec-— clients then skip it cleanly
|
|
47
57
|
{
|
|
58
|
+
disableAuth: true,
|
|
48
59
|
handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),
|
|
49
60
|
method: 'get',
|
|
50
61
|
path: '/mcp',
|
|
51
62
|
},
|
|
63
|
+
{
|
|
64
|
+
disableAuth: true,
|
|
65
|
+
handler: oauthProtectedResourceEndpoint,
|
|
66
|
+
method: 'get',
|
|
67
|
+
path: '/mcp/oauth-protected-resource',
|
|
68
|
+
},
|
|
52
69
|
],
|
|
53
70
|
}
|
|
54
71
|
},
|