Contentrain MCP
Extract, govern, and ship structured content from your codebase.
@contentrain/mcp
Local-first MCP server and core primitives for Contentrain.
Start here:
Contentrain is AI-generated content governance infrastructure:
- agent produces content decisions
- MCP applies deterministic filesystem and git workflow
- humans review and merge
- the system keeps schema, locale, and serialization consistent
This package is the runtime core behind Contentrain's MCP integration. It can be used as:
- a stdio MCP server (
contentrain-mcp) - an embeddable server (
createServer(projectRoot)) - a low-level toolkit for config, models, content, validation, scanning, and git transaction flow
๐ Install
pnpm add @contentrain/mcp
Requirements:
- Node.js
22+ - git available on the machine
Optional parser support for higher-quality source scanning:
@vue/compiler-sfc@astrojs/compilersvelte
They are listed as optional dependencies. The scanner still works without them, but Vue/Astro/Svelte detection is stronger when they are installed.
โจ What It Does
@contentrain/mcp manages a .contentrain/ directory in your project and exposes MCP tools for:
- project initialization
- model creation and deletion
- content save, delete, and list
- validation and auto-fix
- normalize scan and apply flows
- bulk operations
- branch submission and branch-health awareness
All write operations are designed around git-backed safety:
- a dedicated
contentrainbranch serves as the content state single source of truth - each write creates a temporary worktree on a feature branch forked from
contentrain - auto-merge: feature merges into
contentrain, baseBranch advanced via update-ref,.contentrain/files selectively synced to developer's working tree - review: feature branch pushed to remote for team review
- developer's working tree is never mutated during MCP git operations (no stash, no checkout, no merge)
- context.json is committed together with content changes, not as a separate commit
- keep canonical JSON output
- surface validation and next-step hints to the caller
๐งฐ Tool Surface
16 MCP tools with annotations (readOnlyHint, destructiveHint, idempotentHint) for client safety hints:
| Tool | Purpose | Read-only | Destructive |
|---|---|---|---|
contentrain_status | Project status, config, models, branch health, context | Yes | โ |
contentrain_describe | Full schema and sample data for a model | Yes | โ |
contentrain_describe_format | File-format and storage contract reference | Yes | โ |
contentrain_init | Create .contentrain/ structure and base config | โ | โ |
contentrain_scaffold | Apply a starter template such as blog, docs, landing, saas | โ | โ |
contentrain_model_save | Create or update a model definition | โ | โ |
contentrain_model_delete | Delete a model definition | โ | Yes |
contentrain_content_save | Save content entries for any model kind | โ | โ |
contentrain_content_delete | Delete content entries | โ | Yes |
contentrain_content_list | Read content entries | Yes | โ |
contentrain_validate | Validate project content, optionally auto-fix structural issues | โ | โ |
contentrain_submit | Push contentrain/* branches to remote | โ | โ |
contentrain_merge | Merge a review-mode branch into contentrain locally | โ | โ |
contentrain_scan | Graph- and candidate-based hardcoded string scan | Yes | โ |
contentrain_apply | Normalize extract/reuse execution with dry-run support | โ | โ |
contentrain_bulk | Bulk locale copy, status updates, and deletes | โ | โ |
๐ Quick Start
Configure via CLI (recommended)
npx contentrain setup claude-code # or: cursor, vscode, windsurf, copilot
This auto-creates the correct MCP config file for your IDE. See CLI docs for details.
Run as a standalone MCP server
CONTENTRAIN_PROJECT_ROOT=/path/to/project npx contentrain-mcp
If CONTENTRAIN_PROJECT_ROOT is omitted, the current working directory is used.
Embed the server in your own process
import { createServer } from '@contentrain/mcp/server'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
const server = createServer(process.cwd())
const transport = new StdioServerTransport()
await server.connect(transport)
๐ Example MCP Flow
Typical agent workflow:
- Call
contentrain_status - If needed, call
contentrain_init - Create models with
contentrain_model_saveorcontentrain_scaffold - Save content with
contentrain_content_save - Validate with
contentrain_validate - For hardcoded strings, use
contentrain_scanthencontentrain_apply - Push review branches with
contentrain_submit
๐งช Normalize Flow
Normalize is intentionally split into two phases:
1. Extract
contentrain_scan finds candidate strings.
contentrain_apply with mode: "extract":
- creates or updates models
- writes content entries
- records source tracking
- creates a review branch
2. Reuse
contentrain_apply with mode: "reuse":
- patches source files using agent-provided expressions
- adds imports when needed
- enforces patch path safety and scope checks
- creates a separate review branch
This split keeps content extraction separate from source rewriting.
๐ฆ Core Exports
The package also exposes low-level modules for embedding and advanced use:
@contentrain/mcp/server@contentrain/mcp/core/config@contentrain/mcp/core/context@contentrain/mcp/core/model-manager@contentrain/mcp/core/content-manager@contentrain/mcp/core/validator@contentrain/mcp/core/scanner@contentrain/mcp/core/graph-builder@contentrain/mcp/core/apply-manager@contentrain/mcp/util/detect@contentrain/mcp/util/fs@contentrain/mcp/git/transaction@contentrain/mcp/git/branch-lifecycle@contentrain/mcp/templates
These are intended for Contentrain tooling and advanced integrations, not for direct manual editing of .contentrain/ files.
๐ง Design Constraints
Key design decisions in this package:
- local-first, filesystem-based MCP
- no GitHub API dependency in MCP
- JSON-only content storage
- git-backed write workflow
- canonical serialization
- framework-agnostic MCP layer
- agent decides content semantics, MCP enforces deterministic execution
๐ Development
From the monorepo root:
pnpm --filter @contentrain/mcp build
pnpm --filter @contentrain/mcp test
pnpm --filter @contentrain/mcp typecheck
pnpm exec oxlint packages/mcp/src packages/mcp/tests
๐ Related Packages
contentrainโ CLI and local review tooling@contentrain/queryโ generated runtime query SDK@contentrain/rulesโ IDE/agent rules and prompts@contentrain/typesโ shared schema and model types
๐ Documentation
Full documentation at ai.contentrain.io/packages/mcp.
๐ License
MIT
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
MCP Code Crosscheck
A server for bias-resistant AI code review using cross-model evaluation.
BrandKity MCP
Build entire brand kits with a single prompt
Fal.ai OpenAI Image
A server for the Fal.ai text-to-image API, powered by OpenAI's image model. Requires Fal.ai and OpenAI API keys.
ACR โ Agent Composition Records
Interaction profile registry for AI agents โ log interactions, build a behavioral profile, query it through behavioral lenses. 21 tools, zero-config.
Search Tools MCP Server
An MCP server that enhances code analysis with advanced search and dependency mapping capabilities.
SSH Rails Runner
Execute Rails console commands remotely and securely over SSH.
Shipyard
The Shipyard CLI provides an MCP server for agents to manage Shipyard environments directly: by pulling logs, comparing branches, running tests, and stopping/starting environments..
MCP Server with GitHub OAuth
A remote MCP server with built-in GitHub OAuth support, designed for deployment on Cloudflare Workers.
Volatility3 MCP Server
Perform advanced memory forensics analysis using Volatility3 via a conversational interface. Requires user-specified memory dump files.
Python Weather Server
A FastAPI-based server that provides weather information from the National Weather Service API, secured with OAuth 2.1.