Download mcp/arxiv.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/c1cd51c3d819831e10326b8bcf37375fe7315ebb/mcp/arxiv.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@c1cd51c3d819831e10326b8bcf37375fe7315ebb/mcp/arxiv.py
-
curl -L -o arxiv.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/c1cd51c3d819831e10326b8bcf37375fe7315ebb/mcp/arxiv.py
774 Bytes
| # 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) # Ensures spaces become +, etc. | |
| 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]), | |
| "summary": entry.summary, | |
| "link": entry.link, | |
| "published": entry.published, | |
| "source": "arXiv" | |
| }) | |
| return results | |