File size: 2,723 Bytes
c3aa9b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node

/**
 * Test script for the MCP server
 * This script demonstrates how to test individual components
 */

import { AIService } from '../services/ai-service.js';
import { DocumentationService } from '../services/documentation-service.js';
import { VectorService } from '../services/vector-service.js';
import dotenv from 'dotenv';

dotenv.config();

async function testAIService() {
  console.log('\n=== Testing AI Service ===');
  const aiService = new AIService();
  
  const available = await aiService.checkAvailability();
  console.log(`AI Service Available: ${available}`);
  
  if (available) {
    console.log('Generating test summary...');
    const summary = await aiService.summarize(
      'SUSE Linux Enterprise Server (SLES) is a reliable, scalable, and secure server operating system, built to power mission-critical workloads.',
      'brief'
    );
    console.log('Summary:', summary);
  }
}

async function testDocumentationService() {
  console.log('\n=== Testing Documentation Service ===');
  const docService = new DocumentationService();
  
  const sources = await docService.listSources();
  console.log('Available Documentation Sources:');
  sources.forEach(source => {
    console.log(`  - ${source.name} (${source.baseUrl})`);
  });
}

async function testVectorService() {
  console.log('\n=== Testing Vector Service ===');
  const vectorService = new VectorService();
  
  // Test adding a document
  console.log('Adding test document...');
  await vectorService.addDocument({
    id: 'test-doc-1',
    content: 'K3s is a lightweight Kubernetes distribution. It is easy to install and requires minimal resources.',
    metadata: {
      source: 'test',
      url: 'https://example.com/test',
      title: 'Test Document',
      indexedAt: new Date().toISOString(),
    },
  });
  
  console.log('Searching for "kubernetes"...');
  const results = await vectorService.search('kubernetes', 'all', 3);
  console.log(`Found ${results.length} results`);
  results.forEach((result, idx) => {
    console.log(`\n  Result ${idx + 1}:`);
    console.log(`    Title: ${result.metadata.title}`);
    console.log(`    Score: ${result.metadata.score}`);
  });
}

async function main() {
  console.log('Docs Navigator MCP - Component Tests\n');
  console.log('Configuration:');
  console.log(`  AI Provider: ${process.env.AI_PROVIDER || 'ollama'}`);
  console.log(`  Model: ${process.env.OLLAMA_MODEL || 'llama3.2:latest'}`);
  
  try {
    await testDocumentationService();
    await testAIService();
    await testVectorService();
    
    console.log('\n✅ All tests completed!');
  } catch (error) {
    console.error('\n❌ Test failed:', error);
    process.exit(1);
  }
}

main();