Skip to main content
Glama

download_article

Download arXiv articles as PDF files by providing the article title. The tool searches for the article, retrieves the PDF, and saves it locally using the arXiv ID as the filename.

Instructions

Download the article hosted on arXiv.org as a PDF file. This tool searches for the article based on its title, retrieves the article's PDF, and saves it to a specified download location using the arXiv ID as the filename.

Args: title: Article title.

Returns: Success or error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes

Implementation Reference

  • The main execution logic for the 'download_article' MCP tool. It finds the arXiv PDF URL from the title, downloads the PDF bytes, and saves the file locally using the arXiv ID as the filename.
    @mcp.tool() async def download_article(title: str) -> str: """ Download the article hosted on arXiv.org as a PDF file. This tool searches for the article based on its title, retrieves the article's PDF, and saves it to a specified download location using the arXiv ID as the filename. Args: title: Article title. Returns: Success or error message. """ result = await get_url_and_arxiv_id(title) if isinstance(result, str): return result article_url, arxiv_id = result pdf_doc = await get_pdf(article_url) if pdf_doc is None: return "Unable to retrieve the article from arXiv.org." file_path = os.path.join(DOWNLOAD_PATH, f"{arxiv_id}.pdf") try: with open(file_path, "wb") as file: file.write(pdf_doc) return f"Download successful. Find the PDF at {DOWNLOAD_PATH}" except Exception: return f"Unable to save the article to local directory."
  • Helper function that searches arXiv API for the article by title, finds the best match, and returns the direct PDF URL and arXiv ID.
    async def get_url_and_arxiv_id(title: str) -> tuple[str, str] | str: """Get URL of the article hosted on arXiv.org.""" info = await fetch_information(title) if isinstance(info, str): return info arxiv_id = info.id.split("/abs/")[-1] direct_pdf_url = f"https://arxiv.org/pdf/{arxiv_id}" return (direct_pdf_url, arxiv_id)
  • Helper function to fetch the PDF content as bytes from the given arXiv PDF URL.
    async def get_pdf(url: str) -> bytes | None: """Get PDF document as bytes from arXiv.org.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/pdf" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.content except Exception: return None
  • The @mcp.tool() decorator registers the download_article function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/prashalruchiranga/arxiv-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server