Skip to main content
Glama

search

Search arXiv papers by title, keywords, or arXiv ID to find relevant scientific literature and research papers.

Instructions

Search arXiv papers by title, keywords, or arXiv ID.

Args: query: Search query (title, keywords, or arXiv ID like 2401.12345) max_results: Maximum number of results to return (default: 10) Returns: List of matching papers with ID, title, authors, and abstract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNo

Implementation Reference

  • The handler function for the 'search' tool, decorated with @mcp.tool() to register it with the MCP server. It formats search results from search_papers into a string response.
    @mcp.tool() def search(query: str, max_results: int = 10) -> str: """Search arXiv papers by title, keywords, or arXiv ID. Args: query: Search query (title, keywords, or arXiv ID like 2401.12345) max_results: Maximum number of results to return (default: 10) Returns: List of matching papers with ID, title, authors, and abstract """ papers = search_papers(query, max_results) if not papers: return "No papers found." results = [] for p in papers: authors = ", ".join(p.authors[:3]) if len(p.authors) > 3: authors += " et al." results.append( f"**{p.id}**: {p.title}\n" f"Authors: {authors}\n" f"Published: {p.published}\n" f"Abstract: {p.abstract[:300]}...\n" ) return "\n---\n".join(results)
  • Core helper function that performs the actual arXiv paper search using the arxiv library, handling both ID lookups and keyword searches, and returns a list of Paper objects.
    def search_papers(query: str, max_results: int = 10) -> list[Paper]: """Search arXiv papers by query or ID.""" arxiv_id = extract_arxiv_id(query) if arxiv_id: # Direct ID lookup client = arxiv.Client() search = arxiv.Search(id_list=[arxiv_id]) results = list(client.results(search)) else: # Keyword search client = arxiv.Client() search = arxiv.Search( query=query, max_results=max_results, sort_by=arxiv.SortCriterion.Relevance, ) results = list(client.results(search)) papers = [] for result in results: paper = Paper( id=result.entry_id.split("/")[-1], title=result.title, authors=[author.name for author in result.authors], abstract=result.summary, published=result.published.strftime("%Y-%m-%d"), pdf_url=result.pdf_url, categories=result.categories, ) papers.append(paper) return papers
  • Dataclass defining the structure of a Paper object used in search results.
    @dataclass class Paper: """Represents an arXiv paper.""" id: str title: str authors: list[str] abstract: str published: str pdf_url: str categories: list[str]
  • Helper function to extract arXiv ID from the search query for direct lookups.
    def extract_arxiv_id(query: str) -> str | None: """Extract arXiv ID from query if present.""" # Patterns: 2401.12345, arXiv:2401.12345, etc. patterns = [ r"(\d{4}\.\d{4,5})", # 2401.12345 r"arxiv[:\s]*(\d{4}\.\d{4,5})", # arXiv:2401.12345 ] for pattern in patterns: match = re.search(pattern, query, re.IGNORECASE) if match: return match.group(1) return None
  • The @mcp.tool() decorator that registers the search function as an MCP tool.
    @mcp.tool()
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/AnnaSuSu/arxiv-mcp'

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