Skip to main content
Glama
libralm-ai

LibraLM MCP Server

Official
by libralm-ai

list_books

Browse available AI-generated book summaries and chapter breakdowns to discover titles by business, self-help, and educational categories.

Instructions

List all available books with their basic information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'list_books' tool. It fetches the list of books from the LibraLM API endpoint '/books', parses the response into BookInfo models, sorts them by title, and returns the list. Includes error handling and debug logging.
    @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)}")
  • Pydantic BaseModel defining the structure of BookInfo objects returned by the list_books tool, including fields like book_id, title, author, and flags for available content.
    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
  • Helper function used by list_books to make 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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states it lists books with basic information, implying a read-only operation, but doesn't disclose behavioral traits like whether it requires authentication, has rate limits, pagination behavior, or what 'basic information' includes. For a tool with no annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('List all available books') and adds necessary context ('with their basic information'). There is zero waste or redundancy, making it appropriately sized for a simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 0 parameters, 100% schema coverage, and an output schema exists, the description is minimally complete. However, with no annotations and siblings present, it lacks guidance on usage context and behavioral details. The output schema handles return values, but the description could better address when to use this versus alternatives.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so there are no parameters to document. The description doesn't need to add parameter semantics beyond what the schema provides, and it appropriately doesn't mention any parameters. Baseline for 0 parameters is 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List') and resource ('all available books') with the scope of 'basic information'. It distinguishes from siblings like get_book_details or get_book_summary by specifying it returns basic information for all books rather than detailed information for specific books. However, it doesn't explicitly contrast with all siblings (e.g., get_table_of_contents).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling tools. It doesn't mention alternatives like get_book_details for detailed information or get_book_summary for summaries, nor does it specify any prerequisites or contextual constraints for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/libralm-ai/libralm_mcp_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server