Skip to main content
Glama
test-anomaly-detection.cjs6.83 kB
#!/usr/bin/env node const https = require('https'); const BEARER_TOKEN = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkYXZpZCtzYW9sYUB1bWJyZWxsYWNvc3QuY29tIiwiY2xpZW50SWQiOiJjbGF1ZGUtbWNwLWNsaWVudC1iNzFhNzljNmY0YzQ0YzY1IiwiaWF0IjoxNzU4NzMzNzI0LCJleHAiOjE3NTg4MjAxMjR9.hVS1kxOWnN7vJdE6wbC-OTErcYgdLKzAv2qGE9CgCzpKV2C8C1xV-fKg5xqwhT5P0jF4aOZrw3_Z8YxrNeD6Qw3kZvGQrT7uY4Lm0I9sJ6HqeA4-rRzW8fT3NxPcUeKjVnB2lYdDhMm0Sz7X4qQ-5vFgL9xN2I6hTcPjOy8K'; const MCP_ENDPOINT = 'https://vsnet-leon-election-ghz.trycloudflare.com/mcp'; async function testAnomalyDetection() { console.log('🔍 Testing Anomaly Detection API through MCP...\n'); const requestData = { jsonrpc: '2.0', method: 'tools/call', params: { name: 'api_anomaly_detection', arguments: { isFull: true, userQuery: 'Show me open cost anomalies' } }, id: 1 }; const postData = JSON.stringify(requestData); const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${BEARER_TOKEN}`, 'Content-Length': Buffer.byteLength(postData) } }; return new Promise((resolve, reject) => { console.log(`📍 Making MCP request to: ${MCP_ENDPOINT}`); console.log(`📦 Request data:`, JSON.stringify(requestData, null, 2)); console.log(`🔑 Authorization header: Bearer ${BEARER_TOKEN.substring(0, 20)}...`); const req = https.request(MCP_ENDPOINT, options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(`\n✅ Response Status: ${res.statusCode}`); console.log(`📋 Response Headers:`, JSON.stringify(res.headers, null, 2)); console.log(`📄 Response Body:`, data); try { const jsonResponse = JSON.parse(data); console.log(`\n🔍 Parsed Response:`, JSON.stringify(jsonResponse, null, 2)); if (jsonResponse.error) { console.log(`\n❌ MCP Error:`, jsonResponse.error); } else if (jsonResponse.result) { console.log(`\n✅ MCP Result Content:`, jsonResponse.result.content); } resolve(jsonResponse); } catch (parseError) { console.log(`\n❌ JSON Parse Error:`, parseError.message); resolve({ rawData: data, error: parseError.message }); } }); }); req.on('error', (error) => { console.log(`\n❌ Request Error:`, error); reject(error); }); req.write(postData); req.end(); }); } async function testDirectApiCall() { console.log('\n📞 Testing Direct API Call to anomaly-detection endpoint...\n'); const API_ENDPOINT = 'https://api.umbrellacost.io/api/v1/anomaly-detection?userQuery=Show+me+cost+anomalies&startDate=2025-05-01&endDate=2025-08-31&isFull=true'; const API_KEY = '8bd39ae4-ebea-4426-bd22-07349dd8b962:9350:0'; const AUTH_TOKEN = 'eyJraWQiOiJoUFBoZTFRaWM4TklLU1dHcjQ4NEFHK3UwU2c5bCtmUHFWRWZUeCtcL0FcL1k9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI4YmQzOWFlNC1lYmVhLTQ0MjYtYmQyMi0wNzM0OWRkOGI5NjIiLCJhdWQiOiI3aTgyY25wdDQ2OXJjZDkzZmlmMWdsaG5rbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJldmVudF9pZCI6IjY4YTliNTNkLWFmYmItNGUxNC04YjZhLTZlMjIwNzVhNzNlMyIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNzU4NzMzNTU2LCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9VdjZBck5kU0siLCJjb2duaXRvOnVzZXJuYW1lIjoiOGJkMzlhZTQtZWJlYS00NDI2LWJkMjItMDczNDlkZDhiOTYyIiwiZXhwIjoxNzU4ODE5OTU2LCJpYXQiOjE3NTg3MzM1NTYsImVtYWlsIjoiZGF2aWQrc2FvbGFAdW1icmVsbGFjb3N0LmNvbSJ9.Ydv8CiI4zfpgCf0sm_yKlLYB9ybn89gKd7KfkwWCATLB_eC0fMO96SXyFyqSH4JqaW9RRKNvAt9qppLtPTQfKrO7YGcFnh1X0l7d0YbL8otunQi3bUXy2NAMXNAxzrwbW9HMhNg9UQVtPvBS3-Dd8orFgJ-BnTpzdLo5RhSslpZJdpjKpw1RoXC3MweQyZXZW_uW7gvcgWjLUqEJz2htHKydwy3d-0YFotY6PwbTrbUI3A0CF9nrmrZ6JbYzh2YcM-h2SZsB3lgsFpAd1IJLwdwtp9_y224RQuljkbxjxqPvLnULTsM2X2eT_2achPh9KPUMumKk5bX1akhNd6nIJA'; const options = { method: 'GET', headers: { 'Authorization': AUTH_TOKEN, 'apikey': API_KEY } }; return new Promise((resolve, reject) => { console.log(`📍 Making direct API request to: ${API_ENDPOINT}`); console.log(`🔑 API Key: ${API_KEY}`); console.log(`🔑 Auth Token: ${AUTH_TOKEN.substring(0, 50)}...`); const req = https.request(API_ENDPOINT, options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(`\n✅ Direct API Response Status: ${res.statusCode}`); console.log(`📋 Direct API Response Headers:`, JSON.stringify(res.headers, null, 2)); try { const jsonResponse = JSON.parse(data); console.log(`\n🔍 Direct API Response (first 500 chars):`, JSON.stringify(jsonResponse, null, 2).substring(0, 500)); resolve(jsonResponse); } catch (parseError) { console.log(`\n❌ JSON Parse Error:`, parseError.message); console.log(`📄 Raw Data (first 500 chars):`, data.substring(0, 500)); resolve({ rawData: data, error: parseError.message }); } }); }); req.on('error', (error) => { console.log(`\n❌ Direct API Request Error:`, error); reject(error); }); req.end(); }); } async function runTests() { try { console.log('='.repeat(60)); console.log('🧪 ANOMALY DETECTION DIAGNOSTIC TEST'); console.log('='.repeat(60)); // Test 1: MCP Tool Call console.log('\n📋 TEST 1: MCP Tool Call'); console.log('-'.repeat(30)); const mcpResult = await testAnomalyDetection(); // Test 2: Direct API Call console.log('\n📋 TEST 2: Direct API Call'); console.log('-'.repeat(30)); const directResult = await testDirectApiCall(); // Analysis console.log('\n📋 ANALYSIS'); console.log('-'.repeat(30)); console.log('✅ Direct API Call:', directResult.anomalies ? 'SUCCESS' : 'FAILED'); console.log('✅ MCP Tool Call:', mcpResult.result ? 'SUCCESS' : 'FAILED'); if (mcpResult.error) { console.log(`❌ MCP Error Details:`, mcpResult.error); } console.log('\n📋 SUMMARY'); console.log('-'.repeat(30)); if (directResult.anomalies && !mcpResult.result) { console.log('🔍 Issue Found: Direct API works, but MCP tool fails'); console.log('💡 Recommendation: Check MCP tool implementation'); } else if (!directResult.anomalies) { console.log('🔍 Issue Found: Direct API call failed'); console.log('💡 Recommendation: Check API connectivity and authentication'); } else { console.log('✅ Both tests successful'); } } catch (error) { console.error('❌ Test failed:', error); } } runTests();

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