Skip to main content
Glama
Contentrain MCP Server

Contentrain MCP Server

Official
by Contentrain

@contentrain/mcp

MCP (Model Context Protocol) server for Contentrain CMS content management. Enables AI agents (Claude, Codex, Cursor, etc.) and humans to create, read, update, and delete Contentrain models, content, and assets — with automatic git branch synchronization.

Why?

Contentrain is a git-based headless CMS. This MCP server lets AI assistants directly manage your Contentrain content through a standardized protocol, so you can say things like:

  • "Create a blog post model with title, excerpt, and cover image fields"

  • "Add a new blog post in English and Turkish"

  • "List all FAQ entries and update the second one"

All changes are committed and pushed to your git repository automatically.

Prerequisites

  • A Contentrain project already set up via the Contentrain Web App

  • The project's GitHub repository cloned locally

  • Node.js >= 18

Important: Contentrain projects must be initialized through the Web App first. The Web App creates the repository structure, the contentrain branch, models, and environment configuration. This MCP server operates on an existing Contentrain project — it does not replace the initial setup.

Quick Start

1. Install

# From npm (when published)
npm install -g @contentrain/mcp

# Or from source
git clone https://github.com/Contentrain/contentrain-mcp.git
cd contentrain-mcp
pnpm install && pnpm build

2. Configure your MCP client

Add to your MCP client configuration:

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "contentrain": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/your/contentrain-project",
        "CONTENTRAIN_BRANCH": "contentrain"
      }
    }
  }
}

Cursor (.cursor/mcp.json in your project root):

{
  "mcpServers": {
    "contentrain": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/your/contentrain-project",
        "CONTENTRAIN_BRANCH": "contentrain"
      }
    }
  }
}

Claude Code (.mcp.json in your project root):

{
  "mcpServers": {
    "contentrain": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/your/contentrain-project",
        "CONTENTRAIN_BRANCH": "contentrain"
      }
    }
  }
}

If installed from source instead of globally, replace "command": "contentrain-mcp" with "command": "node" and add "args": ["/absolute/path/to/contentrain-mcp/dist/index.mjs"].

3. Start using

Once configured, your AI assistant has access to 14 tools. Here's an example conversation:

You:    List all my models
Agent:  → calls contentrain_list_models
        You have 3 models: blog (MD, localized), faq (JSON), authors (JSON)

You:    Show me the blog model schema
Agent:  → calls contentrain_describe_model { modelId: "blog" }
        Blog model has fields: title (string, required), description (string),
        category (one-to-one → blogcategories), imagesrc (media), author (one-to-one → authors)

You:    Create a new blog post titled "Getting Started with Contentrain"
Agent:  → calls contentrain_create_content {
            modelId: "blog",
            data: { title: "Getting Started with Contentrain", slug: "getting-started-with-contentrain", description: "..." },
            locale: "en",
            status: "draft",
            content: "# Getting Started\n\nWelcome to Contentrain..."
          }
        Created entry e7f3a1b9c0d2 in blog model (draft).
        Committed and pushed to contentrain branch.

You:    Now publish it
Agent:  → calls contentrain_update_content {
            modelId: "blog",
            entryId: "e7f3a1b9c0d2",
            data: { status: "publish" },
            locale: "en"
          }
        Updated and published.

Environments

Contentrain uses git branches to manage environments. Each environment maps to a branch:

Environment

Branch

Description

Default

contentrain

Main content branch (created automatically)

Staging

contentrain-staging

Preview/staging environment

Production

contentrain-production

Production environment

Environments are created via the Contentrain Web App. The branch naming follows the pattern contentrain-{environment-name}.

Targeting a specific environment

Set the CONTENTRAIN_BRANCH environment variable to the target environment's branch:

{
  "mcpServers": {
    "contentrain": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/project",
        "CONTENTRAIN_BRANCH": "contentrain-staging"
      }
    }
  }
}

Multiple environments simultaneously

You can register multiple MCP server instances — one per environment:

{
  "mcpServers": {
    "contentrain-default": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/project",
        "CONTENTRAIN_BRANCH": "contentrain"
      }
    },
    "contentrain-staging": {
      "command": "contentrain-mcp",
      "env": {
        "CONTENTRAIN_REPO_PATH": "/path/to/project",
        "CONTENTRAIN_BRANCH": "contentrain-staging"
      }
    }
  }
}

Available Tools

Model Management

Tool

Description

contentrain_list_models

List all models with metadata

contentrain_describe_model

Get full schema with field definitions

contentrain_create_model

Create a new model (JSON, MD, or MDX)

contentrain_add_field

Add a field to an existing model

contentrain_delete_model

Delete a model and all its content

Content Management

Tool

Description

contentrain_list_content

List all entries for a model

contentrain_get_content

Get a single entry by ID

contentrain_create_content

Create a new entry with validation

contentrain_update_content

Update specific fields of an entry

contentrain_delete_content

Delete an entry (all locales + markdown)

contentrain_validate

Dry-run validation against model schema

Asset Management

Tool

Description

contentrain_list_assets

List all registered assets

contentrain_register_asset

Register an existing file as an asset

contentrain_deregister_asset

Remove an asset from the registry

Environment Variables

Variable

Default

Description

CONTENTRAIN_REPO_PATH

process.cwd()

Path to the git repository

CONTENTRAIN_BRANCH

contentrain

Target environment branch

CONTENTRAIN_REMOTE

origin

Git remote name

CONTENTRAIN_DIR

contentrain

Contentrain directory name

CONTENTRAIN_DRY_RUN

false

Skip git operations (local changes only)

CONTENTRAIN_AUTHOR_NAME

—

Git commit author name

CONTENTRAIN_AUTHOR_EMAIL

—

Git commit author email

Programmatic Usage

You can also use the writer directly in your own code:

import { ContentrainWriter } from '@contentrain/mcp'

const writer = new ContentrainWriter({
  repoPath: '/path/to/your/project',
  branch: 'contentrain',
})

// Read operations (no git transaction needed)
const models = await writer.model.list()
const entries = await writer.content.list('blog-posts')

// Write operations (uses git worktree + commit + push)
await writer.transaction(async (tx) => {
  await tx.content.create('blog-posts', {
    title: 'Hello World',
    excerpt: 'My first post',
  }, { status: 'draft' })
}, { message: 'add new blog post' })

How Git Sync Works

Every write operation runs inside a transaction:

  1. Creates an isolated git worktree from the target branch

  2. Applies all changes inside the worktree

  3. Commits and pushes to the target branch

  4. If the push is rejected (remote advanced), performs a structural 3-way merge — diffing JSON entries by their ID field instead of text lines — then retries (up to 3 attempts)

  5. Cleans up the worktree

This means concurrent writes from multiple agents or the Contentrain web app won't conflict.

Development

pnpm install        # Install dependencies
pnpm dev            # Watch mode build
pnpm test           # Run tests (watch mode)
pnpm test:run       # Run tests once
pnpm lint           # Lint with oxlint
pnpm build          # Production build

License

MIT

Available Tools

14 tools
contentrain_add_fieldC

Add a new field to an existing model.

NameRequiredDescriptionDefault
modelIdYesTarget model ID
nameYesDisplay name of the field
fieldIdYesUnique field identifier
componentIdYesUI component (single-line-text, integer, one-to-one, media, etc.)
fieldTypeYesData type (string, number, boolean, relation, media, date, array)
optionsNoField options (title-field, default-value, reference, etc.)
validationsNoField validations (required-field, unique-field)
contentrain_create_contentA

Create a new content entry. System fields (ID, createdAt, updatedAt, status) are auto-generated. For localized models, specify locale to create in that language. Call contentrain_describe_model first to know required fields.

NameRequiredDescriptionDefault
modelIdYesTarget model ID
dataYesContent data object with field values matching model schema
localeNoLocale code (e.g., "en") — required for localized models
statusNoEntry status (default: "draft")
contentNoMarkdown body content (only for MD/MDX models)
contentrain_create_modelA

Create a new Contentrain model with field definitions. System fields (ID, createdAt, updatedAt, status) are auto-added. For MD/MDX models, slug and content fields are also auto-added.

NameRequiredDescriptionDefault
nameYesDisplay name of the model
modelIdYesUnique model ID in kebab-case
typeYesContent type
localizationYesWhether the model supports multiple languages
descriptionNoModel description
pathNoBase path for MD/MDX files
fieldsNoCustom field definitions (system fields are auto-added)
contentrain_delete_contentA
Destructive

Delete a content entry by ID. For localized models, removes from all locale files. For MD/MDX, also deletes markdown files.

NameRequiredDescriptionDefault
modelIdYesModel ID
entryIdYesEntry ID to delete (12-char hex)
contentrain_delete_modelA
Destructive

Delete a model and all its content. WARNING: This is destructive and cannot be undone.

NameRequiredDescriptionDefault
modelIdYesModel ID to delete
contentrain_deregister_assetA
Destructive

Remove an asset from assets.json registry. Does NOT delete the physical file.

NameRequiredDescriptionDefault
pathYesAsset path to deregister
contentrain_describe_modelA

Get detailed schema for a model including all field definitions, types, validations, and options. Call this BEFORE creating or updating content to understand required fields.

NameRequiredDescriptionDefault
modelIdYesThe model ID to describe
contentrain_get_contentB
Read-only

Get a single content entry by ID.

NameRequiredDescriptionDefault
modelIdYesModel ID
entryIdYesEntry ID (12-char hex)
localeNoLocale code for localized models
contentrain_list_assetsB
Read-only

List all registered assets in assets.json.

NameRequiredDescriptionDefault

No parameters

contentrain_list_contentA
Read-only

List all content entries for a model. For localized models, specify a locale.

NameRequiredDescriptionDefault
modelIdYesModel ID to list content from
localeNoLocale code (e.g., "en", "tr") for localized models
contentrain_list_modelsB

List all Contentrain models with their metadata (type, localization, etc.)

NameRequiredDescriptionDefault

No parameters

contentrain_register_assetB

Register a new asset in assets.json. The file must already exist at the specified path in the repository.

NameRequiredDescriptionDefault
pathYesRelative path to the asset file (e.g., "contentrain/static/hero.png")
mimetypeYesMIME type (e.g., "image/png", "image/jpeg", "application/pdf")
altNoAlt text for the asset
contentrain_update_contentB

Update an existing content entry. Only provide fields you want to change. updatedAt is auto-set.

NameRequiredDescriptionDefault
modelIdYesModel ID
entryIdYesEntry ID to update (12-char hex)
dataYesFields to update
localeNoLocale code for localized models
contentNoUpdated markdown body (only for MD/MDX models)
contentrain_validateA
Read-only

Validate content data against model schema without writing. Use for dry-run checks.

NameRequiredDescriptionDefault
modelIdYesModel ID to validate against
dataYesContent data to validate

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 14 tool updatesv0.1.0
    • First observedcontentrain_add_field
    • First observedcontentrain_create_content
    • First observedcontentrain_create_model
    • First observedcontentrain_delete_content
    • First observedcontentrain_delete_model
    • First observedcontentrain_deregister_asset
    • First observedcontentrain_describe_model
    • First observedcontentrain_get_content
    • First observedcontentrain_list_assets
    • First observedcontentrain_list_content
    • First observedcontentrain_list_models
    • First observedcontentrain_register_asset
    • First observedcontentrain_update_content
    • First observedcontentrain_validate

TDQS

A3.9/5.0

Scored across 14 tools

Disambiguation5/5

Each tool has a distinct purpose with clear boundaries: model management (create/delete/describe/list), content operations (create/get/list/update/delete/validate), and asset handling (register/deregister/list). No tools overlap in functionality, and the descriptions explicitly differentiate them (e.g., contentrain_describe_model is for schema inspection, while contentrain_validate is for dry-run validation).

Naming Consistency5/5

All tools follow a consistent 'contentrain_verb_noun' pattern with snake_case throughout (e.g., contentrain_create_model, contentrain_list_content). Verbs are descriptive and aligned with CRUD operations (create, get, list, update, delete) and domain-specific actions (describe, validate, register, deregister), making the naming highly predictable and readable.

Tool Count5/5

With 14 tools, the server is well-scoped for a content management system, covering model lifecycle, content CRUD, asset management, and validation. Each tool serves a clear, non-redundant function, and the count is typical for this domain (similar to the GitHub MCP example), avoiding bloat or thin coverage.

Completeness5/5

The toolset provides complete coverage for content management: full CRUD for models and content, asset registration/deregistration, schema inspection, and validation. There are no obvious gaps; agents can perform all core workflows from model creation to content operations and asset handling, with no dead ends in the lifecycle.

Related MCP Connectors