get_paper
Retrieve detailed information about a specific academic paper using its ID (e.g., Semantic Scholar ID, DOI, ArXiv ID). Specify desired fields to streamline results for research or analysis.
Instructions
Get detailed information about a specific paper.
Args:
paper_id: Paper ID (can be Semantic Scholar ID, DOI, ArXiv ID, etc.)
fields: Comma-separated list of fields to return
Returns:
Detailed paper information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | ||
| paper_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"fields": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Fields"
},
"paper_id": {
"title": "Paper Id",
"type": "string"
}
},
"required": [
"paper_id"
],
"title": "get_paperArguments",
"type": "object"
}
Implementation Reference
- The @mcp.tool()-decorated handler function that implements the core logic for retrieving and formatting detailed information about a specific academic paper from the Semantic Scholar API.@mcp.tool() async def get_paper(paper_id: str, fields: Optional[str] = None) -> str: """ Get detailed information about a specific paper. Args: paper_id: Paper ID (can be Semantic Scholar ID, DOI, ArXiv ID, etc.) fields: Comma-separated list of fields to return Returns: Detailed paper information """ params = {} if fields: params["fields"] = fields else: params["fields"] = ( "paperId,title,authors,year,venue,citationCount,abstract,references,citations,openAccessPdf" ) # URL encode the paper ID to handle DOIs and other special characters encoded_id = quote(paper_id, safe="") result = await make_api_request(f"paper/{encoded_id}", params) if result is None: return "Error: Failed to fetch paper" if "error" in result: return f"Error: {result['error']}" paper = result title = paper.get("title", "Unknown Title") authors = paper.get("authors", []) author_names = [author.get("name", "Unknown") for author in authors] year = paper.get("year", "Unknown") venue = paper.get("venue", "Unknown") citation_count = paper.get("citationCount", 0) abstract = paper.get("abstract", "No abstract available") references = paper.get("references", []) citations = paper.get("citations", []) open_access = paper.get("openAccessPdf") pdf_url = open_access.get("url") if open_access else "No open access PDF" result_text = f"""Title: {title} Authors: {', '.join(author_names)} Year: {year} Venue: {venue} Citations: {citation_count} Paper ID: {paper.get('paperId', 'Unknown')} Abstract: {abstract} References: {len(references)} Cited by: {len(citations)} Open Access PDF: {pdf_url}""" return result_text
- Helper function that performs API requests to Semantic Scholar, handles errors, authentication, and rate limiting. Called by get_paper to fetch paper data.async def make_api_request( endpoint: str, params: Optional[Dict[str, Any]] = None, method: str = "GET" ) -> Optional[Dict[str, Any]]: """Make a request to the Semantic Scholar API.""" url = f"{BASE_URL}/{endpoint.lstrip('/')}" headers = { "Accept": "application/json", "User-Agent": f"semantic-scholar-mcp/{USER_AGENT_VERSION}", } if API_KEY: headers["x-api-key"] = API_KEY try: async with httpx.AsyncClient(timeout=API_TIMEOUT) as client: if method == "GET": response = await client.get(url, headers=headers, params=params) elif method == "POST": response = await client.post(url, headers=headers, json=params) else: raise ValueError(f"Unsupported HTTP method: {method}") response.raise_for_status() return response.json() except httpx.HTTPStatusError as e: if e.response.status_code == 403: if not API_KEY: return { "error": "Rate limit exceeded. The shared public rate limit (1000 req/sec) may be exceeded. Get a free API key from https://www.semanticscholar.org/product/api for dedicated limits." } else: return { "error": f"API key may be invalid or rate limit exceeded: {str(e)}" } elif e.response.status_code == 429: return { "error": "Rate limit exceeded. Please wait a moment and try again, or get an API key for dedicated higher limits." } else: return {"error": f"HTTP error: {str(e)}"} except httpx.HTTPError as e: return {"error": f"HTTP error: {str(e)}"} except Exception as e: return {"error": f"Request failed: {str(e)}"}
- src/semantic_scholar_mcp/server.py:176-176 (registration)The @mcp.tool() decorator registers the get_paper function as an MCP tool.@mcp.tool()
- Docstring defining the input parameters (paper_id: str, fields: Optional[str]) and return type (str), serving as the tool schema for MCP.""" Get detailed information about a specific paper. Args: paper_id: Paper ID (can be Semantic Scholar ID, DOI, ArXiv ID, etc.) fields: Comma-separated list of fields to return Returns: Detailed paper information """