Payload模型配置管理平台

@Matmax-Worldwide/payloadcmsmcp
0 Stars 23 次浏览 Matmax-Worldwide 更新于 2026-08-23

通过自然语言命令启用对 Payload CMS 项目的管理,允许开发人员使用对话式人工智能创建、配置和部署内容模型。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

🚀 Payload CMS 3.0 MCP 服务器

📋 概览

Payload CMS 3.0 MCP 服务器是一个专门设计的模型上下文协议服务器,旨在增强您的 Payload CMS 开发体验。它通过提供代码验证、模板生成和项目脚手架功能来帮助开发人员构建更好的 Payload CMS 应用程序,这些功能均遵循最佳实践。

✨ 功能

🔧 Payload CMS 3.0 功能

验证工具

  • validate - 验证集合、字段、全局变量和配置文件的代码
  • query - 查询验证规则和最佳实践
  • mcp_query - 执行类似 SQL 的查询以处理 Payload CMS 结构

代码生成

  • generate_template - 为各种组件生成代码模板
  • generate_collection - 创建完整的集合定义
  • generate_field - 生成带有正确类型的字段定义

项目设置

  • scaffold_project - 创建整个 Payload CMS 项目结构
  • validate_scaffold_options - 确保脚手架选项遵循最佳实践(由 scaffold_project 内部使用)

📝 详细工具参考

验证工具

validate

验证 Payload CMS 代码的语法和最佳实践。

参数:

  • code (字符串): 要验证的代码
  • fileType (枚举): 文件类型 - "collection", "field", "global", 或 "config"

示例提示:

Can you validate this Payload CMS collection code?

```typescript
export const Posts = {
  slug: 'posts',
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    {
      name: 'content',
      type: 'richText',
    }
  ],
  admin: {
    useAsTitle: 'title',
  }
}

query

查询 Payload CMS 的验证规则和最佳实践。

参数:

  • query (字符串): 查询字符串
  • fileType (可选枚举): 文件类型 - "collection", "field", "global", 或 "config"

示例提示:

What are the best practices for implementing access control in Payload CMS collections?

mcp_query

对 Payload CMS 结构执行类似 SQL 的查询。

参数:

  • sql (字符串): 类似 SQL 的查询字符串

示例提示:

Can you execute this query to find all valid field types in Payload CMS?
SELECT field_types FROM payload_schema WHERE version = '3.0'

代码生成

generate_template

为各种 Payload CMS 组件生成代码模板。

参数:

  • templateType (枚举): 模板类型 - "collection", "field", "global", "config", "access-control", "hook", "endpoint", "plugin", "block", "migration"
  • options (记录): 模板配置选项

示例提示:

Generate a template for a Payload CMS hook that logs when a document is created.

generate_collection

生成完整的 Payload CMS 集合定义。

参数:

  • slug (字符串): 集合 slug
  • fields (可选数组): 字段对象数组
  • auth (可选布尔值): 是否是认证集合
  • timestamps (可选布尔值): 是否包含时间戳
  • admin (可选对象): 管理面板配置
  • hooks (可选布尔值): 是否包含钩子
  • access (可选布尔值): 是否包含访问控制
  • versions (可选布尔值): 是否启用版本控制

示例提示:

Generate a Payload CMS collection for a blog with title, content, author, and published date fields. Include timestamps and versioning.

generate_field

生成 Payload CMS 字段定义。

参数:

  • name (字符串): 字段名称
  • type (字符串): 字段类型
  • required (可选布尔值): 字段是否必填
  • unique (可选布尔值): 字段是否唯一
  • localized (可选布尔值): 字段是否本地化
  • access (可选布尔值): 是否包含访问控制
  • admin (可选对象): 管理面板配置
  • validation (可选布尔值): 是否包含验证
  • defaultValue (可选任意类型): 字段默认值

示例提示:

Generate a Payload CMS image field with validation that requires alt text and has a description in the admin panel.

项目设置

scaffold_project

搭建完整的 Payload CMS 项目结构。

参数:

  • projectName (字符串): 项目名称
  • description (可选字符串): 项目描述
  • serverUrl (可选字符串): 服务器 URL
  • database (可选枚举): 数据库类型 - "mongodb" 或 "postgres"
  • auth (可选布尔值): 是否包含认证
  • admin (可选对象): 管理面板配置
  • collections (可选数组): 集合对象数组
  • globals (可选数组): 全局对象数组
  • blocks (可选数组): 块对象数组
  • plugins (可选数组): 插件字符串数组
  • typescript (可选布尔值): 是否使用 TypeScript

示例提示:

Scaffold a Payload CMS project called "blog-platform" with MongoDB, authentication, and collections for posts, categories, and users. Include a global for site settings.

🚀 开始

1. 前提条件

在开始之前,请确保您已经具备以下条件:

  • Node.js 18+(Payload CMS 3.0 所需)
  • 一个活跃的 Railway 账户
  • 一个 Railway API 令牌(可以在 railway.app/account/tokens 创建)
  • 对 Payload CMS 3.0 概念的基本了解

2. 配置 Cursor

要与 Cursor IDE 一起使用,请执行以下步骤:

  1. 打开 Cursor 设置
  2. 转到 MCP 服务器部分
  3. 添加一个新的 MCP 服务器
  4. 将其命名为 "Payload CMS 3.0 MCP"
  5. 将传输类型设置为 "命令"
  6. 将命令设置为:railway run --service=YOUR_SERVICE_ID
  7. 保存配置

3. 使用 MCP 服务器

配置完成后,您可以在 AI 提示中使用这些工具:

  • 代码验证:"验证这段 Payload CMS 集合代码"
  • 模板生成:"为媒体集合生成一个模板"
  • 查询规则:"查询访问控制的验证规则"
  • SQL 类似查询:"执行查询以查找集合中的字段类型"

4. 示例工作流程

使用 Payload CMS MCP 服务器的典型工作流程如下:

  1. 生成具有特定字段的集合模板
  2. 验证生成的代码是否遵循最佳实践
  3. 查询特定的验证规则以改进代码
  4. 生成额外的组件,如钩子或端点
  5. 准备就绪时搭建完整的项目结构

5. 完整工作流示例

这里是一个如何在对话中使用 MCP 服务器的完整示例:

User: I need to create a Payload CMS collection for a product catalog.

AI: I'll help you create a product catalog collection. Let me generate a template for you.

[Uses generate_collection tool]

Here's a collection template for your product catalog:

```typescript
import { CollectionConfig } from 'payload/types';

export const Products: CollectionConfig = {
  slug: 'products',
  admin: {
    useAsTitle: 'name',
    defaultColumns: ['name', 'price', 'category', 'inStock'],
    group: 'Shop',
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true,
    },
    {
      name: 'description',
      type: 'richText',
    },
    {
      name: 'price',
      type: 'number',
      required: true,
    },
    {
      name: 'category',
      type: 'relationship',
      relationTo: 'categories',
      required: true,
    },
    {
      name: 'images',
      type: 'array',
      fields: [
        {
          name: 'image',
          type: 'upload',
          relationTo: 'media',
          required: true,
        },
        {
          name: 'altText',
          type: 'text',
          required: true,
        }
      ]
    },
    {
      name: 'inStock',
      type: 'checkbox',
      defaultValue: true,
    },
  ],
  timestamps: true,
}

用户:你能验证一下这段代码是否遵循了最佳实践吗?

AI:我将为您验证代码。

[使用验证工具]

验证结果显示您的代码是有效的,并且遵循了最佳实践。这里有一些建议:

  1. 考虑为您的类别关系字段添加 maxDepth 以防止深层查询
  2. 您可能需要为创建、更新和删除操作添加访问控制
  3. 当产品更新时,考虑添加用于库存管理的钩子

用户:在 Payload CMS 中,访问控制的最佳实践是什么?

AI:让我查询一下访问控制的验证规则。

[使用查询工具]

这里是 Payload CMS 中访问控制的最佳实践:

  1. 始终为创建、读取、更新和删除操作定义明确的访问控制函数
  2. 为管理员用户使用基于角色的访问控制
  3. 对敏感数据实施字段级访问控制
  4. 对广泛权限使用集合级访问控制
  5. 考虑在复杂逻辑中结合使用钩子和访问控制

用户:现在我需要用这个产品集合和一个类别集合来构建一个完整的项目。

AI:我将为您构建一个完整的项目。

[使用 scaffold_project 工具]

我已经为您生成了一个完整的 Payload CMS 项目结构,包括:

  • 您指定的产品集合
  • 包含名称和描述字段的类别集合
  • 用于产品图片的媒体集合
  • 管理员用户的认证
  • TypeScript 配置
  • MongoDB 数据库设置
  • 所有必要的文件和配置

项目已经准备好使用 npm installnpm run dev 进行初始化。

📋 项目脚手架示例及详细提示

项目脚手架示例

当你使用 MCP 服务器搭建一个项目时,你将获得一个完整的项目结构。以下是一个电子商务项目的脚手架可能的样子:

e-commerce-platform/
├── .env
├── .eslintrc.js
├── .gitignore
├── README.md
├── package.json
├── tsconfig.json
├── src/
│   ├── payload.config.ts
│   ├── server.ts
│   ├── collections/
│   │   ├── Products.ts
│   │   ├── Categories.ts
│   │   ├── Orders.ts
│   │   ├── Customers.ts
│   │   ├── Media.ts
│   │   └── Users.ts
│   ├── globals/
│   │   ├── Settings.ts
│   │   └── Footer.ts
│   ├── blocks/
│   │   ├── Hero.ts
│   │   ├── ProductGrid.ts
│   │   └── CallToAction.ts
│   ├── fields/
│   │   ├── richText/
│   │   ├── metaImage.ts
│   │   └── slug.ts
│   ├── hooks/
│   │   ├── beforeChange.ts
│   │   └── afterChange.ts
│   ├── access/
│   │   ├── isAdmin.ts
│   │   └── isAdminOrSelf.ts
│   └── utilities/
│       ├── formatSlug.ts
│       └── sendEmail.ts

示例项目脚手架提示(基础)

Scaffold a Payload CMS project for a blog platform with the following:
- Project name: blog-platform
- Database: MongoDB
- Authentication: Yes
- Collections: Posts, Categories, Authors, Media
- Globals: SiteSettings
- TypeScript: Yes

示例项目脚手架提示(详细)

Scaffold a comprehensive Payload CMS project for an e-commerce platform with the following specifications:

Project details:
- Name: luxury-watches-store
- Description: "An e-commerce platform for luxury watches"
- Database: PostgreSQL
- TypeScript: Yes

Collections needed:
1. Products collection with:
   - Name (text, required)
   - Description (rich text)
   - Price (number, required)
   - SKU (text, unique)
   - Brand (relationship to Brands collection)
   - Categories (relationship to Categories, multiple)
   - Features (array of text fields)
   - Specifications (array of key-value pairs)
   - Images (array of media uploads with alt text)
   - Stock quantity (number)
   - Status (select: available, out of stock, discontinued)

2. Categories collection with:
   - Name (text, required)
   - Description (rich text)
   - Parent category (self-relationship)
   - Image (media upload)

3. Brands collection with:
   - Name (text, required)
   - Logo (media upload)
   - Description (rich text)
   - Founded year (number)
   - Country of origin (text)

4. Orders collection with:
   - Order number (text, generated)
   - Customer (relationship to Users)
   - Products (array of relationships to Products with quantity)
   - Status (select: pending, processing, shipped, delivered, cancelled)
   - Shipping address (group of fields)
   - Billing address (group of fields)
   - Payment method (select)
   - Total amount (number, calculated)
   - Notes (text)

5. Users collection (auth enabled) with:
   - Email (email, required)
   - Name (text, required)
   - Shipping addresses (array of address groups)
   - Order history (relationship to Orders)
   - Wishlist (relationship to Products)
   - Role (select: customer, admin)

Globals:
1. SiteSettings with:
   - Site name
   - Logo
   - Contact information
   - Social media links
   - SEO defaults

2. ShippingMethods with:
   - Array of shipping options with prices

Include access control for:
- Admin-only access to manage products, categories, brands
- Customer access to their own orders and profile
- Public read access to products and categories

Add hooks for:
- Updating stock when orders are placed
- Generating order numbers
- Sending email notifications on order status changes

示例集合创建提示(基础)

Generate a Payload CMS collection for blog posts with title, content, author, and published date fields.

示例集合创建提示(详细)

Generate a Payload CMS collection for a real estate property listing with the following specifications:

Collection name: Properties
Admin configuration:
- Use "title" as the display field
- Group under "Listings" in the admin panel
- Default columns: title, price, location, status, createdAt

Fields:
1. Title (text, required)
2. Slug (text, unique, generated from title)
3. Description (rich text with basic formatting options)
4. Price (number, required)
5. Location (group) with:
   - Address (text)
   - City (text, required)
   - State/Province (text, required)
   - Postal code (text)
   - Country (select from predefined list)
   - Coordinates (point) for map display
6. Property details (group) with:
   - Property type (select: house, apartment, condo, land, commercial)
   - Bedrooms (number)
   - Bathrooms (number)
   - Square footage (number)
   - Lot size (number)
   - Year built (number)
   - Parking spaces (number)
7. Features (array of checkboxes) including:
   - Air conditioning
   - Swimming pool
   - Garden
   - Garage
   - Fireplace
   - Security system
   - Elevator
   - Furnished
8. Images (array of media uploads with alt text and caption)
9. Documents (array of file uploads for floor plans, certificates, etc.)
10. Status (select: available, under contract, sold, off market)
11. Featured (checkbox to highlight on homepage)
12. Agent (relationship to Users collection, required)
13. Related properties (relationship to self, multiple)

Access control:
- Public read access
- Agent can create and edit their own listings
- Admin can manage all listings

Hooks:
- Before change: Format slug from title
- After change: Notify agent of status changes

Versioning: Enabled
Timestamps: Enabled

提示中的细节程度

MCP 服务器可以处理不同细节程度的提示:

最小细节(AI 填补空白)

Generate a collection for blog posts.

中等细节(具体要求)

Generate a collection for blog posts with title, content, featured image, categories, and author fields. Make title and content required.

高度细节(完整规格)

Generate a collection for blog posts with:
- Slug: posts
- Fields:
  - Title (text, required)
  - Content (rich text with custom formatting options)
  - Featured image (upload with alt text)
  - Categories (relationship to categories collection, multiple)
  - Author (relationship to users collection)
  - Status (select: draft, published, archived)
  - Published date (date)
  - SEO (group with title, description, and keywords)
- Admin configuration:
  - Use title as display field
  - Group under "Content"
  - Default columns: title, author, status, publishedDate
- Access control for different user roles
- Hooks for slug generation and notification
- Enable versioning and timestamps

有效提示的小贴士

  1. 明确需求:提供的细节越多,输出就越符合你的需求。
  2. 指定关系:清楚地表明集合之间的关系。
  3. 包含验证需求:提及任何字段的验证规则或约束。
  4. 描述管理界面偏好:指明希望集合在管理面板中如何显示。
  5. 提及钩子和访问控制:如果需要特定的业务逻辑或安全规则,请将其包含在提示中。
  6. 使用领域特定术语:用与您的行业或用例相关的术语来描述您的项目。

📄 许可证

该项目根据 MIT 许可证授权 - 请参阅 LICENSE 文件以获取详情。

🌍 关于 MATMAX WORLDWIDE

我们相信科技向善——这些工具可以改善我们的生活同时尊重人性。

加入我们一起构建一个未来,在那里技术服务于健康、联系和目标。共同创造能激发我们所有人最好的一面的数字体验。

访问 matmax.world 了解更多关于我们以人为中心的技术愿景的信息。

🖥️ 本地运行

你可以使用 npm 在本地运行 Payload CMS MCP 服务器:

npm version
npm downloads

选项 1: 从 npm 安装

# Install globally
npm install -g payload-cms-mcp

# Run the server
payload-cms-mcp

选项 2: 克隆仓库

  1. 克隆仓库:
git clone https://github.com/Matmax-Worldwide/payloadcmsmcp.git
cd payloadcmsmcp
  1. 安装依赖:
npm install
  1. 本地运行服务器:
npm run dev

或者:

npm run local

现在你的 MCP 服务器将在本地运行,并可用于开发和测试,而无需 Railway API 令牌。

🚀 部署选项

部署到 Railway(推荐)

部署 MCP 服务器最简单的方法是使用 Railway 的一键部署:

Deploy on Railway

点击按钮后:

  1. 选择“从 GitHub 仓库部署”
  2. 搜索 "Matmax-Worldwide/payloadcmsmcp"
  3. 点击“立即部署”

快速光标 IDE 设置

部署完成后:

  1. 安装 Railway CLI: npm install -g @railway/cli
  2. 登录 Railway: railway login
  3. 关联到您的项目: railway link
  4. 在光标设置 > MCP 服务器中,将命令设置为: railway run

相关 MCP 服务