# anatomy_server.py from mcp.server.fastmcp import FastMCP from serpapi import GoogleSearch import os from dotenv import load_dotenv load_dotenv() mcp = FastMCP("Anato-Mitra Tools") # Keep the backup just in case your API limit hits 0 BACKUP_IMAGE = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Human_body_features-en.svg/656px-Human_body_features-en.svg.png" @mcp.tool() def search_anatomy_diagrams(topic: str) -> str: """ Searches Google Images for a schematic anatomy diagram of the topic. """ print(f"🔎 Google Searching for: {topic}...") api_key = os.getenv("SERPAPI_KEY") if not api_key: return "Error: SERPAPI_KEY not found in .env file." try: # Configure the Google Image Search params = { "q": f"{topic} anatomy schematic drawing medical labeling", "engine": "google_images", "ijn": "0", # First page "api_key": api_key } search = GoogleSearch(params) results = search.get_dict() # Extract the first valid image images_results = results.get("images_results", []) if images_results: # Get the top result top_image = images_results[0] image_url = top_image.get("original") source = top_image.get("source") print(f"✅ Found Image: {image_url}") return f"![Diagram]({image_url})\n(Source: {source})" else: print("⚠️ No results found on Google.") return f"![Diagram]({BACKUP_IMAGE})\n(No specific Google Image found)" except Exception as e: print(f"❌ API Error: {e}") return f"![Diagram]({BACKUP_IMAGE})\n(Search failed, showing generic backup)" if __name__ == "__main__": mcp.run()