list_books
Browse all available AI-generated book summaries and chapter breakdowns to quickly access key insights from business, self-help, and educational books.
Instructions
List all available books with their basic information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- libralm_mcp_server.py:130-156 (handler)The primary handler for the 'list_books' tool. Decorated with @mcp.tool() for registration. Fetches the list of books from the LibraLM API endpoint '/books', converts each to BookInfo model, sorts by title, and returns the list. Includes debug logging and comprehensive error handling.@mcp.tool() def list_books() -> List[BookInfo]: """List all available books with their basic information""" try: # Debug: Check what API key and URL we're using api_key = get_api_key() api_url = get_api_base_url() print(f"DEBUG: Using API URL: {api_url}") print(f"DEBUG: API key present: {bool(api_key)}, length: {len(api_key) if api_key else 0}") data = _make_api_request("/books") print(f"DEBUG: Received data: {data}") books = [] for book_data in data.get("books", []): books.append(BookInfo(**book_data)) print(f"DEBUG: Returning {len(books)} books") return sorted(books, key=lambda x: x.title) except Exception as e: print(f"ERROR listing books: {str(e)}") import traceback traceback.print_exc() # Raise the error instead of silently returning empty list raise ValueError(f"Error listing books: {str(e)}")
- libralm_mcp_server.py:86-101 (schema)Pydantic model defining the BookInfo schema, used as the return type (List[BookInfo]) for the list_books tool.class BookInfo(BaseModel): """Book information structure""" book_id: str title: str author: Optional[str] = None category: Optional[str] = None subtitle: Optional[str] = None summary: Optional[str] = None length: Optional[str] = None release_date: Optional[str] = None tier: Optional[str] = None has_summary: bool has_chapter_summaries: bool has_table_of_contents: bool
- libralm_mcp_server.py:103-128 (helper)Helper function used by list_books to perform authenticated GET requests to the LibraLM API, handling authentication, errors, and response parsing.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