const axios = require('axios');
async function testMcpUnblendedFinal() {
const BASE_URL = 'https://api.dev.umbrellacost.dev/api';
const USERNAME = 'elisha+testmcpdev@anodot.com';
const PASSWORD = 'Test123!';
const ACCOUNT_KEY = '111111639';
const DIVISION_ID = '0';
try {
console.log('🔐 Authenticating...\n');
const authResponse = await axios.post(`${BASE_URL}/v1/users/signin`, {
username: USERNAME,
password: PASSWORD
});
const token = authResponse.data.jwtToken;
const tokenPayload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
const userKey = tokenPayload.sub;
const apiKey = `${userKey}:${ACCOUNT_KEY}:${DIVISION_ID}`;
console.log('✅ Authenticated\n');
console.log('═'.repeat(80));
console.log('SIMULATING MCP SERVER REQUEST FOR UNBLENDED COSTS');
console.log('═'.repeat(80));
console.log('This matches what the MCP sends to Umbrella API:\n');
// Exactly what the MCP server sends after processing
const params = {
startDate: '2025-01-01',
endDate: '2025-10-08',
groupBy: 'none',
periodGranLevel: 'month',
// From enum mapping: costCalculationType: 'unblended' -> isUnblended: true
isUnblended: true,
// Default costType
costType: ['cost', 'discount'],
// MSP parameters (mapped from accountKey/divisionId)
customer_account_key: ACCOUNT_KEY,
customer_division_id: DIVISION_ID,
// Tax exclusion (added automatically for MSP customers at lines 908-911)
excludeFilters: {
chargetype: ['Tax']
}
};
console.log('Request Parameters:');
console.log(JSON.stringify(params, null, 2));
console.log('');
const response = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response.data.data && response.data.data.length > 0) {
console.log('═'.repeat(80));
console.log('RESULT');
console.log('═'.repeat(80));
console.log(`Jan 2025: $${response.data.data[0].total_cost.toFixed(2)}`);
console.log(`Expected: $120,021.98 (unblended with tax excluded)`);
if (Math.abs(response.data.data[0].total_cost - 120021.98) < 1) {
console.log('\n✅ SUCCESS! MCP is returning the correct unblended value!');
} else {
console.log(`\n❌ MISMATCH! Got $${response.data.data[0].total_cost.toFixed(2)} instead of $120,021.98`);
}
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', JSON.stringify(error.response.data, null, 2));
}
}
}
testMcpUnblendedFinal();