#!/usr/bin/env node
const { spawn } = require('child_process');
async function testToolExecution() {
console.log('š Testing Tool Execution');
console.log('=========================\n');
return new Promise((resolve) => {
const serverProcess = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, NODE_ENV: 'production' }
});
let messageId = 1;
function sendMessage(method, params = {}) {
const message = {
jsonrpc: '2.0',
id: messageId++,
method,
params
};
const messageStr = JSON.stringify(message) + '\n';
console.log(`š¤ Sending: ${method} (id: ${messageId - 1})`);
serverProcess.stdin.write(messageStr);
return messageId - 1;
}
serverProcess.stdout.on('data', (data) => {
const responses = data.toString().trim().split('\n');
responses.forEach(response => {
if (response.trim()) {
try {
const parsed = JSON.parse(response);
console.log(`š„ Response (id: ${parsed.id}):`, {
hasResult: !!parsed.result,
hasError: !!parsed.error,
resultType: parsed.result ? typeof parsed.result : 'none',
errorMessage: parsed.error ? parsed.error.message : 'none'
});
if (parsed.id === 1) {
console.log('ā
Initialization complete, sending tools/list...');
setTimeout(() => sendMessage('tools/list'), 100);
} else if (parsed.id === 2) {
console.log('ā
Tools list complete, testing detect-errors...');
setTimeout(() => {
sendMessage('tools/call', {
name: 'detect-errors',
arguments: {
source: 'console',
includeWarnings: false
}
});
}, 100);
} else if (parsed.id === 3) {
console.log('ā
detect-errors tool completed!');
if (parsed.result && parsed.result.content) {
console.log('Tool result preview:', parsed.result.content[0]?.text?.substring(0, 100) + '...');
}
setTimeout(() => {
console.log('\nš Tool execution test successful!');
serverProcess.kill('SIGTERM');
}, 100);
}
} catch (error) {
console.error('ā JSON parse error:', error.message);
console.error('Raw response:', response);
}
}
});
});
serverProcess.stderr.on('data', (data) => {
console.log('š„ STDERR:', data.toString());
});
serverProcess.on('close', (code) => {
console.log(`\nš Server exited with code ${code}`);
resolve();
});
serverProcess.on('error', (error) => {
console.error('ā Process error:', error);
resolve();
});
// Start test
console.log('š Starting tool execution test...');
sendMessage('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'tool-test-client',
version: '1.0.0'
}
});
// Extended timeout for tool execution
setTimeout(() => {
console.log('\nā° Extended timeout reached');
serverProcess.kill('SIGTERM');
}, 30000);
});
}
testToolExecution().catch(console.error);