get_chapter_summary
Generate chapter summaries from books to understand key content without reading the full text. Input book ID and chapter number to get structured insights.
Instructions
Get the summary for a specific chapter of a book
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| book_id | Yes | ||
| chapter_number | Yes |
Implementation Reference
- libralm_mcp_server.py:190-200 (handler)Handler function for the 'get_chapter_summary' tool, registered via @mcp.tool() decorator. Fetches the summary for a specific chapter using an API request to the LibraLM service.@mcp.tool() def get_chapter_summary(book_id: str, chapter_number: int) -> str: """Get the summary for a specific chapter of a book""" try: data = _make_api_request(f"/books/{book_id}/chapters/{chapter_number}") return data.get("summary", "") except Exception as e: raise ValueError( f"Error getting chapter {chapter_number} summary for book '{book_id}': {str(e)}" )
- libralm_mcp_server.py:103-128 (helper)Internal helper function that performs authenticated API requests, crucial for the implementation of get_chapter_summary and other tools.def _make_api_request(endpoint: str) -> dict: """Make an authenticated request to the LibraLM API""" # Get API key and base URL from request context or environment api_key = get_api_key() base_url = get_api_base_url() headers = {"x-api-key": api_key, "Content-Type": "application/json"} url = f"{base_url}{endpoint}" response = requests.get(url, headers=headers) if response.status_code == 401: raise ValueError("Invalid API key. Please check your LibraLM API key.") elif response.status_code == 404: raise ValueError(f"Resource not found: {endpoint}") elif response.status_code != 200: raise ValueError( f"API request failed with status {response.status_code}: {response.text}" ) # Handle wrapped response format from Lambda result = response.json() if isinstance(result, dict) and "data" in result: return result["data"] return result