task-engine-ai-core
Version:
Revolutionary AI-driven task management system with complete transformation trilogy: Frontend v0.1.0, Backend v0.2.0, CLI v0.3.0 - Enterprise-grade performance with 95% improvements
230 lines (182 loc) โข 8.21 kB
JavaScript
/**
* Test MCP Bridge Configuration
* Verifies that the MCP bridge server can be started and responds correctly
*/
import { spawn } from 'child_process';
import fs from 'fs/promises';
import path from 'path';
class MCPBridgeTest {
constructor() {
this.projectRoot = process.cwd();
}
/**
* Run MCP bridge tests
*/
async runTests() {
console.log('๐งช Testing MCP Bridge Configuration...\n');
try {
// Test 1: Check MCP configuration files
await this.testMCPConfigFiles();
// Test 2: Test MCP bridge server startup
await this.testMCPBridgeServer();
// Test 3: Validate MCP configuration syntax
await this.validateMCPConfigs();
console.log('\nโ
All MCP Bridge tests passed!');
this.printNextSteps();
} catch (error) {
console.error('\nโ MCP Bridge tests failed:', error.message);
process.exit(1);
}
}
/**
* Test MCP configuration files exist
*/
async testMCPConfigFiles() {
console.log('๐ Testing MCP configuration files...');
const configPaths = [
'.cursor/mcp.json',
'.vscode/mcp.json'
];
let foundConfigs = 0;
for (const configPath of configPaths) {
const fullPath = path.join(this.projectRoot, configPath);
try {
await fs.access(fullPath);
console.log(` โ
${configPath} exists`);
foundConfigs++;
} catch (error) {
console.log(` โ ๏ธ ${configPath} not found (this is OK if you don't use this IDE)`);
}
}
if (foundConfigs === 0) {
throw new Error('No MCP configuration files found. Run "npm run setup:mcp-ide" first.');
}
console.log(` โ
Found ${foundConfigs} MCP configuration file(s)`);
}
/**
* Test MCP bridge server startup
*/
async testMCPBridgeServer() {
console.log('\n๐ Testing MCP bridge server startup...');
return new Promise((resolve, reject) => {
const serverPath = path.join(this.projectRoot, 'src/bridge/mcp-bridge-server.js');
console.log(` Starting server: node ${serverPath}`);
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: this.projectRoot
});
let output = '';
let errorOutput = '';
let serverStarted = false;
server.stdout.on('data', (data) => {
output += data.toString();
if (output.includes('MCP Bridge Server started')) {
serverStarted = true;
console.log(' โ
MCP Bridge Server started successfully');
// Send a test ping
server.stdin.write('{"method":"ping","jsonrpc":"2.0","id":1}\n');
// Give it a moment to respond, then kill
setTimeout(() => {
server.kill('SIGTERM');
}, 1000);
}
});
server.stderr.on('data', (data) => {
errorOutput += data.toString();
});
server.on('close', (code) => {
if (serverStarted) {
console.log(' โ
MCP Bridge Server stopped gracefully');
resolve();
} else {
console.log(' โ Server output:', output);
console.log(' โ Server errors:', errorOutput);
reject(new Error(`MCP Bridge Server failed to start (exit code: ${code})`));
}
});
server.on('error', (error) => {
reject(new Error(`Failed to start MCP Bridge Server: ${error.message}`));
});
// Timeout after 10 seconds
setTimeout(() => {
if (!serverStarted) {
server.kill('SIGKILL');
reject(new Error('MCP Bridge Server startup timed out'));
}
}, 10000);
});
}
/**
* Validate MCP configuration syntax
*/
async validateMCPConfigs() {
console.log('\n๐ Validating MCP configuration syntax...');
const configPaths = [
'.cursor/mcp.json',
'.vscode/mcp.json'
];
for (const configPath of configPaths) {
const fullPath = path.join(this.projectRoot, configPath);
try {
await fs.access(fullPath);
const configContent = await fs.readFile(fullPath, 'utf8');
const config = JSON.parse(configContent);
// Validate structure
const hasServers = config.mcpServers || config.servers;
if (!hasServers) {
throw new Error(`${configPath}: Missing mcpServers or servers section`);
}
const servers = config.mcpServers || config.servers;
// Check for task-master-ai server
if (!servers['task-master-ai']) {
throw new Error(`${configPath}: Missing task-master-ai server configuration`);
}
// Check for task-master-ide-bridge server
if (!servers['task-master-ide-bridge']) {
throw new Error(`${configPath}: Missing task-master-ide-bridge server configuration`);
}
// Validate task-master-ide-bridge configuration
const bridgeConfig = servers['task-master-ide-bridge'];
if (!bridgeConfig.command || !bridgeConfig.args) {
throw new Error(`${configPath}: Invalid task-master-ide-bridge configuration`);
}
console.log(` โ
${configPath} syntax is valid`);
} catch (error) {
if (error.code === 'ENOENT') {
console.log(` โ ๏ธ ${configPath} not found (skipping)`);
} else {
throw new Error(`${configPath}: ${error.message}`);
}
}
}
}
/**
* Print next steps for the user
*/
printNextSteps() {
console.log('\n๐ Next Steps:');
console.log('==============');
console.log('\n1. **Restart your IDE** to load the MCP configuration');
console.log('\n2. **Set your API keys** in the MCP configuration file:');
console.log(' - Edit .cursor/mcp.json or .vscode/mcp.json');
console.log(' - Replace "YOUR_*_API_KEY_HERE" with actual API keys');
console.log('\n3. **Test the integration** in your IDE:');
console.log(' - Open your IDE\'s MCP/AI chat interface');
console.log(' - Try using these MCP tools:');
console.log(' โข detect_ide - Detect available IDEs');
console.log(' โข connect_ide - Connect to your IDE agent');
console.log(' โข ide_generate_text - Generate text using your IDE');
console.log(' โข ide_status - Check connection status');
console.log('\n4. **Verify real IDE connection**:');
console.log(' - The system will try real IDE connection first');
console.log(' - Check logs to see if using real IDE or mock fallback');
console.log('\n๐ Your MCP IDE integration is ready to use!');
}
}
// Run tests if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
const tester = new MCPBridgeTest();
tester.runTests().catch(console.error);
}
export default MCPBridgeTest;