Skip to main content
Glama
test-leumi-monthly.cjs9.33 kB
#!/usr/bin/env node const axios = require('axios'); const https = require('https'); const crypto = require('crypto'); const axiosInstance = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }), timeout: 30000 }); const MCP_BASE = 'https://produces-cartoon-august-persistent.trycloudflare.com'; async function testLeumiMonthly() { console.log('\n════════════════════════════════════════════════════════════'); console.log(' 📊 BANK LEUMI MONTHLY COSTS BREAKDOWN'); console.log('════════════════════════════════════════════════════════════\n'); try { // Step 1: OAuth flow (same as before) console.log('1️⃣ Authenticating through OAuth...'); const metadataResponse = await axiosInstance.get(`${MCP_BASE}/.well-known/oauth-authorization-server`); const registerResponse = await axiosInstance.post(`${MCP_BASE}/register`, { client_name: "Claude Desktop", grant_types: ["authorization_code", "refresh_token"], response_types: ["code"], token_endpoint_auth_method: "client_secret_post", scope: "claudeai", redirect_uris: ["https://claude.ai/api/mcp/auth_callback"] }); const clientId = registerResponse.data.client_id; const loginResponse = await axiosInstance.post(`${MCP_BASE}/login`, 'username=david%2Ballcloud%40umbrellacost.com&password=Dsamsung1%21123&state=test&client_id=' + clientId, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, maxRedirects: 0, validateStatus: (status) => status === 302 } ); const cookies = loginResponse.headers['set-cookie']; const sidCookie = cookies?.find(c => c.startsWith('sid=')); const sid = sidCookie?.split(';')[0].split('=')[1]; const codeVerifier = crypto.randomBytes(32).toString('base64url'); const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url'); const authResponse = await axiosInstance.get(`${MCP_BASE}/authorize`, { params: { response_type: 'code', client_id: clientId, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', state: 'test-state', code_challenge: codeChallenge, code_challenge_method: 'S256' }, headers: { 'Cookie': `sid=${sid}` } }); const codeMatch = authResponse.data.match(/code=([^&\"]+)/); const authCode = codeMatch ? codeMatch[1] : null; const tokenResponse = await axiosInstance.post(`${MCP_BASE}/oauth/token`, new URLSearchParams({ grant_type: 'authorization_code', code: authCode, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', client_id: clientId, code_verifier: codeVerifier }).toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ); const accessToken = tokenResponse.data.access_token; console.log('✅ Authentication successful\n'); // Step 2: Initialize MCP console.log('2️⃣ Initializing MCP session...'); await axiosInstance.post(`${MCP_BASE}/mcp`, { method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "claude-desktop", version: "1.0.0" } }, jsonrpc: "2.0", id: 0 }, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' } }); console.log('✅ MCP session initialized\n'); // Step 3: Get Bank Leumi August 2025 cost (to match MANUAL_ANSWERS.txt) console.log('3️⃣ Fetching Bank Leumi costs for August 2025...'); console.log('════════════════════════════════════════════════════════════'); const testRequest = { method: "tools/call", params: { name: "api__invoices_caui", arguments: { customer_account_key: "22676", // Bank Leumi customer_division_id: "139", // Bank Leumi Division ID startDate: "2025-08-01", endDate: "2025-08-31", periodGranLevel: "month", groupBy: "none", costType: "[\"cost\", \"discount\"]", isUnblended: "true", userQuery: "Bank Leumi Reseller-1 August no grouping" } }, jsonrpc: "2.0", id: 1 }; console.log('📤 Requesting data for August 2025 only (should be $0.0026837)...\n'); const mcpResponse = await axiosInstance.post(`${MCP_BASE}/mcp`, testRequest, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' } }); // Parse SSE response const responseData = mcpResponse.data; let parsedData; if (typeof responseData === 'string' && responseData.includes('event: message')) { const dataMatch = responseData.match(/data: ({.*})/); if (dataMatch) { parsedData = JSON.parse(dataMatch[1]); } } else { parsedData = responseData; } if (parsedData?.result?.content?.[0]?.text) { const content = parsedData.result.content[0].text; // Extract account ID first to confirm it's Bank Leumi const accountMatch = content.match(/\"account_id\":\s*\"(\d+)\"/); if (accountMatch) { const accountId = accountMatch[1]; console.log(`📋 Account: ${accountId}`); if (accountId === '696314371547') { console.log(' ✅ CONFIRMED: Bank Leumi account\n'); } else { console.log(` ❌ WRONG ACCOUNT: Expected 696314371547 (Bank Leumi)\n`); } } // Parse the August data const costMatch = content.match(/\"total_cost\":\s*([0-9.]+)/); const usageMatch = content.match(/\"total_usage_quantity\":\s*([0-9.]+)/); if (costMatch) { const totalCost = parseFloat(costMatch[1]); const totalUsage = usageMatch ? parseFloat(usageMatch[1]) : 0; const expectedCost = 0.0026837670123269763; // From MANUAL_ANSWERS.txt console.log('📊 BANK LEUMI AUGUST 2025 COSTS:'); console.log('═══════════════════════════════'); console.log(` Total Cost: $${totalCost.toFixed(10)}`); console.log(` Expected Cost: $${expectedCost.toFixed(10)}`); console.log(` Usage Quantity: ${totalUsage.toFixed(4)} units`); console.log('═══════════════════════════════'); if (Math.abs(totalCost - expectedCost) < 0.0001) { console.log(' ✅ CORRECT! Matches expected value from MANUAL_ANSWERS.txt'); } else { console.log(` ❌ WRONG! Expected $${expectedCost.toFixed(10)} but got $${totalCost.toFixed(10)}`); console.log(` Difference: $${Math.abs(totalCost - expectedCost).toFixed(10)}`); } } else { console.log('⚠️ Could not parse cost from response'); } } else { console.log('⚠️ Unexpected response format'); console.log(JSON.stringify(parsedData, null, 2)); } console.log('\n════════════════════════════════════════════════════════════\n'); } catch (error) { console.error('\n❌ Error:', error.message); if (error.response) { console.error('Status:', error.response.status); console.error('Response:', JSON.stringify(error.response.data, null, 2)); } } } testLeumiMonthly().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