Skip to main content
Glama
test-mcp-bank-leumi.cjs9.76 kB
#!/usr/bin/env node const https = require('https'); const axios = require('axios'); const crypto = require('crypto'); const axiosInstance = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }), timeout: 30000 }); async function testMcpBankLeumi() { console.log('\n════════════════════════════════════════════════════════════'); console.log(' TESTING BANK LEUMI VIA MCP PROTOCOL'); console.log('════════════════════════════════════════════════════════════'); const mcpBaseUrl = 'https://injuries-opposite-mine-pmid.trycloudflare.com'; try { // Step 1: Get OAuth authorization server info console.log('\n1️⃣ Getting OAuth server info...'); const authServerResponse = await axiosInstance.get(`${mcpBaseUrl}/.well-known/oauth-authorization-server`); console.log('✅ OAuth server info retrieved'); // Step 2: Register client console.log('\n2️⃣ Registering client...'); const registerResponse = await axiosInstance.post(`${mcpBaseUrl}/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; console.log('✅ Client registered:', clientId); // Step 3: Get authorization code (simulating user login) console.log('\n3️⃣ Simulating user login...'); // Generate PKCE challenge const verifier = crypto.randomBytes(32).toString('base64url'); const challenge = crypto.createHash('sha256').update(verifier).digest('base64url'); const state = crypto.randomBytes(16).toString('base64url'); // First get the login page const authUrl = `${mcpBaseUrl}/authorize?` + new URLSearchParams({ response_type: 'code', client_id: clientId, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', code_challenge: challenge, code_challenge_method: 'S256', state: state, scope: 'claudeai', resource: `${mcpBaseUrl}/mcp` }); // Simulate login by posting credentials const loginResponse = await axiosInstance.post(`${mcpBaseUrl}/login`, new URLSearchParams({ username: 'david+allcloud@umbrellacost.com', password: 'Dsamsung1!123', response_type: 'code', client_id: clientId, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', scope: 'claudeai', state: state, code_challenge: challenge, code_challenge_method: 'S256' }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, maxRedirects: 0, validateStatus: function (status) { return status >= 200 && status < 400; // Accept redirects } } ); // Extract authorization code from redirect const location = loginResponse.headers.location; const codeMatch = location?.match(/code=([^&]+)/); const authCode = codeMatch ? codeMatch[1] : null; if (!authCode) { throw new Error('Failed to get authorization code'); } console.log('✅ Got authorization code'); // Step 4: Exchange code for token console.log('\n4️⃣ Exchanging code for token...'); const tokenResponse = await axiosInstance.post(`${mcpBaseUrl}/oauth/token`, new URLSearchParams({ grant_type: 'authorization_code', code: authCode, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', client_id: clientId, code_verifier: verifier }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' } } ); const accessToken = tokenResponse.data.access_token; console.log('✅ Got access token'); // Step 5: Test Bank Leumi query console.log('\n5️⃣ Testing Bank Leumi query via MCP...\n'); const mcpRequest = { method: 'tools/call', params: { name: 'api__invoices_caui', arguments: { endDate: '2025-08-31', groupBy: 'none', costType: '["cost", "discount"]', startDate: '2025-08-01', userQuery: 'Show me Bank Leumi costs for August 2025', isUnblended: 'true', periodGranLevel: 'month', customer_account_key: '22676', customer_division_id: '139' } }, jsonrpc: '2.0', id: 1 }; console.log('📤 Sending MCP request:'); console.log(' Tool: api__invoices_caui'); console.log(' Query: "Show me Bank Leumi costs for August 2025"'); console.log(' Customer Key: 22676'); console.log(' Division ID: 139'); console.log(' Date Range: 2025-08-01 to 2025-08-31'); const mcpResponse = await axiosInstance.post(`${mcpBaseUrl}/mcp`, mcpRequest, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}`, 'User-Agent': 'Claude-User', 'Accept': 'application/json, text/event-stream' } }); console.log('\n📥 MCP Response received'); if (mcpResponse.data && mcpResponse.data.result && mcpResponse.data.result.content) { const content = mcpResponse.data.result.content[0]; if (content && content.text) { const text = content.text; // Extract JSON from markdown const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { const jsonData = JSON.parse(jsonMatch[1]); console.log('\n📊 RESULTS:'); console.log('════════════════════════════════════════'); jsonData.forEach(item => { console.log(`Month: ${item.usage_date}`); console.log(` Account ID: ${item.account_id}`); console.log(` Total Cost: $${item.total_cost.toFixed(6)}`); console.log(` Usage Quantity: ${item.total_usage_quantity}`); console.log(''); }); // Check expectations console.log('📝 VALIDATION:'); console.log('════════════════════════════════════════'); console.log('Expected from MANUAL_ANSWERS.txt:'); console.log(' Account ID: 696314371547'); console.log(' August Cost: $0.002684'); if (jsonData[0]) { const actualAccount = jsonData[0].account_id; const actualCost = jsonData[0].total_cost; if (actualAccount === '696314371547') { console.log('\n✅ Account ID matches!'); } else if (actualAccount === '268413799883') { console.log('\n❌ WRONG ACCOUNT RETURNED!'); console.log(' This is the bug - MCP is returning account 268413799883'); console.log(' instead of the requested Bank Leumi account 696314371547'); } else { console.log(`\n❌ Unknown account returned: ${actualAccount}`); } if (Math.abs(actualCost - 0.002684) < 0.0001) { console.log('✅ Cost matches expected value!'); } else { console.log(`❌ Cost mismatch: $${actualCost.toFixed(6)} vs expected $0.002684`); } } } else { console.log('Response text:', text); } } } else { console.log('Full response:', JSON.stringify(mcpResponse.data, null, 2)); } } catch (error) { console.error('\n❌ Error:', error.message); if (error.response) { console.error('Response status:', error.response.status); console.error('Response data:', JSON.stringify(error.response.data, null, 2)); } } } testMcpBankLeumi().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