add_book
Adds new books to your personal library by entering ISBN, title, author, genre, and publication year. Track ownership and reading status to manage your collection.
Instructions
Adds a new book to the library.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isbn | Yes | ||
| name | Yes | ||
| author | Yes | ||
| genre | Yes | ||
| year | Yes | ||
| owned | No | ||
| read | No |
Implementation Reference
- server.py:68-84 (handler)The handler function for the `add_book` tool, which inserts a new book record into the SQLite database.
@mcp.tool() def add_book(isbn: str, name: str, author: str, genre: str, year: int, owned: bool = False, read: bool = False) -> str: """Adds a new book to the library.""" metadata = json.dumps({"author": author, "genre": genre, "year": year}) conn = get_db_connection() cursor = conn.cursor() try: cursor.execute(""" INSERT INTO books (isbn, name, metadata, owned, read) VALUES (?, ?, ?, ?, ?) """, (isbn, name, metadata, int(owned), int(read))) conn.commit() return f"Success: Book '{name}' added with ISBN {isbn}." except sqlite3.IntegrityError: return f"Error: Book with ISBN {isbn} already exists." finally: conn.close()