Skip to main content
Glama

download_article

Download arXiv articles as PDFs by title. The tool fetches the article, saves it to a specified location, and uses 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 handler function for the 'download_article' tool, decorated with @mcp.tool() which also serves as registration. It orchestrates article lookup, PDF download, and local file saving.
    @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 that fetches article information and constructs the direct PDF URL and arXiv ID from the title.
    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 download PDF bytes from the arXiv 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

Other Tools

Related Tools

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