eventpulse-mcp
Version:
EventPulse MCP Server - Hyper-local event-driven marketing campaigns for small businesses
239 lines (202 loc) โข 7.69 kB
JavaScript
const { spawn } = require('child_process');
const path = require('path');
class MCPTester {
constructor() {
this.serverProcess = null;
this.testResults = [];
}
async runTest() {
console.log('๐งช Starting EventPulse MCP Server Tests\n');
try {
await this.testListTools();
await this.testCampaignGeneration();
await this.testFestivalInsights();
await this.testErrorHandling();
this.printResults();
} catch (error) {
console.error('โ Test suite failed:', error);
}
}
async testListTools() {
console.log('๐ Testing list_tools...');
const request = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {}
};
const result = await this.sendMCPRequest(request);
if (result && result.tools && result.tools.length === 2) {
this.testResults.push({ test: 'list_tools', status: 'โ
PASS', details: `Found ${result.tools.length} tools` });
console.log(' โ
Tools listed successfully');
console.log(` ๐ Available tools: ${result.tools.map(t => t.name).join(', ')}\n`);
} else {
this.testResults.push({ test: 'list_tools', status: 'โ FAIL', details: 'Invalid tools response' });
console.log(' โ Failed to list tools\n');
}
}
async testCampaignGeneration() {
console.log('๐ฏ Testing campaign generation...');
const request = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'generate_festival_campaign',
arguments: {
business_type: 'sweet_shop',
event: 'diwali',
language: 'hindi',
location: 'Mumbai',
goal: 'increase_sales'
}
}
};
const result = await this.sendMCPRequest(request);
if (result && result.content && result.content[0] && result.content[0].text) {
const content = result.content[0].text;
if (content.includes('Campaign ID') && content.includes('WhatsApp Message')) {
this.testResults.push({ test: 'campaign_generation', status: 'โ
PASS', details: 'Campaign generated successfully' });
console.log(' โ
Campaign generated successfully');
console.log(' ๐ฑ Contains WhatsApp message, social posts, and hashtags\n');
} else {
this.testResults.push({ test: 'campaign_generation', status: 'โ FAIL', details: 'Incomplete campaign content' });
console.log(' โ Campaign content incomplete\n');
}
} else {
this.testResults.push({ test: 'campaign_generation', status: 'โ FAIL', details: 'No campaign content returned' });
console.log(' โ Failed to generate campaign\n');
}
}
async testFestivalInsights() {
console.log('๐ญ Testing festival insights...');
const request = {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'get_festival_insights',
arguments: {
event: 'diwali',
region: 'north_india'
}
}
};
const result = await this.sendMCPRequest(request);
if (result && result.content && result.content[0] && result.content[0].text) {
const content = result.content[0].text;
if (content.includes('Cultural Insights') && content.includes('Marketing Opportunities')) {
this.testResults.push({ test: 'festival_insights', status: 'โ
PASS', details: 'Insights retrieved successfully' });
console.log(' โ
Festival insights retrieved successfully');
console.log(' ๐ญ Contains cultural significance and marketing opportunities\n');
} else {
this.testResults.push({ test: 'festival_insights', status: 'โ FAIL', details: 'Incomplete insights content' });
console.log(' โ Insights content incomplete\n');
}
} else {
this.testResults.push({ test: 'festival_insights', status: 'โ FAIL', details: 'No insights content returned' });
console.log(' โ Failed to get festival insights\n');
}
}
async testErrorHandling() {
console.log('โ ๏ธ Testing error handling...');
const request = {
jsonrpc: '2.0',
id: 4,
method: 'tools/call',
params: {
name: 'generate_festival_campaign',
arguments: {
business_type: 'invalid_type',
event: 'invalid_event',
language: 'invalid_language'
}
}
};
const result = await this.sendMCPRequest(request);
if (result && (result.error || (result.content && result.isError))) {
this.testResults.push({ test: 'error_handling', status: 'โ
PASS', details: 'Errors handled properly' });
console.log(' โ
Error handling works correctly');
console.log(' โ ๏ธ Invalid parameters rejected as expected\n');
} else {
this.testResults.push({ test: 'error_handling', status: 'โ FAIL', details: 'Errors not handled properly' });
console.log(' โ Error handling failed\n');
}
}
async sendMCPRequest(request) {
return new Promise((resolve, reject) => {
const serverPath = path.join(__dirname, '../src/mcp-server.js');
const child = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
let stdout = '';
let stderr = '';
child.stdout.on('data', (data) => {
stdout += data.toString();
});
child.stderr.on('data', (data) => {
stderr += data.toString();
});
child.on('close', (code) => {
try {
// Parse the JSON-RPC response
const lines = stdout.split('\n').filter(line => line.trim());
const responseLine = lines.find(line => {
try {
const parsed = JSON.parse(line);
return parsed.id === request.id;
} catch {
return false;
}
});
if (responseLine) {
const response = JSON.parse(responseLine);
resolve(response.result || response);
} else {
resolve(null);
}
} catch (error) {
reject(error);
}
});
child.on('error', (error) => {
reject(error);
});
// Send the request
child.stdin.write(JSON.stringify(request) + '\n');
child.stdin.end();
// Timeout after 10 seconds
setTimeout(() => {
child.kill();
resolve(null);
}, 10000);
});
}
printResults() {
console.log('๐ Test Results Summary');
console.log('========================');
let passed = 0;
let failed = 0;
this.testResults.forEach(result => {
console.log(`${result.status} ${result.test}: ${result.details}`);
if (result.status.includes('โ
')) passed++;
else failed++;
});
console.log('\n๐ Final Score:');
console.log(`โ
Passed: ${passed}`);
console.log(`โ Failed: ${failed}`);
console.log(`๐ Success Rate: ${Math.round((passed / (passed + failed)) * 100)}%`);
if (failed === 0) {
console.log('\n๐ All tests passed! EventPulse MCP Server is ready for production.');
} else {
console.log('\nโ ๏ธ Some tests failed. Please check the implementation.');
}
}
}
// Run tests if called directly
if (require.main === module) {
const tester = new MCPTester();
tester.runTest().catch(console.error);
}
module.exports = MCPTester;