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 data generated by the LLM before it is used in an operation. |
| | A function that allows you to override the response from the operation tool call |
| | Determines whether the LLM can find, create, update, and delete documents in the collection. |
| | Whether to allow the LLM to find documents in the collection. |
| | Whether to allow the LLM to create documents in the collection. |
| | Whether to allow the LLM to update documents in the collection. |
| | Whether to allow the LLM 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 custom 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 custom prompts to add to the MCP server. |
| | The name of the prompt. |
| | The title of the prompt (used by LLMs 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 custom resources to add to the MCP server. |
| | The name of the resource. |
| | The title of the resource (used by LLMs 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'). |
Override API Keys Collection
The plugin automatically creates an API Keys collection that provides high-resolution control over MCP capabilities. This collection allows admins to:
- Create API keys for MCP clients
- Allow or disallow specific MCP capabilities in real-time
- Control which collections can be accessed via MCP
- Enable or disable custom tools
You can customize this collection using the overrideApiKeyCollection option:
Custom Prompts
Prompts allow LLMs to generate structured messages for specific tasks. Each prompt defines a schema for arguments and returns formatted messages:
Custom Resources
Resources provide access to data or content that LLMs can read. They can be static or dynamic with parameterized URIs:
Data Override Example
Use override functions to modify data before it's processed:
Use overrideResponse to modify response data:
Custom Tool with Database Access
Custom 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.
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.