# mcp/arxiv.py import feedparser from urllib.parse import quote_plus ARXIV_BASE = "http://export.arxiv.org/api/query?search_query=" async def fetch_arxiv(query: str, max_results: int = 5) -> list[dict]: url = f"{ARXIV_BASE}{quote_plus(query)}&max_results={max_results}" feed = feedparser.parse(url) out = [] for e in feed.entries: out.append({ "title": e.get("title",""), "authors": ", ".join([a.name for a in getattr(e,"authors",[])]), "summary": e.get("summary",""), "link": e.get("link",""), "published": getattr(e,"published",""), "source": "arXiv" }) return out