const https = require('https');
// Test configuration
const MCP_ENDPOINT = 'https://wireless-humanities-reality-batch.trycloudflare.com/mcp';
const AUTH_TOKEN = process.env.AUTH_TOKEN;
async function makeRequest(body) {
return new Promise((resolve, reject) => {
const url = new URL(MCP_ENDPOINT);
const options = {
hostname: url.hostname,
port: url.port || 443,
path: url.pathname,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': AUTH_TOKEN ? `Bearer ${AUTH_TOKEN}` : undefined,
'Accept': 'application/json, text/event-stream'
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
resolve(JSON.parse(data));
} catch (e) {
resolve(data);
}
});
});
req.on('error', reject);
req.write(JSON.stringify(body));
req.end();
});
}
async function analyzeDetectionLogic() {
console.log('🔍 Analyzing Customer Detection Logic\n');
// Test queries that should trigger different detection behavior
const testCases = [
{
name: "Bank Leumi (main account)",
query: "show me Bank Leumi costs last 6 months",
expectedAccount: "22676", // Reseller-1
expectedCustomer: "Bank Leumi"
},
{
name: "Bank Leumi Test Env",
query: "show me Bank Leumi Test Env costs last 6 months",
expectedAccount: "24223", // BL Test Env
expectedCustomer: "Bank Leumi"
},
{
name: "BL Test Env",
query: "show me BL Test Env costs last 6 months",
expectedAccount: "24223", // BL Test Env
expectedCustomer: "Bank Leumi"
},
{
name: "Bank Leumi TestEnv",
query: "show me Bank Leumi TestEnv costs last 6 months",
expectedAccount: "24223", // BL Test Env
expectedCustomer: "Bank Leumi"
}
];
for (const testCase of testCases) {
console.log(`\n=== Testing: ${testCase.name} ===`);
console.log(`Query: "${testCase.query}"`);
console.log(`Expected Account: ${testCase.expectedAccount}`);
const request = {
jsonrpc: '2.0',
method: 'tools/call',
params: {
name: 'api__invoices_caui',
arguments: {
accountId: '696314371547',
startDate: '2025-03-01',
endDate: '2025-09-26',
periodGranLevel: 'month',
groupBy: 'none',
costType: '["cost", "discount"]',
userQuery: testCase.query
}
},
id: Math.floor(Math.random() * 1000)
};
try {
const response = await makeRequest(request);
if (response.result) {
const responseStr = JSON.stringify(response.result);
// Look for API key patterns
const apiKeyMatch = responseStr.match(/([a-f0-9-]{36}):(\d+):(\d+)/);
if (apiKeyMatch) {
const [fullKey, uuid, accountKey, divisionFlag] = apiKeyMatch;
console.log(`✅ API Key Found: ${fullKey}`);
console.log(` Account Key: ${accountKey}`);
console.log(` Division Flag: ${divisionFlag}`);
if (accountKey === testCase.expectedAccount) {
console.log(`✅ CORRECT: Account key matches expected ${testCase.expectedAccount}`);
} else {
console.log(`❌ WRONG: Account key ${accountKey} != expected ${testCase.expectedAccount}`);
}
} else {
console.log('❌ No API key pattern found in response');
}
// Look for account name mentions in the request/response
if (responseStr.includes('22676')) {
console.log('📍 Found account 22676 (Reseller-1) in response');
}
if (responseStr.includes('24223')) {
console.log('📍 Found account 24223 (BL Test Env) in response');
}
// Check isPpApplied
const ppMatch = responseStr.match(/"isPpApplied":\s*(true|false)/);
if (ppMatch) {
console.log(`isPpApplied: ${ppMatch[1]}`);
}
} else if (response.error) {
console.log('❌ Error:', response.error.message);
}
} catch (error) {
console.error('❌ Request failed:', error.message);
}
// Wait between requests
await new Promise(resolve => setTimeout(resolve, 1000));
}
// Now test the word matching logic manually
console.log('\n\n🧪 Manual Word Matching Analysis\n');
const accountNames = [
"Reseller-1",
"BL Test Env"
];
const queries = [
"show me Bank Leumi costs last 6 months",
"show me Bank Leumi Test Env costs last 6 months",
"show me BL Test Env costs last 6 months"
];
for (const query of queries) {
console.log(`\nQuery: "${query}"`);
const queryLower = query.toLowerCase();
const queryWords = queryLower.split(/[\s-]+/).filter(w => w.length > 2);
console.log(`Query words: [${queryWords.join(', ')}]`);
for (const accountName of accountNames) {
console.log(` Testing account: "${accountName}"`);
const accountNameLower = accountName.toLowerCase();
const accountWords = accountNameLower.split(/[\s-]+/).filter(w => w.length > 2);
console.log(` Account words: [${accountWords.join(', ')}]`);
// Check matching logic
const matchingWords = accountWords.filter(word =>
queryWords.some(qWord => qWord.includes(word) || word.includes(qWord))
);
console.log(` Matching words: [${matchingWords.join(', ')}]`);
// Check the various conditions
const fullMatch = queryLower.includes(accountNameLower);
const wordOverlap = matchingWords.length >= Math.min(2, accountWords.length);
const partialMatch = accountNameLower.split(/[\s-]+/).some(part => part.length > 3 && queryLower.includes(part));
console.log(` Full match: ${fullMatch}`);
console.log(` Word overlap (${matchingWords.length} >= ${Math.min(2, accountWords.length)}): ${wordOverlap}`);
console.log(` Partial match: ${partialMatch}`);
const isMatch = fullMatch || wordOverlap || partialMatch;
console.log(` → Would match: ${isMatch ? '✅ YES' : '❌ NO'}`);
}
}
}
// Check if auth token is provided
if (!AUTH_TOKEN) {
console.error('Please provide AUTH_TOKEN environment variable');
console.error('Usage: AUTH_TOKEN="Bearer eyJ..." node analyze-detection-logic.cjs');
process.exit(1);
}
analyzeDetectionLogic().catch(console.error);