#!/usr/bin/env python3
"""
Test script for Google Scholar MCP Server
This script tests the functionality of the Google Scholar scraper
without requiring a full MCP client setup.
"""
import asyncio
import json
from main import GoogleScholarScraper
async def test_scraper():
"""Test the Google Scholar scraper functionality"""
scraper = GoogleScholarScraper()
print("š¬ Testing Google Scholar MCP Server")
print("=" * 50)
# Test 1: Basic paper search
print("\nš Test 1: Basic paper search")
try:
papers = scraper.search_papers("machine learning", num_results=5)
print(f"ā
Found {len(papers)} papers")
for i, paper in enumerate(papers[:2], 1):
print(f"\n{i}. {paper.get('title', 'No title')[:80]}...")
print(f" Authors: {paper.get('authors', 'Unknown')}")
print(f" Year: {paper.get('year', 'Unknown')}")
print(f" Citations: {paper.get('cited_by', 'Unknown')}")
except Exception as e:
print(f"ā Error: {e}")
# Test 2: Search with year filter
print("\nš
Test 2: Search with year filter (2020-2024)")
try:
papers = scraper.search_papers("neural networks", num_results=3, start_year=2020, end_year=2024)
print(f"ā
Found {len(papers)} recent papers")
for paper in papers:
print(f" - {paper.get('title', 'No title')[:60]}... ({paper.get('year', 'Unknown')})")
except Exception as e:
print(f"ā Error: {e}")
# Test 3: Author search
print("\nšØāš¬ Test 3: Author search")
try:
papers = scraper.search_papers('author:"Yann LeCun"', num_results=3)
print(f"ā
Found {len(papers)} papers by Yann LeCun")
for paper in papers:
print(f" - {paper.get('title', 'No title')[:60]}...")
except Exception as e:
print(f"ā Error: {e}")
print("\nš Testing completed!")
print("\nNote: This is a simplified test. In a real MCP setup,")
print("these functions would be called through the MCP protocol.")
def test_json_serialization():
"""Test JSON serialization of results"""
print("\nš§ Test 4: JSON serialization")
sample_paper = {
"title": "Test Paper",
"authors": "Test Author",
"year": 2023,
"cited_by": 42,
"url": "https://example.com"
}
try:
json_str = json.dumps(sample_paper, indent=2, ensure_ascii=False)
parsed = json.loads(json_str)
print("ā
JSON serialization works correctly")
print(f"Sample output:\n{json_str}")
except Exception as e:
print(f"ā JSON error: {e}")
if __name__ == "__main__":
print("Starting Google Scholar MCP Server Tests...")
print("This will make actual requests to Google Scholar.")
print("Please be patient and respectful of rate limits.\n")
test_json_serialization()
asyncio.run(test_scraper())