test_server.pyā¢2.63 kB
#!/usr/bin/env python3
"""
Test script for Wikipedia MCP Server.
This script tests the Wikipedia client directly to verify functionality.
"""
import asyncio
import sys
import os
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from src.wikipedia_mcp_server.wikipedia_client import WikipediaClient
async def test_wikipedia_client():
"""Test the Wikipedia client functionality."""
print("š Testing Wikipedia MCP Server Client")
print("=" * 50)
async with WikipediaClient() as client:
try:
# Test 1: Search Wikipedia
print("\n1. Testing search_wikipedia...")
search_result = await client.search_wikipedia("artificial intelligence", limit=3)
print(f"ā
Found {len(search_result.results)} results for 'artificial intelligence'")
for result in search_result.results[:2]:
print(f" - {result.title}: {result.snippet[:100]}...")
# Test 2: Get Summary
print("\n2. Testing get_summary...")
summary = await client.get_summary("Albert Einstein")
print(f"ā
Got summary for '{summary.title}' ({len(summary.summary)} chars)")
print(f" Summary: {summary.summary[:200]}...")
print(f" Key facts: {len(summary.key_facts)} facts")
# Test 3: Get Article (limited content to avoid spam)
print("\n3. Testing get_article...")
article = await client.get_article("Python (programming language)")
print(f"ā
Got article '{article.title}' ({article.word_count} words)")
print(f" Sections: {len(article.sections)} sections")
print(f" Content preview: {article.content[:200]}...")
# Test 4: Find Related
print("\n4. Testing find_related...")
related = await client.find_related("Machine learning", limit=3)
print(f"ā
Found {len(related.related)} related articles to 'Machine learning'")
for rel in related.related[:2]:
print(f" - {rel.title} ({rel.relation_type})")
print("\nš All tests passed! The Wikipedia MCP server is working correctly.")
except Exception as e:
print(f"ā Test failed: {e}")
return False
return True
async def main():
"""Main test function."""
success = await test_wikipedia_client()
return 0 if success else 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)