Skip to main content
Glama
huanongfish

ArXiv MCP Server

by huanongfish

download_paper

Download arXiv research papers by ID to create accessible resources for reading and analysis.

Instructions

Download a paper and create a resource for it

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paper_idYesThe arXiv ID of the paper to download
check_statusNoIf true, only check conversion status without downloading

Implementation Reference

  • Main execution logic for the download_paper tool: downloads arXiv paper PDF, converts to Markdown asynchronously, tracks status, and returns JSON status updates.
    async def handle_download(arguments: Dict[str, Any]) -> List[types.TextContent]:
        """Handle paper download and conversion requests."""
        try:
            paper_id = arguments["paper_id"]
            check_status = arguments.get("check_status", False)
            
            # If only checking status
            if check_status:
                status = conversion_statuses.get(paper_id)
                if not status:
                    if get_paper_path(paper_id, ".md").exists():
                        return [types.TextContent(
                            type="text",
                            text=json.dumps({
                                "status": "success",
                                "message": "Paper is ready",
                                "resource_uri": f"file://{get_paper_path(paper_id, '.md')}"
                            })
                        )]
                    return [types.TextContent(
                        type="text",
                        text=json.dumps({
                            "status": "unknown",
                            "message": "No download or conversion in progress"
                        })
                    )]
                
                return [types.TextContent(
                    type="text",
                    text=json.dumps({
                        "status": status.status,
                        "started_at": status.started_at.isoformat(),
                        "completed_at": status.completed_at.isoformat() if status.completed_at else None,
                        "error": status.error,
                        "message": f"Paper conversion {status.status}"
                    })
                )]
            
            # Check if paper is already converted
            if get_paper_path(paper_id, ".md").exists():
                return [types.TextContent(
                    type="text",
                    text=json.dumps({
                        "status": "success",
                        "message": "Paper already available",
                        "resource_uri": f"file://{get_paper_path(paper_id, '.md')}"
                    })
                )]
            
            # Check if already in progress
            if paper_id in conversion_statuses:
                status = conversion_statuses[paper_id]
                return [types.TextContent(
                    type="text",
                    text=json.dumps({
                        "status": status.status,
                        "message": f"Paper conversion {status.status}",
                        "started_at": status.started_at.isoformat()
                    })
                )]
            
            # Start new download and conversion
            pdf_path = get_paper_path(paper_id, ".pdf")
            client = arxiv.Client()
            
            # Initialize status
            conversion_statuses[paper_id] = ConversionStatus(
                paper_id=paper_id,
                status="downloading", 
                started_at=datetime.now()
            )
            
            # Download PDF
            paper = next(client.results(arxiv.Search(id_list=[paper_id])))
            paper.download_pdf(dirpath=pdf_path.parent, filename=pdf_path.name)
            
            # Update status and start conversion
            status = conversion_statuses[paper_id]
            status.status = "converting"
            
            # Start conversion in thread
            asyncio.create_task(
                asyncio.to_thread(convert_pdf_to_markdown, paper_id, pdf_path)
            )
            
            return [types.TextContent(
                type="text",
                text=json.dumps({
                    "status": "converting",
                    "message": "Paper downloaded, conversion started",
                    "started_at": status.started_at.isoformat()
                })
            )]
            
        except StopIteration:
            return [types.TextContent(
                type="text",
                text=json.dumps({
                    "status": "error",
                    "message": f"Paper {paper_id} not found on arXiv"
                })
            )]
        except Exception as e:
            return [types.TextContent(
                type="text",
                text=json.dumps({
                    "status": "error",
                    "message": f"Error: {str(e)}"
                })
            )]
  • Tool schema defining name, description, and input validation schema for download_paper.
    download_tool = types.Tool(
        name="download_paper",
        description="Download a paper and create a resource for it",
        inputSchema={
            "type": "object",
            "properties": {
                "paper_id": {
                    "type": "string",
                    "description": "The arXiv ID of the paper to download"
                },
                "check_status": {
                    "type": "boolean",
                    "description": "If true, only check conversion status without downloading",
                    "default": False
                }
            },
            "required": ["paper_id"]
        }
    )
  • Registers the download_paper tool by including download_tool in the list returned by list_tools().
    @server.list_tools()
    async def list_tools() -> List[types.Tool]:
        """List available arXiv research tools."""
        return [search_tool, download_tool, list_tool, read_tool]
  • MCP server call_tool handler that dispatches download_paper calls to the handle_download function.
    @server.call_tool()
    async def call_tool(name: str, arguments: Dict[str, Any]) -> List[types.TextContent]:
        """Handle tool calls for arXiv research functionality."""
        logger.debug(f"Calling tool {name} with arguments {arguments}")
        try:
            if name == "search_papers":
                return await handle_search(arguments)
            elif name == "download_paper":
                return await handle_download(arguments)
            elif name == "list_papers":
                return await handle_list_papers(arguments)
            elif name == "read_paper":
                return await handle_read_paper(arguments)
            else:
                return [types.TextContent(type="text", text=f"Error: Unknown tool {name}")]
        except Exception as e:
            logger.error(f"Tool error: {str(e)}")
            return [types.TextContent(type="text", text=f"Error: {str(e)}")]
  • Helper function to convert downloaded PDF to Markdown format asynchronously, updates status, and cleans up PDF.
    def convert_pdf_to_markdown(paper_id: str, pdf_path: Path) -> None:
        """Convert PDF to Markdown in a separate thread."""
        try:
            logger.info(f"Starting conversion for {paper_id}")
            markdown = pymupdf4llm.to_markdown(pdf_path, show_progress=False)
            md_path = get_paper_path(paper_id, ".md")
            
            with open(md_path, "w", encoding="utf-8") as f:
                f.write(markdown)
    
            status = conversion_statuses.get(paper_id)
            if status:
                status.status = "success"
                status.completed_at = datetime.now()
                
            # Clean up PDF after successful conversion
            pdf_path.unlink()
            logger.info(f"Conversion completed for {paper_id}")
            
        except Exception as e:
            logger.error(f"Conversion failed for {paper_id}: {str(e)}")
            status = conversion_statuses.get(paper_id)
            if status:
                status.status = "error"
                status.completed_at = datetime.now()
                status.error = str(e)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'download a paper and create a resource', implying a write operation, but doesn't specify details like file format, storage location, permissions required, or error handling. For a tool with no annotations, this is insufficient to inform the agent adequately.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is front-loaded with the core action ('download a paper') and avoids unnecessary details, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (involving download and resource creation), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like what 'create a resource' entails, potential side effects, or return values. This leaves significant gaps for the agent to understand the tool fully.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting both parameters ('paper_id' and 'check_status'). The description adds no additional meaning beyond the schema, such as explaining the resource creation process or default behaviors. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('download a paper') and resource ('create a resource for it'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'read_paper' or 'list_papers', which might involve similar paper-related operations without the download aspect.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'read_paper' or 'search_papers'. It lacks context such as prerequisites (e.g., needing a valid arXiv ID) or exclusions (e.g., not for checking status only). This leaves the agent without clear usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/huanongfish/arxiv-mcp'

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