Skip to main content
Glama
final-all-questions.cjs14.7 kB
#!/usr/bin/env node // Final comprehensive test of all 12 questions with correct tax-excluded baseline const { spawn } = require('child_process'); class FinalQuestionsTest { 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-02-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 final comprehensive 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) {} } }); this.server.stderr.on('data', (data) => { const message = data.toString().trim(); if (message.includes('authenticated') || message.includes('TAX-EXCLUSION')) { console.log('🔍 SERVER:', message); } }); 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); } extractTopServices(data, limit = 5) { if (!Array.isArray(data)) return []; // Group by service and sum costs const serviceMap = {}; data.forEach(item => { const serviceName = item.service_name || item.group_by || 'Unknown'; if (!serviceMap[serviceName]) { serviceMap[serviceName] = 0; } serviceMap[serviceName] += (item.total_cost || 0); }); // Convert to array and sort by cost return Object.entries(serviceMap) .sort(([,a], [,b]) => b - a) .slice(0, limit); } extractDailyBreakdown(data, limit = 7) { if (!Array.isArray(data)) return []; return data .filter(item => item.usage_date) .sort((a, b) => new Date(b.usage_date) - new Date(a.usage_date)) .slice(0, limit); } async runQuestion(questionObj) { console.log(`\n${'='.repeat(100)}`); console.log(`📊 QUESTION ${questionObj.id}: ${questionObj.question}`); console.log(`${'='.repeat(100)}`); 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; // Try to extract JSON data for analysis const jsonMatch = text.match(/```json\n(.*?)\n```/s); let data = null; let total = 0; if (jsonMatch) { try { data = JSON.parse(jsonMatch[1]); total = this.calculateTotal(data); } catch (e) { console.log('⚠️ JSON parsing error, showing raw response'); } } console.log(`\n✅ RESPONSE (${endTime - startTime}ms):`); // Provide detailed analysis based on question type if (questionObj.id === 1) { // Question 1: Total AWS cost console.log(`💰 **ANSWER: $${total.toFixed(2)}** (tax excluded by default)`); if (Math.abs(total - 104755.07) < 1) { console.log(`🎯 ✅ CORRECT! Matches expected $104,755.07`); } if (data && data.length > 0) { console.log(`\n📊 Daily breakdown (last 7 days):`); const dailyData = this.extractDailyBreakdown(data, 7); dailyData.forEach(item => { console.log(` ${item.usage_date}: $${(item.total_cost || 0).toFixed(2)}`); }); } } else if (questionObj.id === 2) { // Question 2: Unblended cost console.log(`💰 **UNBLENDED COST: $${total.toFixed(2)}**`); if (Math.abs(total - 104755.07) < 1) { console.log(`🎯 ✅ CORRECT! Matches baseline $104,755.07`); } } else if (questionObj.id === 3) { // Question 3: Amortized cost console.log(`💰 **AMORTIZED COST: $${total.toFixed(2)}**`); if (total < 104755.07) { const savings = 104755.07 - total; const percentage = (savings / 104755.07 * 100); console.log(`💡 RI/SP Savings: $${savings.toFixed(2)} (${percentage.toFixed(1)}% savings)`); } } else if (questionObj.id === 4) { // Question 4: Net amortized console.log(`💰 **NET AMORTIZED COST: $${total.toFixed(2)}**`); if (total < 104755.07) { const savings = 104755.07 - total; console.log(`💡 Total RI/SP + discount savings: $${savings.toFixed(2)}`); } } else if (questionObj.id === 5) { // Question 5: Top services console.log(`💰 **TOTAL ACROSS ALL SERVICES: $${total.toFixed(2)}**`); if (data) { const topServices = this.extractTopServices(data, 5); console.log(`\n🏆 **TOP 5 AWS SERVICES BY COST:**`); topServices.forEach(([service, cost], index) => { const percentage = (cost / total * 100); console.log(` ${index + 1}. ${service}: $${cost.toFixed(2)} (${percentage.toFixed(1)}%)`); }); } } else if (questionObj.id === 6) { // Question 6: By account console.log(`💰 **TOTAL ACROSS ALL ACCOUNTS: $${total.toFixed(2)}**`); if (data) { console.log(`📊 Found ${data.length} account cost entries`); } } else if (questionObj.id === 7) { // Question 7: By region console.log(`💰 **TOTAL ACROSS ALL REGIONS: $${total.toFixed(2)}**`); if (data) { console.log(`🌍 Found ${data.length} regional cost entries`); } } else if (questionObj.id === 8) { // Question 8: Month comparison console.log(`💰 **TOTAL FOR PERIOD: $${total.toFixed(2)}**`); console.log(`📈 This includes February + March 2025 for comparison`); } else if (questionObj.id === 9) { // Question 9: 6 months console.log(`💰 **6-MONTH TOTAL: $${total.toFixed(2)}**`); const monthlyAvg = total / 6; console.log(`📊 Average monthly cost: $${monthlyAvg.toFixed(2)}`); } else if (questionObj.id === 10) { // Question 10: 3-month trend console.log(`💰 **3-MONTH TOTAL: $${total.toFixed(2)}**`); const monthlyAvg = total / 3; console.log(`📈 Q1 2025 average: $${monthlyAvg.toFixed(2)}/month`); } else if (questionObj.id === 11 || questionObj.id === 12) { // Questions 11 & 12: Recommendations const recCountMatch = text.match(/(\d+)\s+recommendations/i); const savingsMatch = text.match(/\$([0-9,]+(?:\.\d+)?)/); if (questionObj.id === 11) { console.log(`🎯 **COST OPTIMIZATION RECOMMENDATIONS**`); if (recCountMatch) { console.log(`📊 Total recommendations: ${recCountMatch[1]}`); } } else { console.log(`💰 **POTENTIAL ANNUAL SAVINGS**`); if (savingsMatch) { console.log(`💵 Annual savings: $${savingsMatch[1]}`); const monthlySavings = parseFloat(savingsMatch[1].replace(',', '')) / 12; console.log(`📅 Monthly savings: $${monthlySavings.toFixed(2)}`); } } // Show first part of recommendations response console.log(`\n📋 Summary:`); const lines = text.split('\n').slice(0, 15); lines.forEach(line => { if (line.trim() && !line.includes('```')) { console.log(` ${line.substring(0, 80)}`); } }); } // Show total for all cost questions if (total > 0 && questionObj.id <= 10) { console.log(`\n💰 **CALCULATED TOTAL: $${total.toFixed(2)}**`); } } 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, 1500)); } cleanup() { if (this.server) { this.server.kill(); } } } async function runFinalTest() { console.log('🎯 FINAL COMPREHENSIVE TEST - ALL 12 QUESTIONS'); console.log('✅ Tax exclusion fixed - baseline should be $104,755.07'); console.log('🔧 Server configured to exclude tax by default for AWS'); console.log('═'.repeat(100)); const client = new FinalQuestionsTest(); 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) { try { await client.runQuestion(question); } catch (error) { console.log(`❌ Error in question ${question.id}:`, error.message); } } console.log(`\n${'='.repeat(100)}`); console.log('🎉 ✅ COMPLETED: All 12 questions tested with correct tax-excluded baseline'); console.log('💰 March 2025 AWS baseline: $104,755.07 (tax excluded)'); console.log('🏛️ Tax amount: $18,855.91 (18.0%) - excluded by default'); console.log(`${'='.repeat(100)}`); setTimeout(() => { client.cleanup(); process.exit(0); }, 3000); } runFinalTest().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daviddraiumbrella/invoice-monitoring'

If you have feedback or need assistance with the MCP directory API, please join our Discord server