#!/usr/bin/env node
/**
* Test script for enhanced MCP server features
*/
import { spawn } from 'child_process';
import { config } from 'dotenv';
config();
const server = spawn('node', ['dist/index.js'], {
env: { ...process.env },
stdio: ['pipe', 'pipe', 'pipe']
});
const tests = [
{
name: 'Reasoning (Saptiva Cortex)',
request: {
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'saptiva_reason',
arguments: {
question: 'If a train leaves Station A at 9:00 AM traveling at 60 mph, and another train leaves Station B (100 miles away) at 9:30 AM traveling at 80 mph toward Station A, at what time will they meet?',
max_tokens: 800
}
}
}
},
{
name: 'Similarity Check',
request: {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'saptiva_similarity',
arguments: {
text1: 'The quick brown fox jumps over the lazy dog',
text2: 'A fast brown fox leaps above a sleepy canine'
}
}
}
},
{
name: 'Summarize',
request: {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'saptiva_summarize',
arguments: {
text: 'Artificial intelligence (AI) is intelligence demonstrated by machines, as opposed to intelligence displayed by animals and humans. AI research has been defined as the field of study of intelligent agents, which refers to any system that perceives its environment and takes actions that maximize its chance of achieving its goals. The term "artificial intelligence" had previously been used to describe machines that mimic and display human cognitive skills that are associated with the human mind, such as learning and problem-solving.',
style: 'bullets',
max_length: 100
}
}
}
},
{
name: 'Translate',
request: {
jsonrpc: '2.0',
id: 4,
method: 'tools/call',
params: {
name: 'saptiva_translate',
arguments: {
text: 'Hello, how are you today? I hope you are having a wonderful day!',
target_language: 'Spanish'
}
}
}
},
{
name: 'Sentiment Analysis',
request: {
jsonrpc: '2.0',
id: 5,
method: 'tools/call',
params: {
name: 'saptiva_analyze',
arguments: {
text: 'I absolutely love this product! It exceeded all my expectations and the customer service was fantastic. However, the shipping took a bit longer than expected.',
analysis_type: 'sentiment'
}
}
}
}
];
let currentTest = 0;
let buffer = '';
function sendNextTest() {
if (currentTest >= tests.length) {
console.log('\n' + '='.repeat(50));
console.log('All enhanced tests completed!');
server.kill();
process.exit(0);
return;
}
const test = tests[currentTest];
console.log(`\n${'='.repeat(50)}`);
console.log(`Test ${currentTest + 1}/${tests.length}: ${test.name}`);
console.log('='.repeat(50));
buffer = '';
server.stdin.write(JSON.stringify(test.request) + '\n');
}
server.stdout.on('data', (data) => {
buffer += data.toString();
try {
const response = JSON.parse(buffer);
if (response.error) {
console.log('Error:', response.error.message);
} else if (response.result) {
const content = response.result.content?.[0]?.text;
if (content) {
// Try to parse as JSON for prettier output
try {
const parsed = JSON.parse(content);
console.log('\nResponse:');
console.log(JSON.stringify(parsed, null, 2));
} catch {
console.log('\nResponse:');
console.log(content);
}
}
if (response.result.isError) {
console.log('\nStatus: FAILED');
} else {
console.log('\nStatus: SUCCESS');
}
}
currentTest++;
setTimeout(sendNextTest, 1000);
} catch {
// Not complete JSON yet
}
});
server.stderr.on('data', (data) => {
const msg = data.toString().trim();
if (msg && !msg.includes('running on stdio') && !msg.includes('injecting env')) {
console.error('Server:', msg);
}
});
server.on('error', (err) => {
console.error('Failed to start server:', err);
process.exit(1);
});
setTimeout(sendNextTest, 1000);
setTimeout(() => {
console.log('\nTimeout reached');
server.kill();
process.exit(1);
}, 120000);