import PDFParser from '../src/pdf-parser.js';
import GoodbookTools from '../src/tools.js';
console.log('Testing Goodbook MCP Server Components...\n');
async function testPDFParser() {
console.log('=== Testing PDF Parser ===');
const parser = new PDFParser();
try {
const initialized = await parser.initialize();
if (initialized) {
console.log('✓ PDF Parser initialized successfully');
// Test search functionality
const searchResult = parser.searchContent('приготовление');
console.log(`✓ Search test: Found ${searchResult.totalResults} results for "приготовление"`);
// Test sections
const sections = parser.getSections();
console.log(`✓ Sections parsed: ${sections.length} sections found`);
return true;
} else {
console.log('✗ PDF Parser failed to initialize');
return false;
}
} catch (error) {
console.log(`✗ PDF Parser error: ${error.message}`);
return false;
}
}
async function testGoodbookTools() {
console.log('\n=== Testing Goodbook Tools ===');
const tools = new GoodbookTools();
try {
const initialized = await tools.initialize();
if (initialized) {
console.log('✓ Goodbook Tools initialized successfully');
// Test tool definitions
const toolDefs = tools.getToolDefinitions();
console.log(`✓ Tool definitions: ${toolDefs.length} tools available`);
toolDefs.forEach(tool => {
console.log(` - ${tool.name}: ${tool.description.substring(0, 60)}...`);
});
return true;
} else {
console.log('✗ Goodbook Tools failed to initialize');
return false;
}
} catch (error) {
console.log(`✗ Goodbook Tools error: ${error.message}`);
return false;
}
}
async function testToolExecution() {
console.log('\n=== Testing Tool Execution ===');
const tools = new GoodbookTools();
try {
await tools.initialize();
// Test list_sections tool
console.log('Testing list_sections tool...');
const sectionsResult = await tools.handleTool('list_sections', {});
console.log('✓ list_sections executed successfully');
// Test search_food_standards tool
console.log('Testing search_food_standards tool...');
const searchResult = await tools.handleTool('search_food_standards', {
query: 'температура'
});
console.log('✓ search_food_standards executed successfully');
return true;
} catch (error) {
console.log(`✗ Tool execution error: ${error.message}`);
return false;
}
}
async function runTests() {
const tests = [
testPDFParser,
testGoodbookTools,
testToolExecution
];
let passed = 0;
let total = tests.length;
for (const test of tests) {
if (await test()) {
passed++;
}
}
console.log(`\n=== Test Results ===`);
console.log(`Passed: ${passed}/${total} tests`);
if (passed === total) {
console.log('🎉 All tests passed! The Goodbook MCP server is ready to use.');
} else {
console.log('⚠️ Some tests failed. Please check the errors above.');
}
}
runTests().catch(error => {
console.error('Test execution failed:', error);
process.exit(1);
});