#!/usr/bin/env node
// Simple test to validate the MCP server
const { spawn } = require('child_process');
async function testMCPServer() {
console.log('Testing MCP Server...\n');
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'inherit']
});
// Helper function to send JSON-RPC request
function sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: Math.random().toString(36).substr(2, 9),
method,
params
};
let response = '';
const onData = (data) => {
response += data.toString();
try {
const parsed = JSON.parse(response);
server.stdout.off('data', onData);
resolve(parsed);
} catch (e) {
// Continue collecting data
}
};
server.stdout.on('data', onData);
server.stdin.write(JSON.stringify(request) + '\n');
setTimeout(() => {
server.stdout.off('data', onData);
reject(new Error('Request timeout'));
}, 5000);
});
}
try {
// Test 1: Initialize
console.log('1. Testing initialization...');
const initResponse = await sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'test-client', version: '1.0.0' }
});
console.log('✓ Initialization successful');
// Test 2: List tools
console.log('2. Testing tool listing...');
const toolsResponse = await sendRequest('tools/list');
console.log('✓ Tools listed:', toolsResponse.result.tools.map(t => t.name).join(', '));
// Test 3: List resources
console.log('3. Testing resource listing...');
const resourcesResponse = await sendRequest('resources/list');
console.log('✓ Resources listed:', resourcesResponse.result.resources.map(r => r.name).join(', '));
console.log('\n✓ All tests passed! MCP Server is working correctly.');
} catch (error) {
console.error('✗ Test failed:', error.message);
} finally {
server.kill();
}
}
testMCPServer();