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
| Name | Required | Description | Default |
|---|---|---|---|
| book_id | Yes |
Implementation Reference
- src/bookstore_mcp/server.py:33-37 (handler)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)
- src/bookstore_mcp/server.py:9-14 (helper)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 []
- src/bookstore_mcp/server.py:33-33 (registration)The @mcp.tool() decorator registers the get_book_by_id function as an MCP tool.@mcp.tool()