Spaces:
Running
Running
| #!/usr/bin/env python | |
| """ | |
| Quick test script to verify MCP integration is working. | |
| This script: | |
| 1. Checks if Gradio MCP dependencies are installed | |
| 2. Verifies the MCP function registration | |
| 3. Tests the generate_ai_words wrapper | |
| Usage: | |
| python test_mcp.py | |
| """ | |
| import os | |
| import sys | |
| def test_gradio_mcp(): | |
| """Test Gradio MCP support.""" | |
| print("="*70) | |
| print("Testing Gradio MCP Integration") | |
| print("="*70) | |
| # Test 1: Check Gradio installation | |
| print("\n1. Checking Gradio installation...") | |
| try: | |
| import gradio as gr | |
| print(f" ? Gradio version: {gr.__version__}") | |
| except ImportError as e: | |
| print(f" ? Gradio not installed: {e}") | |
| return False | |
| # Test 2: Check MCP dependencies | |
| print("\n2. Checking MCP dependencies...") | |
| try: | |
| import mcp | |
| print(f" ? MCP package installed") | |
| except ImportError: | |
| print(f" ?? MCP package not installed") | |
| print(f" Install with: pip install 'gradio[mcp]'") | |
| # Not critical - continue anyway | |
| # Test 3: Check word_loader_ai module | |
| print("\n3. Checking word_loader_ai module...") | |
| try: | |
| from wrdler import word_loader_ai | |
| print(f" ? word_loader_ai module loaded") | |
| # Check if MCP function exists | |
| if hasattr(word_loader_ai, 'mcp_generate_ai_words'): | |
| print(f" ? MCP function 'mcp_generate_ai_words' registered") | |
| else: | |
| print(f" ?? MCP function not registered (may be disabled by USE_HF_WORDS flag)") | |
| except ImportError as e: | |
| print(f" ? Failed to load word_loader_ai: {e}") | |
| return False | |
| # Test 4: Check environment variables | |
| print("\n4. Checking environment configuration...") | |
| use_hf_words = os.getenv("USE_HF_WORDS", "false").lower() == "true" | |
| print(f" USE_HF_WORDS: {use_hf_words}") | |
| if use_hf_words: | |
| print(f" ?? MCP server will be DISABLED (remote mode)") | |
| else: | |
| print(f" ? MCP server will be ENABLED (local mode)") | |
| # Test 5: Verify function can be called | |
| print("\n5. Testing MCP function wrapper...") | |
| try: | |
| if hasattr(word_loader_ai, 'mcp_generate_ai_words'): | |
| print(f" ?? Function callable: mcp_generate_ai_words") | |
| print(f" ?? Note: Full test requires AI model (skipping actual generation)") | |
| else: | |
| print(f" ?? Function not available (USE_HF_WORDS=true or Gradio not available)") | |
| except Exception as e: | |
| print(f" ? Error testing function: {e}") | |
| print("\n" + "="*70) | |
| print("MCP Integration Test Complete") | |
| print("="*70) | |
| print("\nTo enable MCP server:") | |
| print(" 1. Set USE_HF_WORDS=false in your environment") | |
| print(" 2. Run: python gradio_app.py") | |
| print(" 3. Connect your MCP client to http://localhost:7860") | |
| print("\nFor detailed setup, see: docs/MCP_INTEGRATION.md") | |
| return True | |
| if __name__ == "__main__": | |
| success = test_gradio_mcp() | |
| sys.exit(0 if success else 1) | |