test_mcp_tools.py•2.26 kB
#!/usr/bin/env python
"""
Test script to verify MCP server tools functionality
"""
import sys
def test_tools():
"""Test MCP server tools"""
print("Testing YouTube MCP Server Tools\n")
print("=" * 50)
# Test 1: Import server
print("\n[Test 1] Importing server modules...")
try:
from src.main import search_youtube, mcp
print("✓ Server modules imported successfully")
except ImportError as e:
print(f"✗ Failed to import server: {e}")
return False
# Test 2: Check MCP instance
print("\n[Test 2] Checking MCP instance...")
print(f" Server name: {mcp.name}")
print("✓ MCP instance configured correctly")
# Test 3: Test search_youtube tool (limit to 5 results for speed)
print("\n[Test 3] Testing search_youtube tool...")
try:
results = search_youtube("Python tutorial", lang="en", max_results=5)
print(f"✓ Search completed: Found {len(results)} results")
if results:
first = results[0]
print(f"\n Sample result:")
print(f" Title: {first['video_title'][:60]}...")
print(f" Channel: {first['channel_name']}")
print(f" Views: {first['view_count']}")
print(f" Duration: {first['duration']}")
except Exception as e:
print(f"✗ Search failed: {e}")
return False
# Test 4: Test parameter validation
print("\n[Test 4] Testing parameter validation...")
try:
# Test max_results cap at 100
results = search_youtube("test", max_results=150)
print("✓ max_results properly capped")
# Test minimum results
results = search_youtube("test", max_results=0)
print("✓ max_results minimum enforced")
except Exception as e:
print(f"✗ Validation test failed: {e}")
return False
print("\n" + "=" * 50)
print("✓ All tests passed!")
print("\nReady for deployment:")
print(" 1. Local STDIO mode: uv run main --stdio")
print(" 2. HTTP mode: uv run main --port 8080")
print(" 3. Dedalus deployment: dedalus deploy . --name youtube-mcp")
return True
if __name__ == "__main__":
success = test_tools()
sys.exit(0 if success else 1)