#!/usr/bin/env node
const { spawn } = require('child_process');
// Debug what's actually returned from production monthly API calls
class DebugProductionMonthly {
constructor() {
this.mcpProcess = null;
}
async startMCP() {
console.log('๐ Starting Production MCP Server (STDIO)...');
this.mcpProcess = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: '/Users/david/Downloads/MCP/UmbrellaMCP/production'
});
this.mcpProcess.stderr.on('data', (data) => {
console.log('MCP Server:', data.toString().trim());
});
await new Promise(resolve => setTimeout(resolve, 3000));
}
sendMCPRequest(method, params) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method,
params: params || {}
};
this.mcpProcess.stdin.write(JSON.stringify(request) + '\n');
let buffer = '';
const handler = (data) => {
buffer += data.toString();
const lines = buffer.split('\n');
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i].trim();
if (line) {
try {
const response = JSON.parse(line);
if (response.id === request.id) {
this.mcpProcess.stdout.removeListener('data', handler);
resolve(response);
return;
}
} catch (e) {
// Not complete JSON yet
}
}
}
buffer = lines[lines.length - 1];
};
this.mcpProcess.stdout.on('data', handler);
setTimeout(() => {
this.mcpProcess.stdout.removeListener('data', handler);
reject(new Error('Request timeout'));
}, 30000);
});
}
async authenticate() {
console.log('๐ Authenticating SAOLA account...');
try {
// Initialize
await this.sendMCPRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'debug-monthly-client', version: '1.0.0' }
});
// Authenticate
const authResponse = await this.sendMCPRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
if (authResponse.result?.content?.[0]?.text?.includes('Successfully')) {
console.log('โ
Authentication successful\n');
return true;
} else {
console.log('โ Authentication failed');
return false;
}
} catch (error) {
console.log('โ Authentication error:', error.message);
return false;
}
}
async debugSingleMonth() {
try {
await this.startMCP();
const authSuccess = await this.authenticate();
if (!authSuccess) {
console.log('โ Cannot proceed without authentication');
return;
}
console.log('๐ DEBUGGING SINGLE MONTH API CALL (August 2025)');
console.log('=' .repeat(80));
console.log('๐ค Sending request to api__invoices_caui...');
const response = await this.sendMCPRequest('tools/call', {
name: 'api__invoices_caui',
arguments: {
startDate: '2025-08-01',
endDate: '2025-08-31',
groupBy: 'service',
periodGranLevel: 'day',
costType: ['cost', 'discount'],
isUnblended: true,
accountId: '532523076083' // SAOLA account ID
}
});
console.log('๐ฅ FULL RESPONSE STRUCTURE:');
console.log('- jsonrpc:', response.jsonrpc);
console.log('- id:', response.id);
console.log('- result exists:', !!response.result);
console.log('- error exists:', !!response.error);
if (response.error) {
console.log('\nโ ERROR DETAILS:');
console.log(JSON.stringify(response.error, null, 2));
}
if (response.result) {
console.log('\n๐ RESULT STRUCTURE:');
console.log('- result type:', typeof response.result);
console.log('- result keys:', Object.keys(response.result));
console.log('- content exists:', !!response.result.content);
console.log('- content type:', Array.isArray(response.result.content) ? 'array' : typeof response.result.content);
console.log('- content length:', response.result.content?.length);
if (response.result.content?.[0]) {
const contentItem = response.result.content[0];
console.log('\n๐ CONTENT[0] DETAILS:');
console.log('- type:', contentItem.type);
console.log('- text exists:', !!contentItem.text);
console.log('- text type:', typeof contentItem.text);
console.log('- text length:', contentItem.text?.length);
if (contentItem.text) {
console.log('\n๐ RAW TEXT CONTENT (first 500 chars):');
console.log(contentItem.text.substring(0, 500));
console.log('...');
// Try parsing as JSON
try {
const parsed = JSON.parse(contentItem.text);
console.log('\nโ
JSON PARSE SUCCESSFUL:');
console.log('- Parsed type:', Array.isArray(parsed) ? 'array' : typeof parsed);
if (Array.isArray(parsed)) {
console.log('- Array length:', parsed.length);
if (parsed.length > 0) {
console.log('- First item keys:', Object.keys(parsed[0]));
console.log('- First item sample:', JSON.stringify(parsed[0], null, 2));
}
} else {
console.log('- Object keys:', Object.keys(parsed));
}
} catch (parseError) {
console.log('\nโ JSON PARSE FAILED:');
console.log('- Parse error:', parseError.message);
console.log('- Content is not valid JSON');
}
}
}
}
} finally {
if (this.mcpProcess) {
this.mcpProcess.kill();
console.log('\n๐ MCP Server stopped');
}
}
}
}
const debug = new DebugProductionMonthly();
debug.debugSingleMonth().catch(console.error);