Skip to main content
Glama

search_arxiv

Query the arXiv database using specific parameters like title, author, or abstract to retrieve article metadata. Results are returned in JSON format with titles and arXiv IDs for easy access.

Instructions

Performs a search query on the arXiv API based on specified parameters and returns matching article metadata. This function allows for flexible querying of the arXiv database. Only parameters that are explicitly provided will be included in the final search query. Results are returned in a JSON-formatted string with article titles as keys and their corresponding arXiv IDs as values.

Args: all_fields: General keyword search across all metadata fields including title, abstract, authors, comments, and categories. title: Keyword(s) to search for within the titles of articles. author: Author name(s) to filter results by. abstract: Keyword(s) to search for within article abstracts. start: Index of the first result to return; used for paginating through search results. Defaults to 0.

Returns: A JSON-formatted string containing article titles and their associated arXiv IDs; otherwise, a plain error message string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abstractNo
all_fieldsNo
authorNo
startNo
titleNo

Implementation Reference

  • The handler function for the 'search_arxiv' tool, registered via @mcp.tool() decorator. It constructs a search query for the arXiv API using provided parameters (all_fields, title, author, abstract, start), fetches results, parses the feed, and returns a dictionary of article titles to arXiv IDs and authors in string format.
    @mcp.tool() async def search_arxiv(ctx: Context, all_fields: Optional[str]=None, title: Optional[str]=None, author: Optional[str]=None, abstract: Optional[str]=None, start: int=0) -> str: """ Performs a search query on the arXiv API based on specified parameters and returns matching article metadata. This function allows for flexible querying of the arXiv database. Only parameters that are explicitly provided will be included in the final search query. Results are returned in a JSON-formatted string with article titles as keys and their corresponding arXiv IDs as values. Args: all_fields: General keyword search across all metadata fields including title, abstract, authors, comments, and categories. title: Keyword(s) to search for within the titles of articles. author: Author name(s) to filter results by. abstract: Keyword(s) to search for within article abstracts. start: Index of the first result to return; used for paginating through search results. Defaults to 0. Returns: A JSON-formatted string containing article titles and their associated arXiv IDs; otherwise, a plain error message string. """ prefixed_params = [] if author: author = format_text(author) prefixed_params.append(f'au:{author}') if all_fields: all_fields = format_text(all_fields) prefixed_params.append(f'all:{all_fields}') if title: title = format_text(title) prefixed_params.append(f'ti:{title}') if abstract: abstract = format_text(abstract) prefixed_params.append(f'abs:{abstract}') # Construct search query search_query = " AND ".join(prefixed_params) params = { "search_query": search_query, "start": start, "max_results": 10 } await ctx.info("Calling the API") response = await make_api_call(f"{ARXIV_API_BASE}/query", params=params) if response is None: return "Unable to retrieve data from arXiv.org." feed = feedparser.parse(response) error_msg = ( "Unable to extract information for your query. " "This issue may stem from an incorrect search query." ) if not feed.entries: return error_msg entries = {} await ctx.info("Extracting information") for entry in feed.entries: id = entry.id article_title = entry.title arxiv_id = id.split("/abs/")[-1] authors = [author['name'] for author in entry.authors] entries[article_title] = {"arXiv ID": arxiv_id, "Authors": authors} return entries
  • The @mcp.tool() decorator registers the search_arxiv function as an MCP tool.
    @mcp.tool()
  • Type hints and docstring define the input schema (optional parameters for search fields and pagination) and output (str JSON-like dict or error).
    async def search_arxiv(ctx: Context, all_fields: Optional[str]=None, title: Optional[str]=None, author: Optional[str]=None, abstract: Optional[str]=None, start: int=0) -> str: """ Performs a search query on the arXiv API based on specified parameters and returns matching article metadata. This function allows for flexible querying of the arXiv database. Only parameters that are explicitly provided will be included in the final search query. Results are returned in a JSON-formatted string with article titles as keys and their corresponding arXiv IDs as values. Args: all_fields: General keyword search across all metadata fields including title, abstract, authors, comments, and categories. title: Keyword(s) to search for within the titles of articles. author: Author name(s) to filter results by. abstract: Keyword(s) to search for within article abstracts. start: Index of the first result to return; used for paginating through search results. Defaults to 0. Returns: A JSON-formatted string containing article titles and their associated arXiv IDs; otherwise, a plain error message string. """

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