ads_mcp.client — ADS HTTP Client¶
HTTP client for the SAO/NASA Astrophysics Data System (ADS) API.
This module provides a thin, async wrapper around the ADS REST API
(https://github.com/adsabs/adsabs-dev-api). All network I/O is performed
with httpx so it plays nicely with FastMCP’s async event loop.
Example
Basic usage with an async context manager:
async with ADSClient(api_key="my-token") as client:
result = await client.search("black hole accretion", rows=5)
print(result)
- ads_mcp.client.ADS_BASE_URL = 'https://api.adsabs.harvard.edu/v1'¶
Base URL for all ADS v1 API requests.
- ads_mcp.client.DEFAULT_SEARCH_FIELDS = 'bibcode,title,author,year,abstract,doi,arxiv_class,identifier,citation_count,read_count,pub,volume,page,keyword'¶
Default fields returned by the search endpoint.
- exception ads_mcp.client.ADSError(status_code, message)[source]¶
Bases:
ExceptionRaised when the ADS API returns a non-2xx response.
- status_code¶
HTTP status code returned by the server.
- message¶
Human-readable error description.
- class ads_mcp.client.ADSClient(api_key=None, timeout=30.0)[source]¶
Bases:
objectAsync HTTP client for the ADS API.
Wraps the ADS REST API endpoints into straightforward async methods. An API key is required; obtain one at https://ui.adsabs.harvard.edu/user/settings/token.
- Parameters:
- Raises:
ValueError – If no API key is provided and
ADS_API_TOKENis not set in the environment.
Example
async with ADSClient() as client: papers = await client.search("exoplanet atmospheres", rows=10)
- async search(query, fields='bibcode,title,author,year,abstract,doi,arxiv_class,identifier,citation_count,read_count,pub,volume,page,keyword', rows=10, start=0, sort='date desc')[source]¶
Search the ADS database.
Calls
GET /v1/search/query.- Parameters:
query (
str) – Solr/ADS query string, e.g."author:Einstein relativity".fields (
str) – Comma-separated list of fields to return.rows (
int) – Maximum number of results. Capped at 2000 by ADS.start (
int) – Offset into the result set (for pagination).sort (
str) – Sort order, e.g."citation_count desc".
- Return type:
- Returns:
Parsed JSON response from ADS containing
response.docsandresponse.numFound.- Raises:
ADSError – If ADS returns a non-2xx status.
- async export(bibcodes, fmt='bibtex')[source]¶
Export one or more records in a bibliographic format.
Calls
POST /v1/export/{fmt}.- Parameters:
- Return type:
- Returns:
The exported bibliography as a plain string.
- Raises:
ADSError – If ADS returns a non-2xx status.
- async metrics(bibcodes, types=None)[source]¶
Retrieve citation and usage metrics for a set of papers.
Calls
POST /v1/metrics.- Parameters:
- Return type:
- Returns:
Parsed JSON metrics object from ADS.
- Raises:
ADSError – If ADS returns a non-2xx status.
- async search_by_bibcode(bibcodes, fields='bibcode,title,author,year,abstract,doi,arxiv_class,identifier,citation_count,read_count,pub,volume,page,keyword', rows=2000)[source]¶
Retrieve records for a list of bibcodes via a big-query POST.
Calls
POST /v1/search/bigquery.
- async get_references(bibcode, rows=200)[source]¶
Fetch the reference list of a paper.
Uses the
references()operator in the ADS search API.