Skip to content

Commit 042d7eb

Browse files
fix(plugin-mcp): adds collection and strategy to user (#14981)
Fixes: #14923 Correctly adds `collectionSlug` and `_strategy` to the `user` when using MCP operations.
1 parent 519a3c6 commit 042d7eb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • packages/plugin-mcp/src/endpoints

packages/plugin-mcp/src/endpoints/mcp.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from 'crypto'
2-
import { type PayloadHandler, UnauthorizedError, type Where } from 'payload'
2+
import { type PayloadHandler, type TypedUser, UnauthorizedError, type Where } from 'payload'
33

44
import type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'
55

@@ -57,6 +57,14 @@ export const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {
5757
payload.logger.info('[payload-mcp] API Key is valid')
5858
}
5959

60+
const user = docs[0]?.user as TypedUser
61+
const customUserCollection =
62+
typeof pluginOptions.userCollection === 'string'
63+
? pluginOptions.userCollection
64+
: pluginOptions.userCollection?.slug
65+
user.collection = customUserCollection ?? 'users'
66+
user._strategy = 'mcp-api-key' as const
67+
6068
return docs[0] as unknown as MCPAccessSettings
6169
}
6270

0 commit comments

Comments
 (0)