Skip to main content
Glama
hongfanmeng

Bookstore MCP Server

by hongfanmeng

get_book_by_id

Retrieve detailed book information by providing a specific book ID to access title, author, and inventory data from the bookstore database.

Instructions

Get book by ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
book_idYes

Implementation Reference

  • The handler function decorated with @mcp.tool() which registers it in FastMCP. Executes the tool logic by loading books and finding the one matching the given book_id.
    @mcp.tool() def get_book_by_id(book_id: int): """Get book by ID.""" books = load_books() return next((book for book in books if book["id"] == book_id), None)
  • Supporting helper function that loads the books data from a JSON file, essential for the get_book_by_id handler.
    def load_books() -> list[dict]: try: with open(DATA_PATH, "r") as f: return json.load(f) except (FileNotFoundError, json.JSONDecodeError): return []
  • The @mcp.tool() decorator registers the get_book_by_id function as an MCP tool.
    @mcp.tool()

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/hongfanmeng/bookstore-mcp'

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