MCP Plugin
This plugin adds Model Context Protocol capabilities.
Core features
- Adds a collection to your config where:
- You can allow / disallow
find,create,update, anddeleteoperations for each collection - You can to allow / disallow capabilities in real time
- You can define your own Prompts, Tools and Resources available over MCP
Installation
Install the plugin using any JavaScript package manager like pnpm, npm, or Yarn:
Basic Usage
In the plugins array of your Payload Config, call the plugin with options:
Options
Option | Type | Description |
|---|---|---|
| | An object of collection slugs to use for MCP capabilities. |
| | An object of collection slugs to use for MCP capabilities. |
| | A description for the collection. |
| | A function that allows you to override the response from the operation tool call |
| | Determines whether the model can find, create, update, and delete documents in the collection. |
| | Whether to allow the model to find documents in the collection. |
| | Whether to allow the model to create documents in the collection. |
| | Whether to allow the model to update documents in the collection. |
| | Whether to allow the model to delete documents in the collection. |
| | Disable the MCP plugin while keeping database schema consistent. |
| | A function that allows you to override the automatically generated API Keys collection. |
| | MCP options that allow you to customize the MCP server. |
| | An array of tools to add to the MCP server. |
| | The name of the tool. |
| | The description of the tool. |
| | The handler function for the tool. |
| | The parameters for the tool (Zod schema). |
| | An array of prompts to add to the MCP server. |
| | The name of the prompt. |
| | The title of the prompt (used by models to determine when to use it). |
| | The description of the prompt. |
| | The handler function for the prompt. |
| | The arguments schema for the prompt (Zod schema). |
| | An array of resources to add to the MCP server. |
| | The name of the resource. |
| | The title of the resource (used by models to determine when to use it). |
| | The description of the resource. |
| | The handler function for the resource. |
| | The URI of the resource (can be a string or ResourceTemplate for dynamic URIs). |
| | The MIME type of the resource. |
| | The handler options for the MCP server. |
| | The base path for the MCP server (default: '/api'). |
| | Whether to log verbose logs to the console (default: false). |
| | The maximum duration for the MCP server requests (default: 60). |
| | The server options for the MCP server. |
| | The server info for the MCP server. |
| | The name of the MCP server (default: 'Payload MCP Server'). |
| | The version of the MCP server (default: '1.0.0'). |
Connecting to MCP Clients
After installing and configuring the plugin, you can connect apps with MCP client capabilities to Payload.
Step 1: Create an API Key
- Start your Payload server
- Navigate to your admin panel at
http://localhost:3000/admin - Go to the MCP → API Keys collection
- Click Create New
- Allow or Disallow MCP traffic permissions for each collection (enable find, create, update, delete as needed)
- Click Create and copy the uniquely generated API key
Step 2: Configure Your MCP Client
MCP Clients can be configured to interact with your MCP server. These clients require some JSON configuration, or platform configuration in order to know how to reach your MCP server.
Our recommended approach to make your server available for most MCP clients is to use the mcp-remote package via npx.
Below are configuration examples for popular MCP clients.
VSCode
Cursor
Other MCP Clients
For connections without using mcp-remote you can use this configuration format:
Customizations
The plugin supports fully custom prompts, tools and resources that can be called or retrieved by MCP clients. After defining a custom method you can allow / disallow the feature from the admin panel by adjusting the API Key MCP Options checklist.
Prompts
Prompts allow models to generate structured messages for specific tasks. Each prompt defines a schema for arguments and returns formatted messages:
Resources
Resources provide access to data or content that models can read. They can be static or dynamic with parameterized URIs:
Tools
Tools allow you to extend MCP capabilities beyond basic CRUD operations. Use them when you need to perform complex queries, aggregations, or business logic that isn't covered by the standard collection operations.
API Key access to MCP
Payload adds an API key collection that allows admins to manage MCP capabilities. Admins can:
- Create user associated API keys for MCP clients
Allowordisallowendpoint traffic in real-timeAllowordisallowtools, resources, and prompts
You can customize the API Key collection using the overrideApiKeyCollection option:
You can create an MCP access strategy using the overrideAuth option:
If you want the default MCPAccessSettings, you can use the addtional argument getDefaultMcpAccessSettings. This will use the Bearer token found in the headers on the req to return the MCPAccessSettings related to the user assigned to the API key.
Hooks
To understand or modify data returned by models at runtime use a collection Hook. Within a hook you can look up the API context. If the context is MCP that collection was triggered by the MCP Plugin. This does not apply to custom tools or resources that have their own context, and can make unrelated database calls.
In this example, Post titles are modified to include '(MCP Hook Override)' when they are read using MCP.
Performance
The description you choose to use for your collection greatly impacts the way a model will decide to use it.
The description in this example is more difficult for a model to understand it's purpose.
The description in this example gives a model a stronger ability to know when to use this collection.