#!/usr/bin/env node
/**
* Simple MCP stdio test for prompt-to-project tool
* Run with: HELIOS_API_KEY=your_key node test-mcp-stdio.js
*/
import { spawn } from 'child_process';
import readline from 'readline';
const HELIOS_API_KEY = process.env.HELIOS_API_KEY;
const HELIOS_API_URL = process.env.HELIOS_API_URL || 'https://helios9.app';
if (!HELIOS_API_KEY) {
console.error('❌ Please set HELIOS_API_KEY environment variable');
console.error('Usage: HELIOS_API_KEY=hel9_xxx node test-mcp-stdio.js');
process.exit(1);
}
console.log('🚀 Starting MCP server test...');
console.log(`API URL: ${HELIOS_API_URL}`);
console.log(`API Key: ${HELIOS_API_KEY.substring(0, 20)}...`);
// Start the MCP server
const mcp = spawn('node', ['dist/index.js'], {
env: {
...process.env,
HELIOS_API_URL,
HELIOS_API_KEY
},
stdio: ['pipe', 'pipe', 'inherit']
});
// Create interface for reading responses
const rl = readline.createInterface({
input: mcp.stdout,
crlfDelay: Infinity
});
let requestId = 0;
const pendingRequests = new Map();
// Handle responses
rl.on('line', (line) => {
try {
const response = JSON.parse(line);
if (response.id && pendingRequests.has(response.id)) {
const { resolve, reject } = pendingRequests.get(response.id);
pendingRequests.delete(response.id);
if (response.error) {
reject(new Error(response.error.message));
} else {
resolve(response.result);
}
}
} catch (e) {
// Not JSON, ignore
}
});
// Helper to send requests
function sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const id = ++requestId;
const request = {
jsonrpc: '2.0',
method,
params,
id
};
pendingRequests.set(id, { resolve, reject });
mcp.stdin.write(JSON.stringify(request) + '\n');
// Timeout after 10 seconds
setTimeout(() => {
if (pendingRequests.has(id)) {
pendingRequests.delete(id);
reject(new Error('Request timeout'));
}
}, 10000);
});
}
async function runTests() {
try {
// Wait for server to initialize
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('\n📋 Listing tools...');
const toolsResponse = await sendRequest('tools/list');
const promptTool = toolsResponse.tools.find(t => t.name === 'prompt_to_project');
if (promptTool) {
console.log('✅ Found prompt_to_project tool');
console.log(` Description: ${promptTool.description}`);
} else {
throw new Error('prompt_to_project tool not found');
}
console.log('\n🔍 Testing ANALYZE mode...');
const analyzeResult = await sendRequest('tools/call', {
name: 'prompt_to_project',
arguments: {
prompt: 'Build an e-commerce platform with product catalog, shopping cart, and payment processing',
execution_mode: 'analyze'
}
});
console.log('✅ Analyze mode successful');
const analysisData = JSON.parse(analyzeResult.content[0].text);
console.log('\n📊 Analysis Results:');
console.log('- Mode:', analysisData.mode);
if (analysisData.guidance && analysisData.guidance.key_considerations) {
console.log('- Guidelines provided:', analysisData.guidance.key_considerations.length);
}
if (analysisData.template && analysisData.template.initiatives) {
console.log('- Template initiatives:', analysisData.template.initiatives.length);
}
if (analysisData.requirements) {
console.log('- Requirements detected:');
Object.entries(analysisData.requirements).forEach(([key, value]) => {
if (value) console.log(` • ${key}: ${value}`);
});
}
console.log('\n🏗️ Testing CREATE mode...');
// Create a minimal project plan
const projectPlan = {
project: {
name: 'E-Commerce Platform',
description: 'Modern e-commerce platform with essential features',
status: 'active'
},
initiatives: [
{
name: 'Product Catalog',
objective: 'Build product listing and management system',
priority: 'high',
status: 'active',
tasks: [
{
title: 'Create product database schema',
priority: 'high',
status: 'todo'
},
{
title: 'Build product API endpoints',
priority: 'medium',
status: 'todo'
}
]
}
]
};
const createResult = await sendRequest('tools/call', {
name: 'prompt_to_project',
arguments: {
prompt: 'Build an e-commerce platform',
execution_mode: 'create',
project_plan: projectPlan
}
});
console.log('✅ Create mode successful');
// The response has content array with text
let creationData;
try {
if (createResult.content && createResult.content[0] && createResult.content[0].text) {
// Parse the nested JSON string
const textContent = createResult.content[0].text;
creationData = JSON.parse(textContent);
} else {
console.log('Unexpected response structure:', JSON.stringify(createResult, null, 2));
throw new Error('Could not parse response');
}
} catch (e) {
console.log('Parse error:', e.message);
console.log('Raw result:', JSON.stringify(createResult, null, 2));
throw e;
}
if (creationData && creationData.success) {
console.log('\n🎉 Project created successfully!');
console.log('- Project ID:', creationData.created.project.id);
console.log('- Project Name:', creationData.created.project.name);
console.log('- Initiatives created:', creationData.created.initiatives.length);
console.log('- Tasks created:', creationData.created.tasks.length);
console.log('\nSummary:', creationData.summary);
} else {
console.log('❌ Creation failed:', creationData.error);
}
} catch (error) {
console.error('❌ Test failed:', error.message);
} finally {
mcp.kill();
process.exit(0);
}
}
// Run tests
runTests();