// Test the MCP's api-client directly to see what it sends for net_amortized
// This will help us see the exact parameters being sent to the API
const axios = require('axios');
async function testApiClientNetAmortized() {
const BASE_URL = 'https://api.dev.umbrellacost.dev/api';
const USERNAME = 'elisha+testmcpdev@anodot.com';
const PASSWORD = 'Test123!';
try {
// 1. Authenticate
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;
console.log(`✅ Authenticated as: ${userKey}\n`);
// 2. Simulate what the MCP server does
const accountKey = '111111639';
const divisionId = '0';
const apiKey = `${userKey}:${accountKey}:${divisionId}`;
// These are the parameters the MCP should be sending
// (accountKey and divisionId are stripped by api-client and go in the apikey header instead)
const params = {
startDate: '2025-01-01',
endDate: '2025-10-08',
groupBy: 'none',
periodGranLevel: 'month',
// After enum-to-boolean mapping:
isNetAmortized: true,
// After costType defaults:
costType: ['cost', 'discount']
};
console.log('📤 Sending request with parameters:');
console.log(JSON.stringify(params, null, 2));
console.log('');
// 3. Make the request
const response = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
console.log('✅ Response received\n');
if (response.data.data && response.data.data.length > 0) {
console.log('📊 Results:');
response.data.data.forEach(item => {
console.log(` ${item.usage_date}: $${item.total_cost.toFixed(2)}`);
});
const totalCost = response.data.data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(`\nTotal: $${totalCost.toFixed(2)}`);
console.log(`\n🔍 Jan 2025 cost: $${response.data.data[0].total_cost.toFixed(2)}`);
console.log(` Expected from direct API test: $74,082.34`);
if (Math.abs(response.data.data[0].total_cost - 74082.34) < 1) {
console.log(' ✅ VALUES MATCH! API is working correctly.');
} else if (Math.abs(response.data.data[0].total_cost - 120021.98) < 1) {
console.log(' ❌ BUG CONFIRMED: Returning unblended instead of net_amortized!');
} else {
console.log(` ⚠️ UNEXPECTED VALUE`);
}
}
} 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));
}
}
}
testApiClientNetAmortized();