#!/usr/bin/env node
const { spawn } = require('child_process');
// Check divisions and test with correct division ID
class CheckDivisions {
constructor() {
this.mcpProcess = null;
}
async startMCP() {
console.log('๐ Starting Production MCP Server...');
this.mcpProcess = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: '/Users/david/Downloads/MCP/UmbrellaMCP/production'
});
this.mcpProcess.stderr.on('data', (data) => {
const output = data.toString().trim();
console.log('MCP Server:', output);
// Look for division information in the logs
if (output.includes('division') || output.includes('Division')) {
console.log('๐ DIVISION INFO FOUND:', output);
}
});
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...');
try {
await this.sendMCPRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'division-check-client', version: '1.0.0' }
});
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;
}
} catch (error) {
console.log('โ Authentication error:', error.message);
}
return false;
}
async checkDivisions() {
try {
await this.startMCP();
const authSuccess = await this.authenticate();
if (!authSuccess) return;
console.log('๐ CHECKING DIVISIONS AND CUSTOMERS');
console.log('=' .repeat(80));
// First, let's check the plain_sub_users to see divisions/customers
console.log('\n๐ค Checking api___plain_sub_users for divisions...');
const subUsersResponse = await this.sendMCPRequest('tools/call', {
name: 'api___plain_sub_users',
arguments: {}
});
if (subUsersResponse.result?.content?.[0]?.text) {
console.log('\n๐ Plain Sub Users Response:');
const text = subUsersResponse.result.content[0].text;
console.log(text.substring(0, 2000));
try {
const data = JSON.parse(text);
if (Array.isArray(data)) {
console.log(`\n๐ Found ${data.length} divisions/customers:`);
data.forEach((item, i) => {
console.log(`${i + 1}. Division ID: ${item.division_id || item.id}, Name: ${item.name || item.division_name}`);
});
}
} catch (e) {
// Not JSON
}
}
// Now test with different division IDs
console.log('\n' + '='.repeat(80));
console.log('๐ค Testing with different account/division combinations...\n');
// Test with account key 9350 and different divisions
const testCases = [
{ accountId: '9350', division: '0', desc: 'Account Key 9350, Division 0' },
{ accountId: '932213950603', division: '0', desc: 'Account ID 932213950603, Division 0' },
{ accountId: '9350', division: '1', desc: 'Account Key 9350, Division 1' },
];
for (const test of testCases) {
console.log(`\n๐ Testing: ${test.desc}`);
console.log('-'.repeat(50));
const response = await this.sendMCPRequest('tools/call', {
name: 'api___invoices_caui',
arguments: {
accountId: test.accountId,
startDate: '2025-08-01',
endDate: '2025-08-31',
periodGranLevel: 'month',
groupBy: 'none'
}
});
if (response.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log(`Response length: ${text.length} chars`);
try {
const data = JSON.parse(text);
if (Array.isArray(data) && data.length > 0) {
const total = data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(`โ
Success: Total cost = $${total.toFixed(2)}`);
console.log(` Records: ${data.length}`);
if (data[0].account_id) {
console.log(` Account: ${data[0].account_id}`);
}
} else {
console.log('โ ๏ธ Empty or no data');
}
} catch (e) {
console.log(`โ Error: ${text.substring(0, 200)}`);
}
} else {
console.log('โ No response');
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
} finally {
if (this.mcpProcess) {
this.mcpProcess.kill();
console.log('\n๐ MCP Server stopped');
}
}
}
}
const checker = new CheckDivisions();
checker.checkDivisions().catch(console.error);