// Comprehensive test suite for the MCP server
import { spawn } from 'child_process';
// Define test cases
const testCases = [
// Propositional Logic Tests
{
name: 'Propositional - Validate Simple Formula',
request: {
name: 'logic-action',
parameters: {
system: 'propositional',
operation: 'validate',
input: 'P implies Q',
format: 'natural'
}
}
},
{
name: 'Propositional - Validate Complex Formula',
request: {
name: 'logic-action',
parameters: {
system: 'propositional',
operation: 'validate',
input: '(P and Q) or (not P and R)',
format: 'natural'
}
}
},
{
name: 'Propositional - Formalize',
request: {
name: 'logic-action',
parameters: {
system: 'propositional',
operation: 'formalize',
input: 'if it rains then the street gets wet',
format: 'natural'
}
}
},
{
name: 'Propositional - Visualize Circuit',
request: {
name: 'logic-action',
parameters: {
system: 'propositional',
operation: 'visualize',
input: 'P and (Q or R)',
format: 'natural'
}
}
},
// Syllogistic Logic Tests
{
name: 'Syllogistic - Barbara Syllogism',
request: {
name: 'logic-action',
parameters: {
system: 'syllogistic',
operation: 'validate',
input: 'All men are mortal. Socrates is a man. Therefore, Socrates is mortal.',
format: 'natural'
}
}
},
{
name: 'Syllogistic - Invalid Syllogism',
request: {
name: 'logic-action',
parameters: {
system: 'syllogistic',
operation: 'validate',
input: 'Some cats are black. Some black things are dangerous. Therefore, some cats are dangerous.',
format: 'natural'
}
}
},
// Predicate Logic Tests
{
name: 'Predicate - Universal Statement',
request: {
name: 'logic-action',
parameters: {
system: 'predicate',
operation: 'formalize',
input: 'All students who study hard will pass the exam',
format: 'natural'
}
}
},
// Command Tests
{
name: 'Command - List Systems',
request: {
name: 'command',
parameters: {
command: {
type: 'listSystems'
}
}
}
},
{
name: 'Command - List Operations',
request: {
name: 'command',
parameters: {
command: {
type: 'listOperations'
}
}
}
}
];
console.log('Starting comprehensive MCP server test suite...\n');
// Run all tests
async function runTests() {
for (let i = 0; i < testCases.length; i++) {
const test = testCases[i];
console.log(`\n${'='.repeat(50)}`);
console.log(`Test ${i + 1}/${testCases.length}: ${test.name}`);
console.log(`${'='.repeat(50)}\n`);
await runSingleTest(test);
// Add delay between tests
await new Promise(resolve => setTimeout(resolve, 500));
}
console.log('\n\nAll tests completed!');
}
// Run a single test
function runSingleTest(test) {
return new Promise((resolve) => {
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']
});
console.log('Request:');
console.log(JSON.stringify(test.request, null, 2));
console.log('\nResponse:');
// Handle server output
mcpServer.stdout.on('data', (data) => {
const responses = data.toString().split('\n');
responses.forEach(response => {
if (response.trim() && response.trim() !== 'Logic Thinking MCP Server started') {
try {
const parsed = JSON.parse(response);
console.log(JSON.stringify(parsed, null, 2));
} catch (e) {
console.log(response);
}
}
});
});
// Handle server errors
mcpServer.stderr.on('data', (data) => {
console.error('Error:', data.toString());
});
// Send test request after a short delay
setTimeout(() => {
mcpServer.stdin.write(JSON.stringify(test.request) + '\n');
// Close after 1 second
setTimeout(() => {
mcpServer.kill('SIGINT');
resolve();
}, 1000);
}, 300);
});
}
// Run all tests
runTests().catch(console.error);