#!/usr/bin/env node
import { existsSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { homedir } from "os";
import { readFile } from "fs/promises";
import dotenv from "dotenv";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = join(__dirname, "..");
class ClaudeIntegrationVerifier {
constructor() {
this.envPath = join(rootDir, ".env");
this.loadConfig();
this.claudeConfigPath = this.getClaudeConfigPath();
}
loadConfig() {
if (existsSync(this.envPath)) {
dotenv.config({ path: this.envPath, debug: false });
}
}
getClaudeConfigPath() {
const platform = process.platform;
switch (platform) {
case "darwin": // macOS
return join(homedir(), "Library/Application Support/Claude/claude_desktop_config.json");
case "win32": // Windows
return join(process.env.APPDATA || "", "Claude/claude_desktop_config.json");
case "linux": // Linux
return join(homedir(), ".config/Claude/claude_desktop_config.json");
default:
throw new Error(`Unsupported platform: ${platform}`);
}
}
async run() {
console.log("π Claude Desktop Integration Verification");
console.log("==========================================\n");
let allPassed = true;
// 1. Check local MCP server health
allPassed &= await this.checkLocalServerHealth();
console.log("");
// 2. Check Claude Desktop configuration
allPassed &= await this.checkClaudeDesktopConfig();
console.log("");
// 3. Test MCP server startup
allPassed &= await this.testMCPServerStartup();
console.log("");
// 4. Verify environment variables
allPassed &= await this.verifyEnvironmentVariables();
console.log("");
// 5. Check file permissions
allPassed &= await this.checkFilePermissions();
console.log("");
// Summary
this.showSummary(allPassed);
process.exit(allPassed ? 0 : 1);
}
async checkLocalServerHealth() {
console.log("π 1. Local MCP Server Health Check");
console.log("-----------------------------------");
try {
// Check if dist/index.js exists and is executable
const serverPath = join(rootDir, "dist/index.js");
if (!existsSync(serverPath)) {
console.log("β Server file not found: dist/index.js");
console.log(" Run: npm run build");
return false;
}
console.log("β
Server file exists: dist/index.js");
// Test module import
try {
await import(join(rootDir, "dist/index.js"));
console.log("β
Server module loads correctly");
} catch (error) {
console.log("β Server module failed to load:", error.message);
return false;
}
// Check dependencies
const nodeModulesPath = join(rootDir, "node_modules");
if (!existsSync(nodeModulesPath)) {
console.log("β Dependencies not installed");
console.log(" Run: npm install");
return false;
}
console.log("β
Dependencies installed");
return true;
} catch (error) {
console.log("β Server health check failed:", error.message);
return false;
}
}
async checkClaudeDesktopConfig() {
console.log("βοΈ 2. Claude Desktop Configuration Check");
console.log("-----------------------------------------");
try {
// Check if Claude config file exists
if (!existsSync(this.claudeConfigPath)) {
console.log("β Claude Desktop config file not found:");
console.log(` Expected: ${this.claudeConfigPath}`);
console.log(" Create the file and add MCP server configuration");
return false;
}
console.log("β
Claude Desktop config file exists");
// Read and parse config
const configContent = await readFile(this.claudeConfigPath, "utf-8");
let config;
try {
config = JSON.parse(configContent);
} catch (_error) {
console.log("β Invalid JSON in Claude config file");
return false;
}
console.log("β
Claude config file is valid JSON");
// Check for MCP servers section
if (!config.mcpServers) {
console.log("β No mcpServers section in Claude config");
return false;
}
console.log("β
mcpServers section found");
// Check for WordPress MCP server
const wpServer = config.mcpServers["mcp-wordpress"];
if (!wpServer) {
console.log("β WordPress MCP server not configured in Claude Desktop");
console.log(" Add 'mcp-wordpress' server configuration");
return false;
}
console.log("β
WordPress MCP server configured");
// Validate server configuration
const serverPath = join(rootDir, "dist/index.js");
if (wpServer.command === "node" && wpServer.args && wpServer.args[0] === serverPath) {
console.log("β
Server path correctly configured");
} else if (wpServer.command === "npx" && wpServer.args && wpServer.args[0] === "mcp-wordpress") {
console.log("β
NPX command correctly configured");
} else {
console.log("β οΈ Server configuration may need adjustment");
console.log(` Current: ${wpServer.command} ${wpServer.args ? wpServer.args.join(" ") : ""}`);
console.log(` Expected: node ${serverPath}`);
console.log(" Or: npx mcp-wordpress");
}
return true;
} catch (error) {
console.log("β Claude Desktop config check failed:", error.message);
return false;
}
}
async testMCPServerStartup() {
console.log("π 3. MCP Server Startup Test");
console.log("-----------------------------");
try {
// Import and instantiate server
const { default: MCPWordPressServer } = await import(join(rootDir, "dist/index.js"));
const server = new MCPWordPressServer();
if (!server) {
console.log("β Failed to create MCP server instance");
return false;
}
console.log("β
MCP server instance created");
// Check if server has required methods
if (typeof server.run !== "function") {
console.log("β Server missing run() method");
return false;
}
console.log("β
Server has required methods");
return true;
} catch (error) {
console.log("β MCP server startup test failed:", error.message);
return false;
}
}
async verifyEnvironmentVariables() {
console.log("π 4. Environment Variables Check");
console.log("----------------------------------");
const requiredVars = ["WORDPRESS_SITE_URL", "WORDPRESS_USERNAME"];
const authVars = ["WORDPRESS_APP_PASSWORD", "WORDPRESS_JWT_PASSWORD", "WORDPRESS_API_KEY"];
let allSet = true;
// Check required variables
for (const varName of requiredVars) {
if (process.env[varName]) {
console.log(`β
${varName} is set`);
} else {
console.log(`β ${varName} is not set`);
allSet = false;
}
}
// Check authentication variables (at least one should be set)
const authSet = authVars.some((varName) => process.env[varName]);
if (authSet) {
console.log("β
Authentication credentials configured");
} else {
console.log("β No authentication credentials found");
console.log(" Set one of: WORDPRESS_APP_PASSWORD, WORDPRESS_JWT_PASSWORD, or WORDPRESS_API_KEY");
allSet = false;
}
// Check .env file
if (existsSync(this.envPath)) {
console.log("β
.env file exists");
} else {
console.log("β οΈ .env file not found (using system environment variables)");
}
return allSet;
}
async checkFilePermissions() {
console.log("π 5. File Permissions Check");
console.log("-----------------------------");
try {
// Check server file permissions
const serverPath = join(rootDir, "dist/index.js");
if (existsSync(serverPath)) {
console.log("β
Server file is accessible");
} else {
console.log("β Server file not accessible");
return false;
}
// Check Claude config file permissions
if (existsSync(this.claudeConfigPath)) {
try {
await readFile(this.claudeConfigPath, "utf-8");
console.log("β
Claude config file is readable");
} catch (error) {
console.log("β Claude config file is not readable:", error.message);
return false;
}
}
return true;
} catch (error) {
console.log("β File permissions check failed:", error.message);
return false;
}
}
showSummary(allPassed) {
console.log("π Integration Verification Summary");
console.log("==================================");
if (allPassed) {
console.log("π β
All checks passed!");
console.log("");
console.log("Your WordPress MCP server is ready for Claude Desktop integration.");
console.log("");
console.log("Next steps:");
console.log("1. Restart Claude Desktop to pick up the new configuration");
console.log("2. Open Claude Desktop and look for WordPress tools");
console.log("3. Test a simple command like 'List my WordPress posts'");
console.log("");
console.log("Available tools include:");
console.log("β’ Post management (create, read, update, delete)");
console.log("β’ Page management");
console.log("β’ Media library access");
console.log("β’ User management");
console.log("β’ Comment moderation");
console.log("β’ Category and tag management");
console.log("β’ Site settings and statistics");
console.log("β’ Authentication testing");
} else {
console.log("β Some checks failed.");
console.log("");
console.log("Please resolve the issues above before using with Claude Desktop.");
console.log("");
console.log("Common solutions:");
console.log("β’ Run 'npm run build' to compile TypeScript");
console.log("β’ Run 'npm install' to install dependencies");
console.log("β’ Run 'npm run setup' to configure environment");
console.log("β’ Check Claude Desktop config file syntax");
console.log("β’ Verify WordPress credentials are correct");
}
}
}
// Run the verifier
const verifier = new ClaudeIntegrationVerifier();
verifier.run().catch((error) => {
console.error("β Verification failed with error:", error.message);
process.exit(1);
});