Programmatic Blog Publishing: Automate Your Content Pipeline
Working patterns for programmatic blog publishing: a Node.js helper, publishing Markdown from CI, an SEO gate, syndication and managing several blogs.
Programmatic blog publishing means a program creates and updates posts instead of a person in an editor. This guide is a set of working patterns for Modern Blogging: a small Node.js helper, a CI pipeline that publishes Markdown from Git, an SEO gate, cross-posting, and running several blogs from one script.
Everything here uses one endpoint and an API key. If you have not made a request yet, start with the blog API guide .
Use cases for programmatic publishing
- Docs-as-code blogs : posts are Markdown files reviewed in pull requests and published on merge.
- Changelogs and release notes : generated from a release and posted without anyone opening an editor.
- Pages with changing facts : prices, schedules or tables refreshed from a data source.
- Migrations : a one-off script that moves an archive in.
- Agencies : the same routine applied across many client blogs.
- Backups : a nightly export to your own storage.
Architecture — API keys, webhooks, cache invalidation
Piece | How it works on Modern Blogging |
|---|---|
Endpoint | POST https://modernblogging.net/api/mcp, JSON-RPC 2.0, one tool call per request |
API keys | Generated at /dashboard/api-key, sent as a Bearer token. One key reaches every blog you own. |
Webhooks | None. Your pipeline is the source of events: the job that publishes also notifies what depends on it. |
Cache | Public pages are cached. There is no purge call; allow for a delay before a change shows. |
Drafts | Updates go to a draft. Readers see the change only after a publish. |
Limits | 100 posts and pages on Free, 1,000 on Pro, per blog. |
A helper that wraps the endpoint keeps the rest short. It needs Node.js 18 or newer.
// mb.mjs
const ENDPOINT = 'https://modernblogging.net/api/mcp'
export async function callTool(name, args = {}) {
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.MB_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: { name, arguments: args },
}),
})
if (!res.ok) throw new Error(`HTTP ${res.status}`)
const { result, error } = await res.json()
if (error) throw new Error(error.message)
const text = result.content[0].text
if (result.isError) throw new Error(text)
return JSON.parse(text)
}A tool's result arrives as JSON text inside the response, which is why the helper parses twice.
Publishing a post from a CI/CD pipeline
Keep one Markdown file per post with a small header. The script creates the post the first time and updates it afterwards, finding it by its address.
// publish.mjs — usage: node publish.mjs posts/my-post.md
import { readFileSync } from 'node:fs'
import { callTool } from './mb.mjs'
const raw = readFileSync(process.argv[2], 'utf8')
const [, header, body] = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/)
const meta = Object.fromEntries(
header.split('\n').map(line => {
const i = line.indexOf(':')
return [line.slice(0, i).trim(), line.slice(i + 1).trim()]
}),
)
const fields = {
title: meta.title,
slug: meta.slug,
excerpt: meta.excerpt,
seoTitle: meta.seoTitle,
seoDescription: meta.seoDescription,
focusKeyword: meta.focusKeyword,
body,
}
const posts = await callTool('list_posts')
const existing = posts.find(p => p.slug === meta.slug)
const result = existing
? await callTool('update_post', { id: existing._id, ...fields })
: await callTool('create_post', { ...fields, categories: meta.category ? [meta.category] : undefined })
console.log(existing ? 'updated' : 'created', meta.slug, 'SEO score:', result.seo.score)In CI, store the key as a secret, pass it as MB_API_KEY, and run the script for the files changed in the merge. A GitHub Actions job looks like this:
name: publish-posts
on:
push:
branches: [main]
paths: ['posts/**.md']
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: 20
- run: |
for f in $(git diff --name-only HEAD~1 HEAD -- 'posts/*.md'); do
node publish.mjs "$f"
done
env:
MB_API_KEY: ${{ secrets.MB_API_KEY }}Run the script once by hand against a test blog before trusting it in CI. Keep posts as drafts until the pipeline has proved itself.
Building a content syndication workflow
Syndication means the same article appears in more than one place. To keep search engines pointing at your blog, treat your blog as the original:
- Publish on your blog first, from the pipeline above.
- Cross-post to the other platform through its own API, setting its canonical URL field to the address of your post. Platforms that accept cross-posts generally have such a field.
- Post a summary with a link where full cross-posting is not possible, such as social networks and newsletters.
- Because there are no webhooks, run these steps in the same job, straight after the publish call succeeds.
Going the other way, to pull posts into Modern Blogging from another system, loop over that system's export and call create_post for each item, one request at a time.
Automated SEO checks before publish
create_post and update_post return an SEO score and the checks behind it, so a pipeline can refuse to publish a post that fails. The checks and thresholds .
const MIN_SCORE = 80
const id = existing ? existing._id : result.id
if (result.seo.score >= MIN_SCORE) {
await callTool('publish_post', { id })
console.log('published')
} else {
for (const check of result.seo.feedback) {
if (check.status !== 'pass') console.log(check.status, check.field, check.message)
}
process.exitCode = 1
}A failed job then shows the exact problems in the CI log: a missing meta description, a title that is too long, no focus keyword in the headings.
Multi-blog management via API
One key covers every blog you own. Each tool accepts a subdomain, so a script can address blogs explicitly instead of switching state:
import { writeFileSync } from 'node:fs'
import { callTool } from './mb.mjs'
const blogs = await callTool('list_tenants')
for (const blog of blogs) {
const data = await callTool('export_data', { subdomain: blog.subdomain })
writeFileSync(`backup-${blog.subdomain}.json`, JSON.stringify(data, null, 2))
}- create_tenant makes a new blog with a title and, optionally, a theme description.
- update_settings applies the same navigation or footer to each blog.
- transfer_tenant hands a finished blog to a client by email invitation.
MCP for AI-driven pipelines
The endpoint is an MCP server, so the tools your script calls are the same ones an AI assistant can use. So programmatic blog publishing and conversational editing can share one setup: the assistant drafts and fixes SEO issues in conversation, and the script handles the repeatable parts, such as publishing on merge and backups. The MCP blog tool guide shows the assistant side, and create a blog with AI starts from an empty account.
Automation makes it easy to produce hundreds of near-identical pages. Search engines treat pages with little original content as low quality. Use pipelines to remove manual steps from posts worth publishing, not to multiply thin ones.
To start, create a free blog and generate a key.
This article was written, styled, and published using the Modern Blogging platform. Launch your own fast, SEO-ready publication in minutes.