-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Labels
Description
Describe the Bug
The @payloadcms/plugin-mcp crashes when defaultDepth: 0 is configured in Payload, making it impossible to use the MCP plugin with this common performance optimization setting.
Root Cause
In packages/plugin-mcp/src/endpoints/mcp.ts (lines 45-50), the plugin queries the payload-mcp-api-keys collection without specifying a depth parameter:
const { docs } = await payload.find({
collection: 'payload-mcp-api-keys',
// No depth specified - uses global defaultDepth
limit: 1,
pagination: false,
where,
})When defaultDepth: 0, the user field returns as a string ID instead of the populated user object. The code then attempts to set properties on this string primitive (line 65):
const user = docs[0]?.user as TypedUser // This is a string when depth:0
user.collection = customUserCollection ?? 'users' // TypeError!
user._strategy = 'mcp-api-key' as constExpected Behavior
The MCP plugin should work correctly regardless of the defaultDepth setting. The plugin should either:
- Override the depth for its internal queries, or
- Handle the case when relationships are not populated
Link to the code that reproduces this issue
https://github.com/jonathanelmgren/payload-repro
Reproduction Steps
- Install Payload 3.69.0 with
@payloadcms/plugin-mcp - Configure
defaultDepth: 0in payload.config.ts:
export default buildConfig({
defaultDepth: 0, // This triggers the bug
plugins: [
mcpPlugin({
collections: {
posts: { enabled: true },
},
}),
],
// ... rest of config
})- Create an API key in the admin panel at
/admin/collections/payload-mcp-api-keys - Add your new API key to
.mcp.json - Try to connect via MCP using the API key
- Server crashes with TypeError
Error Message
TypeError: Cannot create property 'collection' on string '69495e5d1c30e1099b58e9df'
at getDefaultMcpAccessSettings (packages/plugin-mcp/src/endpoints/mcp.ts:65)
Which area(s) are affected?
plugin: mcp
Environment Info
Binaries:
Node: 24.2.0
npm: 11.3.0
Yarn: 1.22.19
pnpm: 10.18.3
Relevant Packages:
payload: 3.69.0
next: 15.4.10
@payloadcms/db-mongodb: 3.69.0
@payloadcms/graphql: 3.69.0
@payloadcms/next/utilities: 3.69.0
@payloadcms/plugin-mcp: 3.69.0
@payloadcms/richtext-lexical: 3.69.0
@payloadcms/translations: 3.69.0
@payloadcms/ui/shared: 3.69.0
react: 19.2.1
react-dom: 19.2.1
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6020
Available memory (MB): 16384
Available CPU cores: 10