Installation
Content Details
Alternatives
Installation
{
"mcpServers": {
"apostrophe-generator": {
"command": "node",
"args": ["/absolute/path/to/apostrophe-code-generator/mcp-server/index.js"],
"env": {},
"description": "Apostrophe CMS code generation tools"
}
}
}๐ Apostrophe Code Generator
The Apostrophe Code Generator is an AI - powered web - based tool. It leverages Claude AI and MCP (Model Context Protocol) architecture to generate production - ready Apostrophe CMS modules. This tool simplifies the process of creating pieces, pages, widgets, and complete bundles, and it can even generate SCSS using your project's design tokens.
๐ Quick Start
# 1. Ensure prerequisites are installed
node --version # Must be >= 18
claude --version # Must have Claude Code CLI
# 2. Install
./install.sh # Linux/macOS
# OR manually:
npm install && cd mcp-server && npm install
# 3. Run
npm start
# 4. Open browser
# http://localhost:3031
That's it! Select a project, choose module type, configure, generate.
โจ Features
- Piece Generator: Create content types stored in the database.
- Page Generator: Generate page types with content areas and piece relationships.
- Widget Generator: Create reusable UI components with relationship patterns.
- Bundle Generator: Generate complete feature sets (piece + page + widget) in one go.
- Design Token Extraction: Automatically extracts and uses your project's design tokens for SCSS.
- BEM Methodology: Optional SCSS generation following BEM naming conventions (experimental).
- Auto - Registration: Automatically registers generated modules in your project's
modules.js. - SCSS Integration: Creates and imports SCSS files automatically.
- Generation History: Browse and re - use previously generated modules.
โ ๏ธ Important Note
CSS/SCSS generation is experimental. Results may vary depending on project complexity and design token availability. Always review generated styles before deploying to production.
๐ฆ Installation
Quick Install (Recommended)
# Clone or download the repository
cd /path/to/apostrophe-code-generator
# Run the install script
./install.sh
The install script will:
- Check for Node.js and npm.
- Install main application dependencies.
- Install MCP server dependencies.
- Optionally configure Claude Code integration.
Manual Installation
If you prefer to install manually:
# Navigate to the project directory
cd /path/to/apostrophe-code-generator
# Install main dependencies
npm install
# Install MCP server dependencies
cd mcp-server
npm install
cd ..
๐ป Usage Examples
Starting the Application
# From the project root directory
npm start
# Or for development with auto-reload
npm run dev
The server will start on http://localhost:3031
Using the Web Interface
- Open your browser and navigate to
http://localhost:3031. - Select a Project: Choose an Apostrophe project from the dropdown. Projects are automatically discovered from the parent directory.
- Choose Module Type: Select what you want to generate:
- Piece: Content type stored in the database.
- Page: Page type with content areas.
- Widget: Reusable UI component.
- Bundle: Complete feature set (piece + page + widget).
- Configure Options: Fill in the module details:
- Module name.
- Description.
- Fields and relationships.
- Styling options (BEM, design tokens).
- Generate: Click "Generate Code" and watch the AI create your module.
- Save to Project: Review the generated code and save it directly to your project.
Generation History
All generated modules are saved to the history. You can:
- View previously generated modules.
- Re - generate with modified settings.
- Copy code to clipboard.
- Delete from history.
๐ง Technical Details
Prerequisites
Before installing, ensure you have the following:
Required
| Property | Details |
|---|---|
| Node.js | >= 18.x. JavaScript runtime. |
| npm | >= 9.x. Node package manager (comes with Node.js). |
| Claude Code | Latest. Anthropic's CLI for AI - powered code generation. |
Installing Claude Code
Claude Code is required for the AI - powered code generation. The application calls the claude CLI directly to generate Apostrophe modules.
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Configure with your Anthropic API key
claude configure
You'll need an Anthropic API key. Get one at: https://console.anthropic.com/
To verify Claude Code is installed correctly:
claude --version
ESM (ES Modules) Requirement
Important: This tool generates code using ES Module syntax (export default) rather than CommonJS (module.exports). Your Apostrophe project must be configured for ESM.
Ensure your project's package.json contains:
{
"type": "module"
}
Generated code syntax:
// โ
This tool generates (ESM):
export default {
extend: '@apostrophecms/widget-type',
fields: { ... }
};
// โ NOT CommonJS:
module.exports = {
extend: '@apostrophecms/widget-type',
fields: { ... }
};
If your project uses CommonJS, you'll need to either:
- Convert to ESM (recommended for Apostrophe 3.x/4.x).
- Manually convert generated
export defaulttomodule.exports.
Apostrophe CMS Projects
The tool automatically discovers Apostrophe CMS projects in the parent directory. A folder is recognized as an Apostrophe project if it contains an app.js file with a shortName property.
Example directory structure:
/projects/ # Parent directory
โโโ apostrophe-code-generator/ # This tool
โโโ my-apostrophe-site/ # โ Discovered (has app.js with shortName)
โโโ another-apostrophe-project/ # โ Discovered
โโโ some-other-folder/ # โ Ignored (no app.js with shortName)
Advanced: Direct Claude Code MCP Integration
โ ๏ธ Important Note
This section is optional. The web UI at
localhost:3031is the primary way to use this tool. This MCP integration is only for advanced users who want to call the generator directly from Claude Code CLI without using the web interface.
Why Use This?
If you're already working in a Claude Code session on your Apostrophe project, you can generate modules directly by asking Claude Code to use the generator tools - no need to switch to the browser.
Example: In Claude Code, you could say:
"Use the apostrophe - generator to create a widget called news - feed for my - project"
Configuration
- Locate your Claude Code settings file:
- Linux/macOS:
~/.claude/settings.json. - Windows:
%USERPROFILE%\.claude\settings.json.
- Linux/macOS:
- Add the MCP server configuration:
{
"mcpServers": {
"apostrophe-generator": {
"command": "node",
"args": ["/absolute/path/to/apostrophe-code-generator/mcp-server/index.js"],
"env": {},
"description": "Apostrophe CMS code generation tools"
}
}
}
Replace /absolute/path/to/ with the actual path to your installation.
3. Restart Claude Code to load the new MCP server.
Available MCP Tools
Once configured, the following tools are available in Claude Code:
| Tool | Description |
|---|---|
list_apostrophe_projects |
List all discovered Apostrophe projects. |
generate_piece |
Generate a piece module. |
generate_page |
Generate a page module. |
generate_widget |
Generate a widget module. |
generate_bundle |
Generate a complete bundle. |
save_generated_code |
Save generated code to project. |
Generated Module Structure
Piece Module
Pieces are content types stored in the database (like articles, products, team members).
Generated Files:
modules/pieces/{piece-name}/
โโโ index.js # Schema definition with fields
No templates - Pieces are data - only; they're displayed through piece - pages or widgets.
index.js Structure:
export default {
extend: '@apostrophecms/piece-type',
options: {
label: 'Piece Name',
pluralLabel: 'Piece Names',
seoFields: false,
openGraph: false
},
fields: {
add: {
// Custom fields defined here
description: { type: 'string', label: 'Description' },
featuredImage: {
type: 'area',
label: 'Featured Image',
options: {
widgets: { '@apostrophecms/image': {} }
}
}
},
group: {
basics: {
label: 'Basics',
fields: ['title', 'description', 'featuredImage']
}
}
}
};
Page Module
Pages are URL - routable content that can display pieces (piece - pages) or standalone content.
Generated Files:
modules/pages/{page-name}/
โโโ index.js # Schema definition
โโโ views/
โโโ index.html # List view (for piece - pages)
โโโ show.html # Detail view (for piece - pages)
For standalone pages, only page.html is generated instead of index/show.
index.js Structure:
export default {
extend: '@apostrophecms/piece-page-type', // or '@apostrophecms/page-type'
options: {
label: 'Page Name',
pieceModuleName: 'piece-name' // For piece - pages only
},
fields: {
add: {
// Page - specific fields
},
group: {
// Field groups
}
}
};
Widget Module
Widgets are reusable UI components that can be placed in content areas.
Generated Files:
modules/widgets/{widget-name}-widget/
โโโ index.js # Schema definition
โโโ views/
โโโ widget.html # Widget template
Note: Widget folder names always end with -widget suffix.
index.js Structure:
export default {
extend: '@apostrophecms/widget-type',
fields: {
add: {
heading: { type: 'string', label: 'Heading' },
content: {
type: 'area',
label: 'Content',
options: {
widgets: {
'@apostrophecms/rich-text': {},
'@apostrophecms/image': {}
}
}
}
},
group: {
basics: {
label: 'Basics',
fields: ['heading', 'content']
}
}
}
};
widget.html Template:
<div class="widget-name-widget" data-widget-name-widget>
<h2>{{ data.widget.heading }}</h2>
{% area data.widget, 'content' %}
</div>
Bundle Module
Bundles generate a complete feature set: piece + piece - page + widget in one operation.
Generated Files:
modules/
โโโ pieces/{name}/
โ โโโ index.js
โโโ pages/{name}-page/
โ โโโ index.js
โ โโโ views/
โ โโโ index.html
โ โโโ show.html
โโโ widgets/{name}-widget/
โโโ index.js
โโโ views/
โโโ widget.html
Bundle Relationships:
- The widget automatically includes a
_piecesrelationship field to reference the piece. - The page is configured as a piece - page for the piece type.
SCSS Generation (Optional)
When BEM Styles is enabled, additional SCSS files are generated.
Generated SCSS Files
modules/asset/ui/src/scss/
โโโ components/
โ โโโ _{widget-name}.scss # For widgets
โโโ pages/
โโโ _{page-name}.scss # For pages
SCSS Features
- BEM Methodology: Block - Element - Modifier naming convention.
- Design Token Integration: Uses your project's existing design tokens (colors, spacing, typography).
- Auto - Import: SCSS files are automatically imported into your main stylesheet.
Example Generated SCSS:
// _news-widget.scss
.news-widget {
padding: $spacing-lg;
background-color: $color-background;
&__heading {
font-size: $font-size-xl;
color: $color-text-primary;
margin-bottom: $spacing-md;
}
&__content {
line-height: $line-height-relaxed;
}
&__item {
border-bottom: 1px solid $color-border;
padding: $spacing-md 0;
&:last-child {
border-bottom: none;
}
}
}
Design Token Extraction
The generator automatically scans your project for design tokens in:
modules/asset/ui/src/scss/_settings.scss.modules/asset/ui/src/scss/_variables.scss.- Any file matching
*variables*or*tokens*pattern.
Extracted token types:
- Colors (
$color-*). - Spacing (
$spacing-*). - Typography (
$font-*,$line-height-*). - Breakpoints (
$breakpoint-*).
Auto - Registration
Generated modules are automatically registered in your project's modules.js file.
What Gets Added
// modules.js
module.exports = {
// ... existing modules ...
// Auto - added by Code Generator:
'news': {}, // Piece
'news-page': {}, // Page
'news-widget': {}, // Widget
};
SCSS Import
If SCSS is generated, an import statement is added to your main stylesheet:
// In _components.scss or main.scss
@import 'components/_news-widget';
History Storage
All generated modules are saved to the history/ folder for reference and re - use.
History Folder Structure
history/
โโโ 2025-11-18_14-30-45_news-widget/
โโโ metadata.json
โโโ modules/
โโโ widgets/
โโโ news-widget/
โโโ index.js
โโโ views/
โโโ widget.html
Metadata Format
{
"moduleName": "news-widget",
"moduleType": "widget",
"projectName": "my-apostrophe-project",
"fileCount": 2,
"fullDesign": false,
"description": "A widget to display latest news items",
"timestamp": "2025-11-18T14:30:45.123Z"
}
History Features
- View: Browse previously generated modules.
- Re - generate: Use previous settings as a starting point.
- Copy: Copy code directly to clipboard.
- Delete: Remove entries from history (does not affect saved project files).
API Endpoints
The Express server exposes these endpoints:
| Endpoint | Method | Description |
|---|---|---|
/api/projects |
GET | List discovered Apostrophe projects. |
/api/generate |
POST | Generate a module. |
/api/save |
POST | Save generated files to project. |
/api/delete |
POST | Delete saved files from project. |
/api/history |
GET | List generation history. |
/api/history/:id |
GET | Get specific history entry. |
/api/history/:id |
DELETE | Delete history entry. |
Generate Request Format
{
"projectId": "my-project",
"type": "widget",
"name": "news",
"label": "News Widget",
"description": "Display latest news with images and summaries",
"includeBemStyles": true,
"fullDesign": false
}
Generate Response Format
{
"success": true,
"files": [
{
"path": "modules/widgets/news-widget/index.js",
"content": "export default { ... }"
},
{
"path": "modules/widgets/news-widget/views/widget.html",
"content": "<div class=\"news-widget\">...</div>"
}
],
"registrationNote": "Module registered in modules.js",
"historyId": "2025-11-18_14-30-45_news-widget"
}
Field Types Reference
Available field types for module schemas:
| Type | Description | Example |
|---|---|---|
string |
Single - line text | { type: 'string', label: 'Title' } |
area |
Rich content area | { type: 'area', options: { widgets: {...} } } |
boolean |
Checkbox (true/false) | { type: 'boolean', label: 'Featured' } |
select |
Dropdown menu | { type: 'select', choices: [...] } |
checkboxes |
Multiple selection | { type: 'checkboxes', choices: [...] } |
relationship |
Link to other pieces | { type: 'relationship', withType: 'article' } |
array |
Repeating field group | { type: 'array', fields: { add: {...} } } |
date |
Date picker | { type: 'date', label: 'Publish Date' } |
time |
Time picker | { type: 'time', label: 'Event Time' } |
url |
URL input | { type: 'url', label: 'Website' } |
email |
Email input | { type: 'email', label: 'Contact Email' } |
integer |
Whole number | { type: 'integer', label: 'Quantity' } |
float |
Decimal number | { type: 'float', label: 'Price' } |
slug |
URL - safe string | { type: 'slug', following: 'title' } |
color |
Color picker | { type: 'color', label: 'Background Color' } |
range |
Slider input | { type: 'range', min: 0, max: 100 } |
attachment |
File upload | { type: 'attachment', label: 'Document' } |
Reserved Field Names
Never use these names - they are reserved by Apostrophe:
type,_id,slug,published,archivedtrash,visibility,createdAt,updatedAtmetaType,aposMode,aposLocale
Alternatives:
- Instead of
typeโ usecategory,kind,itemType. - Instead of
statusโ usecurrentStatus,statusLabel.
Project Structure
apostrophe-code-generator/
โโโ server/ # Express server
โ โโโ index.js # Main server entry point
โ โโโ mcp-client.js # MCP client for AI generation
โ โโโ apostrophe-docs/ # Apostrophe documentation & patterns
โโโ mcp-server/ # MCP server for Claude Code
โ โโโ index.js # MCP server entry point
โ โโโ generator.js # Code generation logic
โ โโโ design-token-parser.js # Design token extraction
โ โโโ package.json # MCP server dependencies
โ โโโ mcp-config.json # Example MCP configuration
โโโ public/ # Web UI
โ โโโ index.html # Main wizard interface
โ โโโ css/ # Stylesheets
โ โโโ js/ # Client - side JavaScript
โโโ docs/ # Documentation
โโโ history/ # Generated module history
โโโ install.sh # Installation script
โโโ package.json # Main dependencies
โโโ README.md # This file
Configuration
Server Port
The default port is 3031. To change it, set the PORT environment variable:
PORT=8080 npm start
Project Discovery
By default, the tool looks for Apostrophe projects in the parent directory. This behavior is automatic and requires no configuration.
Troubleshooting
Common Issues
"Cannot find module '@modelcontextprotocol/sdk'"
The MCP server dependencies are not installed. Run:
cd mcp-server
npm install
"No projects found"
Ensure your Apostrophe projects are in the parent directory and contain an app.js file with a shortName property:
// app.js
module.exports = require('apostrophe')({
shortName: 'my-project',
// ...
});
"Claude API timeout" or generation fails
- Ensure Claude Code is installed:
claude --version. - Ensure Claude Code is configured:
claude configure. - Check your Anthropic API key is valid.
- Try a simpler module description.
- Check your internet connection.
"MCP server failed"
- Check that the MCP server path in your Claude settings is correct.
- Ensure all dependencies are installed.
- Check the Node.js version (>= 18 required).
Port already in use
Another application is using port 3031. Either:
- Stop the other application.
- Use a different port:
PORT=3032 npm start.
Getting Help
If you encounter issues:
- Check the browser console for errors.
- Check the terminal for server - side errors.
- Ensure all prerequisites are met.
- Verify project structure matches expected format.
Architecture
Components
- Express Server (
server/index.js):- Serves the web UI.
- Handles API requests.
- Manages project discovery.
- Communicates with MCP server.
- MCP Server (
mcp-server/index.js):- Provides AI - powered code generation.
- Integrates with Claude AI.
- Exposes tools for Claude Code integration.
- Web UI (
public/):- Wizard - style interface.
- Real - time generation progress.
- History management.
Data Flow
User Input โ Express Server โ MCP Server โ Claude AI
โ
User โ Web UI โ Express Server โ Generated Code
Development
Running in Development Mode
npm run dev
This starts the server with auto - reload on file changes.
Building Tailwind CSS
If you modify the styles:
./tailwindcss-linux-x64 -i public/css/input.css -o public/css/styles.css --watch
Windows Installation
The install.sh script is for Linux/macOS. Windows users should install manually:
Using Command Prompt
cd path\to\apostrophe-code-generator
:: Install main dependencies
npm install
:: Install MCP server dependencies
cd mcp-server
npm install
cd ..
:: Start the server
npm start
Using PowerShell
cd path\to\apostrophe-code-generator
# Install main dependencies
npm install
# Install MCP server dependencies
cd mcp-server
npm install
cd ..
# Start the server
npm start
Windows Prerequisites
- Node.js: Download from https://nodejs.org/ (v18+).
- Claude Code:
npm install -g @anthropic-ai/claude-code. - Configure Claude:
claude configure.
Compatibility
Apostrophe CMS Versions
| Apostrophe Version | Supported |
|---|---|
| 4.x (A4) | โ Yes |
| 3.x (A3) | โ Yes |
| 2.x (A2) | โ No |
This tool generates code for Apostrophe 3.x and 4.x. The module structure, field types, and template syntax are compatible with both A3 and A4.
Node.js Versions
| Node.js Version | Supported |
|---|---|
| 22.x | โ Yes |
| 20.x | โ Yes |
| 18.x | โ Yes |
| 16.x and below | โ No |
Operating Systems
| OS | Supported |
|---|---|
| Linux | โ Yes |
| macOS | โ Yes |
| Windows 10/11 | โ Yes |
| WSL/WSL2 | โ Yes |
Known Limitations
SCSS Generation (Experimental)
- SCSS generation works best when your project has well - defined design tokens.
- Generated SCSS may contain undefined variables if tokens don't exist in your project.
- Always review generated SCSS before compiling.
- Complex layouts may require manual adjustment.
AI Generation
- Results depend on the quality of your description.
- Very complex modules may require multiple generations or manual editing.
- Generation time varies (typically 10 - 60 seconds depending on complexity).
- Occasional JSON parsing errors may require retry.
Project Discovery
- Only discovers projects in the parent directory.
- Projects must have
app.jswithshortNameproperty. - Symlinked projects may not be discovered.
Bundle Generation
- Bundles generate 3 modules at once - this can take longer.
- All 3 modules share the same base name.
- Cannot customize individual module names within a bundle.
FAQ
General
โ ๏ธ Important Note
Q: Do I need an Anthropic API key? A: Yes. Claude Code requires an API key from https://console.anthropic.com/.
๐ก Usage Tip
Q: How much does it cost to use? A: The tool itself is free. You pay for Claude API usage through your Anthropic account. Each generation typically uses 1,000 - 5,000 tokens.
โ ๏ธ Important Note
Q: Can I use this offline? A: No. The tool requires internet access to communicate with Claude AI.
Projects
โ ๏ธ Important Note
Q: Why doesn't my project appear in the dropdown? A: Ensure your project:
- Is in the parent directory of this tool.
- Has an
app.jsfile.- Contains
shortName: 'your - project'in app.js.
๐ก Usage Tip
Q: Can I change the project discovery location? A: Currently no. Projects must be in the parent directory. This may be configurable in a future version.
Generation
โ ๏ธ Important Note
Q: The generated code has errors. What do I do? A: Try:
- Simplify your description.
- Generate again (AI responses vary).
- Manually edit the generated code.
- Check for reserved field names.
๐ก Usage Tip
Q: Can I edit the generated code before saving? A: Not in the UI currently. Generate, save, then edit in your IDE.
๐ก Usage Tip
Q: How do I regenerate a module? A: Use the History feature to view previous generations and regenerate with modified settings.
Styling
โ ๏ธ Important Note
Q: The SCSS has undefined variables. Why? A: The generator uses your project's design tokens. If a token doesn't exist, the variable will be undefined. Replace with actual values or add the tokens to your project.
๐ก Usage Tip
Q: Can I disable SCSS generation? A: Yes. Uncheck "Include BEM Styles" when configuring your module.
๐ License
MIT License - see LICENSE file for details.
Credits
Created by: Andrei Mateas For: GLOOBUS A - Team
Built with Claude AI & MCP (Model Context Protocol)
Changelog
v1.0.0
- Initial release.
- Piece, Page, Widget, and Bundle generators.
- Design token extraction.
- BEM SCSS generation (experimental).
- Generation history.
- Claude Code MCP integration.
Alternatives








