File size: 819 Bytes
ee63964
 
 
83ccb99
ee63964
 
 
 
 
3036ad5
83ccb99
ee63964
 
 
 
 
3036ad5
ee63964
 
3036ad5
ee63964
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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):
    """Fetch latest arXiv papers for the query."""
    encoded_query = quote_plus(query)
    search_url = f"{ARXIV_BASE}{encoded_query}&max_results={max_results}"
    feed = feedparser.parse(search_url)
    results = []
    for entry in feed.entries:
        results.append({
            "title": entry.title,
            "authors": ", ".join([a.name for a in entry.authors]) if hasattr(entry, 'authors') else "",
            "summary": entry.summary,
            "link": entry.link,
            "published": entry.get("published", ""),  # <--- THIS FIXES THE ERROR!
            "source": "arXiv"
        })
    return results