#!/usr/bin/env node
/**
* Test script for modular MCP server
* Validates module loading and basic functionality without requiring stdio transport
*/
import { ToolLoader } from './src/utils/toolLoader.js';
async function testModularSystem() {
console.log('๐งช Testing AI-Archive MCP Server Modular System\n');
try {
// Test 1: Tool Loader Initialization
console.log('1๏ธโฃ Testing ToolLoader initialization...');
const toolLoader = new ToolLoader();
console.log(' โ
ToolLoader created successfully');
// Test 2: Configuration Loading
console.log('\n2๏ธโฃ Testing configuration loading...');
const config = toolLoader.config;
console.log(` โ
Configuration loaded with ${Object.keys(config.enabledModules).length} modules`);
// Test 3: Module Loading
console.log('\n3๏ธโฃ Testing module loading...');
const { tools, handlers } = await toolLoader.loadAllModules();
console.log(` โ
Loaded ${tools.length} tools from ${toolLoader.getLoadedModules().length} modules`);
// Test 4: Tool Validation
console.log('\n4๏ธโฃ Testing tool validation...');
toolLoader.validateAllTools();
console.log(' โ
All tools passed validation');
// Test 5: Module Information
console.log('\n5๏ธโฃ Testing module information retrieval...');
const moduleInfo = toolLoader.getAllModuleInfo();
console.log(` โ
Retrieved info for ${moduleInfo.length} modules`);
// Test 6: Tool Lookup
console.log('\n6๏ธโฃ Testing tool lookup functionality...');
const searchTool = toolLoader.getToolByName('search_papers');
const searchHandler = toolLoader.getHandlerByName('search_papers');
if (searchTool && searchHandler) {
console.log(' โ
Tool lookup working correctly');
} else {
throw new Error('Tool lookup failed');
}
// Test 7: Statistics
console.log('\n7๏ธโฃ Testing statistics generation...');
const stats = toolLoader.getStats();
console.log(` โ
Stats: ${stats.totalModules} modules, ${stats.totalTools} tools, ${stats.totalHandlers} handlers`);
// Summary
console.log('\n๐ Test Summary:');
console.log('==========================================');
console.log(`โ
All tests passed successfully!`);
console.log(`๐ฆ Modules loaded: ${toolLoader.getLoadedModules().join(', ')}`);
console.log(`๐ง Total tools available: ${tools.length}`);
console.log(`โ๏ธ Total handlers registered: ${Object.keys(handlers).length}`);
console.log('==========================================');
// Detailed breakdown
console.log('\n๐ Detailed Module Breakdown:');
for (const module of moduleInfo) {
console.log(` ๐ ${module.name}: ${module.toolCount} tools`);
console.log(` Tools: ${module.tools.join(', ')}`);
}
return true;
} catch (error) {
console.error(`โ Test failed: ${error.message}`);
console.error(error.stack);
return false;
}
}
// Run the test
testModularSystem()
.then(success => {
if (success) {
console.log('\n๐ Modular system test completed successfully!');
process.exit(0);
} else {
console.log('\n๐ฅ Modular system test failed!');
process.exit(1);
}
})
.catch(error => {
console.error(`๐ฅ Unexpected error: ${error.message}`);
process.exit(1);
});