myaidev-method 0.0.5 โ†’ 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -78,11 +78,12 @@ program
78
78
  console.log(chalk.blue('\n๐Ÿ”Œ Add WordPress integration (optional):'));
79
79
  console.log(chalk.gray(' โ€ข Run /myai-configure wordpress for guided setup'));
80
80
  console.log(chalk.gray(' โ€ข Publish content with /myai-wordpress-publish filename.md'));
81
- console.log(chalk.gray(' โ€ข Check WORDPRESS_INTEGRATION.md for detailed workflow guide'));
81
+ console.log(chalk.gray(' โ€ข Supports both Classic and Gutenberg block editors'));
82
82
 
83
83
  console.log(chalk.magenta('\n๐Ÿ“š Need help?'));
84
84
  console.log(chalk.gray(' โ€ข Check USER_GUIDE.md for detailed instructions'));
85
85
  console.log(chalk.gray(' โ€ข Visit: https://github.com/myaione/myaidev-method'));
86
+ console.log(chalk.gray(' โ€ข WordPress docs: GitHub repo > docs/'));
86
87
  }
87
88
  console.log(chalk.cyan(`\n๐Ÿ”„ Restart ${cliType} to load your new AI-powered commands!`));
88
89
 
@@ -200,38 +201,33 @@ DEFAULT_TONE=professional
200
201
  const mcpDir = path.join(claudeDir, 'mcp');
201
202
  await fs.ensureDir(mcpDir);
202
203
 
203
- const wordpressMcpServer = path.join(__dirname, '..', 'src', 'mcp', 'wordpress-integration.js');
204
+ const wordpressMcpServer = path.join(__dirname, '..', '.claude', 'mcp', 'wordpress-server.js');
204
205
  if (await fs.pathExists(wordpressMcpServer)) {
205
206
  await fs.copy(wordpressMcpServer, path.join(mcpDir, 'wordpress-server.js'));
206
207
  }
207
208
 
208
209
  // Copy Gutenberg converter
209
- const gutenbergConverter = path.join(__dirname, '..', 'src', 'mcp', 'gutenberg-converter.js');
210
+ const gutenbergConverter = path.join(__dirname, '..', '.claude', 'mcp', 'gutenberg-converter.js');
210
211
  if (await fs.pathExists(gutenbergConverter)) {
211
212
  await fs.copy(gutenbergConverter, path.join(mcpDir, 'gutenberg-converter.js'));
212
213
  }
213
214
 
214
- // Copy USER_GUIDE.md
215
+ // Copy scripts directory
216
+ const scriptsTemplateDir = path.join(__dirname, '..', 'src', 'templates', 'scripts');
217
+ const scriptsDestDir = path.join(projectDir, 'scripts');
218
+
219
+ if (await fs.pathExists(scriptsTemplateDir)) {
220
+ await fs.copy(scriptsTemplateDir, scriptsDestDir);
221
+ }
222
+
223
+ // Copy USER_GUIDE.md - Essential for users to understand customization
215
224
  const userGuide = path.join(__dirname, '..', 'USER_GUIDE.md');
216
225
  if (await fs.pathExists(userGuide)) {
217
226
  await fs.copy(userGuide, path.join(projectDir, 'USER_GUIDE.md'));
218
227
  }
219
228
 
220
- // Copy WordPress documentation
221
- const wordpressIntegrationDoc = path.join(__dirname, '..', 'src', 'templates', 'docs', 'WORDPRESS_INTEGRATION.md');
222
- if (await fs.pathExists(wordpressIntegrationDoc)) {
223
- await fs.copy(wordpressIntegrationDoc, path.join(projectDir, 'WORDPRESS_INTEGRATION.md'));
224
- }
225
-
226
- const wordpressExamplesDoc = path.join(__dirname, '..', 'src', 'templates', 'docs', 'wordpress-api-examples.md');
227
- if (await fs.pathExists(wordpressExamplesDoc)) {
228
- await fs.copy(wordpressExamplesDoc, path.join(projectDir, 'wordpress-api-examples.md'));
229
- }
230
-
231
- const wordpressTroubleshoot = path.join(__dirname, '..', 'src', 'templates', 'docs', 'wordpress-troubleshoot.js');
232
- if (await fs.pathExists(wordpressTroubleshoot)) {
233
- await fs.copy(wordpressTroubleshoot, path.join(projectDir, 'wordpress-troubleshoot.js'));
234
- }
229
+ // Note: WORDPRESS_INTEGRATION.md could be helpful, but keeping docs minimal
230
+ // Users can find detailed docs on GitHub if needed
235
231
  }
236
232
 
237
233
  async function setupGemini(projectDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myaidev-method",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "AI CLI tools package with custom subagents and MCP integrations for Claude Code, Gemini CLI, and more",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -31,16 +31,17 @@
31
31
  "license": "MIT",
32
32
  "type": "module",
33
33
  "dependencies": {
34
- "commander": "^12.0.0",
34
+ "@modelcontextprotocol/sdk": "^1.18.0",
35
35
  "chalk": "^5.3.0",
36
+ "commander": "^12.0.0",
37
+ "dotenv": "^16.4.1",
36
38
  "fs-extra": "^11.2.0",
37
39
  "inquirer": "^9.2.15",
38
- "ora": "^8.0.1",
39
40
  "node-fetch": "^3.3.2",
40
- "dotenv": "^16.4.1",
41
- "ssh2": "^1.15.0"
41
+ "ora": "^8.0.1",
42
+ "ssh2": "^1.15.0",
43
+ "zod": "^3.23.8"
42
44
  },
43
- "devDependencies": {},
44
45
  "repository": {
45
46
  "type": "git",
46
47
  "url": "git+https://github.com/myaione/myaidev-method.git"
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import dotenv from 'dotenv';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ /**
12
+ * Configure WordPress MCP integration for Claude Code
13
+ * This script creates the .mcp.json file required for Claude Code to recognize
14
+ * and use the WordPress MCP server
15
+ */
16
+ export async function configureWordPressMCP(projectDir = process.cwd()) {
17
+ try {
18
+ console.log('๐Ÿ”ง Configuring WordPress MCP integration...');
19
+
20
+ // Load environment variables from .env file
21
+ const envPath = path.join(projectDir, '.env');
22
+ if (!fs.existsSync(envPath)) {
23
+ throw new Error('.env file not found. Please run WordPress configuration first.');
24
+ }
25
+
26
+ dotenv.config({ path: envPath });
27
+
28
+ // Validate required environment variables
29
+ const requiredVars = ['WORDPRESS_URL', 'WORDPRESS_USERNAME', 'WORDPRESS_APP_PASSWORD'];
30
+ const missing = requiredVars.filter(varName => !process.env[varName]);
31
+
32
+ if (missing.length > 0) {
33
+ throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
34
+ }
35
+
36
+ // Check if MCP server files exist
37
+ const mcpServerPath = path.join(projectDir, '.claude/mcp/wordpress-server.js');
38
+ const gutenbergConverterPath = path.join(projectDir, '.claude/mcp/gutenberg-converter.js');
39
+
40
+ if (!fs.existsSync(mcpServerPath)) {
41
+ throw new Error(`WordPress MCP server not found at: ${mcpServerPath}`);
42
+ }
43
+
44
+ if (!fs.existsSync(gutenbergConverterPath)) {
45
+ throw new Error(`Gutenberg converter not found at: ${gutenbergConverterPath}`);
46
+ }
47
+
48
+ // Create MCP configuration
49
+ const mcpConfigPath = path.join(projectDir, '.mcp.json');
50
+ const mcpConfig = {
51
+ mcpServers: {
52
+ wordpress: {
53
+ command: "node",
54
+ args: [path.resolve(projectDir, ".claude/mcp/wordpress-server.js")],
55
+ env: {
56
+ WORDPRESS_URL: process.env.WORDPRESS_URL,
57
+ WORDPRESS_USERNAME: process.env.WORDPRESS_USERNAME,
58
+ WORDPRESS_APP_PASSWORD: process.env.WORDPRESS_APP_PASSWORD,
59
+ WORDPRESS_USE_GUTENBERG: process.env.WORDPRESS_USE_GUTENBERG || "false"
60
+ }
61
+ }
62
+ }
63
+ };
64
+
65
+ // If .mcp.json already exists, merge with existing configuration
66
+ let existingConfig = {};
67
+ if (fs.existsSync(mcpConfigPath)) {
68
+ try {
69
+ existingConfig = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
70
+ console.log('๐Ÿ“ Found existing .mcp.json file, merging configuration...');
71
+ } catch (error) {
72
+ console.warn('โš ๏ธ Existing .mcp.json file is invalid, creating new one...');
73
+ }
74
+ }
75
+
76
+ // Merge configurations
77
+ const finalConfig = {
78
+ ...existingConfig,
79
+ mcpServers: {
80
+ ...existingConfig.mcpServers,
81
+ ...mcpConfig.mcpServers
82
+ }
83
+ };
84
+
85
+ // Write MCP configuration file
86
+ fs.writeFileSync(mcpConfigPath, JSON.stringify(finalConfig, null, 2));
87
+ console.log('โœ… Created .mcp.json configuration file');
88
+
89
+ // Set executable permissions on MCP server
90
+ try {
91
+ fs.chmodSync(mcpServerPath, 0o755);
92
+ console.log('โœ… Set executable permissions on WordPress MCP server');
93
+ } catch (error) {
94
+ console.warn('โš ๏ธ Could not set executable permissions:', error.message);
95
+ }
96
+
97
+ // Test MCP server startup
98
+ console.log('๐Ÿงช Testing MCP server startup...');
99
+
100
+ try {
101
+ const { spawn } = await import('child_process');
102
+
103
+ return new Promise((resolve, reject) => {
104
+ const testProcess = spawn('node', [mcpServerPath], {
105
+ env: { ...process.env, ...mcpConfig.mcpServers.wordpress.env },
106
+ stdio: ['pipe', 'pipe', 'pipe']
107
+ });
108
+
109
+ let stderr = '';
110
+ testProcess.stderr.on('data', (data) => {
111
+ stderr += data.toString();
112
+ });
113
+
114
+ // Give the server 3 seconds to start up
115
+ setTimeout(() => {
116
+ testProcess.kill('SIGTERM');
117
+
118
+ if (stderr.includes('WordPress MCP Server running') || stderr.includes('Server running')) {
119
+ console.log('โœ… MCP server startup test successful');
120
+ resolve(true);
121
+ } else if (stderr.includes('Error') || stderr.includes('Missing required environment')) {
122
+ console.error('โŒ MCP server startup failed:', stderr);
123
+ reject(new Error('MCP server failed to start'));
124
+ } else {
125
+ console.log('โœ… MCP server appears to be working');
126
+ resolve(true);
127
+ }
128
+ }, 3000);
129
+
130
+ testProcess.on('error', (error) => {
131
+ reject(new Error(`Failed to start MCP server: ${error.message}`));
132
+ });
133
+ });
134
+ } catch (testError) {
135
+ console.warn('โš ๏ธ Could not test MCP server startup:', testError.message);
136
+ console.log(' MCP configuration created, but please test manually if needed');
137
+ }
138
+
139
+ console.log('\n๐ŸŽ‰ WordPress MCP integration configured successfully!');
140
+ console.log('\n๐Ÿ“‹ Configuration Summary:');
141
+ console.log(` โ€ข WordPress URL: ${process.env.WORDPRESS_URL}`);
142
+ console.log(` โ€ข Username: ${process.env.WORDPRESS_USERNAME}`);
143
+ console.log(` โ€ข Gutenberg mode: ${process.env.WORDPRESS_USE_GUTENBERG || 'false'}`);
144
+ console.log(` โ€ข MCP config: ${mcpConfigPath}`);
145
+ console.log(` โ€ข MCP server: ${mcpServerPath}`);
146
+
147
+ console.log('\n๐Ÿ”„ Next steps:');
148
+ console.log(' 1. Restart Claude Code to load the new MCP configuration');
149
+ console.log(' 2. Use WordPress MCP tools in your agents and commands');
150
+ console.log(' 3. Test with: /myai-wordpress-admin or /myai-wordpress-publish');
151
+
152
+ return true;
153
+
154
+ } catch (error) {
155
+ console.error('โŒ WordPress MCP configuration failed:', error.message);
156
+ console.log('\n๐Ÿ› ๏ธ Troubleshooting:');
157
+ console.log(' โ€ข Ensure WordPress credentials are configured in .env');
158
+ console.log(' โ€ข Check that .claude/mcp/wordpress-server.js exists');
159
+ console.log(' โ€ข Verify Node.js version is 18+ (required for MCP SDK)');
160
+ console.log(' โ€ข Run: npm install to ensure dependencies are installed');
161
+
162
+ return false;
163
+ }
164
+ }
165
+
166
+ // Allow running as standalone script
167
+ if (import.meta.url === `file://${process.argv[1]}`) {
168
+ configureWordPressMCP()
169
+ .then((success) => {
170
+ process.exit(success ? 0 : 1);
171
+ })
172
+ .catch((error) => {
173
+ console.error('Configuration script error:', error);
174
+ process.exit(1);
175
+ });
176
+ }
@@ -1,10 +1,43 @@
1
1
  ---
2
2
  name: wordpress-admin
3
3
  description: WordPress administrator for site management, security, performance, and health analysis
4
- tools: Read, Write, Edit, Bash, WebSearch, WebFetch, Task, Grep, Glob
4
+ tools: Read, Write, Edit, Task, WebFetch
5
5
  ---
6
6
 
7
- You are a WordPress administrator with expertise in site management, security, performance optimization, and health monitoring. You have access to WordPress via MCP integration and can perform server-level operations through SSH when available.
7
+ You are a WordPress administrator with expertise in site management, security, performance optimization, and health monitoring. You use the existing MyAIDev Method WordPress MCP integration and configuration.
8
+
9
+ ## WordPress Integration Setup
10
+
11
+ ### Prerequisites
12
+ Before performing any WordPress operations, ensure configuration is complete:
13
+
14
+ 1. **Check Configuration**: Use `/myai-configure wordpress` if not already set up
15
+ 2. **Verify Credentials**: Ensure `.env` file contains:
16
+ ```
17
+ WORDPRESS_URL=https://your-site.com
18
+ WORDPRESS_USERNAME=your-username
19
+ WORDPRESS_APP_PASSWORD=your-app-password
20
+ ```
21
+ 3. **Use Existing MCP**: Leverage the WordPress MCP server in `.claude/mcp/wordpress-server.js`
22
+
23
+ ### WordPress Operations via MCP
24
+ All WordPress operations MUST use our existing WordPress MCP integration. Never write new REST API code - use the provided MCP functions:
25
+
26
+ **Available MCP Functions:**
27
+ - `wp_get_site_info()` - Site statistics and information
28
+ - `wp_list_posts(params)` - Get posts with filtering options
29
+ - `wp_create_post(params)` - Create new posts/pages
30
+ - `wp_update_post(id, params)` - Update existing content
31
+ - `wp_delete_post(id)` - Delete posts/pages
32
+ - `wp_list_users()` - Get user accounts
33
+ - `wp_create_user(params)` - Add new users
34
+ - `wp_update_user(id, params)` - Modify user settings
35
+ - `wp_list_plugins()` - Get installed plugins
36
+ - `wp_activate_plugin(slug)` - Enable plugins
37
+ - `wp_deactivate_plugin(slug)` - Disable plugins
38
+ - `wp_list_themes()` - Get available themes
39
+ - `wp_get_media(params)` - Media library access
40
+ - `wp_upload_media(file_data)` - Upload files
8
41
 
9
42
  ## Core Responsibilities
10
43
 
@@ -44,30 +77,59 @@ You are a WordPress administrator with expertise in site management, security, p
44
77
  ## Available Operations
45
78
 
46
79
  ### WordPress MCP Operations
47
- - Site information and statistics
48
- - Plugin/theme management
49
- - User administration
50
- - Content management
51
- - Database operations
52
- - Media library management
53
- - Settings configuration
54
-
55
- ### SSH Server Operations (when available)
56
- - File system access and permissions
57
- - Log file analysis
58
- - Server resource monitoring
59
- - Database direct access
60
- - Web server configuration
61
- - System updates and maintenance
80
+ Use the following MCP functions for all WordPress operations:
81
+
82
+ **Site Management:**
83
+ - `wp_get_site_info()` - Get site statistics, version, and health
84
+ - `wp_list_posts({status: 'any', per_page: 100})` - Audit content
85
+ - `wp_list_users()` - Review user accounts and roles
86
+
87
+ **Security Operations:**
88
+ - `wp_list_plugins()` - Check plugin versions and security
89
+ - `wp_list_users()` - Audit user permissions and roles
90
+ - `wp_get_site_info()` - Check WordPress version for updates
91
+
92
+ **Content Management:**
93
+ - `wp_list_posts({status: 'draft'})` - Find draft content
94
+ - `wp_list_posts({status: 'trash'})` - Review deleted content
95
+ - `wp_update_post(id, {status: 'trash'})` - Clean up spam content
96
+
97
+ **User Administration:**
98
+ - `wp_create_user({username, email, password, role})` - Add users
99
+ - `wp_update_user(id, {role, password})` - Modify permissions
100
+ - `wp_delete_user(id)` - Remove accounts
101
+
102
+ **Plugin/Theme Management:**
103
+ - `wp_activate_plugin(slug)` / `wp_deactivate_plugin(slug)` - Control plugins
104
+ - `wp_list_themes()` - Review installed themes
105
+
106
+ ### SSH Server Operations (optional, when available)
107
+ - File system access and permissions (use when MCP functions insufficient)
108
+ - Log file analysis (`/var/log/apache2/`, `/var/log/nginx/`)
109
+ - Server resource monitoring (`htop`, `df -h`)
110
+ - Direct database access (only for complex queries)
111
+ - Web server configuration (when MCP cannot modify settings)
62
112
 
63
113
  ## Security Assessment Workflow
64
114
 
65
115
  ### 1. Initial Security Scan
66
- - Check WordPress version and update status
67
- - Audit installed plugins and themes for vulnerabilities
68
- - Review user accounts and permissions
69
- - Scan for malware and suspicious files
70
- - Check file permissions and ownership
116
+ **Using MCP Functions:**
117
+ ```javascript
118
+ // Check WordPress version and site health
119
+ const siteInfo = await wp_get_site_info();
120
+
121
+ // Audit user accounts and permissions
122
+ const users = await wp_list_users();
123
+
124
+ // Review installed plugins for vulnerabilities
125
+ const plugins = await wp_list_plugins();
126
+
127
+ // Check themes for updates
128
+ const themes = await wp_list_themes();
129
+
130
+ // Review content for spam/malicious posts
131
+ const allPosts = await wp_list_posts({status: 'any', per_page: 100});
132
+ ```
71
133
 
72
134
  ### 2. Configuration Review
73
135
  - WordPress security settings audit
@@ -92,11 +154,19 @@ You are a WordPress administrator with expertise in site management, security, p
92
154
  ## Performance Analysis Workflow
93
155
 
94
156
  ### 1. Site Speed Analysis
95
- - Page load time measurement
96
- - Core Web Vitals assessment
97
- - Resource loading analysis
98
- - Database query performance
99
- - Server response time evaluation
157
+ **Using MCP Functions:**
158
+ ```javascript
159
+ // Get site information for performance baseline
160
+ const siteInfo = await wp_get_site_info();
161
+
162
+ // Analyze content structure for optimization
163
+ const posts = await wp_list_posts({per_page: 100});
164
+ const media = await wp_get_media({per_page: 100});
165
+
166
+ // Review active plugins for performance impact
167
+ const plugins = await wp_list_plugins();
168
+ ```
169
+ **Additional Analysis:** Page load time measurement, Core Web Vitals assessment, database query performance (use SSH access for detailed server metrics when needed)
100
170
 
101
171
  ### 2. Resource Optimization
102
172
  - Image compression recommendations
@@ -201,16 +271,30 @@ For each operation, provide:
201
271
  ## Error Handling
202
272
 
203
273
  ### WordPress MCP Failures
204
- - Provide fallback procedures
205
- - Document connection issues
206
- - Suggest alternative approaches
207
- - Report specific error details
274
+ **When MCP functions fail:**
275
+ 1. **Check Configuration**: Verify `/myai-configure wordpress` setup
276
+ 2. **Validate Credentials**: Ensure `.env` variables are correct
277
+ 3. **Test Connection**: Use `wp_get_site_info()` to test basic connectivity
278
+ 4. **Fallback Options**: Document specific MCP errors and suggest SSH alternatives
279
+ 5. **Error Reporting**: Provide exact error messages for troubleshooting
280
+
281
+ **Example Error Handling:**
282
+ ```javascript
283
+ try {
284
+ const siteInfo = await wp_get_site_info();
285
+ console.log('WordPress connection successful');
286
+ } catch (error) {
287
+ console.error('MCP Connection failed:', error.message);
288
+ // Suggest checking .env configuration
289
+ // Recommend running /myai-configure wordpress
290
+ }
291
+ ```
208
292
 
209
293
  ### SSH Access Issues
210
- - Gracefully handle connection failures
211
- - Provide WordPress-only alternatives
212
- - Document permission requirements
213
- - Suggest credential verification steps
294
+ - Use SSH only when MCP functions are insufficient
295
+ - Document when SSH is required vs optional
296
+ - Always try MCP functions first before SSH alternatives
297
+ - Provide WordPress-admin-only alternatives when SSH unavailable
214
298
 
215
299
  ## Integration Guidelines
216
300
 
@@ -39,7 +39,14 @@ Interactive WordPress setup - no manual .env file creation needed!
39
39
  - Set proper file permissions (600)
40
40
  - Show confirmation of saved settings
41
41
 
42
- 6. **Optional SSH setup**
42
+ 6. **Configure MCP integration**
43
+ - Run the MCP configuration script: `node scripts/configure-wordpress-mcp.js`
44
+ - Create/update `.mcp.json` file for Claude Code MCP integration
45
+ - Configure WordPress MCP server with proper paths and environment
46
+ - Enable WordPress MCP tools in Claude Code
47
+ - Test MCP server connectivity
48
+
49
+ 7. **Optional SSH setup**
43
50
  - Ask: "Do you want to set up SSH for advanced WordPress administration? (y/n)"
44
51
  - If yes, prompt for SSH details:
45
52
  * SSH host/IP
@@ -77,7 +84,71 @@ List and manage available agents:
77
84
  2. Interactive prompts for required values
78
85
  3. Validate configuration
79
86
  4. Save to appropriate location (.env or .claude/config/)
80
- 5. Confirm successful configuration
87
+ 5. **For WordPress configuration**: Create `.mcp.json` file with WordPress MCP server configuration
88
+ 6. Confirm successful configuration
89
+
90
+ ## MCP Configuration Details
91
+
92
+ When configuring WordPress, the command should:
93
+
94
+ 1. **Create `.mcp.json` file** in the project root with the following structure:
95
+ ```json
96
+ {
97
+ "mcpServers": {
98
+ "wordpress": {
99
+ "command": "node",
100
+ "args": [".claude/mcp/wordpress-server.js"],
101
+ "env": {
102
+ "WORDPRESS_URL": "loaded from .env",
103
+ "WORDPRESS_USERNAME": "loaded from .env",
104
+ "WORDPRESS_APP_PASSWORD": "loaded from .env",
105
+ "WORDPRESS_USE_GUTENBERG": "loaded from .env"
106
+ }
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ 2. **Verify MCP server executable** by checking:
113
+ - `.claude/mcp/wordpress-server.js` exists
114
+ - `.claude/mcp/gutenberg-converter.js` exists
115
+ - File permissions are correct (executable)
116
+
117
+ 3. **Test MCP server startup** by running:
118
+ - `node .claude/mcp/wordpress-server.js` to verify it starts without errors
119
+ - Check that all dependencies are installed
120
+
121
+ 4. **Environment integration** by:
122
+ - Reading existing `.env` values
123
+ - Populating MCP environment variables
124
+ - Ensuring `.env` file is properly formatted
125
+
126
+ 5. **Implementation steps**:
127
+ - Read the current `.env` file to get WordPress credentials
128
+ - Create the `.mcp.json` file with proper server configuration
129
+ - Use absolute paths for the MCP server script
130
+ - Set executable permissions on MCP server files
131
+ - Test that Claude Code can load the MCP configuration
132
+
133
+ ```javascript
134
+ // Example implementation for creating .mcp.json:
135
+ const mcpConfig = {
136
+ mcpServers: {
137
+ wordpress: {
138
+ command: "node",
139
+ args: [path.resolve(".claude/mcp/wordpress-server.js")],
140
+ env: {
141
+ WORDPRESS_URL: process.env.WORDPRESS_URL,
142
+ WORDPRESS_USERNAME: process.env.WORDPRESS_USERNAME,
143
+ WORDPRESS_APP_PASSWORD: process.env.WORDPRESS_APP_PASSWORD,
144
+ WORDPRESS_USE_GUTENBERG: process.env.WORDPRESS_USE_GUTENBERG || "false"
145
+ }
146
+ }
147
+ }
148
+ };
149
+
150
+ fs.writeFileSync('.mcp.json', JSON.stringify(mcpConfig, null, 2));
151
+ ```
81
152
 
82
153
  ## WordPress Setup Example
83
154
 
@@ -113,6 +184,8 @@ List and manage available agents:
113
184
 
114
185
  โœ… Configuration saved to .env
115
186
  โœ… File permissions set to 600 (secure)
187
+ โœ… MCP configuration saved to .mcp.json
188
+ โœ… WordPress MCP server configured
116
189
 
117
190
  WordPress integration ready! Available commands:
118
191
  โ€ข /myai-wordpress-admin health-check
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import dotenv from 'dotenv';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ /**
12
+ * Configure WordPress MCP integration for Claude Code
13
+ * This script creates the .mcp.json file required for Claude Code to recognize
14
+ * and use the WordPress MCP server
15
+ */
16
+ export async function configureWordPressMCP(projectDir = process.cwd()) {
17
+ try {
18
+ console.log('๐Ÿ”ง Configuring WordPress MCP integration...');
19
+
20
+ // Load environment variables from .env file
21
+ const envPath = path.join(projectDir, '.env');
22
+ if (!fs.existsSync(envPath)) {
23
+ throw new Error('.env file not found. Please run WordPress configuration first.');
24
+ }
25
+
26
+ dotenv.config({ path: envPath });
27
+
28
+ // Validate required environment variables
29
+ const requiredVars = ['WORDPRESS_URL', 'WORDPRESS_USERNAME', 'WORDPRESS_APP_PASSWORD'];
30
+ const missing = requiredVars.filter(varName => !process.env[varName]);
31
+
32
+ if (missing.length > 0) {
33
+ throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
34
+ }
35
+
36
+ // Check if MCP server files exist
37
+ const mcpServerPath = path.join(projectDir, '.claude/mcp/wordpress-server.js');
38
+ const gutenbergConverterPath = path.join(projectDir, '.claude/mcp/gutenberg-converter.js');
39
+
40
+ if (!fs.existsSync(mcpServerPath)) {
41
+ throw new Error(`WordPress MCP server not found at: ${mcpServerPath}`);
42
+ }
43
+
44
+ if (!fs.existsSync(gutenbergConverterPath)) {
45
+ throw new Error(`Gutenberg converter not found at: ${gutenbergConverterPath}`);
46
+ }
47
+
48
+ // Create MCP configuration
49
+ const mcpConfigPath = path.join(projectDir, '.mcp.json');
50
+
51
+ // Use relative path for portability across different environments
52
+ const relativeMcpServerPath = ".claude/mcp/wordpress-server.js";
53
+
54
+ const mcpConfig = {
55
+ mcpServers: {
56
+ wordpress: {
57
+ command: "node",
58
+ args: [relativeMcpServerPath],
59
+ env: {
60
+ WORDPRESS_URL: process.env.WORDPRESS_URL,
61
+ WORDPRESS_USERNAME: process.env.WORDPRESS_USERNAME,
62
+ WORDPRESS_APP_PASSWORD: process.env.WORDPRESS_APP_PASSWORD,
63
+ WORDPRESS_USE_GUTENBERG: process.env.WORDPRESS_USE_GUTENBERG || "false"
64
+ }
65
+ }
66
+ }
67
+ };
68
+
69
+ // If .mcp.json already exists, merge with existing configuration
70
+ let existingConfig = {};
71
+ if (fs.existsSync(mcpConfigPath)) {
72
+ try {
73
+ existingConfig = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
74
+ console.log('๐Ÿ“ Found existing .mcp.json file, merging configuration...');
75
+ } catch (error) {
76
+ console.warn('โš ๏ธ Existing .mcp.json file is invalid, creating new one...');
77
+ }
78
+ }
79
+
80
+ // Merge configurations
81
+ const finalConfig = {
82
+ ...existingConfig,
83
+ mcpServers: {
84
+ ...existingConfig.mcpServers,
85
+ ...mcpConfig.mcpServers
86
+ }
87
+ };
88
+
89
+ // Write MCP configuration file
90
+ fs.writeFileSync(mcpConfigPath, JSON.stringify(finalConfig, null, 2));
91
+ console.log('โœ… Created .mcp.json configuration file');
92
+
93
+ // Set executable permissions on MCP server
94
+ try {
95
+ fs.chmodSync(mcpServerPath, 0o755);
96
+ console.log('โœ… Set executable permissions on WordPress MCP server');
97
+ } catch (error) {
98
+ console.warn('โš ๏ธ Could not set executable permissions:', error.message);
99
+ }
100
+
101
+ // Test MCP server startup
102
+ console.log('๐Ÿงช Testing MCP server startup...');
103
+
104
+ try {
105
+ const { spawn } = await import('child_process');
106
+
107
+ return new Promise((resolve, reject) => {
108
+ const testProcess = spawn('node', [relativeMcpServerPath], {
109
+ cwd: projectDir, // Set working directory to project root
110
+ env: { ...process.env, ...mcpConfig.mcpServers.wordpress.env },
111
+ stdio: ['pipe', 'pipe', 'pipe']
112
+ });
113
+
114
+ let stderr = '';
115
+ testProcess.stderr.on('data', (data) => {
116
+ stderr += data.toString();
117
+ });
118
+
119
+ // Give the server 3 seconds to start up
120
+ setTimeout(() => {
121
+ testProcess.kill('SIGTERM');
122
+
123
+ if (stderr.includes('WordPress MCP Server running') || stderr.includes('Server running')) {
124
+ console.log('โœ… MCP server startup test successful');
125
+ resolve(true);
126
+ } else if (stderr.includes('Error') || stderr.includes('Missing required environment')) {
127
+ console.error('โŒ MCP server startup failed:', stderr);
128
+ reject(new Error('MCP server failed to start'));
129
+ } else {
130
+ console.log('โœ… MCP server appears to be working');
131
+ resolve(true);
132
+ }
133
+ }, 3000);
134
+
135
+ testProcess.on('error', (error) => {
136
+ reject(new Error(`Failed to start MCP server: ${error.message}`));
137
+ });
138
+ });
139
+ } catch (testError) {
140
+ console.warn('โš ๏ธ Could not test MCP server startup:', testError.message);
141
+ console.log(' MCP configuration created, but please test manually if needed');
142
+ }
143
+
144
+ console.log('\n๐ŸŽ‰ WordPress MCP integration configured successfully!');
145
+ console.log('\n๐Ÿ“‹ Configuration Summary:');
146
+ console.log(` โ€ข WordPress URL: ${process.env.WORDPRESS_URL}`);
147
+ console.log(` โ€ข Username: ${process.env.WORDPRESS_USERNAME}`);
148
+ console.log(` โ€ข Gutenberg mode: ${process.env.WORDPRESS_USE_GUTENBERG || 'false'}`);
149
+ console.log(` โ€ข MCP config: ${mcpConfigPath}`);
150
+ console.log(` โ€ข MCP server: ${relativeMcpServerPath}`);
151
+
152
+ console.log('\n๐Ÿ”„ Next steps:');
153
+ console.log(' 1. Restart Claude Code to load the new MCP configuration');
154
+ console.log(' 2. Use WordPress MCP tools in your agents and commands');
155
+ console.log(' 3. Test with: /myai-wordpress-admin or /myai-wordpress-publish');
156
+
157
+ return true;
158
+
159
+ } catch (error) {
160
+ console.error('โŒ WordPress MCP configuration failed:', error.message);
161
+ console.log('\n๐Ÿ› ๏ธ Troubleshooting:');
162
+ console.log(' โ€ข Ensure WordPress credentials are configured in .env');
163
+ console.log(' โ€ข Check that .claude/mcp/wordpress-server.js exists');
164
+ console.log(' โ€ข Verify Node.js version is 18+ (required for MCP SDK)');
165
+ console.log(' โ€ข Run: npm install to ensure dependencies are installed');
166
+
167
+ return false;
168
+ }
169
+ }
170
+
171
+ // Allow running as standalone script
172
+ if (import.meta.url === `file://${process.argv[1]}`) {
173
+ configureWordPressMCP()
174
+ .then((success) => {
175
+ process.exit(success ? 0 : 1);
176
+ })
177
+ .catch((error) => {
178
+ console.error('Configuration script error:', error);
179
+ process.exit(1);
180
+ });
181
+ }