#!/usr/bin/env node
const { spawn } = require('child_process');
async function detailedResponseTest() {
console.log('π DETAILED RESPONSE TEST - ALL 13 QUESTIONS');
console.log('=' .repeat(80));
console.log('Showing complete responses for each question');
console.log('');
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1'
}
});
const responses = [];
let requestId = 0;
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const parsed = JSON.parse(line);
responses.push(parsed);
} catch (e) {}
}
});
server.stderr.on('data', () => {}); // Suppress logs for cleaner output
await new Promise(resolve => setTimeout(resolve, 2000));
// Authenticate
console.log('π Authenticating...\n');
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'authenticate_user',
arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }
}
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 5000));
const questions = [
{
id: 1,
name: "MSP customers",
question: "show me the list of MSP customers",
request: {
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: { name: 'api___customer_list', arguments: {} }
}
},
{
id: 2,
name: "Total cost",
question: "what is my total cost?",
request: {
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01', endDate: '2025-08-27',
periodGranLevel: 'month', costType: ['cost'], isAmortized: true,
cloud_context: 'aws', accountId: '932213950603'
}
}
}
},
{
id: 3,
name: "AWS total cost",
question: "what is my total AWS cost?",
request: {
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01', endDate: '2025-08-27',
periodGranLevel: 'month', costType: ['cost'], isAmortized: true,
cloud_context: 'aws', accountId: '932213950603'
}
}
}
},
{
id: 4,
name: "GCP total cost",
question: "what is my total GCP cost?",
request: {
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01', endDate: '2025-08-27',
periodGranLevel: 'month', costType: ['cost'], isAmortized: true,
cloud_context: 'gcp', accountId: '932213950603'
}
}
}
},
{
id: 13,
name: "CloudWatch 30-day costs",
question: "what is the last 30 days (per day) amortized cost for Cloudwatch service?",
request: {
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-07-28', endDate: '2025-08-27',
periodGranLevel: 'day', costType: ['cost'], isAmortized: true,
cloud_context: 'aws', accountId: '932213950603',
service: 'CloudWatch'
}
}
}
}
];
// Send requests one by one and show responses
for (const q of questions) {
console.log('=' .repeat(80));
console.log(`Q${q.id}: ${q.name.toUpperCase()}`);
console.log('=' .repeat(80));
console.log(`Question: "${q.question}"`);
console.log('');
console.log('π€ REQUEST:');
console.log(JSON.stringify(q.request, null, 2));
console.log('');
console.log('π₯ Sending and waiting for response...');
server.stdin.write(JSON.stringify(q.request) + '\n');
await new Promise(resolve => setTimeout(resolve, 8000));
const response = responses.find(r => r.id === q.request.id);
console.log('');
console.log('π RESPONSE:');
console.log('-'.repeat(80));
if (!response) {
console.log('β NO RESPONSE RECEIVED');
} else if (response.error) {
console.log('β ERROR:');
console.log(JSON.stringify(response.error, null, 2));
} else if (response.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log(text);
// Analysis
console.log('');
console.log('π ANALYSIS:');
console.log('-'.repeat(40));
if (q.id === 13) {
// Special analysis for Q13
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
const totalCost = data.reduce((sum, item) => sum + parseFloat(item.total_cost || 0), 0);
const services = new Set();
data.forEach(item => {
if (item.service_name) services.add(item.service_name);
if (item.group_by && item.group_by !== 'Total') services.add(item.group_by);
});
console.log(`β’ Records: ${data.length}`);
console.log(`β’ Total cost: $${totalCost.toFixed(2)}`);
console.log(`β’ Services: ${Array.from(services).join(', ')}`);
if (services.size === 1 && services.has('AmazonCloudWatch')) {
console.log('β
SUCCESS: Only CloudWatch data returned (service filtering works!)');
} else {
console.log(`β ISSUE: Expected only CloudWatch, got ${services.size} services`);
}
if (data.length === 30) {
console.log('β
SUCCESS: 30 daily records as expected');
} else {
console.log(`β οΈ WARNING: ${data.length} records, expected 30`);
}
} catch (e) {
console.log('β JSON parsing failed');
}
} else {
console.log('β No JSON data found');
}
} else if ([2, 3, 4].includes(q.id)) {
// Cost analysis
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (Array.isArray(data)) {
const totalCost = data.reduce((sum, item) => sum + parseFloat(item.total_cost || 0), 0);
console.log(`β’ Records: ${data.length}`);
console.log(`β’ Total cost: $${totalCost.toFixed(2)}`);
if (data.length > 0) {
console.log(`β’ Usage date: ${data[0].usage_date}`);
console.log(`β’ Account: ${data[0].account_id}`);
if (data[0].group_by) console.log(`β’ Group by: ${data[0].group_by}`);
}
// Expected vs actual
const expected = { 2: 136045.96, 3: 136045.96, 4: 0.00 };
const exp = expected[q.id];
const diff = Math.abs(totalCost - exp);
const percent = exp > 0 ? (diff / exp * 100) : (totalCost > 0 ? 100 : 0);
if (percent <= 5) {
console.log(`β
GOOD: Within 5% of expected $${exp.toFixed(2)}`);
} else if (q.id === 4 && totalCost > 0) {
console.log(`β ISSUE: Expected $0 for GCP, but got $${totalCost.toFixed(2)}`);
console.log(' This suggests cloud_context=gcp is not filtering correctly');
} else {
console.log(`β οΈ DIFFERENCE: ${percent.toFixed(1)}% from expected $${exp.toFixed(2)}`);
}
}
} catch (e) {
console.log('β JSON parsing failed');
}
} else {
console.log('β No JSON data found');
}
} else {
// General analysis
console.log(`β’ Response length: ${text.length} characters`);
if (text.includes('MSP') || text.includes('customer')) {
console.log('β
SUCCESS: Contains MSP/customer information');
} else if (text.includes('accounts')) {
console.log('β
SUCCESS: Contains account information');
} else {
console.log('β οΈ INFO: Response format may differ from expected');
}
}
} else {
console.log('β UNEXPECTED RESPONSE FORMAT:');
console.log(JSON.stringify(response, null, 2));
}
console.log('');
}
server.kill();
console.log('=' .repeat(80));
console.log('π Detailed response test complete!');
console.log('=' .repeat(80));
}
detailedResponseTest().catch(console.error);