#!/usr/bin/env node
const { spawn } = require('child_process');
// Test production MCP server correctly using STDIO protocol
class CorrectProductionTest {
constructor() {
this.mcpProcess = null;
this.results = [];
this.authenticated = false;
}
async startMCP() {
console.log('π Starting Production MCP Server via STDIO (correct method)...');
this.mcpProcess = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: '/Users/david/Downloads/MCP/UmbrellaMCP/production'
});
this.mcpProcess.stderr.on('data', (data) => {
console.log('MCP Server:', data.toString().trim());
});
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 3000));
}
sendMCPRequest(method, params) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method,
params: params || {}
};
console.log('π€ Sending MCP Request:', JSON.stringify(request, null, 2));
this.mcpProcess.stdin.write(JSON.stringify(request) + '\n');
let buffer = '';
const handler = (data) => {
buffer += data.toString();
const lines = buffer.split('\n');
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i].trim();
if (line) {
try {
const response = JSON.parse(line);
if (response.id === request.id) {
this.mcpProcess.stdout.removeListener('data', handler);
console.log('π₯ Received MCP Response:', JSON.stringify(response, null, 2));
resolve(response);
return;
}
} catch (e) {
// Not complete JSON yet
}
}
}
buffer = lines[lines.length - 1];
};
this.mcpProcess.stdout.on('data', handler);
setTimeout(() => {
this.mcpProcess.stdout.removeListener('data', handler);
reject(new Error('Request timeout'));
}, 30000);
});
}
async authenticate() {
console.log('\nπ Authenticating SAOLA account via MCP...');
try {
// First initialize
await this.sendMCPRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
});
// Then authenticate
const authResponse = await this.sendMCPRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
if (authResponse.result?.content?.[0]?.text?.includes('Successfully')) {
console.log('β
Authentication successful');
this.authenticated = true;
return true;
} else {
console.log('β Authentication failed:', authResponse);
return false;
}
} catch (error) {
console.log('β Authentication error:', error.message);
return false;
}
}
async testProductionQuestions() {
console.log('\nπ Testing Production MCP Server with Correct Protocol');
console.log('=' .repeat(80));
try {
await this.startMCP();
const authSuccess = await this.authenticate();
if (!authSuccess) {
console.log('β Cannot proceed without authentication');
return;
}
console.log('\nπ Testing questions with correct tools...\n');
// Test the questions from the production test file
const questions = [
{
id: 'Q1',
query: 'what is my total cost?',
tool: 'api__invoices_caui',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
groupBy: 'service',
periodGranLevel: 'day',
costType: ['cost', 'discount'],
isUnblended: true,
accountId: '532523076083' // Correct SAOLA account ID
}
},
{
id: 'Q2',
query: 'show me the total cost per month',
tool: 'api__invoices_caui',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
groupBy: 'service',
periodGranLevel: 'month',
costType: ['cost', 'discount'],
isUnblended: true,
accountId: '532523076083'
}
},
{
id: 'Q3',
query: 'show me all available accounts',
tool: 'api__users',
params: {}
},
{
id: 'Q4',
query: 'what do you recommend for saving AWS costs?',
tool: 'api__recommendations_report',
params: {}
},
{
id: 'Q5',
query: 'are there any anomalies on AWS?',
tool: 'api__anomaly_detection',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31'
}
}
];
for (const question of questions) {
console.log(`\n${'='.repeat(60)}`);
console.log(`${question.id}: ${question.query}`);
console.log(`Tool: ${question.tool}`);
console.log(`${'='.repeat(60)}`);
try {
const response = await this.sendMCPRequest('tools/call', {
name: question.tool,
arguments: question.params
});
if (response.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log(`π Response (${text.length} chars):`, text.substring(0, 500) + '...');
// Try to extract meaningful data
try {
const data = JSON.parse(text);
if (Array.isArray(data)) {
console.log(`π JSON Array with ${data.length} items`);
if (data.length > 0 && data[0].total_cost !== undefined) {
const total = data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(`π° Total Cost: $${total.toFixed(2)}`);
}
} else {
console.log(`π JSON Object with keys: ${Object.keys(data)}`);
}
} catch (e) {
console.log(`π Text response (not JSON)`);
}
} else if (response.error) {
console.log(`β Error:`, response.error);
} else {
console.log(`β Unexpected response format`);
}
} catch (error) {
console.log(`β Request failed:`, error.message);
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
} finally {
if (this.mcpProcess) {
this.mcpProcess.kill();
console.log('\nπ MCP Server stopped');
}
}
}
}
const test = new CorrectProductionTest();
test.testProductionQuestions().catch(console.error);