Skip to content

Commit eea3b28

Browse files
jonradoffclaude
andcommitted
Add LIGHTCMS_CONFIG_DIR support for MCP server setup
- Add LIGHTCMS_CONFIG_DIR env var to config loader for custom config paths - Add portable wrapper script for MCP server registration - Update README with MCP setup documentation - Remove site-specific migrate_theme.sh script Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5a29c79 commit eea3b28

File tree

5 files changed

+119
-74
lines changed

5 files changed

+119
-74
lines changed

CLAUDE.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ LightCMS is a lightweight, self-hosted content management system built in Go. It
1111

1212
## MCP Server Integration
1313

14-
**IMPORTANT:** When the user asks about changing website content, templates, themes, assets, or site configuration, prefer using the LightCMS MCP server tools instead of making code changes. The MCP server provides 38 tools for content management operations.
14+
**IMPORTANT:** All website content operations MUST go through the MCP server. Do NOT:
15+
- Write scripts to directly modify the database
16+
- Use Go code to create/edit/delete content
17+
- Bypass the MCP server for any content management tasks
1518

16-
### When to Use MCP Server:
19+
If the MCP server is not available or not working, ASK the user for permission before attempting any content changes through other means.
20+
21+
### Content Operations (REQUIRE MCP or explicit user permission):
1722
- Creating, editing, publishing, or deleting content
1823
- Managing templates and their HTML layouts
1924
- Uploading or managing assets (images, CSS, JS, documents)
@@ -22,14 +27,36 @@ LightCMS is a lightweight, self-hosted content management system built in Go. It
2227
- Viewing or reverting content versions
2328
- Site configuration changes
2429

25-
### When to Make Code Changes:
30+
### Code Changes (allowed without MCP):
2631
- Adding new features to LightCMS itself
2732
- Fixing bugs in the application
2833
- Changing application behavior or logic
2934
- Adding new MCP tools
3035
- Modifying database schemas or indexes
3136
- Security improvements
3237

38+
### Setting Up MCP with Claude Code
39+
40+
To use LightCMS with Claude Code, register the MCP server:
41+
42+
```bash
43+
# Build the MCP server first
44+
go build -o bin/lightcms-mcp ./cmd/mcp
45+
46+
# Register with Claude Code
47+
claude mcp add --transport stdio lightcms-mcp -- /path/to/lightcms/bin/lightcms-mcp
48+
```
49+
50+
After registering, restart Claude Code. You can verify the server is connected:
51+
- Run `/mcp` in Claude Code to check status
52+
- Run `claude mcp list` in terminal to see registered servers
53+
54+
Once connected, you can ask Claude to manage your content naturally:
55+
- "Create a new blog post about AI"
56+
- "List all my published content"
57+
- "Update the homepage hero image"
58+
- "Delete the /random page"
59+
3360
### MCP Server Location
3461
Binary: `bin/lightcms-mcp`
3562
Config: Uses same `config.dev.json` or environment variables as main server

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,68 @@ Fields: headline, subheadline, dateline, release_date, body, boilerplate, contac
215215
### Explanatory Page
216216
Fields: title, subtitle, hero_image, intro, main_content, sidebar, cta_text, cta_link
217217

218+
## Using with Claude Code (AI-Powered Content Management)
219+
220+
LightCMS includes an MCP (Model Context Protocol) server that allows you to manage your website content using Claude Code. Instead of navigating the admin UI, you can simply ask Claude to create pages, update content, manage assets, and more.
221+
222+
### Setup
223+
224+
1. Build the MCP server:
225+
```bash
226+
go build -o bin/lightcms-mcp ./cmd/mcp
227+
```
228+
229+
2. Register the MCP server with Claude Code using the wrapper script:
230+
```bash
231+
claude mcp add --transport stdio lightcms-mcp -- /path/to/lightcms/lightcms-mcp-wrapper.sh
232+
```
233+
234+
The wrapper script automatically sets `LIGHTCMS_CONFIG_DIR` so the MCP server can find your config files regardless of where Claude Code runs from.
235+
236+
3. Restart Claude Code (or start a new session)
237+
238+
4. Verify the connection by running `/mcp` in Claude Code
239+
240+
### Alternative: Environment Variables
241+
242+
Instead of using config files, you can configure via environment variables:
243+
244+
```bash
245+
claude mcp add --transport stdio lightcms-mcp \
246+
-e MONGO_URI="mongodb+srv://..." \
247+
-e SESSION_SECRET="your-secret" \
248+
-- /path/to/lightcms/bin/lightcms-mcp
249+
```
250+
251+
### Configuration Options
252+
253+
The MCP server supports these environment variables:
254+
- `LIGHTCMS_CONFIG_DIR` - Directory containing config.dev.json or config.prod.json
255+
- `MONGO_URI` - MongoDB connection string (bypasses config files)
256+
- `SESSION_SECRET` - Session encryption key (required with MONGO_URI)
257+
- `BASE_URL` - Public site URL (optional)
258+
259+
### Example Commands
260+
261+
Once connected, you can manage your site with natural language:
262+
263+
- "Create a new blog post about machine learning"
264+
- "List all my draft content"
265+
- "Update the homepage title to 'Welcome to My Site'"
266+
- "Delete the /old-page content"
267+
- "Show me all templates"
268+
- "Upload an image for my latest blog post"
269+
- "Change the site's primary color to blue"
270+
271+
### Available Tools
272+
273+
The MCP server provides 38 tools for complete content management:
274+
275+
- **Content**: Create, read, update, delete, publish, unpublish, versioning
276+
- **Templates**: Manage content templates and their fields
277+
- **Assets**: Upload and manage images, documents, and other files
278+
- **Settings**: Theme customization, redirects, folders, collections
279+
218280
## Development
219281

220282
```bash

config/config.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func DefaultProd() *Config {
4343

4444
// Load loads configuration from JSON config file or environment variables
4545
// Priority: environment variables > config.prod.json > config.dev.json
46+
// Set LIGHTCMS_CONFIG_DIR to specify a custom config directory
4647
func Load() (*Config, error) {
4748
// Check if running with environment variables (e.g., Fly.io)
4849
if mongoURI := os.Getenv("MONGO_URI"); mongoURI != "" {
@@ -53,15 +54,24 @@ func Load() (*Config, error) {
5354
var configPath string
5455
var cfg *Config
5556

57+
// Check for custom config directory
58+
configDir := os.Getenv("LIGHTCMS_CONFIG_DIR")
59+
if configDir == "" {
60+
configDir = "."
61+
}
62+
5663
// Check for production config first
57-
if _, err := os.Stat("config.prod.json"); err == nil {
58-
configPath = "config.prod.json"
64+
prodPath := filepath.Join(configDir, "config.prod.json")
65+
devPath := filepath.Join(configDir, "config.dev.json")
66+
67+
if _, err := os.Stat(prodPath); err == nil {
68+
configPath = prodPath
5969
cfg = DefaultProd()
60-
} else if _, err := os.Stat("config.dev.json"); err == nil {
61-
configPath = "config.dev.json"
70+
} else if _, err := os.Stat(devPath); err == nil {
71+
configPath = devPath
6272
cfg = DefaultDev()
6373
} else {
64-
return nil, fmt.Errorf("no config file found (expected config.dev.json or config.prod.json)")
74+
return nil, fmt.Errorf("no config file found (expected config.dev.json or config.prod.json in %s)", configDir)
6575
}
6676

6777
if err := loadFromFile(configPath, cfg); err != nil {

lightcms-mcp-wrapper.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Wrapper script for lightcms-mcp that sets the config directory
3+
# This allows the MCP server to find config files regardless of working directory
4+
5+
# Get the directory where this script is located (lightcms root)
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
8+
# Export the config directory so the MCP server can find config files
9+
export LIGHTCMS_CONFIG_DIR="$SCRIPT_DIR"
10+
11+
# Run the MCP server from bin/
12+
exec "$SCRIPT_DIR/bin/lightcms-mcp" "$@"

migrate_theme.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)