🚀 Payload CMS 3.0 MCP Server について
Payload CMS 3.0 MCP サーバーは、Payload CMS アプリケーションの開発に特化した MCP サーバーです。コードのバリデーション、テンプレート生成、プロジェクトのスキャフォールディングを提供します。Payload CMS で開発する開発者が対象で、READMEに記載されたベストプラクティスに沿った出力を目指しています。
主な機能
- 01collection、field、global、config コードのバリデーション
- 02collection、field、hook などのテンプレート生成
- 03検証済みオプションによるプロジェクトのスキャフォールディング
- 04バリデーションルールとベストプラクティスの照会
活用シーン
- 01ブログや商品カタログ用の collection 定義を生成する
- 02コミット前に Payload CMS の設定コードを検証する
- 03複数の collection を含む新規プロジェクトを作成する
MCP 対応
MCP サーバーとして、validate、generate_collection、scaffold_project などのツールと照会用ツールを MCP クライアントに公開します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
🚀 Payload CMS 3.0 MCP サーバー
Payload CMS 3.0 専用の MCP サーバー
ベストプラクティスに沿って、コードの検証、テンプレートの生成、プロジェクトのスキャフォールディングを行います
📋 概要
Payload CMS 3.0 MCP サーバーは、Payload CMS の開発体験を向上させるために設計された専用の Model Context Protocol サーバーです。ベストプラクティスに沿ったコード検証、テンプレート生成、プロジェクトのスキャフォールディング機能を提供し、より優れた Payload CMS アプリケーションの構築を支援します。
✨ 機能
📚コード検証コレクション、フィールド、グローバル、設定ファイルの Payload CMS コードを検証し、構文エラーやベストプラクティスについて詳しいフィードバックを提供します。 |
🔍コード生成コレクション、フィールド、グローバル、アクセス制御、フック、エンドポイント、プラグイン、ブロック、マイグレーション用のコードテンプレートを生成します。 |
🚀プロジェクトのスキャフォールディング検証済みのオプションを使って Payload CMS プロジェクト全体をスキャフォールディングし、一貫性を保ち、ベストプラクティスに準拠します。 |
🔧 Payload CMS 3.0 の機能
検証ツール
validate- コレクション、フィールド、グローバル、設定のコードを検証しますquery- 検証ルールとベストプラクティスを照会しますmcp_query- Payload CMS の構造に対して SQL に似たクエリを実行します
コード生成
generate_template- さまざまなコンポーネントのコードテンプレートを生成しますgenerate_collection- コレクション定義一式を作成しますgenerate_field- 適切な型付けでフィールド定義を生成します
プロジェクトのセットアップ
scaffold_project- Payload CMS プロジェクトの構造全体を作成しますvalidate_scaffold_options- スキャフォールディングのオプションがベストプラクティスに沿っていることを確認します(scaffold_project内部で使用)
📝 ツールの詳細リファレンス
検証ツール
validate
Payload CMS のコードについて、構文とベストプラクティスを検証します。
パラメーター:
code(string):検証するコードfileType(enum):ファイルの種類。「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(string):クエリー文字列fileType(optional enum):ファイルの種類。「collection」、「field」、「global」、または「config」
プロンプトの例:
What are the best practices for implementing access control in Payload CMS collections?
mcp_query
Payload CMS の構造に対して、SQL に似たクエリーを実行します。
パラメーター:
sql(string):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(enum):テンプレートの種類。「collection」、「field」、「global」、「config」、「access-control」、「hook」、「endpoint」、「plugin」、「block」、「migration」options(record):テンプレートの設定オプション
プロンプトの例:
Generate a template for a Payload CMS hook that logs when a document is created.
generate_collection
完全な Payload CMS コレクション定義を生成します。
パラメーター:
slug(string):コレクションのスラッグfields(任意の array):フィールドオブジェクトの配列auth(任意の boolean):認証コレクションかどうかtimestamps(任意の boolean):タイムスタンプを含めるかどうかadmin(任意の object):管理パネルの設定hooks(任意の boolean):フックを含めるかどうかaccess(任意の boolean):アクセス制御を含めるかどうかversions(任意の boolean):バージョン管理を有効にするかどうか
プロンプトの例:
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(string):フィールド名type(string):フィールドの種類required(任意の boolean):フィールドが必須かどうかunique(任意の boolean):フィールドを一意にするかどうかlocalized(任意の boolean):フィールドをローカライズするかどうかaccess(任意の boolean):アクセス制御を含めるかどうかadmin(任意の object):管理パネルの設定validation(任意の boolean):バリデーションを含めるかどうかdefaultValue(任意の any):フィールドのデフォルト値
プロンプトの例:
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(string):プロジェクト名description(任意の string):プロジェクトの説明serverUrl(任意の string):サーバー URLdatabase(任意の enum):データベースの種類。「mongodb」または「postgres」auth(任意の boolean):認証を含めるかどうかadmin(任意の object):管理パネルの設定collections(任意の array):コレクションオブジェクトの配列globals(任意の array):グローバルオブジェクトの配列blocks(任意の array):ブロックオブジェクトの配列plugins(任意の array):プラグイン文字列の配列typescript(任意の boolean):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 で使用するには、次の手順を実行します。
- Cursor の設定を開きます
- MCP Servers セクションに移動します
- 新しい MCP サーバーを追加します
- 名前を「Payload CMS 3.0 MCP」に設定します
- Transport Type を「Command」に設定します
- Command に
railway run --service=YOUR_SERVICE_IDを設定します - 設定を保存します
3. MCP サーバーの使用
設定が完了すると、AI のプロンプトで以下のツールを使用できます。
- コードの検証: 「この Payload CMS コレクションのコードを検証してください」
- テンプレートの生成: 「メディアコレクションのテンプレートを生成してください」
- クエリルール: 「アクセス制御のバリデーションルールを照会してください」
- SQL のようなクエリ: 「コレクションのフィールド型を見つけるクエリを実行してください」
4. ワークフローの例
Payload CMS MCP サーバーでの一般的なワークフローは次のとおりです。
- 特定のフィールドを含むコレクションテンプレートを生成します
- 生成されたコードをベストプラクティスに照らして検証します
- コードを改善するために、特定のバリデーションルールを照会します
- フックやエンドポイントなどのコンポーネントを追加で生成します
- 準備ができたら、プロジェクトの構成一式を生成します
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:コードを検証します。
[validate ツールを使用]
検証結果によると、コードは有効で、ベストプラクティスにも従っています。いくつか提案があります。
- 深いクエリを防ぐため、カテゴリのリレーションシップフィールドに maxDepth を追加することを検討してください
- 作成、更新、削除の操作にアクセス制御を追加することを検討してください
- 商品の更新時に在庫を管理するフックを追加することを検討してください
ユーザー:Payload CMS におけるアクセス制御のベストプラクティスを教えてください。
AI:アクセス制御の検証ルールを照会します。
[query ツールを使用]
Payload CMS におけるアクセス制御のベストプラクティスは次のとおりです。
- 作成、読み取り、更新、削除の各操作に、必ず明示的なアクセス制御関数を定義する
- 管理者ユーザーにはロールベースのアクセス制御を使用する
- 機密データにはフィールドレベルのアクセス制御を実装する
- 広範な権限にはコレクションレベルのアクセス制御を使用する
- 複雑なロジックには、アクセス制御と併せてフックを使用することを検討する
ユーザー:次に、この商品コレクションとカテゴリコレクションを含む完全なプロジェクトをスキャフォールドする必要があります。
AI:完全なプロジェクトをスキャフォールドします。
[scaffold_project ツールを使用]
次の内容を含む、完全な Payload CMS プロジェクト構成を生成しました。
- 指定された商品コレクション
- 名前と説明フィールドを含むカテゴリコレクション
- 商品画像用のメディアコレクション
- 管理者ユーザーの認証
- TypeScript の設定
- MongoDB データベースのセットアップ
- 必要なすべてのファイルと設定
プロジェクトは npm install と npm run dev で初期化できます。
📋 スキャフォールディングの例と詳細なプロンプト
プロジェクトのスキャフォールディング例
MCP サーバーを使用してプロジェクトをスキャフォールドすると、完全なプロジェクト構成が得られます。スキャフォールドされた EC サイトのプロジェクト例を紹介します。
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
効果的なプロンプトのヒント
-
要件を具体的にする:詳細を多く伝えるほど、出力はより要件に合ったものになります。
-
リレーションシップを指定する:コレクション同士の関係を明確に示します。
-
バリデーションの要件を含める:フィールドに適用するバリデーションルールや制約があれば、記載します。
-
管理画面の UI に関する希望を説明する:管理パネルでコレクションをどのように表示したいかを指定します。
-
フックとアクセス制御について言及する:特定のビジネスロジックやセキュリティルールが必要な場合は、プロンプトに含めます。
-
ドメイン固有の用語を使う:業界やユースケースに関連する用語を使ってプロジェクトを説明します。
📄 ライセンス
このプロジェクトは MIT License の下でライセンスされています。詳細については LICENSE ファイルをご覧ください。
🌍 MATMAX WORLDWIDE について
MATMAX WORLDWIDE
人間がより人間らしくいられるよう支援するテクノロジーを創造します。
私たちは、人間らしさを尊重しながら暮らしを豊かにするツールなど、より良い社会のためのテクノロジーを信じています。
テクノロジーがウェルネス、つながり、目的に役立つ未来を一緒に築きましょう。力を合わせれば、誰もが持つ最良のものを引き出すデジタル体験を創造できます。
人間を中心としたテクノロジーという私たちのビジョンについては、matmax.world をご覧ください。
## 🖥️ ローカルで実行する
npm を使って Payload CMS MCP サーバーをローカルで実行できます。
方法 1:npm からインストール
# Install globally
npm install -g payload-cms-mcp
# Run the server
payload-cms-mcp
方法 2:リポジトリをクローンする
- リポジトリをクローンします。
git clone https://github.com/Matmax-Worldwide/payloadcmsmcp.git
cd payloadcmsmcp
- 依存関係をインストールします。
npm install
- サーバーをローカルで実行します。
npm run dev
または、次の方法でも実行できます。
npm run local
これで MCP サーバーがローカルで実行され、Railway API トークンがなくても開発やテストに利用できるようになります。
🚀 デプロイ方法
Railway にデプロイする(推奨)
MCP サーバーをデプロイする最も簡単な方法は、Railway のワンクリックデプロイを利用することです。
ボタンをクリックした後:
- 「Deploy from GitHub repo」を選択します
- 「Matmax-Worldwide/payloadcmsmcp」を検索します
- 「Deploy Now」をクリックします
Cursor IDE のクイックセットアップ
デプロイ後:
- Railway CLI をインストールします:
npm install -g @railway/cli - Railway にログインします:
railway login - プロジェクトにリンクします:
railway link - Cursor Settings > MCP Servers で、Command に
railway runを設定します
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。