#!/usr/bin/env node
// Detailed MCP Protocol Test - Shows exact Claude Desktop responses
const { spawn } = require('child_process');
const { EventEmitter } = require('events');
class DetailedMCPTest extends EventEmitter {
constructor() {
super();
this.serverProcess = null;
this.messageId = 1;
this.pendingRequests = new Map();
}
async startServer() {
console.log('๐ Starting MCP server...');
this.serverProcess = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
this.serverProcess.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
lines.forEach(line => {
try {
const message = JSON.parse(line);
this.handleMessage(message);
} catch (e) {
// Ignore non-JSON lines
}
});
});
this.serverProcess.stderr.on('data', (data) => {
// Suppress server logs for cleaner output
});
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('โ
MCP server ready');
}
handleMessage(message) {
if (message.id && this.pendingRequests.has(message.id)) {
const resolve = this.pendingRequests.get(message.id);
this.pendingRequests.delete(message.id);
resolve(message);
}
}
async sendRequest(method, params) {
const id = this.messageId++;
const request = {
jsonrpc: '2.0',
id,
method,
params
};
return new Promise((resolve, reject) => {
this.pendingRequests.set(id, resolve);
this.serverProcess.stdin.write(JSON.stringify(request) + '\n');
setTimeout(() => {
if (this.pendingRequests.has(id)) {
this.pendingRequests.delete(id);
reject(new Error('Request timeout'));
}
}, 30000);
});
}
async initialize() {
await this.sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'claude-desktop-test',
version: '1.0.0'
}
});
}
async authenticate() {
console.log('\n๐ Authenticating david+saola@umbrellacost.com...');
const authResult = await this.sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
const authResponse = authResult.result.content[0].text;
console.log('โ
', authResponse.split('\n')[0]);
return authResponse.includes('Successfully authenticated');
}
async testQuestion(questionNum, questionText, toolName, args) {
console.log('\n' + 'โ'.repeat(80));
console.log(`๐ QUESTION ${questionNum}: "${questionText}"`);
console.log('โ'.repeat(80));
try {
const result = await this.sendRequest('tools/call', {
name: toolName,
arguments: args
});
const response = result.result.content[0].text;
console.log('\n๐ค CLAUDE DESKTOP RECEIVES:');
console.log('โ'.repeat(50));
// Show first 1000 characters of response to keep it readable
if (response.length > 1000) {
console.log(response.substring(0, 1000) + '\n... [response truncated for readability]');
} else {
console.log(response);
}
// Extract key metrics for cost questions
if (toolName === 'api___invoices_caui') {
const costMatch = response.match(/Total.*?\$([0-9,]+\.?[0-9]*)/i);
const periodMatch = response.match(/Period: ([^\n]+)/);
const accountMatch = response.match(/Account: ([^\n]+)/);
console.log('\n๐ KEY METRICS:');
console.log(` Period: ${periodMatch ? periodMatch[1] : 'Not specified'}`);
console.log(` Account: ${accountMatch ? accountMatch[1] : 'Multi-account'}`);
console.log(` Total Cost: ${costMatch ? '$' + costMatch[1] : 'Not displayed in summary'}`);
}
// Extract key info for recommendations
if (toolName === 'api___recommendations_report') {
const totalSavings = response.match(/Total.*?\$([0-9,]+)/i);
const rightSizing = response.match(/Right Sizing.*?\$([0-9,]+)/i);
const categories = (response.match(/Category: ([^\n]+)/g) || []).length;
console.log('\n๐ก RECOMMENDATIONS SUMMARY:');
console.log(` Total Savings: ${totalSavings ? '$' + totalSavings[1] : 'Not specified'}`);
console.log(` Right Sizing: ${rightSizing ? '$' + rightSizing[1] : 'Not specified'}`);
console.log(` Categories: ${categories} recommendation types`);
}
// Extract account info
if (toolName === 'api___users') {
const accountMatches = response.match(/Account \d+:/g) || [];
const cloudTypes = [...new Set((response.match(/Cloud Type: ([^\n]+)/g) || []).map(m => m.replace('Cloud Type: ', '')))];
console.log('\n๐ข ACCOUNT SUMMARY:');
console.log(` Total Accounts: ${accountMatches.length}`);
console.log(` Cloud Providers: ${cloudTypes.join(', ')}`);
}
console.log('\nโ
SUCCESS - Response received and processed');
} catch (error) {
console.log('\nโ FAILED:', error.message);
}
}
async disconnect() {
if (this.serverProcess) {
this.serverProcess.kill();
console.log('\n๐ Disconnected from MCP server');
}
}
}
async function runDetailedTest() {
console.log('๐ฌ DETAILED MCP PROTOCOL TEST');
console.log('Shows exactly what Claude Desktop receives for each question');
console.log('โ'.repeat(80));
const client = new DetailedMCPTest();
try {
await client.startServer();
await client.initialize();
const authenticated = await client.authenticate();
if (!authenticated) {
console.log('โ Authentication failed');
return;
}
// Test all questions from questions.test file
const questions = [
{
question: "show me the list of customers",
tool: "api___msp_customers",
args: {}
},
{
question: "what is my total cost?",
tool: "api___invoices_caui",
args: {
startDate: "2025-08-11",
endDate: "2025-08-17",
groupBy: "none",
periodGranLevel: "day",
costType: ["cost", "discount"],
isUnblended: true
}
},
{
question: "what is my total AWS cost?",
tool: "api___invoices_caui",
args: {
startDate: "2025-08-11",
endDate: "2025-08-17",
groupBy: "none",
periodGranLevel: "day",
costType: ["cost", "discount"],
isUnblended: true,
cloud_context: "aws"
}
},
{
question: "what is my total GCP cost?",
tool: "api___invoices_caui",
args: {
startDate: "2025-08-11",
endDate: "2025-08-17",
groupBy: "none",
periodGranLevel: "day",
costType: ["cost", "discount"],
isUnblended: true,
cloud_context: "gcp"
}
},
{
question: "what is my total Azure cost?",
tool: "api___invoices_caui",
args: {
startDate: "2025-08-11",
endDate: "2025-08-17",
groupBy: "none",
periodGranLevel: "day",
costType: ["cost", "discount"],
isUnblended: true,
cloud_context: "azure"
}
},
{
question: "show me the total cost per month",
tool: "api___invoices_caui",
args: {
startDate: "2025-02-01",
endDate: "2025-08-17",
groupBy: "none",
periodGranLevel: "month",
costType: ["cost", "discount"],
isUnblended: true
}
},
{
question: "show me all available accounts",
tool: "api___users",
args: {}
},
{
question: "what do you recommend to do for saving AWS costs?",
tool: "api___recommendations_report",
args: {}
},
{
question: "what are the potential savings per category?",
tool: "api___recommendations_report",
args: {}
},
{
question: "Is there any anomalies on AWS?",
tool: "api___anomaly_detection",
args: {
startDate: "2025-08-11",
endDate: "2025-08-17"
}
}
];
for (let i = 0; i < questions.length; i++) {
const q = questions[i];
await client.testQuestion(i + 1, q.question, q.tool, q.args);
}
console.log('\n' + '๐'.repeat(40));
console.log('๐ ALL QUESTIONS TESTED');
console.log('This is exactly what Claude Desktop will receive!');
console.log('๐'.repeat(40));
} catch (error) {
console.error('โ Test failed:', error.message);
} finally {
await client.disconnect();
}
}
runDetailedTest();