payload-mcp
Skill0 starsChanged 13 days agoMITView on GitHub
Optional Payload CMS 3 MCP plugin for editor AI clients. Least-privilege API keys, drafts-only writes, no access to users, leads, bookings, or payments, an env switch that removes the endpoint, and client setup for Cursor, Claude, and VS Code. Use when connecting an AI client to the CMS, or when deciding whether AI write access should be enabled.
- Reads credentials
- Installs packages
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-guardrailsSkill
- creative-frontendSkill
- figma-handoffSkill
- payload-admin-brandingSkill
- payload-auth-rbacSkill
- payload-bookings-paymentsSkill
- payload-bootstrapSkill
- payload-deploy-vercelSkill
- payload-forms-crmSkill
- payload-integrationsSkill
- payload-legal-trustSkill
- payload-live-previewSkill
- payload-localizationSkill
- payload-mediaSkill
- payload-performanceSkill
- payload-project-kickoffSkill
- payload-seo-geoSkill
- payload-testingSkill
- project-architectureSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Do not enable it when:
- Very specific: line 25
Stop before installing the plugin.
- Very specific: line 56
Never put users, leads, bookings, payment-events, form-submissions, or payload-mcp-api-keys in collections or globals.
- Very specific: line 73
Do not attach this hook to a collection that has no drafts.
- Very specific: line 92
Leave mcp.handlerOptions.verboseLogs unset.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Payload MCP
Adds POST /api/mcp so an editor's AI client can read and draft content. It is off unless the client agrees, in writing, that an AI may create and edit drafts.
When to enable it
Enable it when an editor will draft pages or posts from Cursor, Claude Code, or VS Code, and a human publishes in the admin.
Do not enable it when:
- The site has no one who will review drafts before they go live.
- The client has not approved AI write access.
- The only goal is a public chatbot. This endpoint is an admin tool.
Stop and ask
Stop before installing the plugin. Ask the client to approve AI write access, which collections drafts may touch, and who may hold a key. Record the answers in PROJECT.md. If they say no, set PAYLOAD_MCP_ENABLED unset and skip the rest.
Step 1: Install and gate the plugin
pnpm add @payloadcms/plugin-mcp@<same version as payload>.
In src/plugins/index.ts:
import { mcpPlugin } from '@payloadcms/plugin-mcp'
mcpPlugin({
disabled: process.env.PAYLOAD_MCP_ENABLED !== 'true',
collections: {
pages: { enabled: { find: true, create: true, update: true, delete: false } },
posts: { enabled: { find: true, create: true, update: true, delete: false } },
'legal-pages': { enabled: { find: true, create: true, update: true, delete: false } },
},
globals: {
header: { enabled: { find: true, update: false } },
footer: { enabled: { find: true, update: false } },
'site-settings': { enabled: { find: true, update: false } },
},
// overrideApiKeyCollection: see the setup reference
}),disabled is a real option. In @payloadcms/plugin-mcp 3.94.0 the API keys collection is still registered, and the /api/mcp routes are not. Toggling the env var does not change the database schema. Do not conditionally omit the plugin; that drops the collection and breaks migrations.
enabled on a collection is the ceiling. Each API key then turns operations off again. Omit delete or set it false. The plugin's create and update tools default draft to false, so a model that forgets the flag would publish. Step 2 closes that.
Never put users, leads, bookings, payment-events, form-submissions, or payload-mcp-api-keys in collections or globals. Media has no drafts; leave it out unless PROJECT.md accepts immediate file creates. Do not set experimental. Those tools can write source files, and the plugin already refuses them outside development.
Full plugin object, including admin access to the keys collection: references/setup.md.
Step 2: Drafts only, and no deletes
On every collection in Step 1 that has versions.drafts, add the beforeOperation hook from the setup reference.
When req.payloadAPI === 'MCP':
createandupdaterun withdraft: trueand_status: 'draft'.deletethrows a 403 even if a later config enables the tool.
In Payload 3.94.0, beforeOperation does not see the internal names updateByID and deleteByID. operationToHookOperation maps both to update and delete before the hook runs (packages/payload/src/collections/operations/utilities/types.ts). Local API update and delete with an id still enter updateByID and deleteByID, then that mapping. The hook also rejects updateByID and deleteByID so a future Payload that stops mapping those names cannot publish or delete through MCP. Handle both spellings. Do not handle only the ByID names.
The plugin sets req.payloadAPI to 'MCP'. Writes still pass through collection hooks, with overrideAccess: false and the key's user. A draft does not revalidate (the payload-performance skill). Publishing stays a human action in the admin.
Do not attach this hook to a collection that has no drafts. draft: true there is an error.
Step 3: Keys
The generated collection slug is payload-mcp-api-keys. The plugin hides it from the admin until overrideApiKeyCollection sets access. Restrict that access with hasRole('admin') from the payload-auth-rbac skill.
- An admin creates one key per client (one for Cursor, another for Claude). Do not share a key between people.
- On that key, allow find, create, and update only for the collections in Step 1. Leave delete off. Leave every custom tool off.
- The key acts as its owner. Owners are admins, so collection access still allows the write, and Step 2 keeps it a draft.
- Copy the key into the AI client's local config. It does not go in the website repo,
.envof the site, or a screenshot.
Requests without Authorization: Bearer <key> are rejected. Production serverURL is https (the payload-auth-rbac skill). Clients must use that https origin. An http:// production URL would send the bearer token in clear text. http://127.0.0.1:3000 is fine for local development.
Step 4: Time limit
mcp.handlerOptions.maxDuration defaults to 60 seconds inside the MCP handler. That is the right value. Vercel Hobby functions top out at 300 seconds with fluid compute (verify at https://vercel.com/docs/functions/configuring-functions/duration). Do not raise the handler above the plan maximum.
The Next.js limit is the Payload catch-all route, not a route the plugin creates. If that route sets export const maxDuration, keep it at 60 so a stuck MCP call cannot occupy a function for the full Hobby window. maxDuration is a number of seconds on the route module.
Leave mcp.handlerOptions.verboseLogs unset. When true, the plugin logs the document JSON.
Step 5: Clients
Client snippets from the plugin docs, and the rule for checking them again, are in references/clients.md. The endpoint is POST /api/mcp. GET returns "Method not allowed" even with a valid key.
Tool names come from tools/list. For a slug posts the read tool is findPosts. Do not guess names for slugs that contain a hyphen; read the list.
Custom tools, prompts, and resources exist on mcp.tools, mcp.prompts, and mcp.resources. Add one only when PROJECT.md names the task. A tool handler receives (args, req). Pass req, and pass overrideAccess: false plus user: req.user on every Local API call. Do not add a tool that deletes, sends mail, or reads leads.
Environment variables
PAYLOAD_MCP_ENABLED=true registers the endpoint. Any other value, including empty, leaves the keys collection in place and does not register /api/mcp. Restart pnpm dev or redeploy after changing it.
Diagnosis
| Symptom | Cause | Fix |
404 on /api/mcp | PAYLOAD_MCP_ENABLED is not true, or the server was not restarted | Step 1 |
| Tools list is empty | The key allows nothing, or enabled omitted the collection | Steps 1 and 3 |
| A create is published | The draft hook is missing, or the collection has no versions.drafts | Step 2 |
| Admin cannot open API keys | overrideApiKeyCollection was not set | Setup reference |
| Client connects on localhost and fails in production | Production URL is http, or the key was created against another database | Step 3 |
Done when
tools/listwith a restricted key returns find, create, and update for the allowed collections, and no delete tool, no users, and no leads- A create through MCP has
_statusdraftand does not show on the public page - A delete call is refused (tool missing, or 403 from the hook)
- Setting
PAYLOAD_MCP_ENABLEDto empty and restarting makesPOST /api/mcp404 - The key is not in the website repository
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

