Payload MCP
Auto-generates MCP tools from Payload CMS 3.0 TypeScript type definitions, providing an HTTP endpoint for LLMs to generate Payload code.
README
Payload MCP
A Model Context Protocol (MCP) server for Payload CMS 3.0 that auto-generates tools from Payload's TypeScript type definitions.
Features
- Auto-generates MCP tools from Payload CMS 3.0 TypeScript definitions
- Provides an HTTP endpoint for LLMs to generate up-to-date Payload code
- Bridges the gap between LLM training cutoff and current Payload CMS API
- Supports all major Payload CMS features:
- Collections
- Globals
- Fields
- Authentication
- Configuration
How It Works
- Parse Type Definitions: Uses ts-morph to analyze Payload's .d.ts files
- Generate Tools: Converts types into MCP tools with parameters and code-gen logic
- Serve Endpoint: Provides an /api/v1/payload-mcp endpoint for LLMs to query
- Generate Code: Returns properly formatted Payload CMS 3.0 code
Getting Started
Prerequisites
- Node.js (v18 or higher)
- pnpm (v8 or higher)
Installation
# Clone the repository
git clone https://github.com/yourusername/payload-mcp.git
cd payload-mcp
# Install dependencies
pnpm install
# Generate tools from Payload CMS type definitions
pnpm generate-tools
# Start the development server
pnpm dev
Usage
The MCP server exposes an endpoint at /api/v1/payload-mcp that accepts POST requests with the following structure:
{
"model": "claude-3-opus-20240229",
"tools": [
{
"name": "createCollection",
"parameters": {
"slug": "posts",
"fields": [
{
"name": "title",
"type": "text",
"required": true
}
],
"admin": {
"useAsTitle": "title"
}
}
}
]
}
The server will respond with generated Payload CMS 3.0 code:
{
"id": "uuid",
"context": [
{
"id": "uuid",
"data": {
"code": "import { CollectionConfig } from 'payload/types';\n\nexport const postsCollection: CollectionConfig = {\n slug: 'posts',\n fields: [\n {\n \"name\": \"title\",\n \"type\": \"text\",\n \"required\": true\n }\n],\n // Add other properties as needed from params\n ...{\n \"admin\": {\n \"useAsTitle\": \"title\"\n }\n}\n};\n",
"message": "Collection 'posts' created successfully"
}
}
],
"tool_results": [
{
"tool_name": "createCollection",
"output": {
"code": "import { CollectionConfig } from 'payload/types';\n\nexport const postsCollection: CollectionConfig = {\n slug: 'posts',\n fields: [\n {\n \"name\": \"title\",\n \"type\": \"text\",\n \"required\": true\n }\n],\n // Add other properties as needed from params\n ...{\n \"admin\": {\n \"useAsTitle\": \"title\"\n }\n}\n};\n",
"message": "Collection 'posts' created successfully"
}
}
]
}
Available Tools
The following tools are auto-generated from Payload CMS 3.0 type definitions:
- createCollection: Creates a collection configuration
- createGlobal: Creates a global configuration
- createField: Creates a field configuration
- createAuth: Creates authentication configuration
- createConfig: Creates the main Payload CMS configuration
Development
Regenerating Tools
If you update Payload CMS or want to regenerate the tools:
# Update Payload
pnpm add payload@latest
# Regenerate tools
pnpm generate-tools
Logging
The server uses Winston for logging. By default, logs are written to the logs directory with the following files:
combined.log: All logs (info level and above)error.log: Error logs onlyexceptions.log: Uncaught exceptionsrejections.log: Unhandled promise rejections
The server uses npm logging levels (from highest to lowest priority):
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6
By default, the log level is set to info, which means only logs with level info, warn, and error will be recorded. To see more detailed logs:
- Set to
verboseto see tool registration details - Set to
debugfor even more detailed debugging information - Set to
sillyfor the most verbose output
You can change the log level by setting the LOG_LEVEL environment variable:
# Run with verbose logging (shows tool registration)
LOG_LEVEL=verbose pnpm start
# Run with debug logging (more detailed)
LOG_LEVEL=debug pnpm start
# Or set in .env file
# LOG_LEVEL=verbose
Testing
To test the auto-generated tools:
# Start the server
pnpm dev
# In another terminal, run the test script
node test-generated-tools.mjs
License
ISC
Sponsor
Govcraft is a one-person shop—no corporate backing, no investors, just me building useful tools. If this project helps you, sponsoring keeps the work going.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。