// Test script for the JSON-RPC 2.0 compliant MCP server
import { spawn } from 'child_process';
// Test JSON-RPC requests
const testRequests = [
// Initialize request
{
jsonrpc: "2.0",
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
},
id: 1
},
// List tools request
{
jsonrpc: "2.0",
method: "tools/list",
params: {},
id: 2
},
// Tool call request
{
jsonrpc: "2.0",
method: "tools/call",
params: {
name: "validate",
arguments: {
system: "propositional",
input: "P and Q implies R",
format: "natural"
}
},
id: 3
},
// Ping request
{
jsonrpc: "2.0",
method: "ping",
params: {},
id: 4
}
];
console.log('Starting JSON-RPC 2.0 MCP server test...\n');
// Start the MCP server
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']
});
// Handle server output
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:');
console.log(JSON.stringify(parsed, null, 2));
console.log('');
} catch (e) {
console.log('Raw Response:', response);
console.log('');
}
}
});
});
// Handle server errors
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)); // Wait for server to start
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));
console.log('');
mcpServer.stdin.write(JSON.stringify(request) + '\n');
// Wait between requests
await new Promise(resolve => setTimeout(resolve, 500));
}
// Close after sending all requests
setTimeout(() => {
console.log('All tests completed. Shutting down...');
mcpServer.kill('SIGINT');
process.exit(0);
}, 1000);
}
// Start the test sequence
sendTestRequests().catch(console.error);
// Handle process termination
mcpServer.on('close', (code) => {
console.log(`MCP server exited with code ${code}`);
});