#!/usr/bin/env node
// Comprehensive test of all 12 questions for SAOLA account
const { spawn } = require('child_process');
class ComprehensiveQuestionsTest {
constructor() {
this.server = null;
this.requestId = 1;
this.responses = [];
this.questions = [
{
id: 1,
question: "What was my total AWS cost for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none"
}
}
},
{
id: 2,
question: "What was my total unblended AWS cost for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none",
costType: "unblended"
}
}
},
{
id: 3,
question: "What was my total amortized AWS cost for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none",
costType: "amortized"
}
}
},
{
id: 4,
question: "What was my total net amortized AWS cost for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none",
costType: "net amortized"
}
}
},
{
id: 5,
question: "What are my top 5 AWS services by cost for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "service"
}
}
},
{
id: 6,
question: "What are my AWS costs by account for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "account"
}
}
},
{
id: 7,
question: "What are my AWS costs by region for March 2025?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "region"
}
}
},
{
id: 8,
question: "How do my current month costs compare to last month?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-03-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none"
}
}
},
{
id: 9,
question: "What was my total AWS cost for the last 6 months?",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2024-10-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none"
}
}
},
{
id: 10,
question: "Show me my AWS cost trends over the last 3 months",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-01-01",
endDate: "2025-03-31",
cloud_context: "aws",
groupBy: "none"
}
}
},
{
id: 11,
question: "What cost optimization recommendations do you have?",
params: {
name: 'api___recommendations_report',
arguments: {}
}
},
{
id: 12,
question: "How much could I save with recommendations?",
params: {
name: 'api___recommendations_report',
arguments: {}
}
}
];
}
async startServer() {
return new Promise((resolve, reject) => {
console.log('🚀 Starting MCP Server for comprehensive questions test...');
this.server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: process.cwd()
});
this.server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
this.responses.push(response);
} catch (e) {
// Ignore non-JSON output
}
}
});
this.server.stderr.on('data', (data) => {
console.log('🔍 SERVER:', data.toString().trim());
});
this.server.on('error', reject);
setTimeout(resolve, 3000);
});
}
async sendRequest(method, params = {}) {
return new Promise((resolve) => {
const request = {
jsonrpc: "2.0",
id: this.requestId++,
method,
params
};
const startResponseCount = this.responses.length;
this.server.stdin.write(JSON.stringify(request) + '\n');
const checkForResponse = () => {
const newResponses = this.responses.slice(startResponseCount);
const matchingResponse = newResponses.find(r => r.id === request.id);
if (matchingResponse) {
resolve(matchingResponse);
} else {
setTimeout(checkForResponse, 100);
}
};
setTimeout(checkForResponse, 100);
});
}
calculateTotal(data) {
if (!Array.isArray(data)) return 0;
return data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
}
async runQuestion(questionObj) {
console.log(`\n${'='.repeat(80)}`);
console.log(`📊 QUESTION ${questionObj.id}: ${questionObj.question}`);
console.log(`${'='.repeat(80)}`);
const startTime = Date.now();
const response = await this.sendRequest('tools/call', questionObj.params);
const endTime = Date.now();
if (response.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log(`\n✅ RESPONSE (${endTime - startTime}ms):`);
console.log(text);
// Try to extract and calculate totals for cost questions
const jsonMatch = text.match(/```json\n(.*?)\n```/s);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
const total = this.calculateTotal(data);
if (total > 0) {
console.log(`\n💰 CALCULATED TOTAL: $${total.toFixed(2)}`);
}
} catch (e) {
// Ignore parsing errors
}
}
} else if (response.error) {
console.log(`\n❌ ERROR: ${JSON.stringify(response.error, null, 2)}`);
} else {
console.log(`\n⚠️ No response received`);
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
cleanup() {
if (this.server) {
this.server.kill();
}
}
}
async function runComprehensiveQuestionsTest() {
console.log('🧪 COMPREHENSIVE QUESTIONS TEST FOR SAOLA ACCOUNT');
console.log(`Testing all ${12} questions with detailed answers`);
console.log('═'.repeat(80));
const client = new ComprehensiveQuestionsTest();
await client.startServer();
// Authenticate with SAOLA account
console.log('\n🔐 Authenticating as SAOLA...');
const authResponse = await client.sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
if (!authResponse.result?.content?.[0]?.text?.includes('Successfully authenticated')) {
console.log('❌ Authentication failed');
client.cleanup();
return;
}
console.log('✅ Authentication successful - Ready to run all questions');
await new Promise(resolve => setTimeout(resolve, 2000));
// Run all questions sequentially
for (const question of client.questions) {
await client.runQuestion(question);
}
console.log(`\n${'='.repeat(80)}`);
console.log('✅ COMPLETED: All 12 questions have been tested');
console.log(`${'='.repeat(80)}`);
setTimeout(() => {
client.cleanup();
process.exit(0);
}, 3000);
}
runComprehensiveQuestionsTest().catch(console.error);