mdxai
AI agent for creating, editing, enriching, and organizing your MDX files
MDXAI: Your MDX AI Agent
MDXAI is an AI agent that works with your local MDX files - it can create new content, edit existing files, enrich metadata, organize your content library, and maintain your documentation automatically.
What is MDXAI?
Think of MDXAI as your AI content assistant that understands MDX and can:
- Create: Generate new MDX files from prompts or templates
- Edit: Modify existing files while preserving structure
- Enrich: Add frontmatter, SEO metadata, structured data
- Organize: Categorize, tag, and structure your content
- Maintain: Keep content up-to-date and consistent
- Analyze: Understand relationships between documents
Unlike generic AI tools, MDXAI understands:
- YAML frontmatter structure (
$type,$id,$context) - MDX syntax (Markdown + JSX + code exports)
- Semantic relationships between documents
- .org.ai ontologies (schema.org, onet.org, etc.)
How It Works
MDXAI runs as an agent with access to local and/or remote MDX files:
Local Files
# Work with local filesystem
mdxai agent ./content
# The agent can:
# - Read your existing MDX files
# - Create new files based on patterns
# - Edit files to add/update content
# - Organize files into appropriate directories
# - Maintain consistency across your libraryRemote Files (.do Platform)
# Work with remote files on .do platform
mdxai agent --remote platform.do
# The agent can:
# - Query MDX files stored on platform.do
# - Edit files directly on the platform
# - Create new content in platform collections
# - Organize and maintain remote content
# - Sync changes between local and remoteBoth Local and Remote
# Work with both simultaneously
mdxai agent ./content --remote platform.do
# Agent has access to:
# - Local ./content directory
# - Remote platform.do collections
# - Can sync between them
# - Can reference remote data in local filesYou can interact with it via:
- CLI: Run commands directly
- Chat: Conversational interface for complex tasks
- Watch mode: Automatically maintain content as you work
- Scheduled: Run maintenance tasks periodically
Installation
pnpm install mdxaiAuthentication
To work with remote files on the .do platform, you need to authenticate:
DO_TOKEN (API Token)
Set your platform API token as an environment variable:
# Export token
export DO_TOKEN="your-api-token-here"
# Or in .env file
echo "DO_TOKEN=your-api-token-here" >> .env
# Now you can access remote files
mdxai agent --remote platform.doGet your token from platform.do/settings/tokens.
OAuth via OAuth.do
For interactive sessions, use OAuth:
# Login via OAuth
mdxai login
# Opens browser to oauth.do for authentication
# Stores credentials securely
# Now authenticated for all commandsOAuth.do handles:
- Authorization: Secure OAuth 2.0 flow
- Token management: Automatic refresh
- Scope control: Granular permissions
- Multi-account: Switch between accounts
# View current auth status
mdxai whoami
# Logout
mdxai logout
# Switch accounts
mdxai login --account [email protected]Authentication in Code
Use tokens programmatically:
import { mdxai } from 'mdxai'
// With DO_TOKEN
const agent = await mdxai.connect({
token: process.env.DO_TOKEN,
remote: 'platform.do',
})
// With OAuth (interactive)
const agent = await mdxai.connect({
auth: 'oauth',
remote: 'platform.do',
})
// Now work with remote files
await agent.edit('blog/post.mdx', 'add SEO metadata')Permissions and Scopes
OAuth scopes control what the agent can do:
mdx:read- Read MDX filesmdx:write- Create/edit MDX filesmdx:delete- Delete MDX filescollections:read- Query collectionscollections:write- Modify collections
# Login with specific scopes
mdxai login --scope "mdx:read mdx:write collections:read"
# View granted scopes
mdxai whoami --scopesQuick Start
Generate Content (Local)
import { mdxai } from 'mdxai'
// Generate MDX from prompt
const mdx = await mdxai.generate({
prompt: 'Create a product page for Widget Pro',
model: 'gpt-5',
type: 'Product',
})
console.log(mdx)Generate Content (Remote)
import { mdxai } from 'mdxai'
// Connect to platform
const agent = await mdxai.connect({
token: process.env.DO_TOKEN,
remote: 'platform.do',
})
// Generate and save to platform
await agent.generate({
prompt: 'Create a product page for Widget Pro',
collection: 'products',
type: 'Product',
})Augment Existing Content
import { mdxai } from 'mdxai'
// Local files
const enhanced = await mdxai.augment(mdxContent, {
addSEO: true,
addStructuredData: true,
addSchema: 'schema.org.ai/Product',
})
// Remote files
const agent = await mdxai.connect({
token: process.env.DO_TOKEN,
remote: 'platform.do',
})
await agent.enrich('products/*.mdx', {
addSEO: true,
addSchema: 'Product',
})CLI Commands
Agent Mode
Start the interactive AI agent:
# Start agent with access to content directory
mdxai agent ./content
# Agent with specific capabilities
mdxai agent ./content --can create,edit,organize
# Watch mode - maintains content automatically
mdxai agent ./content --watchIn agent mode, you can chat with the AI:
You: Create a blog post about GraphQL
Agent: I'll create a new blog post. What should I title it?
You: "Introduction to GraphQL"
Agent: Created blog/introduction-to-graphql.mdx
Added frontmatter with $type: BlogPost
Added SEO metadata
Would you like me to add related links?Create
Create new MDX files:
# Create from prompt
mdxai create "product page for Widget Pro" \
--type Product --output products/widget-pro.mdx
# Create from template
mdxai create --template blog-post \
--vars title="Getting Started",author="Jane" \
--output blog/getting-started.mdx
# Create multiple from list
mdxai create --batch products.csv --template productEdit
Modify existing MDX files:
# Edit specific file
mdxai edit blog/post.mdx "add a section about performance"
# Edit all files matching pattern
mdxai edit blog/*.mdx "add `published: true` to frontmatter"
# Interactive editing
mdxai edit blog/post.mdx --interactiveEnrich
Add metadata and structured data:
# Add SEO to all blog posts
mdxai enrich blog/*.mdx --seo
# Add structured data
mdxai enrich products/*.mdx --schema Product
# Add tags and categories
mdxai enrich docs/*.mdx --categorize --auto-tag
# Add relationships (backlinks, related content)
mdxai enrich ./content --relationshipsOrganize
Restructure and organize content:
# Auto-organize by type
mdxai organize ./content --by-type
# Auto-categorize
mdxai organize ./blog --categorize
# Rename files for consistency
mdxai organize ./content --rename-pattern "{slug}.mdx"
# Create index files
mdxai organize ./docs --create-indexesMaintain
Keep content up-to-date:
# Fix broken links
mdxai maintain ./content --fix-links
# Update dates and timestamps
mdxai maintain ./blog --update-dates
# Ensure all required frontmatter exists
mdxai maintain ./content --validate-frontmatter
# Update to latest ontology versions
mdxai maintain ./content --update-schemasAnalyze
Understand your content:
# Show content statistics
mdxai analyze ./content --stats
# Find orphaned documents
mdxai analyze ./content --orphans
# Show relationship graph
mdxai analyze ./content --graph
# Find duplicates
mdxai analyze ./content --duplicatesContent Generation
Articles and Blog Posts
const article = await mdxai.article({
topic: 'Getting Started with GraphQL',
keywords: ['graphql', 'api', 'tutorial'],
length: 'medium', // short, medium, long
tone: 'educational',
})Product Pages
const product = await mdxai.product({
name: 'Widget Pro',
features: ['Fast', 'Reliable', 'Scalable'],
benefits: ['Save time', 'Reduce costs'],
tone: 'professional',
})Documentation
const docs = await mdxai.documentation({
api: apiSpec,
sections: ['installation', 'usage', 'examples'],
includeCodeExamples: true,
})Service Definitions
const service = await mdxai.service({
name: 'email-sender',
type: 'Worker',
description: 'Cloudflare Worker for sending emails',
endpoints: ['/send', '/verify'],
})Content Augmentation
SEO Metadata
Add SEO-friendly metadata:
const withSEO = await mdxai.addSEO(mdxContent, {
generateDescription: true,
generateKeywords: true,
generateOgTags: true,
})Structured Data
Add schema.org structured data:
const withSchema = await mdxai.addSchema(mdxContent, {
type: 'Article',
includeAuthor: true,
includePublisher: true,
})Extract Key Points
Generate summaries and highlights:
const summary = await mdxai.summarize(mdxContent, {
maxLength: 200,
style: 'bullet-points',
})Generate Titles
Create compelling titles:
const titles = await mdxai.generateTitles(mdxContent, {
count: 5,
style: 'engaging',
})Batch Processing
Process multiple files:
import { mdxai } from 'mdxai'
import { glob } from 'glob'
// Get all blog posts
const files = await glob('./blog/**/*.mdx')
// Augment all posts
for (const file of files) {
const content = await fs.readFile(file, 'utf-8')
const enhanced = await mdxai.augment(content, {
addSEO: true,
addSchema: 'BlogPost',
})
await fs.writeFile(file, enhanced)
}Configuration
Create mdxai.config.ts:
import { defineConfig } from 'mdxai'
export default defineConfig({
// AI model settings
model: 'gpt-5',
temperature: 0.7,
maxTokens: 2000,
// Default options
defaults: {
addSEO: true,
addSchema: true,
tone: 'professional',
},
// Ontology settings
ontologies: [
'schema.org.ai',
'onet.org.ai',
'gs1.org.ai',
],
// Output settings
output: {
format: 'mdx',
indent: 2,
lineWidth: 80,
},
})Templates
Use built-in templates:
const templates = [
'blog-post',
'product-page',
'landing-page',
'documentation',
'api-reference',
'service-definition',
]
const content = await mdxai.fromTemplate('blog-post', {
title: 'My Blog Post',
author: 'Jane Developer',
date: '2025-10-27',
})Create custom templates:
mdxai.registerTemplate('custom', {
frontmatter: {
$type: 'CustomType',
required: ['title', 'author'],
},
sections: ['introduction', 'content', 'conclusion'],
components: ['Callout', 'CodeBlock'],
})Remote Workflows
Working with files on the .do platform:
Remote Content Management
# Login to platform
mdxai login
# Start agent with remote access
mdxai agent --remote platform.do
You: Show me all blog posts on the platform
Agent: Found 247 blog posts in platform.do/blog
Latest: "Introduction to GraphQL" (2025-10-27)
You: Update all blog posts to add author metadata
Agent: Analyzing 247 posts...
Added author metadata to 182 posts
35 posts already had authors
30 posts need manual reviewHybrid Local + Remote
# Work with both local and remote
mdxai agent ./content --remote platform.do
You: Sync my local blog posts to the platform
Agent: Comparing local ./content/blog with platform.do/blog
Local: 45 posts
Remote: 38 posts
New posts: 7
Modified posts: 3
Pushing changes...
✓ Synced 10 posts to platform.do
You: Pull latest products from platform
Agent: Pulling products from platform.do
Found 120 products
Creating local MDX files in ./content/products
✓ Downloaded 120 productsRemote Editing
# Edit remote files directly
mdxai agent --remote platform.do
You: Edit platform.do/blog/introduction.mdx
Agent: Opening blog/introduction.mdx from platform...
Current title: "Introduction"
You: Change title to "Getting Started Guide"
Agent: ✓ Updated title
✓ Updated slug: getting-started-guide
✓ Updated URL: /blog/getting-started-guide
✓ Saved to platform.doCross-Platform References
# Reference remote data in local files
mdxai agent ./content --remote platform.do
You: Create a blog post that references products from the platform
Agent: Creating blog post with product references...
✓ Created ./content/blog/product-review.mdx
✓ Added references to 5 products from platform.do
✓ Links will resolve when deployedAgent Workflows
Real-world examples of how MDXAI agent helps:
Content Creation Workflow
# Start agent in watch mode
mdxai agent ./content --watch
# In your terminal or via chat:
You: I need to create 10 blog posts about web development
Agent: I'll create a series of blog posts. Here are my suggestions:
1. Introduction to Web Development
2. HTML Fundamentals
...
Should I proceed?
You: Yes, use the blog-post template
Agent: Creating posts...
✓ Created blog/introduction-to-web-development.mdx
✓ Created blog/html-fundamentals.mdx
...
✓ Added cross-references between posts
✓ Created blog/index.mdx with all posts listedContent Maintenance Workflow
# Weekly maintenance
mdxai agent ./content
You: Check for content issues
Agent: Analyzing 247 MDX files...
Found 12 broken links
Found 8 files missing SEO metadata
Found 3 orphaned documents
Would you like me to fix these?
You: Fix the broken links and add SEO
Agent: ✓ Fixed 12 broken links
✓ Added SEO to 8 files
Issues resolved!Migration Workflow
# Migrate from WordPress
mdxai agent ./content
You: Import posts from wordpress-export.xml
Agent: Found 150 posts in export file
Converting to MDX...
✓ Converted 150 posts
✓ Organized into categories
✓ Added $type and $id to all posts
✓ Extracted and converted images
✓ Created category index files
Done! Review in ./content/blogDocumentation Workflow
# Generate docs from code
mdxai agent ./docs
You: Generate API docs from ./src
Agent: Analyzing TypeScript files...
Found 45 exported functions
Found 23 types
Creating documentation...
✓ Created docs/api/functions/
✓ Created docs/api/types/
✓ Added code examples
✓ Generated docs/api/index.mdxSEO Enrichment Workflow
# Optimize existing content
mdxai agent ./content
You: Optimize all pages for SEO
Agent: Analyzing 89 pages...
Adding meta descriptions based on content
Adding OpenGraph tags
Adding structured data (schema.org)
✓ Enriched 89 pages
Preview: blog/introduction.mdx now has:
- Meta description (158 chars)
- OG image and tags
- Article structured dataContent Organization Workflow
# Clean up messy content directory
mdxai agent ./content
You: My content is disorganized. Can you help?
Agent: I'll analyze and organize your content...
Found:
- 50 blog posts (mixed locations)
- 30 products (inconsistent naming)
- 15 docs (no clear structure)
Suggested structure:
./blog/YYYY/MM/slug.mdx
./products/category/slug.mdx
./docs/section/topic.mdx
Should I proceed?
You: Yes
Agent: ✓ Moved 50 blog posts to blog/YYYY/MM/
✓ Organized 30 products by category
✓ Structured 15 docs by section
✓ Created index files for navigation
✓ Updated all internal links