Skip to main content
Glama
test-claude-scenario.cjs9.37 kB
#!/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://chorus-groups-suite-delayed.trycloudflare.com'; async function testClaudeScenario() { console.log('\n════════════════════════════════════════════════════════════'); console.log(' 🧪 TESTING CLAUDE DESKTOP SCENARIO (ONLY customer_account_key)'); console.log('════════════════════════════════════════════════════════════\n'); try { // Step 1: OAuth flow console.log('1️⃣ Authenticating through OAuth...'); const metadataResponse = await axiosInstance.get(`${MCP_BASE}/.well-known/oauth-authorization-server`); const registerResponse = await axiosInstance.post(`${MCP_BASE}/register`, { client_name: "Claude Desktop", 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; 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 } ); const cookies = loginResponse.headers['set-cookie']; const sidCookie = cookies?.find(c => c.startsWith('sid=')); const sid = sidCookie?.split(';')[0].split('=')[1]; 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; 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: "claude-desktop", 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 EXACTLY what Claude Desktop sends - ONLY customer_account_key console.log('3️⃣ Testing Claude Desktop scenario (customer_account_key WITHOUT division_id)...'); console.log('════════════════════════════════════════════════════════════'); const testRequest = { method: "tools/call", params: { name: "api__invoices_caui", arguments: { customer_account_key: "22676", // Bank Leumi - ONLY THIS, NO division_id startDate: "2025-08-01", endDate: "2025-08-31", periodGranLevel: "month", groupBy: "none", costType: "[\"cost\", \"discount\"]", isUnblended: "true", userQuery: "Show me Bank Leumi costs" } }, jsonrpc: "2.0", id: 1 }; console.log('📤 Request (simulating Claude Desktop):'); console.log(` customer_account_key: ${testRequest.params.arguments.customer_account_key}`); console.log(` customer_division_id: NOT PROVIDED (this is the problem)`); 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')) { 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 const accountMatch = content.match(/\"account_id\":\s*\"(\d+)\"/); const costMatch = content.match(/\"total_cost\":\s*([0-9.]+)/); 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 && cost < 20000) { console.log(' ✅ Cost looks correct for Bank Leumi (~$14,000/month)'); } else if (cost < 100) { console.log(' ❌ Cost too low - probably wrong account'); } } console.log('\n════════════════════════════════════════════════════════════'); // Final verdict if (accountMatch && accountMatch[1] === '696314371547') { console.log('🎉 SUCCESS! The fix is working!'); console.log('The server correctly fetched division_id when only customer_account_key was provided.'); } else { console.log('⚠️ ISSUE! The fix may not be working properly.'); console.log('The 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)); } } } testClaudeScenario().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