Skip to main content
Glama
cost-debug.cjs4.37 kB
#!/usr/bin/env node // Debug script to understand why costs are showing as $0 const { spawn } = require('child_process'); class CostDebugger { constructor() { this.mcpProcess = null; } async debugCosts() { console.log('🔍 DEBUG: COST ANALYSIS RESPONSES'); console.log('================================='); try { await this.startServer(); await this.authenticate(); // Test with different accountId values const accountIds = ['268413799883', '932213950603', null]; for (const accountId of accountIds) { console.log(`\n🧪 Testing with accountId: ${accountId || 'none'}`); console.log('=' .repeat(50)); const params = { startDate: '2025-08-01', endDate: '2025-08-31', periodGranLevel: 'month', costType: ['cost', 'discount'], isUnblended: true, cloud_context: 'aws' }; if (accountId) { params.accountId = accountId; } const response = await this.makeCall('api__invoices_caui', params); if (response.success) { console.log('✅ Raw Response:'); if (response.data && response.data.content && response.data.content[0]) { const text = response.data.content[0].text; console.log(text); // Extract costs specifically const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); console.log('\n📊 Parsed Data:'); console.log(JSON.stringify(data, null, 2)); if (Array.isArray(data)) { const totalCost = data.reduce((sum, item) => sum + (parseFloat(item.total_cost) || 0), 0); console.log(`\n💰 Total Cost Calculated: $${totalCost.toFixed(2)}`); } } catch (e) { console.log(`❌ JSON Parse Error: ${e.message}`); } } } } else { console.log(`❌ Failed: ${response.error}`); } } } catch (error) { console.error('Debug failed:', error.message); } finally { await this.cleanup(); } } async startServer() { this.mcpProcess = spawn('node', ['dist/index.js'], { stdio: ['pipe', 'pipe', 'pipe'], cwd: __dirname, env: { ...process.env, UMBRELLA_API_BASE_URL: 'https://api.umbrellacost.io/api/v1' } }); await this.wait(3000); } async authenticate() { await this.makeCall('authenticate_user', { username: 'david+allcloud@umbrellacost.com', password: 'B4*zcI7#F7poEC' }); } async makeCall(endpoint, params) { return new Promise((resolve) => { try { const request = { jsonrpc: '2.0', id: Date.now(), method: 'tools/call', params: { name: endpoint, arguments: params } }; const requestString = JSON.stringify(request) + '\n'; this.mcpProcess.stdin.write(requestString); const timeout = setTimeout(() => { resolve({ success: false, error: 'Timeout' }); }, 10000); const responseHandler = (data) => { clearTimeout(timeout); try { const lines = data.toString().split('\n').filter(line => line.trim()); const lastLine = lines[lines.length - 1]; const response = JSON.parse(lastLine); if (response.error) { resolve({ success: false, error: response.error.message }); } else { resolve({ success: true, data: response.result }); } } catch (error) { resolve({ success: false, error: 'Parse error' }); } }; this.mcpProcess.stdout.once('data', responseHandler); } catch (error) { resolve({ success: false, error: error.message }); } }); } wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async cleanup() { if (this.mcpProcess) { this.mcpProcess.kill(); } } } new CostDebugger().debugCosts();

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