#!/usr/bin/env node
const { spawn } = require('child_process');
class CheckEndpoints {
constructor() {
this.server = null;
this.requestId = 1;
}
async start() {
console.log('🚀 Starting MCP server...');
this.server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
// Log any errors
this.server.stderr.on('data', (data) => {
console.log('SERVER ERROR:', data.toString());
});
await new Promise(resolve => setTimeout(resolve, 3000));
console.log('✅ Server should be ready');
}
async sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: this.requestId++,
method,
params
};
this.server.stdin.write(JSON.stringify(request) + '\n');
const timeout = setTimeout(() => {
reject(new Error(`Timeout: ${method}`));
}, 10000);
const handleData = (data) => {
clearTimeout(timeout);
this.server.stdout.removeListener('data', handleData);
try {
const lines = data.toString().split('\n').filter(line => line.trim());
for (let i = lines.length - 1; i >= 0; i--) {
const line = lines[i];
if (line.trim()) {
try {
const response = JSON.parse(line);
resolve(response);
return;
} catch (e) {
continue;
}
}
}
reject(new Error('No valid JSON response found'));
} catch (error) {
reject(error);
}
};
this.server.stdout.on('data', handleData);
});
}
async check() {
try {
console.log('🔧 Initializing...');
const initResp = await this.sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'Endpoint Check', version: '1.0.0' }
});
console.log('✅ Initialize response:', JSON.stringify(initResp, null, 2));
console.log('📋 Listing tools...');
const resp = await this.sendRequest('tools/list');
console.log('📋 List tools response:', JSON.stringify(resp, null, 2));
if (resp.result && resp.result.tools) {
console.log('\n🔍 All Available Endpoints:');
resp.result.tools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
});
const budgetTools = resp.result.tools.filter(tool =>
tool.name.toLowerCase().includes('budget')
);
if (budgetTools.length > 0) {
console.log('\n💰 Budget-related endpoints:');
budgetTools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
});
} else {
console.log('\n❌ No budget-related endpoints found');
}
} else {
console.log('❌ No tools found in response');
}
} catch (error) {
console.error('❌ Check failed:', error.message);
console.error('Full error:', error);
}
}
async cleanup() {
if (this.server) {
this.server.kill();
}
}
async run() {
try {
await this.start();
await this.check();
} finally {
await this.cleanup();
}
}
}
const checker = new CheckEndpoints();
checker.run();