@payloadcms/plugin-mcp 4.0.0-internal.ea6e8f8 → 4.0.0-internal.ee5d8bd

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.
Files changed (64) hide show
  1. package/dist/endpoint/access.d.ts.map +1 -1
  2. package/dist/endpoint/access.js +15 -3
  3. package/dist/endpoint/access.js.map +1 -1
  4. package/dist/endpoint/index.d.ts.map +1 -1
  5. package/dist/endpoint/index.js +13 -0
  6. package/dist/endpoint/index.js.map +1 -1
  7. package/dist/endpoint/oauth.d.ts +39 -0
  8. package/dist/endpoint/oauth.d.ts.map +1 -0
  9. package/dist/endpoint/oauth.js +94 -0
  10. package/dist/endpoint/oauth.js.map +1 -0
  11. package/dist/endpoint/oauthLoginToken.d.ts +15 -0
  12. package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
  13. package/dist/endpoint/oauthLoginToken.js +45 -0
  14. package/dist/endpoint/oauthLoginToken.js.map +1 -0
  15. package/dist/endpoint/oauthServer.d.ts +12 -0
  16. package/dist/endpoint/oauthServer.d.ts.map +1 -0
  17. package/dist/endpoint/oauthServer.js +386 -0
  18. package/dist/endpoint/oauthServer.js.map +1 -0
  19. package/dist/index.d.ts +10 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +15 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp/buildMcpServer.js +1 -1
  24. package/dist/mcp/buildMcpServer.js.map +1 -1
  25. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  26. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  27. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  28. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  29. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  30. package/dist/mcp/builtin/collections/findTool.js +1 -1
  31. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  32. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  33. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  34. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
  35. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  36. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  37. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  38. package/dist/mcp/sanitizeMCPConfig.js +3 -0
  39. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  40. package/dist/types.d.ts +81 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/types.js.map +1 -1
  43. package/dist/utils/toStandardSchema.js.map +1 -1
  44. package/package.json +20 -23
  45. package/src/endpoint/access.ts +12 -3
  46. package/src/endpoint/index.ts +8 -0
  47. package/src/endpoint/oauth.ts +92 -0
  48. package/src/endpoint/oauthLoginToken.ts +59 -0
  49. package/src/endpoint/oauthServer.ts +440 -0
  50. package/src/index.ts +40 -5
  51. package/src/mcp/buildMcpServer.ts +2 -2
  52. package/src/mcp/builtin/collections/authTools.ts +2 -2
  53. package/src/mcp/builtin/collections/createTool.ts +1 -3
  54. package/src/mcp/builtin/collections/deleteTool.ts +1 -1
  55. package/src/mcp/builtin/collections/duplicateTool.ts +1 -1
  56. package/src/mcp/builtin/collections/findTool.ts +1 -1
  57. package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -1
  58. package/src/mcp/builtin/collections/updateTool.ts +1 -1
  59. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +1 -1
  60. package/src/mcp/builtin/globals/findTool.ts +1 -1
  61. package/src/mcp/builtin/globals/updateTool.ts +1 -1
  62. package/src/mcp/sanitizeMCPConfig.ts +1 -0
  63. package/src/types.ts +82 -0
  64. package/src/utils/toStandardSchema.ts +1 -1
package/dist/types.d.ts CHANGED
@@ -233,6 +233,14 @@ export type MCPPluginConfig = {
233
233
  serverOptions?: MCPServerOptions;
234
234
  verboseLogs?: boolean;
235
235
  };
236
+ /**
237
+ * How MCP clients sign in. MCP requests without an authenticated user get a `401` that points
238
+ * to the protected resource metadata (RFC 9728). Set to `false` to only accept API keys and
239
+ * anonymous requests.
240
+ *
241
+ * @default { type: 'builtin' }
242
+ */
243
+ oauth?: false | MCPOAuthConfig;
236
244
  /**
237
245
  * Replace the default MCP authorization resolver.
238
246
  *
@@ -247,8 +255,81 @@ export type MCPPluginConfig = {
247
255
  /** Cross-cutting tools (not scoped to any collection or global). */
248
256
  tools?: MCPTopLevelToolsMap;
249
257
  };
258
+ export type MCPOAuthConfig = MCPBuiltinOAuthConfig | MCPExternalOAuthConfig;
259
+ /**
260
+ * This Payload app is the authorization server. Users sign in to the admin panel and allow the
261
+ * MCP client, which then gets an access token for them.
262
+ */
263
+ export type MCPBuiltinOAuthConfig = {
264
+ /**
265
+ * Creates the tokens the MCP client gets when the user clicks Allow. `req` is the user's own
266
+ * browser request, so `req.user` is the user who allowed it. Pass `authenticate` too if
267
+ * Payload's auth strategies don't accept the access token.
268
+ *
269
+ * @default a Payload login token for that user, with a refresh token when the collection uses sessions
270
+ */
271
+ issueToken?: (args: {
272
+ req: PayloadRequest;
273
+ }) => MaybePromise<MCPOAuthTokens>;
274
+ /**
275
+ * Trades a refresh token from `issueToken`, or from an earlier refresh, for new tokens. Return
276
+ * `null` when it's no longer valid, and the client sends the user through sign-in again. `req`
277
+ * is the MCP client's request, without a user. Only used together with `issueToken`.
278
+ *
279
+ * OAuth requires noticing copied refresh tokens: return a new refresh token every time, and
280
+ * revoke the tokens when an already used refresh token comes back.
281
+ */
282
+ refreshToken?: (args: {
283
+ refreshToken: string;
284
+ req: PayloadRequest;
285
+ }) => MaybePromise<MCPOAuthTokens | null>;
286
+ type: 'builtin';
287
+ } & MCPOAuthSharedConfig;
288
+ export type MCPOAuthTokens = {
289
+ accessToken: string;
290
+ /** Seconds until the access token expires. */
291
+ expiresIn?: number;
292
+ /** Lets the client get new tokens without the user, through `refreshToken`. */
293
+ refreshToken?: string;
294
+ };
295
+ /** Another service, e.g. your identity provider, is the authorization server. */
296
+ export type MCPExternalOAuthConfig = {
297
+ /**
298
+ * The authorization servers that issue access tokens for MCP clients. Clients require each one
299
+ * to exactly match the `issuer` in that server's metadata, so pass a function when the exact
300
+ * value is only known at runtime, e.g. from the server's OpenID configuration or per host.
301
+ */
302
+ authorizationServers: ((args: {
303
+ req: PayloadRequest;
304
+ }) => MaybePromise<string[]>) | string[];
305
+ /**
306
+ * Scopes MCP clients should request, e.g. `['openid', 'email', 'profile']`. Without them,
307
+ * clients request none, which some authorization servers reject or answer with a token that
308
+ * doesn't identify the user.
309
+ */
310
+ scopes?: string[];
311
+ type: 'external';
312
+ } & MCPOAuthSharedConfig;
313
+ type MCPOAuthSharedConfig = {
314
+ /**
315
+ * Called on MCP requests with a bearer token that Payload's auth strategies didn't accept.
316
+ * Return the Payload user, including its `collection`, or `null` to answer with the OAuth challenge.
317
+ */
318
+ authenticate?: (args: {
319
+ req: PayloadRequest;
320
+ token: string;
321
+ }) => MaybePromise<PayloadRequest['user']>;
322
+ /**
323
+ * The URL clients call to reach the MCP endpoint.
324
+ *
325
+ * @default the absolute URL of `/api/mcp`, based on `serverURL` or the request URL
326
+ */
327
+ resource?: string;
328
+ };
250
329
  export type SanitizedMCPPluginConfig = {
251
330
  items: MCPItem[];
331
+ /** `undefined` when OAuth is turned off. */
332
+ oauth?: MCPOAuthConfig;
252
333
  } & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>;
253
334
  export type MCPServerOptions = {
254
335
  options?: McpServerOptions;
@@ -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,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EAC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,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 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 * 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?: 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":"AAwWA;;;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 * How MCP clients sign in. MCP requests without an authenticated user get a `401` that points\n * to the protected resource metadata (RFC 9728). Set to `false` to only accept API keys and\n * anonymous requests.\n *\n * @default { type: 'builtin' }\n */\n oauth?: false | MCPOAuthConfig\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 MCPOAuthConfig = MCPBuiltinOAuthConfig | MCPExternalOAuthConfig\n\n/**\n * This Payload app is the authorization server. Users sign in to the admin panel and allow the\n * MCP client, which then gets an access token for them.\n */\nexport type MCPBuiltinOAuthConfig = {\n /**\n * Creates the tokens the MCP client gets when the user clicks Allow. `req` is the user's own\n * browser request, so `req.user` is the user who allowed it. Pass `authenticate` too if\n * Payload's auth strategies don't accept the access token.\n *\n * @default a Payload login token for that user, with a refresh token when the collection uses sessions\n */\n issueToken?: (args: { req: PayloadRequest }) => MaybePromise<MCPOAuthTokens>\n /**\n * Trades a refresh token from `issueToken`, or from an earlier refresh, for new tokens. Return\n * `null` when it's no longer valid, and the client sends the user through sign-in again. `req`\n * is the MCP client's request, without a user. Only used together with `issueToken`.\n *\n * OAuth requires noticing copied refresh tokens: return a new refresh token every time, and\n * revoke the tokens when an already used refresh token comes back.\n */\n refreshToken?: (args: {\n refreshToken: string\n req: PayloadRequest\n }) => MaybePromise<MCPOAuthTokens | null>\n type: 'builtin'\n} & MCPOAuthSharedConfig\n\nexport type MCPOAuthTokens = {\n accessToken: string\n /** Seconds until the access token expires. */\n expiresIn?: number\n /** Lets the client get new tokens without the user, through `refreshToken`. */\n refreshToken?: string\n}\n\n/** Another service, e.g. your identity provider, is the authorization server. */\nexport type MCPExternalOAuthConfig = {\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 * 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 type: 'external'\n} & MCPOAuthSharedConfig\n\ntype MCPOAuthSharedConfig = {\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 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\nexport type SanitizedMCPPluginConfig = {\n items: MCPItem[]\n /** `undefined` when OAuth is turned off. */\n oauth?: MCPOAuthConfig\n} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | '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":"AA0bA;;;CAGC,GACD,WAGC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/toStandardSchema.ts"],"sourcesContent":["import { fromJsonSchema, type StandardSchemaWithJSON } from '@modelcontextprotocol/server'\n\nimport type { ToolInputSchema } from '../types.js'\n\n/** Normalize a tool/prompt input to a Standard Schema. Raw JSON Schema gets wrapped; Standard Schema instances pass through. */\nexport const toStandardSchema = (schema: ToolInputSchema): StandardSchemaWithJSON =>\n typeof schema === 'object' && schema !== null && '~standard' in schema\n ? (schema as StandardSchemaWithJSON)\n : fromJsonSchema(schema)\n"],"names":["fromJsonSchema","toStandardSchema","schema"],"mappings":"AAAA,SAASA,cAAc,QAAqC,+BAA8B;AAI1F,8HAA8H,GAC9H,OAAO,MAAMC,mBAAmB,CAACC,SAC/B,OAAOA,WAAW,YAAYA,WAAW,QAAQ,eAAeA,SAC3DA,SACDF,eAAeE,QAAO"}
1
+ {"version":3,"sources":["../../src/utils/toStandardSchema.ts"],"sourcesContent":["import { fromJsonSchema, type StandardSchemaWithJSON } from '@modelcontextprotocol/server'\n\nimport type { ToolInputSchema } from '../types.js'\n\n/** Normalize a tool/prompt input to a Standard Schema. Raw JSON Schema gets wrapped; Standard Schema instances pass through. */\nexport const toStandardSchema = (schema: ToolInputSchema): StandardSchemaWithJSON =>\n typeof schema === 'object' && schema !== null && '~standard' in schema\n ? schema\n : fromJsonSchema(schema)\n"],"names":["fromJsonSchema","toStandardSchema","schema"],"mappings":"AAAA,SAASA,cAAc,QAAqC,+BAA8B;AAI1F,8HAA8H,GAC9H,OAAO,MAAMC,mBAAmB,CAACC,SAC/B,OAAOA,WAAW,YAAYA,WAAW,QAAQ,eAAeA,SAC5DA,SACAF,eAAeE,QAAO"}
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-mcp",
3
- "version": "4.0.0-internal.ea6e8f8",
3
+ "version": "4.0.0-internal.ee5d8bd",
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,26 +54,15 @@
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
58
  "@modelcontextprotocol/server": "2.3.1",
59
59
  "tsx": "4.23.15"
60
60
  },
61
61
  "devDependencies": {
62
- "@payloadcms/eslint-config": "3.28.0",
63
- "payload": "4.0.0-internal.ea6e8f8"
62
+ "payload": "4.0.0-internal.ee5d8bd"
64
63
  },
65
64
  "peerDependencies": {
66
- "payload": "4.0.0-internal.ea6e8f8"
65
+ "payload": "4.0.0-internal.ee5d8bd"
67
66
  },
68
67
  "//deps_notes": {
69
68
  "tsx": "Required by the `bin.js` stdio mcp. Keep the version pinned to whatever `payload` ships to avoid duplicate installs."
@@ -76,8 +75,6 @@
76
75
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
77
76
  "clean": "rimraf {dist,*.tsbuildinfo}",
78
77
  "copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
79
- "lint": "eslint .",
80
- "lint:fix": "eslint . --fix",
81
78
  "pack:plugin": "pnpm build && pnpm pack"
82
79
  }
83
80
  }
@@ -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
- req.user = (await req.payload.auth({ headers, req })).user
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
- if (hasAuthorization && !req.user) {
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
  }
@@ -11,6 +11,7 @@ import { APIError } from 'payload'
11
11
  import { buildMcpServer } from '../mcp/buildMcpServer.js'
12
12
  import { getPluginConfig } from '../utils/getPluginConfig.js'
13
13
  import { getAuthorizedMCP } from './access.js'
14
+ import { getMCPResource, oauthChallenge } from './oauth.js'
14
15
 
15
16
  export const mcpEndpoint: PayloadHandler = async (req) => {
16
17
  if (!req.url) {
@@ -18,6 +19,8 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
18
19
  }
19
20
 
20
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 }) }
21
24
 
22
25
  const pluginConfig = getPluginConfig({ config: req.payload.config })
23
26
  const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
@@ -34,6 +37,11 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
34
37
  }
35
38
 
36
39
  const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
40
+
41
+ if (pluginConfig.oauth && !req.user) {
42
+ return oauthChallenge({ req })
43
+ }
44
+
37
45
  const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
38
46
  // Payload augments the original web-standard Request in place.
39
47
  const mcpRequest = req as PayloadRequest & Request
@@ -0,0 +1,92 @@
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 { oauth } = getPluginConfig({ config: req.payload.config })
44
+ const response = bearerAuthChallengeResponse(
45
+ new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),
46
+ {
47
+ requiredScopes: oauth?.type === 'external' ? oauth.scopes : undefined,
48
+ resourceMetadataUrl: `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth-protected-resource`,
49
+ },
50
+ )
51
+
52
+ // Lets browser-based MCP clients read the challenge, when Payload's `cors` setting allows them
53
+ response.headers.set('Access-Control-Expose-Headers', 'WWW-Authenticate')
54
+
55
+ return response
56
+ }
57
+
58
+ /**
59
+ * The MCP endpoint's address, as advertised in the metadata's `resource`. Clients send it when
60
+ * they sign in, and authorization servers that support it put it in the access token's audience.
61
+ */
62
+ export const getMCPResource = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
63
+ getPluginConfig({ config }).oauth?.resource ?? getMCPURL({ config, url })
64
+
65
+ export const getMCPURL = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
66
+ new URL(`${config.routes.api}/mcp`, config.serverURL || url).href
67
+
68
+ const getMetadataResponse = async ({ req }: { req: PayloadRequest }): Promise<Response> => {
69
+ const { config } = req.payload
70
+ const { oauth } = getPluginConfig({ config })
71
+
72
+ if (!oauth) {
73
+ return new Response(null, { status: 404 })
74
+ }
75
+
76
+ return Response.json(
77
+ {
78
+ authorization_servers:
79
+ oauth.type === 'builtin'
80
+ ? [`${getMCPURL({ config, url: req.url! })}/oauth`]
81
+ : typeof oauth.authorizationServers === 'function'
82
+ ? await oauth.authorizationServers({ req })
83
+ : oauth.authorizationServers,
84
+ bearer_methods_supported: ['header'],
85
+ resource: getMCPResource({ config, url: req.url! }),
86
+ scopes_supported: oauth.type === 'external' ? oauth.scopes : undefined,
87
+ } satisfies OAuthProtectedResourceMetadata,
88
+ // Public document, readable by browser-based MCP clients on any origin. Not cached, since
89
+ // without `serverURL` its URLs come from the request.
90
+ { headers: { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-store' } },
91
+ )
92
+ }
@@ -0,0 +1,59 @@
1
+ import type { PayloadRequest } from 'payload'
2
+
3
+ import { APIError, createAuthToken, refreshAuthToken } from 'payload'
4
+
5
+ import type { MCPOAuthTokens } from '../types.js'
6
+
7
+ /**
8
+ * The default `issueToken`: a Payload login token, which Payload's JWT strategy accepts. When the
9
+ * collection uses sessions, the client also gets a refresh token for the token's session.
10
+ */
11
+ export const issueLoginToken = async ({
12
+ req,
13
+ }: {
14
+ req: PayloadRequest
15
+ }): Promise<MCPOAuthTokens> => {
16
+ const collectionConfig = req.payload.collections[req.user!.collection]!.config
17
+
18
+ if (collectionConfig.auth.disableLocalStrategy) {
19
+ throw new APIError(
20
+ `MCP clients can't get Payload login tokens for the "${collectionConfig.slug}" collection because its local strategy is disabled. Pass oauth.issueToken to the MCP plugin.`,
21
+ )
22
+ }
23
+
24
+ // The full document, like the one a password login starts its session on
25
+ const user = (await req.payload.db.findOne<NonNullable<PayloadRequest['user']>>({
26
+ collection: collectionConfig.slug,
27
+ req,
28
+ where: { id: { equals: req.user!.id } },
29
+ }))!
30
+
31
+ const { refreshToken, token } = await createAuthToken({
32
+ collectionConfig,
33
+ email: user.email!,
34
+ req,
35
+ shouldCreateRefreshToken: true,
36
+ user,
37
+ })
38
+
39
+ return { accessToken: token, expiresIn: collectionConfig.auth.tokenExpiration, refreshToken }
40
+ }
41
+
42
+ /** The default `refreshToken`. Payload logs out the session when a refresh token is reused. */
43
+ export const refreshLoginToken = async ({
44
+ refreshToken,
45
+ req,
46
+ }: {
47
+ refreshToken: string
48
+ req: PayloadRequest
49
+ }): Promise<MCPOAuthTokens | null> => {
50
+ const refreshed = await refreshAuthToken({ refreshToken, req })
51
+
52
+ return (
53
+ refreshed && {
54
+ accessToken: refreshed.token,
55
+ expiresIn: refreshed.collectionConfig.auth.tokenExpiration,
56
+ refreshToken: refreshed.refreshToken,
57
+ }
58
+ )
59
+ }