""" Verify MCP Legacy Files installation and basic functionality. """ import asyncio import tempfile import os from pathlib import Path def create_test_files(): """Create test files for verification.""" test_files = {} # Create mock dBASE file with tempfile.NamedTemporaryFile(suffix='.dbf', delete=False) as f: # dBASE III header header = bytearray(32) header[0] = 0x03 # dBASE III version header[1:4] = [24, 1, 1] # Date: 2024-01-01 header[4:8] = (5).to_bytes(4, 'little') # 5 records header[8:10] = (97).to_bytes(2, 'little') # Header length (32 + 2*32 + 1) header[10:12] = (20).to_bytes(2, 'little') # Record length # Field descriptors for 2 fields (32 bytes each) field1 = bytearray(32) field1[0:8] = b'NAME ' # Field name field1[11] = ord('C') # Character type field1[16] = 15 # Field length field2 = bytearray(32) field2[0:8] = b'AGE ' # Field name field2[11] = ord('N') # Numeric type field2[16] = 3 # Field length # Header terminator terminator = b'\x0D' # Sample records (20 bytes each) record1 = b' John Doe 25 ' record2 = b' Jane Smith 30 ' record3 = b' Bob Johnson 45 ' record4 = b' Alice Brown 28 ' record5 = b' Charlie Davis 35 ' # Write complete file f.write(header) f.write(field1) f.write(field2) f.write(terminator) f.write(record1) f.write(record2) f.write(record3) f.write(record4) f.write(record5) f.flush() test_files['dbase'] = f.name # Create mock WordPerfect file with tempfile.NamedTemporaryFile(suffix='.wpd', delete=False) as f: # WordPerfect 6.0 signature + some content content = b'\xFF\x57\x50\x43' + b'WordPerfect Document\x00Sample content for testing.\x00' f.write(content) f.flush() test_files['wordperfect'] = f.name return test_files def cleanup_test_files(test_files): """Clean up test files.""" for file_path in test_files.values(): try: os.unlink(file_path) except FileNotFoundError: pass async def main(): """Main verification routine.""" print("šŸ›ļø MCP Legacy Files - Installation Verification") print("=" * 60) # Test imports print("\nšŸ“¦ Testing package imports...") try: from mcp_legacy_files import __version__ from mcp_legacy_files.core.detection import LegacyFormatDetector from mcp_legacy_files.core.processing import ProcessingEngine from mcp_legacy_files.core.server import app print(f"āœ… Package imported successfully - Version: {__version__}") except ImportError as e: print(f"āŒ Import failed: {str(e)}") return False # Test core components print("\nšŸ”§ Testing core components...") try: detector = LegacyFormatDetector() engine = ProcessingEngine() print("āœ… Core components initialized successfully") except Exception as e: print(f"āŒ Component initialization failed: {str(e)}") return False # Test format detection print("\nšŸ” Testing format detection...") test_files = create_test_files() try: # Test dBASE detection dbase_info = await detector.detect_format(test_files['dbase']) if dbase_info.format_family == 'dbase' and dbase_info.is_legacy_format: print("āœ… dBASE format detection working") else: print(f"āš ļø dBASE detection issue: {dbase_info.format_name}") # Test WordPerfect detection wp_info = await detector.detect_format(test_files['wordperfect']) if wp_info.format_family == 'wordperfect' and wp_info.is_legacy_format: print("āœ… WordPerfect format detection working") else: print(f"āš ļø WordPerfect detection issue: {wp_info.format_name}") except Exception as e: print(f"āŒ Format detection failed: {str(e)}") return False # Test dBASE processing print("\nāš™ļø Testing dBASE processing...") try: result = await engine.process_document( file_path=test_files['dbase'], format_info=dbase_info, preserve_formatting=True, method="auto", enable_ai_enhancement=True ) if result.success: print("āœ… dBASE processing successful") if result.text_content and "John Doe" in result.text_content: print("āœ… Content extraction working") else: print("āš ļø Content extraction may have issues") else: print(f"āš ļø dBASE processing failed: {result.error_message}") except Exception as e: print(f"āŒ dBASE processing error: {str(e)}") # Test supported formats print("\nšŸ“‹ Testing supported formats...") try: formats = await detector.get_supported_formats() dbase_formats = [f for f in formats if f['format_family'] == 'dbase'] if dbase_formats: print(f"āœ… Format database loaded - {len(formats)} formats supported") else: print("āš ļø Format database may have issues") except Exception as e: print(f"āŒ Format database error: {str(e)}") # Test FastMCP server print("\nšŸ–„ļø Testing FastMCP server...") try: # Just check that the app object exists and has tools if hasattr(app, 'get_tools'): tools = app.get_tools() if tools: print(f"āœ… FastMCP server ready - {len(tools)} tools available") else: print("āš ļø No tools registered") else: print("āœ… FastMCP app object created") except Exception as e: print(f"āŒ FastMCP server error: {str(e)}") # Cleanup cleanup_test_files(test_files) # Final status print("\n" + "=" * 60) print("šŸ† Installation verification completed!") print("\nšŸ’” To start the MCP server:") print(" mcp-legacy-files") print("\nšŸ’” To use the CLI:") print(" legacy-files-cli detect ") print(" legacy-files-cli process ") print(" legacy-files-cli formats") return True if __name__ == "__main__": asyncio.run(main())