// Test script to verify notification handling
import { spawn } from 'child_process';
const testRequests = [
// Initialize request
{
jsonrpc: "2.0",
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
},
id: 0
},
// Initialized notification (no response expected)
{
jsonrpc: "2.0",
method: "notifications/initialized"
},
// Resources list request
{
jsonrpc: "2.0",
method: "resources/list",
params: {},
id: 1
},
// Tools list request
{
jsonrpc: "2.0",
method: "tools/list",
params: {},
id: 2
}
];
console.log('Testing notification and resources handling...\n');
const mcpServer = spawn('node', ['--max-old-space-size=4096', '--expose-gc', '--max-semi-space-size=64', './dist/index.js'], {
cwd: process.cwd(),
stdio: ['pipe', 'pipe', 'pipe']
});
mcpServer.stdout.on('data', (data) => {
const responses = data.toString().split('\n');
responses.forEach(response => {
if (response.trim()) {
try {
const parsed = JSON.parse(response);
console.log('Response:', JSON.stringify(parsed, null, 2), '\n');
} catch (e) {
console.log('Raw Response:', response, '\n');
}
}
});
});
mcpServer.stderr.on('data', (data) => {
console.error('Server:', data.toString());
});
// Send test requests in sequence
async function sendTestRequests() {
await new Promise(resolve => setTimeout(resolve, 500));
for (let i = 0; i < testRequests.length; i++) {
const request = testRequests[i];
console.log(`Sending request ${i + 1}/${testRequests.length}:`);
console.log(JSON.stringify(request, null, 2), '\n');
mcpServer.stdin.write(JSON.stringify(request) + '\n');
// Add delay between requests
await new Promise(resolve => setTimeout(resolve, 300));
}
// Close after sending all requests
setTimeout(() => {
console.log('All tests completed. Shutting down...');
mcpServer.kill('SIGINT');
process.exit(0);
}, 1000);
}
sendTestRequests().catch(console.error);
mcpServer.on('close', (code) => {
console.log(`MCP server exited with code ${code}`);
});