search_snippets
Retrieve specific text snippets from academic papers by entering a search query. Adjust parameters like result limit and offset to refine your search and access relevant content quickly.
Instructions
Search for text snippets across academic papers.
Args:
query: Search query for text snippets
limit: Maximum number of results (default: 10, max: 100)
offset: Number of results to skip (default: 0)
Returns:
Text snippets from papers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| offset | No | ||
| query | Yes |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 10,
"title": "Limit",
"type": "integer"
},
"offset": {
"default": 0,
"title": "Offset",
"type": "integer"
},
"query": {
"title": "Query",
"type": "string"
}
},
"required": [
"query"
],
"title": "search_snippetsArguments",
"type": "object"
}
Implementation Reference
- The handler function for the 'search_snippets' tool. It performs a search for text snippets in academic papers via the Semantic Scholar API's /snippet/search endpoint, formats the results, and returns a formatted string. The @mcp.tool() decorator handles registration and schema definition.@mcp.tool() async def search_snippets(query: str, limit: int = 10, offset: int = 0) -> str: """ Search for text snippets across academic papers. Args: query: Search query for text snippets limit: Maximum number of results (default: 10, max: 100) offset: Number of results to skip (default: 0) Returns: Text snippets from papers """ params = {"query": query, "limit": min(limit, 100), "offset": offset} result = await make_api_request("snippet/search", params) if result is None: return "Error: Failed to fetch snippets" if "error" in result: return f"Error: {result['error']}" snippets = result.get("data", []) total = result.get("total", 0) if not snippets: return "No snippets found matching your query." formatted_snippets = [] for i, snippet in enumerate(snippets, 1): paper = snippet.get("paper", {}) title = paper.get("title", "Unknown Title") year = paper.get("year", "Unknown") text = snippet.get("text", "No text available") formatted_snippets.append(f"{i}. From: {title} ({year})\nSnippet: {text}") result_text = f"Found {total} total snippets (showing {len(snippets)}):\n\n" result_text += "\n\n".join(formatted_snippets) return result_text