const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
// Disable SSL verification for local testing
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
const serverUrl = 'https://localhost:8787';
// Test with both MSP and direct customer authentication
const TEST_ACCOUNTS = [
{
username: 'david+allcloud@umbrellacost.com', // MSP account - can see Bank Leumi
password: 'Dsamsung1!',
description: 'MSP Account (AllCloud)'
},
{
username: 'david+saola@umbrellacost.com', // Direct customer - cannot see Bank Leumi
password: 'Dsamsung1!',
description: 'Direct Customer (SAOLA)'
}
];
async function authenticateAndTest(credentials) {
console.log('\n' + '='.repeat(70));
console.log(`🔑 Testing with: ${credentials.description}`);
console.log(` Username: ${credentials.username}`);
console.log('='.repeat(70));
// Authenticate
console.log('\n📝 Authenticating...');
const authResponse = await fetch(`${serverUrl}/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: credentials.username,
password: credentials.password
})
});
const authData = await authResponse.json();
if (!authData.token) {
console.log('❌ Authentication failed');
return;
}
console.log('âś… Authentication successful');
console.log(` Token: ${authData.token.substring(0, 50)}...`);
// Test Bank Leumi BL Test Env recommendations
console.log('\n🔍 Testing: "Bank Leumi BL Test Env" query');
const response = await fetch(`${serverUrl}/mcp`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${authData.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'tools/call',
params: {
name: 'get_all_recommendations',
arguments: {
userQuery: 'show me recommendations for Bank Leumi BL Test Env',
daysBack: 30,
pageSize: 100,
includeClosedAndDone: false // Explicitly set to open only
}
},
jsonrpc: '2.0',
id: 1
})
});
const result = await response.json();
if (result.result && result.result.content && result.result.content[0]) {
const content = result.result.content[0].text;
// Extract key metrics
const totalMatch = content.match(/\*\*Total Recommendations:\*\* (\d+)/);
const savingsMatch = content.match(/\*\*Total Potential Savings:\*\* \$[\d,]+\.\d{2}/);
const statusMatch = content.match(/\*\*Status Filter:\*\* ([^\n]+)/);
const customerMatch = content.match(/\*\*Customer:\*\* ([^\n]+)/);
console.log('\n📊 Results:');
if (customerMatch) console.log(` Customer Detected: ${customerMatch[1]}`);
if (statusMatch) console.log(` Status Filter: ${statusMatch[1]}`);
if (totalMatch) console.log(` Total Recommendations: ${totalMatch[1]}`);
if (savingsMatch) console.log(` ${savingsMatch[0].replace(/\*\*/g, '')}`);
// Show first few recommendations
const recsMatch = content.match(/## Top \d+ Recommendations by Savings:[\s\S]*?(?=##|$)/);
if (recsMatch) {
const recs = recsMatch[0].split(/\d+\.\s+\*\*/).slice(1, 4);
if (recs.length > 0) {
console.log('\n Top Recommendations:');
recs.forEach((rec, i) => {
const lines = rec.split('\n').filter(l => l.trim());
if (lines[0]) {
const firstLine = lines[0].replace(/\*\*/g, '').trim();
console.log(` ${i + 1}. ${firstLine.substring(0, 80)}...`);
}
});
}
}
// Check if this looks like Bank Leumi data or not
if (totalMatch && parseInt(totalMatch[1]) === 4) {
console.log('\n⚠️ WARNING: Only 4 recommendations found - this might be the wrong account data!');
}
} else if (result.error) {
console.log('❌ Error:', result.error.message || result.error);
}
// Also test without userQuery to see default behavior
console.log('\n🔍 Testing: Default recommendations (no userQuery)');
const response2 = await fetch(`${serverUrl}/mcp`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${authData.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'tools/call',
params: {
name: 'get_all_recommendations',
arguments: {
daysBack: 30,
pageSize: 100,
includeClosedAndDone: false
}
},
jsonrpc: '2.0',
id: 2
})
});
const result2 = await response2.json();
if (result2.result && result2.result.content && result2.result.content[0]) {
const content = result2.result.content[0].text;
const totalMatch = content.match(/\*\*Total Recommendations:\*\* (\d+)/);
const savingsMatch = content.match(/\*\*Total Potential Savings:\*\* \$[\d,]+\.\d{2}/);
console.log('\n📊 Default Results (no userQuery):');
if (totalMatch) console.log(` Total Recommendations: ${totalMatch[1]}`);
if (savingsMatch) console.log(` ${savingsMatch[0].replace(/\*\*/g, '')}`);
}
}
async function main() {
console.log('\n🚀 Bank Leumi Recommendations Test - Local MCP Server');
console.log('=' .repeat(70));
console.log('Testing customer detection and recommendations filtering\n');
try {
// Test with each account
for (const account of TEST_ACCOUNTS) {
await authenticateAndTest(account);
}
console.log('\n' + '='.repeat(70));
console.log('📝 Summary:');
console.log(' - MSP account (AllCloud) should see Bank Leumi data');
console.log(' - Direct customer (SAOLA) should NOT see Bank Leumi data');
console.log(' - includeClosedAndDone=false should show open recommendations only');
console.log('=' .repeat(70));
console.log('\nâś… Testing completed!\n');
} catch (error) {
console.error('❌ Error:', error.message);
console.error(error.stack);
}
}
main();