#!/usr/bin/env node
/**
* Final test for Bank Leumi fix
*/
const { spawn } = require('child_process');
async function finalBankLeumiTest() {
console.log('π FINAL BANK LEUMI TEST\n');
console.log('========================\n');
const mcp = spawn('node', ['dist/index.js'], {
env: {
...process.env,
USERNAME: 'david+allcloud@umbrellacost.com',
PASSWORD: 'B4*zcI7#F7poEC'
}
});
let requestId = 1;
mcp.stdout.on('data', (data) => {
const text = data.toString();
const lines = text.split('\n');
for (const line of lines) {
if (line.trim() && line.startsWith('{')) {
try {
const msg = JSON.parse(line);
// Handle initialization
if (msg.id === 0 && msg.result) {
console.log('β
Server initialized\n');
// First authenticate
setTimeout(() => {
const authRequest = {
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'authenticate_user',
arguments: {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
}
}
};
console.log('π Authenticating...\n');
mcp.stdin.write(JSON.stringify(authRequest) + '\n');
}, 500);
}
// Handle authentication response
if (msg.id === 1 && msg.result) {
console.log('β
Authentication successful\n');
console.log('βββββββββββββββββββββββββββββββββββββ\n');
// Test exactly as Claude Desktop would
setTimeout(() => {
const request = {
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'api___invoices_caui',
arguments: {
userQuery: 'Bank Leumi Account 1: Production Environment',
endDate: '2025-08-31',
groupBy: 'none',
costType: ['cost', 'discount'],
startDate: '2025-06-01',
isUnblended: true,
periodGranLevel: 'month'
}
}
};
console.log('π€ REQUEST: Bank Leumi Account 1: Production Environment\n');
console.log('Parameters:', JSON.stringify(request.params.arguments, null, 2), '\n');
mcp.stdin.write(JSON.stringify(request) + '\n');
}, 500);
}
// Handle cost response
if (msg.id === 2 && msg.result) {
console.log('βββββββββββββββββββββββββββββββββββββ\n');
console.log('π RESPONSE:\n');
if (msg.result.content && msg.result.content[0]) {
const content = msg.result.content[0];
try {
const text = content.text || '';
if (text.includes('```json')) {
const jsonMatch = text.match(/```json\s*([\s\S]*?)\s*```/);
if (jsonMatch) {
const jsonData = JSON.parse(jsonMatch[1]);
console.log(`Records: ${jsonData.length}`);
if (jsonData.length > 0) {
const firstRow = jsonData[0];
console.log(`Account ID returned: ${firstRow.account_id}`);
// Calculate totals by month
const monthly = {};
jsonData.forEach(row => {
const month = row.usage_date;
monthly[month] = (monthly[month] || 0) + row.total_cost;
});
console.log('\nMonthly costs:');
Object.entries(monthly).sort().forEach(([month, cost]) => {
console.log(` ${month}: $${cost.toFixed(2)}`);
});
const total = Object.values(monthly).reduce((sum, cost) => sum + cost, 0);
console.log(` βββββββββββββ`);
console.log(` Total: $${total.toFixed(2)}\n`);
console.log('βββββββββββββββββββββββββββββββββββββ\n');
console.log('β
VERIFICATION:\n');
if (firstRow.account_id === '696314371547') {
console.log(' β
Correct account ID (696314371547)');
} else {
console.log(` β Wrong account ID (${firstRow.account_id} instead of 696314371547)`);
}
if (total < 1) {
console.log(' β
Correct costs (~$0.01 for Reseller-1)');
console.log(' β
FIX IS WORKING!');
} else if (total > 1000) {
console.log(` β Wrong costs ($${total.toFixed(2)} - getting test env data)`);
console.log(' β Still getting wrong division data');
} else {
console.log(` π€ Unexpected cost range: $${total.toFixed(2)}`);
}
}
}
}
} catch (e) {
console.log('Error parsing response:', e.message);
}
}
console.log('\nπ Test complete\n');
setTimeout(() => {
mcp.kill();
process.exit(0);
}, 1000);
}
} catch (e) {
// Not JSON
}
}
}
});
mcp.stderr.on('data', (data) => {
const text = data.toString();
const lines = text.split('\n');
for (const line of lines) {
// Show key debug info
if (line.includes('Using accountKey') && line.includes('divisionId')) {
console.log(`π ${line.trim()}`);
} else if (line.includes('Built customer API key')) {
const match = line.match(/Built customer API key.*:(\d+):(\d+)$/);
if (match) {
console.log(`π API Key: ...accountKey:${match[1]}:divisionId:${match[2]}`);
}
} else if (line.includes('NOT adding as parameter')) {
console.log(`β οΈ ${line.split(']')[1].trim()}`);
}
}
});
// Initialize
setTimeout(() => {
const init = {
jsonrpc: '2.0',
id: 0,
method: 'initialize',
params: {
protocolVersion: '1.0.0',
capabilities: {},
clientInfo: {
name: 'final-test',
version: '1.0.0'
}
}
};
console.log('Initializing MCP server...\n');
mcp.stdin.write(JSON.stringify(init) + '\n');
}, 1000);
// Timeout
setTimeout(() => {
console.log('\nβ±οΈ Timeout');
mcp.kill();
process.exit(1);
}, 15000);
}
finalBankLeumiTest().catch(console.error);