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