Skip to main content
Glama
final-complete-test.cjs15 kB
#!/usr/bin/env node // Final Complete Test - All questions with detailed informative answers const { spawn } = require('child_process'); const { EventEmitter } = require('events'); class FinalCompleteTest extends EventEmitter { constructor() { super(); this.serverProcess = null; this.messageId = 1; this.pendingRequests = new Map(); } async startServer() { console.log('🔌 Starting MCP server for final complete test...'); this.serverProcess = spawn('node', ['dist/index.js'], { stdio: ['pipe', 'pipe', 'pipe'] }); this.serverProcess.stdout.on('data', (data) => { const lines = data.toString().split('\n').filter(line => line.trim()); lines.forEach(line => { try { const message = JSON.parse(line); this.handleMessage(message); } catch (e) {} }); }); this.serverProcess.stderr.on('data', (data) => { // Suppress server logs for clean output }); await new Promise(resolve => setTimeout(resolve, 2000)); console.log('✅ MCP server ready for final test'); } handleMessage(message) { if (message.id && this.pendingRequests.has(message.id)) { const resolve = this.pendingRequests.get(message.id); this.pendingRequests.delete(message.id); resolve(message); } } async sendRequest(method, params) { const id = this.messageId++; const request = { jsonrpc: '2.0', id, method, params }; return new Promise((resolve, reject) => { this.pendingRequests.set(id, resolve); this.serverProcess.stdin.write(JSON.stringify(request) + '\n'); setTimeout(() => { if (this.pendingRequests.has(id)) { this.pendingRequests.delete(id); reject(new Error('Timeout')); } }, 30000); }); } async initialize() { await this.sendRequest('initialize', { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'final-complete-test', version: '1.0.0' } }); } async authenticate() { console.log('\n🔐 Authenticating david+saola@umbrellacost.com...'); const authResult = await this.sendRequest('tools/call', { name: 'authenticate_user', arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' } }); const authResponse = authResult.result.content[0].text; console.log('✅ Authentication successful'); return authResponse.includes('Successfully authenticated'); } formatCurrency(amount) { return `$${amount.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}`; } extractJsonData(response) { const jsonMatch = response.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { return JSON.parse(jsonMatch[1]); } catch (e) { return null; } } return null; } async testQuestion(questionNum, questionText, toolName, args, description) { console.log('\n' + '═'.repeat(80)); console.log(`📝 Q${questionNum}: "${questionText}"`); console.log(`📋 ${description}`); console.log('═'.repeat(80)); try { const result = await this.sendRequest('tools/call', { name: toolName, arguments: args }); const response = result.result.content[0].text; // Extract key metrics based on tool type if (toolName === 'api___invoices_caui') { await this.analyzeCostData(response, questionNum, questionText); } else if (toolName === 'api___recommendations_report') { await this.analyzeRecommendations(response, questionNum); } else if (toolName === 'api___users') { await this.analyzeAccounts(response, questionNum); } else if (toolName === 'api___msp_customers') { await this.analyzeMspCustomers(response, questionNum); } else if (toolName === 'api___anomaly_detection') { await this.analyzeAnomalies(response, questionNum); } } catch (error) { console.log(`❌ Q${questionNum} FAILED: ${error.message}`); } } async analyzeCostData(response, questionNum, questionText) { const itemsMatch = response.match(/\*\*Results:\*\* (\d+) items/); const jsonData = this.extractJsonData(response); if (!itemsMatch || itemsMatch[1] === '0') { console.log(`❌ Q${questionNum} RESULT: No cost data found`); console.log('💡 This may be expected for stale accounts (Azure/GCP) or MultiCloud aggregation issues'); return; } console.log(`✅ Q${questionNum} RESULT: ${itemsMatch[1]} items found`); if (jsonData && jsonData.length > 0) { let totalCost = 0; let totalUsage = 0; const account = jsonData[0].account_id; jsonData.forEach(item => { totalCost += item.total_cost || 0; totalUsage += item.total_usage_quantity || 0; }); console.log(`💰 TOTAL COST: ${this.formatCurrency(totalCost)}`); console.log(`🏢 ACCOUNT: ${account}`); console.log(`📊 USAGE QUANTITY: ${totalUsage.toLocaleString()} units`); // Show breakdown for monthly data if (questionText.includes('month') && jsonData.length > 1) { console.log('\n📅 MONTHLY BREAKDOWN:'); jsonData.forEach((item, index) => { const date = item.usage_date.includes('-') ? new Date(item.usage_date).toLocaleDateString('en-US', { month: 'long', year: 'numeric' }) : item.usage_date; console.log(` ${index + 1}. ${date}: ${this.formatCurrency(item.total_cost)}`); }); console.log(`\n📈 AVERAGE: ${this.formatCurrency(totalCost / jsonData.length)} per period`); } // Show sample daily data for non-monthly queries else if (jsonData.length > 1) { console.log(`\n📊 PERIOD: ${jsonData.length} days (${jsonData[0].usage_date} to ${jsonData[jsonData.length-1].usage_date})`); console.log(`📈 DAILY AVERAGE: ${this.formatCurrency(totalCost / jsonData.length)}`); // Show highest cost day const maxCostItem = jsonData.reduce((max, item) => item.total_cost > (max.total_cost || 0) ? item : max); console.log(`🔥 HIGHEST DAY: ${maxCostItem.usage_date} = ${this.formatCurrency(maxCostItem.total_cost)}`); } } } async analyzeRecommendations(response, questionNum) { const recMatch = response.match(/\*\*Results:\*\* (\d+) recommendations/); const savingsMatch = response.match(/Total.*?\$([0-9,]+\.?[0-9]*)/); console.log(`✅ Q${questionNum} RESULT: ${recMatch ? recMatch[1] : 'Unknown'} recommendations found`); if (savingsMatch) { console.log(`💰 TOTAL ANNUAL SAVINGS: $${savingsMatch[1]}`); } // Extract category breakdowns const categoryMatches = response.match(/\*\*(.*?):\*\* \$([0-9,]+\.?[0-9]*)/g); if (categoryMatches) { console.log('\n💡 SAVINGS BY CATEGORY:'); categoryMatches.forEach(match => { const categoryMatch = match.match(/\*\*(.*?):\*\* \$([0-9,]+\.?[0-9]*)/); if (categoryMatch) { console.log(` ${categoryMatch[1]}: $${categoryMatch[2]}`); } }); } // Extract top recommendations const topRecMatch = response.match(/🔝 Top \d+ Recommendations:([\s\S]*?)(?=\n\n|\n💡|\n\*\*|$)/); if (topRecMatch) { console.log('\n🔝 TOP RECOMMENDATIONS:'); const recommendations = topRecMatch[1].split('\n').filter(line => line.trim()).slice(0, 5); recommendations.forEach((rec, index) => { if (rec.trim()) { console.log(` ${index + 1}. ${rec.trim()}`); } }); } } async analyzeAccounts(response, questionNum) { // Count accounts by extracting account entries const accountMatches = response.match(/\*\*Account \d+:\*\*/g) || []; console.log(`✅ Q${questionNum} RESULT: ${accountMatches.length} accounts discovered`); // Extract cloud types const cloudMatches = response.match(/Cloud Type: ([^\n]+)/g) || []; const cloudTypes = {}; cloudMatches.forEach(match => { const cloud = match.replace('Cloud Type: ', ''); cloudTypes[cloud] = (cloudTypes[cloud] || 0) + 1; }); console.log('\n🌩️ CLOUD DISTRIBUTION:'); Object.entries(cloudTypes).forEach(([cloud, count]) => { console.log(` ${cloud}: ${count} account${count > 1 ? 's' : ''}`); }); // Extract account status info const activeMatch = response.match(/Last Process: 2025-/g) || []; const staleAccounts = accountMatches.length - activeMatch.length; console.log('\n📊 ACCOUNT STATUS:'); console.log(` Active (2025 data): ${activeMatch.length}`); console.log(` Stale (older data): ${staleAccounts}`); } async analyzeMspCustomers(response, questionNum) { const itemsMatch = response.match(/\*\*Results:\*\* (\d+) items/); console.log(`✅ Q${questionNum} RESULT: ${itemsMatch ? itemsMatch[1] : '0'} MSP customers`); console.log('💡 This is expected for this account type (direct customer, not MSP)'); } async analyzeAnomalies(response, questionNum) { console.log(`✅ Q${questionNum} RESULT: Anomaly detection completed`); // Check for anomalies in response if (response.includes('"anomalies": []') || response.includes('no anomalies')) { console.log('📊 ANOMALIES FOUND: 0 (normal operations)'); } else { console.log('🚨 ANOMALIES DETECTED: See detailed response'); } console.log('💡 Anomaly detection analyzes cost patterns for unusual spending spikes'); } async disconnect() { if (this.serverProcess) { this.serverProcess.kill(); console.log('\n🔌 Disconnected from MCP server'); } } } async function runFinalCompleteTest() { console.log('🎯 FINAL COMPLETE MCP TEST'); console.log('All questions from questions.test with detailed informative answers'); console.log('═'.repeat(80)); const tester = new FinalCompleteTest(); try { await tester.startServer(); await tester.initialize(); const authenticated = await tester.authenticate(); if (!authenticated) { console.log('❌ Authentication failed'); return; } // All questions from questions.test file with proper expectations const questions = [ { num: 2, question: "show me the list of customers", tool: "api___msp_customers", args: {}, description: "MSP customer list for account management" }, { num: 4, question: "what is my total cost?", tool: "api___invoices_caui", args: { startDate: "2025-08-11", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "day", costType: ["cost", "discount"], isUnblended: true }, description: "General total costs across all cloud providers (MultiCloud aggregation)" }, { num: 5, question: "what is my total AWS cost?", tool: "api___invoices_caui", args: { startDate: "2025-08-11", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "day", costType: ["cost", "discount"], isUnblended: true, cloud_context: "aws" }, description: "AWS-specific daily costs (should auto-switch to AWS account)" }, { num: 6, question: "what is my total GCP cost?", tool: "api___invoices_caui", args: { startDate: "2025-08-11", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "day", costType: ["cost", "discount"], isUnblended: true, cloud_context: "gcp" }, description: "GCP-specific costs (account last processed 2023-06-07)" }, { num: 7, question: "what is my total Azure cost?", tool: "api___invoices_caui", args: { startDate: "2025-08-11", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "day", costType: ["cost", "discount"], isUnblended: true, cloud_context: "azure" }, description: "Azure-specific costs (account last processed 2024-08-25)" }, { num: 8, question: "show me the total cost per month", tool: "api___invoices_caui", args: { startDate: "2025-02-01", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "month", costType: ["cost", "discount"], isUnblended: true }, description: "Monthly cost trends (MultiCloud aggregation over 7 months)" }, { num: 9, question: "show me the total AWS cost per month", tool: "api___invoices_caui", args: { startDate: "2025-06-01", endDate: "2025-08-17", groupBy: "none", periodGranLevel: "month", costType: ["cost", "discount"], isUnblended: true, cloud_context: "aws" }, description: "AWS monthly cost trends (verified against UI)" }, { num: 11, question: "show me all available accounts", tool: "api___users", args: {}, description: "Complete account inventory across all cloud providers" }, { num: 12, question: "what do you recommend to do for saving AWS costs?", tool: "api___recommendations_report", args: {}, description: "Cost optimization recommendations and potential savings" }, { num: 13, question: "what are the potential savings per category?", tool: "api___recommendations_report", args: {}, description: "Breakdown of cost savings by optimization category" }, { num: 14, question: "Is there any anomalies on AWS?", tool: "api___anomaly_detection", args: { startDate: "2025-08-11", endDate: "2025-08-17" }, description: "AWS cost anomaly detection for unusual spending patterns" } ]; for (const q of questions) { await tester.testQuestion(q.num, q.question, q.tool, q.args, q.description); } console.log('\n' + '🎉'.repeat(50)); console.log('🏁 FINAL COMPLETE TEST FINISHED'); console.log('All questions tested with detailed informative results'); console.log('MCP Server ready for Claude Desktop production!'); console.log('🎉'.repeat(50)); } catch (error) { console.error('❌ Test suite failed:', error.message); } finally { await tester.disconnect(); } } runFinalCompleteTest();

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