Skip to main content
Glama
emi-dm

ArxivSearcher MCP Server

by emi-dm

download_paper

Download PDFs of arXiv papers to a local directory using the paper's arXiv ID for offline access or analysis.

Instructions

Downloads the PDF of a paper to a local directory on the server. NOTE: In a stateless/free hosting environment, this file is temporary and will be deleted when the server restarts or sleeps.

:param arxiv_id: The ArXiv ID of the paper to download (e.g., '2301.12345'). :param directory: The local directory where the paper will be saved.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
arxiv_idYes
directoryNodownloaded_papers

Implementation Reference

  • Synchronous handler function for the 'download_paper' MCP tool. Downloads arXiv paper PDF to a local directory using the arxiv library.
    @mcp.tool
    def download_paper(arxiv_id: str, directory: str = "downloaded_papers") -> dict:
        """
        Downloads the PDF of a paper to a local directory on the server.
        NOTE: In a stateless/free hosting environment, this file is temporary and
        will be deleted when the server restarts or sleeps.
    
        :param arxiv_id: The ArXiv ID of the paper to download (e.g., '2301.12345').
        :param directory: The local directory where the paper will be saved.
        """
        try:
            # Ensure the download directory exists
            os.makedirs(directory, exist_ok=True)
            
            search = arxiv.Search(id_list=[arxiv_id])
            paper = next(search.results())
            
            # Define a clean filename to avoid issues with special characters
            clean_id = re.sub(r'[^0-9v.]', '_', arxiv_id)
            filename = f"{clean_id}.pdf"
            
            # Download the paper to the specified directory
            paper.download_pdf(dirpath=directory, filename=filename)
            
            filepath = os.path.join(directory, filename)
            logging.info(f"Paper {arxiv_id} downloaded to {filepath}")
            
            return {
                "success": True,
                "arxiv_id": arxiv_id,
                "local_path": filepath,
                "message": f"Paper is temporarily available at the server path: {filepath}"
            }
            
        except StopIteration:
            logging.error(f"Paper with ID {arxiv_id} not found.")
            return {"success": False, "error": f"Paper with ID {arxiv_id} not found."}
        except Exception as e:
            logging.error(f"Failed to download paper {arxiv_id}: {e}")
            return {"success": False, "error": f"An unexpected error occurred: {str(e)}"}
  • Asynchronous handler function for the 'download_paper' MCP tool in the remote version. Downloads arXiv paper PDF to a local directory using the arxiv library.
    @mcp.tool
    async def download_paper(arxiv_id: str, directory: str = "downloaded_papers") -> dict:
        """
        Downloads the PDF of a paper to a local directory on the server.
        NOTE: In a stateless/free hosting environment, this file is temporary and
        will be deleted when the server restarts or sleeps.
    
        :param arxiv_id: The ArXiv ID of the paper to download (e.g., '2301.12345').
        :param directory: The local directory where the paper will be saved.
        """
        try:
            # Ensure the download directory exists
            os.makedirs(directory, exist_ok=True)
            
            search = arxiv.Search(id_list=[arxiv_id])
            paper = next(search.results())
            
            # Define a clean filename to avoid issues with special characters
            clean_id = re.sub(r'[^0-9v.]', '_', arxiv_id)
            filename = f"{clean_id}.pdf"
            
            # Download the paper to the specified directory
            paper.download_pdf(dirpath=directory, filename=filename)
            
            filepath = os.path.join(directory, filename)
            logging.info(f"Paper {arxiv_id} downloaded to {filepath}")
            
            return {
                "success": True,
                "arxiv_id": arxiv_id,
                "local_path": filepath,
                "message": f"Paper is temporarily available at the server path: {filepath}"
            }
            
        except StopIteration:
            logging.error(f"Paper with ID {arxiv_id} not found.")
            return {"success": False, "error": f"Paper with ID {arxiv_id} not found."}
        except Exception as e:
            logging.error(f"Failed to download paper {arxiv_id}: {e}")
            return {"success": False, "error": f"An unexpected error occurred: {str(e)}"}

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/emi-dm/Arxiv-MCP'

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