#!/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://guided-opposition-preceding-encryption.trycloudflare.com';
async function verifyBankLeumiFix() {
console.log('\n════════════════════════════════════════════════════════════');
console.log(' 🔍 VERIFYING BANK LEUMI FIX THROUGH MCP');
console.log('════════════════════════════════════════════════════════════\n');
try {
// Step 1: OAuth flow to get token
console.log('1️⃣ Authenticating through OAuth...');
// Get metadata
const metadataResponse = await axiosInstance.get(`${MCP_BASE}/.well-known/oauth-authorization-server`);
// Register client
const registerResponse = await axiosInstance.post(`${MCP_BASE}/register`, {
client_name: "Test Client",
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;
// Login
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
}
);
// Get session
const cookies = loginResponse.headers['set-cookie'];
const sidCookie = cookies?.find(c => c.startsWith('sid='));
const sid = sidCookie?.split(';')[0].split('=')[1];
// Get auth code
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;
// Exchange for token
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: "test-client", 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: Test Bank Leumi query
console.log('3️⃣ Testing Bank Leumi query...');
console.log('════════════════════════════════════════════════════════════');
const testRequest = {
method: "tools/call",
params: {
name: "api__invoices_caui",
arguments: {
customer_account_key: "22676", // Bank Leumi account key
customer_division_id: "139", // Bank Leumi division
startDate: "2025-08-01",
endDate: "2025-08-31",
periodGranLevel: "month",
groupBy: "none",
costType: "[\"cost\", \"discount\"]",
isUnblended: "true"
}
},
jsonrpc: "2.0",
id: 1
};
console.log('📤 Request:');
console.log(` Customer Account Key: ${testRequest.params.arguments.customer_account_key}`);
console.log(` Customer Division ID: ${testRequest.params.arguments.customer_division_id}`);
console.log(` Date Range: Aug 2025\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')) {
// Parse SSE format
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 and cost from the response
const accountMatch = content.match(/"account_id":\s*"(\d+)"/);
const costMatch = content.match(/"total_cost":\s*([\d.]+)/);
console.log('📥 Response:');
if (accountMatch) {
const accountId = accountMatch[1];
console.log(` Account ID: ${accountId}`);
if (accountId === '696314371547') {
console.log(' ✅ CORRECT! This is Bank Leumi (696314371547)');
} else if (accountId === '268413799883') {
console.log(' ❌ WRONG! This is Mark.Watson_Sandbox (268413799883)');
} else {
console.log(` ⚠️ Unknown account: ${accountId}`);
}
}
if (costMatch) {
const cost = parseFloat(costMatch[1]);
console.log(` Total Cost: $${cost.toLocaleString()}`);
if (cost > 10000) {
console.log(' ℹ️ Cost seems high - this might be production data');
} else if (cost < 1) {
console.log(' ℹ️ Cost seems low - this might be test/sandbox data');
}
}
console.log('\n════════════════════════════════════════════════════════════');
// Final verdict
if (accountMatch && accountMatch[1] === '696314371547') {
console.log('🎉 SUCCESS! The fix is working correctly!');
console.log('The MCP server returned the correct Bank Leumi account.');
} else {
console.log('⚠️ ISSUE DETECTED! The fix may not be working properly.');
console.log('The MCP server did not return the expected Bank Leumi account.');
}
} else {
console.log('⚠️ Unexpected response format');
console.log(JSON.stringify(parsedData, null, 2));
}
console.log('════════════════════════════════════════════════════════════\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));
}
}
}
verifyBankLeumiFix().catch(console.error);