myaidev-method 0.0.6 โ†’ 0.0.8

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.
@@ -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
+ }