Skip to main content
Glama
hajifkd

inspirehep-mcp

by hajifkd

inspirehep_search_by_author

Read-onlyIdempotent

Search for high-energy physics literature on INSPIRE-HEP using author names. Filter results by year, collaboration size, and sort by citations or recency to find relevant papers.

Instructions

Search INSPIRE-HEP literature by author.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main async handler for inspirehep_search_by_author tool. Decorated with @mcp.tool, it takes AuthorSearchInput parameters, builds an author query using build_author_query, and executes the search via run_search.
    @mcp.tool(
        name="inspirehep_search_by_author",
        annotations={
            "title": "Search INSPIRE-HEP papers by author",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
    async def inspirehep_search_by_author(params: AuthorSearchInput) -> dict[str, Any]:
        """Search INSPIRE-HEP literature by author."""
    
        query = build_author_query(params.author, params.large_collaboration, params.year)
        return await run_search(
            query=query,
            limit=params.limit,
            sort_by_citation=params.sort_by_citation,
        )
  • Pydantic schema for AuthorSearchInput. Defines the author field as a list of strings with validation, extends BaseSearchInput for common parameters like limit, year, large_collaboration, and sort_by_citation.
    class AuthorSearchInput(BaseSearchInput):
        author: list[str] = Field(
            ...,
            min_length=1,
            max_length=10,
            description="Author names to search (e.g. ['Witten, Edward', 'Maldacena, Juan']).",
        )
    
        @field_validator("author")
        @classmethod
        def validate_author_list(cls, value: list[str]) -> list[str]:
            cleaned = [item.strip() for item in value]
            if any(not item for item in cleaned):
                raise ValueError("author entries must be non-empty strings.")
            return cleaned
  • Tool registration decorator that registers inspirehep_search_by_author with MCP. Sets tool name, title description, and hints (readOnly, idempotent, etc.).
    @mcp.tool(
        name="inspirehep_search_by_author",
        annotations={
            "title": "Search INSPIRE-HEP papers by author",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
  • Helper function that builds the INSPIRE-HEP query string from a list of author names. Escapes quotes and joins author clauses with 'and', then applies year and collaboration filters.
    def build_author_query(
        authors: list[str], large_collaboration: bool, year: int | None = None
    ) -> str:
        clauses = [f'author "{_escape_quotes(author)}"' for author in authors]
        base_query = " and ".join(clauses)
        return _apply_filters(base_query, large_collaboration, year)
  • Helper function that executes the search query using InspireHEPClient. Handles HTTP errors, converts sort preference, and returns formatted results with record count and list.
    async def run_search(
        *,
        query: str,
        limit: int,
        sort_by_citation: bool,
        client: InspireHEPClient | None = None,
    ) -> dict[str, Any]:
        sort = _to_inspire_sort(sort_by_citation)
        try:
            if client is not None:
                search_result = await client.search_literature(query=query, limit=limit, sort=sort)
            else:
                async with InspireHEPClient() as default_client:
                    search_result = await default_client.search_literature(
                        query=query,
                        limit=limit,
                        sort=sort,
                    )
        except httpx.HTTPStatusError as exc:
            status = exc.response.status_code
            message = exc.response.text or "No response body."
            raise RuntimeError(
                f"INSPIRE API error ({status}): {message[:300]}"
            ) from exc
        except httpx.HTTPError as exc:
            raise RuntimeError(f"INSPIRE API request failed: {exc}") from exc
    
        return {
            "count": len(search_result.records),
            "records": search_result.records,
        }

Tool Definition Quality

Score is being calculated. Check back soon.

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/hajifkd/inspirehep-mcp'

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