UNPKG

claudeus-wp-mcp

Version:

The most comprehensive WordPress MCP server - 145 production-ready tools for complete WordPress management with AI

78 lines 2.64 kB
import { EventEmitter } from 'events'; export class MCPTestHarness { messageEmitter = new EventEmitter(); responses = []; messageQueue = []; isConnected = false; // Mock client implementation async connect() { if (this.isConnected) { throw new Error('Already connected'); } this.isConnected = true; return this.sendInitialize(); } async sendInitialize() { const initMessage = { jsonrpc: "2.0", id: 1, method: "initialize", params: { capabilities: { sampling: {}, roots: { listChanged: true } } } }; return this.sendMessage(initMessage); } async sendMessage(message) { if (!this.isConnected) { throw new Error('Not connected'); } this.messageEmitter.emit('message', message); return new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject(new Error('Message timeout')); }, 5000); const handler = (response) => { if (response.id === message.id) { clearTimeout(timeout); this.messageEmitter.off('response', handler); resolve(response); } }; this.messageEmitter.on('response', handler); }); } // Server response handling onServerMessage(message) { this.responses.push(message); this.messageEmitter.emit('response', message); } // Test utilities async waitForNotification(method, timeout = 5000) { return new Promise((resolve, reject) => { const timer = setTimeout(() => { reject(new Error(`Timeout waiting for ${method} notification`)); }, timeout); const checkResponses = () => { const notification = this.responses.find(r => r.method === method && !r.id); if (notification) { clearTimeout(timer); this.messageEmitter.off('response', checkResponses); resolve(notification); } }; this.messageEmitter.on('response', checkResponses); checkResponses(); // Check existing responses }); } clearResponses() { this.responses = []; this.messageQueue = []; this.isConnected = false; this.messageEmitter.removeAllListeners(); } } //# sourceMappingURL=mcp-test-harness.js.map