Skip to main content
Glama
libralm-ai

LibraLM MCP Server

Official
by libralm-ai

get_table_of_contents

Retrieve structured chapter outlines and descriptions for books to quickly understand content organization and key topics.

Instructions

Get the table of contents for a book with chapter descriptions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
book_idYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the core logic to fetch the table of contents via API request for the given book_id.
    @mcp.tool()
    def get_table_of_contents(book_id: str) -> str:
        """Get the table of contents for a book with chapter descriptions"""
        try:
            data = _make_api_request(f"/books/{book_id}/table_of_contents")
            return data.get("table_of_contents", "")
        except Exception as e:
            raise ValueError(
                f"Error getting table of contents for book '{book_id}': {str(e)}"
            )
  • Helper function used by the tool to perform authenticated API requests to the LibraLM service.
    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

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