#!/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);
});