Run the Rust MCP backend and Next.js starter locally, define sections as Zod schemas, connect your agent over OAuth 2.1, and deploy to your own server.
Headcode CMS v4 splits cleanly into two parts: a single-tenant Rust MCP backend (apps/backend on port 3080 with embedded Turso) and a plain Next.js site (apps/base on port 3082).
bash git clone -b v4 https://github.com/headcodecms/headcodecms.git cd headcodecms pnpm install pnpm dev
Generate the JSON Schema and seed content from apps/base, load them into Turso, and mint your first zero-PII admin invite:
bash pnpm --dir apps/base schema cd apps/backend cargo run -- schema ../base/headcode.schema.json cargo run -- seed ../base/headcode.seed.json cargo run -- invite create admin "Owner"
Open the printed /admin?invite=<token> link in your browser to sign in through Better Auth and claim the initial admin role.
When you publish in Headcode, the backend sends a signed POST request (x-mstack-signature and x-mstack-timestamp) to your Next.js site so cached pages refresh immediately:
bash echo "HEADCODE_REVALIDATE_SECRET=$(openssl rand -hex 32)" >> apps/base/.env.local cd apps/backend HEADCODE_REVALIDATE_SECRET="$(grep ^HEADCODE_REVALIDATE_SECRET= ../base/.env.local | cut -d= -f2)" \ cargo run -- site http://localhost:3082/api/revalidate
Point any OAuth 2.1 MCP client at your backend /mcp endpoint. The server advertises Protected Resource Metadata so clients discover your Better Auth login flow automatically.
opencode mcp add --global headcode --url https://v4-api.headcodecms.com/mcp && opencode mcp auth headcode
Deploy the Rust backend with persistent /data storage alongside a shared mstack-auth service, or enable the bundled auth profile for standalone setups.
docker compose --profile with-auth up -d
Built with axum, rmcp (with skills-fs), and native embedded Turso. Media uploads are validated by magic bytes and served from a persistent local volume at /media.
All edits modify draft state first. Share a rotatable preview token for live Next.js draft rendering, publish atomically into a versioned snapshot, or roll back anytime.
Your site reads published content from /live with Next.js use cache and optimizes images from /media via Vercel Image Optimization. No vendor SDK lock-in.
Define reusable sections with Zod helpers in headcode/sections.ts and wire them into globals and collections in headcode/config.ts.
import { LinkField, TextareaField, TextField } from './fields.ts'
export const hero = {
name: 'hero',
label: 'Hero',
fields: {
eyebrow: TextField({ label: 'Eyebrow' }),
title: TextField({ label: 'Title' }),
description: TextareaField({ label: 'Description' }),
primaryButton: LinkField({ label: 'Primary Button' }),
},
}Run linting, typechecking, Rust tests, and the MCP smoke check before committing or deploying.
pnpm lint && pnpm typecheck && pnpm test
plans section in action.