File size: 2,716 Bytes
ec5b689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""
Test script for the MCP Documentation Server
"""

import json
import subprocess
import sys
import os

def test_data_loading():
    """Test that data can be loaded"""
    print("Testing data loading...")
    
    try:
        # Test chunks data
        with open('mcp_docs/index/chunks_md.json', 'r', encoding='utf-8') as f:
            chunks = json.load(f)
        print(f"[OK] Loaded {len(chunks)} chunks")
        
        # Test docs data
        with open('mcp_docs/index/docs_md.json', 'r', encoding='utf-8') as f:
            docs = json.load(f)
        print(f"[OK] Loaded {len(docs)} documents")
        
        return True
        
    except Exception as e:
        print(f"[ERROR] Error loading data: {e}")
        return False

def test_mcp_server_import():
    """Test that the MCP server can be imported"""
    print("\nTesting MCP server import...")
    
    try:
        # Import the MCP server
        from mcp_server import server, load_data
        print("[OK] MCP server imported successfully")
        
        # Test data loading
        load_data()
        print("[OK] Data loading function works")
        
        print("[SUCCESS] MCP server is ready!")
        return True
        
    except Exception as e:
        print(f"[ERROR] Error importing MCP server: {e}")
        return False

def test_mcp_dependencies():
    """Test that MCP dependencies are available"""
    print("\nTesting MCP dependencies...")
    
    try:
        import mcp
        print("[OK] MCP SDK available")
        
        from mcp.server import Server
        print("[OK] MCP Server class available")
        
        from mcp.server.stdio import stdio_server
        print("[OK] MCP stdio server available")
        
        return True
        
    except ImportError as e:
        print(f"[ERROR] MCP dependencies not available: {e}")
        print("Install with: pip install mcp")
        return False

if __name__ == "__main__":
    print("MCP Documentation Server - Test Script")
    print("=" * 50)
    
    success = True
    
    # Test data loading
    success &= test_data_loading()
    
    # Test MCP dependencies
    success &= test_mcp_dependencies()
    
    # Test MCP server import
    success &= test_mcp_server_import()
    
    if success:
        print("\n[SUCCESS] All tests passed! The MCP server is ready for Cursor.")
        print("\nTo use in Cursor:")
        print("1. Add the server to your Cursor MCP configuration")
        print("2. Restart Cursor")
        print("3. Use the tools: search_docs, get_chunk, list_docs")
        sys.exit(0)
    else:
        print("\n[FAILED] Some tests failed. Please check the errors above.")
        sys.exit(1)