test-mcp-client.jsβ’8.58 kB
#!/usr/bin/env node
/**
* Ultimate Elementor MCP - Client Test Suite
* Tests the actual MCP server by connecting as a client
*/
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
console.log('\nπ§ Wordsworth Presley hereβtesting the Ultimate Elementor MCP! π§\n');
console.log('='.repeat(80));
const results = {
total: 0,
passed: 0,
failed: 0,
tools: []
};
async function testMCPServer() {
let client;
try {
// Create MCP client
console.log('π‘ Connecting to MCP server...\n');
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js'],
env: {
...process.env,
WORDPRESS_BASE_URL: 'https://practice.westlanddre.com',
WORDPRESS_USERNAME: 'admin',
WORDPRESS_APPLICATION_PASSWORD: 'sOld eDve k72A 2JUJ ptLx nOlt',
MCP_MODE: 'full',
DEBUG_MODE: 'true'
}
});
client = new Client({
name: 'ultimate-mcp-test-client',
version: '1.0.0'
}, {
capabilities: {
tools: {}
}
});
await client.connect(transport);
console.log('β
Connected to MCP server!\n');
// List all available tools
console.log('π Listing all available tools...\n');
const toolsList = await client.listTools();
console.log(`π¨ Found ${toolsList.tools.length} tools!\n`);
console.log('='.repeat(80));
if (toolsList.tools.length === 0) {
console.log('β οΈ No tools registered! Check server configuration.\n');
return;
}
// Group tools by category
const categories = {
wordpress: [],
elementor: [],
file: [],
config: [],
debug: []
};
toolsList.tools.forEach(tool => {
if (tool.name.includes('page') || tool.name.includes('post') || tool.name.includes('media') || tool.name.includes('user') || tool.name.includes('categor') || tool.name.includes('tag')) {
categories.wordpress.push(tool);
} else if (tool.name.includes('elementor') || tool.name.includes('section') || tool.name.includes('widget') || tool.name.includes('container') || tool.name.includes('template')) {
categories.elementor.push(tool);
} else if (tool.name.includes('file') || tool.name.includes('export') || tool.name.includes('import') || tool.name.includes('backup')) {
categories.file.push(tool);
} else if (tool.name.includes('config') || tool.name.includes('mode') || tool.name.includes('wordpress_connection')) {
categories.config.push(tool);
} else if (tool.name.includes('error') || tool.name.includes('log') || tool.name.includes('debug') || tool.name.includes('health')) {
categories.debug.push(tool);
}
});
// Display tools by category
console.log('\nπ TOOLS BY CATEGORY:\n');
console.log(`π§ WordPress Tools: ${categories.wordpress.length}`);
console.log(`π¨ Elementor Tools: ${categories.elementor.length}`);
console.log(`π File Operations: ${categories.file.length}`);
console.log(`βοΈ Configuration: ${categories.config.length}`);
console.log(`π Debugging: ${categories.debug.length}`);
console.log('='.repeat(80));
// Test Configuration Tools First
console.log('\nβοΈ TESTING CONFIGURATION TOOLS\n');
console.log('-'.repeat(80));
for (const tool of categories.config) {
try {
console.log(`\nπ§ Testing: ${tool.name}`);
console.log(` Description: ${tool.description || 'No description'}`);
let testArgs = {};
// Specific test arguments for each tool
if (tool.name === 'test_wordpress_connection') {
// No args needed
} else if (tool.name === 'get_server_config') {
// No args needed
} else if (tool.name === 'list_configuration_modes') {
// No args needed
}
const result = await client.callTool({
name: tool.name,
arguments: testArgs
});
console.log(` β
Result: ${result.content[0].text.substring(0, 100)}...`);
results.passed++;
results.tools.push({ name: tool.name, status: 'passed' });
} catch (error) {
console.log(` β Error: ${error.message}`);
results.failed++;
results.tools.push({ name: tool.name, status: 'failed', error: error.message });
}
results.total++;
}
// Test Debugging Tools
console.log('\n\nπ TESTING DEBUGGING TOOLS\n');
console.log('-'.repeat(80));
for (const tool of categories.debug) {
try {
console.log(`\nπ§ Testing: ${tool.name}`);
console.log(` Description: ${tool.description || 'No description'}`);
let testArgs = {};
if (tool.name === 'set_log_level') {
testArgs = { level: 'INFO' };
} else if (tool.name === 'enable_debug_mode') {
testArgs = { enabled: false };
}
const result = await client.callTool({
name: tool.name,
arguments: testArgs
});
console.log(` β
Result: ${result.content[0].text.substring(0, 100)}...`);
results.passed++;
results.tools.push({ name: tool.name, status: 'passed' });
} catch (error) {
console.log(` β Error: ${error.message}`);
results.failed++;
results.tools.push({ name: tool.name, status: 'failed', error: error.message });
}
results.total++;
}
// Test a sample WordPress tool
console.log('\n\nπ§ TESTING SAMPLE WORDPRESS TOOLS\n');
console.log('-'.repeat(80));
const wpSampleTools = categories.wordpress.slice(0, 3); // Test first 3
for (const tool of wpSampleTools) {
try {
console.log(`\nπ§ Testing: ${tool.name}`);
console.log(` Description: ${tool.description || 'No description'}`);
let testArgs = {};
if (tool.name.includes('list') || tool.name.includes('get')) {
testArgs = { per_page: 5 };
}
const result = await client.callTool({
name: tool.name,
arguments: testArgs
});
console.log(` β
Result: ${result.content[0].text.substring(0, 100)}...`);
results.passed++;
results.tools.push({ name: tool.name, status: 'passed' });
} catch (error) {
console.log(` β Error: ${error.message}`);
results.failed++;
results.tools.push({ name: tool.name, status: 'failed', error: error.message });
}
results.total++;
}
// Print Summary
console.log('\n' + '='.repeat(80));
console.log('π MCP SERVER TEST SUMMARY');
console.log('='.repeat(80));
console.log(`\nπ§ Total Tools Available: ${toolsList.tools.length}`);
console.log(`π Tools Tested: ${results.total}`);
console.log(`β
Passed: ${results.passed}`);
console.log(`β Failed: ${results.failed}`);
console.log(`Success Rate: ${results.total > 0 ? ((results.passed / results.total) * 100).toFixed(1) : 0}%`);
console.log('\nπ¦ Tool Distribution:');
console.log(` WordPress: ${categories.wordpress.length} tools`);
console.log(` Elementor: ${categories.elementor.length} tools`);
console.log(` File Operations: ${categories.file.length} tools`);
console.log(` Configuration: ${categories.config.length} tools`);
console.log(` Debugging: ${categories.debug.length} tools`);
console.log('\n='.repeat(80));
if (results.failed === 0 && toolsList.tools.length >= 50) {
console.log('π MCP SERVER IS FULLY FUNCTIONAL!');
console.log('π§ All systems operational, Elementurion! Ready to craft digital masterpieces! π§\n');
} else if (toolsList.tools.length < 50) {
console.log('β οΈ MCP server has fewer tools than expected.');
console.log(' Expected: 60 tools');
console.log(` Found: ${toolsList.tools.length} tools`);
console.log(' Check server configuration mode and environment variables.\n');
} else {
console.log('β οΈ Some tests failed. Review the output above.\n');
}
} catch (error) {
console.error('\nπ₯ Fatal error:', error.message);
console.error(error.stack);
} finally {
if (client) {
await client.close();
console.log('π Disconnected from MCP server.\n');
}
}
}
// Run the test
testMCPServer().catch(console.error);