#!/usr/bin/env python3 """Simple test script to verify MCP Office Tools functionality.""" import asyncio import tempfile import os from pathlib import Path # Create simple test documents def create_test_documents(): """Create test documents for verification.""" temp_dir = Path(tempfile.mkdtemp()) # Create a simple CSV file csv_path = temp_dir / "test.csv" csv_content = """Name,Age,City John Doe,30,New York Jane Smith,25,Los Angeles Bob Johnson,35,Chicago""" with open(csv_path, 'w') as f: f.write(csv_content) # Create a simple text file to test validation txt_path = temp_dir / "test.txt" with open(txt_path, 'w') as f: f.write("This is a simple text file, not an Office document.") return temp_dir, csv_path, txt_path async def test_mcp_server(): """Test MCP server functionality.""" print("๐Ÿงช Testing MCP Office Tools Server") print("=" * 50) # Create test documents temp_dir, csv_path, txt_path = create_test_documents() print(f"๐Ÿ“ Created test files in: {temp_dir}") try: # Import the server components from mcwaddams.mixins import UniversalMixin # Test the Universal Mixin directly universal = UniversalMixin() print("\n๐Ÿ” Testing extract_text with CSV file...") try: result = await universal.extract_text(str(csv_path)) print("โœ… CSV text extraction successful!") print(f" Text length: {len(result.get('text', ''))}") print(f" Method used: {result.get('method_used', 'unknown')}") except Exception as e: print(f"โŒ CSV text extraction failed: {e}") print("\n๐Ÿ” Testing get_supported_formats...") try: result = await universal.get_supported_formats() print("โœ… Supported formats query successful!") print(f" Total formats: {len(result.get('formats', []))}") print(f" Excel formats: {len([f for f in result.get('formats', []) if 'Excel' in f.get('description', '')])}") except Exception as e: print(f"โŒ Supported formats query failed: {e}") print("\n๐Ÿ” Testing validation with unsupported file...") try: result = await universal.extract_text(str(txt_path)) print("โŒ Should have failed with unsupported file!") except Exception as e: print(f"โœ… Correctly rejected unsupported file: {type(e).__name__}") print("\n๐Ÿ” Testing detect_office_format...") try: result = await universal.detect_office_format(str(csv_path)) print("โœ… Format detection successful!") print(f" Detected format: {result.get('format', 'unknown')}") print(f" Is supported: {result.get('is_supported', False)}") except Exception as e: print(f"โŒ Format detection failed: {e}") except ImportError as e: print(f"โŒ Failed to import server components: {e}") return False except Exception as e: print(f"โŒ Unexpected error: {e}") return False finally: # Cleanup import shutil shutil.rmtree(temp_dir) print(f"\n๐Ÿงน Cleaned up test files from: {temp_dir}") print("\nโœ… Basic MCP Office Tools testing completed!") return True if __name__ == "__main__": asyncio.run(test_mcp_server())