API Reference
Table of Contents
- Plugin Configuration
- Collection Configuration
- Global Configuration
- MCP Tools
- Authentication
- API Endpoints
- Media Upload
- Rich Text Processing
- Error Handling
Plugin Configuration
PayloadPluginMcp
The main plugin function that returns a PayloadCMS plugin configuration.
1PayloadPluginMcp(options: McpPluginOptions): PayloadPlugin
typescript
2 lines
Parameters
options(McpPluginOptions): Configuration options for the MCP plugin
McpPluginOptions
1interface McpPluginOptions {2apiKey: string3collections?: string[] | 'all'4defaultOperations?: {5list?: boolean6get?: boolean7create?: boolean8update?: boolean9delete?: boolean10}11server?: {12port?: number13host?: string14}15auth?: {16enabled?: boolean17apiKey?: string18}19tools?: {20enabled?: boolean21customTools?: McpTool[]22}23media?: {24uploadEnabled?: boolean25maxFileSize?: number26allowedTypes?: string[]27}28richtext?: {29enabled?: boolean30processors?: RichtextProcessor[]31}32}
typescript
33 lines
Properties
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | - | API key for MCP server authentication |
collections | string[] | 'all' | No | 'all' | Collections to expose via MCP |
defaultOperations | object | No | { list: true, get: true, create: false, update: false, delete: false } | Default operations for collections |
server | object | No | { port: 3001, host: '0.0.0.0' } | MCP server configuration |
auth | object | No | { enabled: true } | Authentication configuration |
tools | object | No | { enabled: true } | MCP tools configuration |
media | object | No | { uploadEnabled: true, maxFileSize: 10485760 } | Media upload configuration |
richtext | object | No | { enabled: true } | Rich text processing configuration |
Collection Configuration
Collection-Specific Options
You can configure individual collections with specific options:
1collections: [2{3name: 'posts',4mcp: {5operations: {6list: true,7get: true,8create: true,9update: true,10delete: false,11},12fields: ['title', 'content', 'author'],13filters: {14published: true,15},16},17},18]
typescript
19 lines
Collection MCP Options
1interface CollectionMcpOptions {2operations?: {3list?: boolean4get?: boolean5create?: boolean6update?: boolean7delete?: boolean8}9fields?: string[]10filters?: Record<string, any>11relations?: {12populate?: boolean13depth?: number14}15}
typescript
16 lines
Global Configuration
Environment Variables
| Variable | Type | Required | Default | Description |
|---|---|---|---|---|
MCP_API_KEY | string | Yes | - | API key for MCP server authentication |
MCP_AUTH_ENABLED | boolean | No | true | Enable authentication |
MCP_MEDIA_UPLOAD_ENABLED | boolean | No | true | Enable media upload |
MCP_MEDIA_MAX_FILE_SIZE | number | No | 10485760 | Max file size in bytes |
MCP Tools
The plugin automatically generates MCP tools for each collection based on the configured operations.
Generated Tools
For each collection, the following tools are generated:
{collection}_list- List documents in a collection{collection}_get- Get a single document by ID{collection}_create- Create a new document (if enabled){collection}_update- Update an existing document (if enabled){collection}_delete- Delete a document (if enabled)
Tool Schemas
Each tool includes a comprehensive schema with:
- Input parameters
- Output format
- Error handling
- Validation rules
Authentication
API Key Authentication
The plugin uses API key authentication by default. Include the API key in the Authorization header:
1Authorization: Bearer your-api-key-here
bash
2 lines
Disabling Authentication
To disable authentication (not recommended for production):
1PayloadPluginMcp({2apiKey: process.env.MCP_API_KEY,3auth: {4enabled: false,5},6})
typescript
7 lines
API Endpoints
MCP Server Endpoint
The MCP server is available at:
1http://localhost:3000/api/plugin/mcp
text
2 lines
Available Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /api/plugin/mcp | Get server information and available tools |
POST | /api/plugin/mcp | Execute MCP tools |
Media Upload
Configuration
1PayloadPluginMcp({2apiKey: process.env.MCP_API_KEY,3media: {4uploadEnabled: true,5maxFileSize: 10485760, // 10MB6allowedTypes: ['image/jpeg', 'image/png', 'image/gif'],7},8})
typescript
9 lines
Upload Process
- Client sends file to MCP server
- Server validates file size and type
- File is processed and stored
- File ID is returned for use in collections
Rich Text Processing
Configuration
1PayloadPluginMcp({2apiKey: process.env.MCP_API_KEY,3richtext: {4enabled: true,5processors: ['markdown', 'html'],6},7})
typescript
8 lines
Supported Processors
- Markdown to HTML
- HTML sanitization
- Link processing
- Image optimization
Error Handling
Error Types
| Error Type | Description | HTTP Status |
|---|---|---|
AuthenticationError | Invalid or missing API key | 401 |
ValidationError | Invalid input parameters | 400 |
NotFoundError | Resource not found | 404 |
PermissionError | Insufficient permissions | 403 |
ServerError | Internal server error | 500 |
Error Response Format
1{2"error": {3"type": "ValidationError",4"message": "Invalid input parameters",5"details": {6"field": "title",7"reason": "required"8}9}10}
json
11 lines
Error Handling in Tools
All MCP tools include comprehensive error handling with:
- Input validation
- Permission checks
- Graceful error responses
- Detailed error messages