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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"isbn": "<isbn>",
"name": "<name>",
"author": "<author>",
"genre": "<genre>",
"year": "<year>"
},
"name": "add_book"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isbn | Yes | ||
| name | Yes | ||
| author | Yes | ||
| genre | Yes | ||
| year | Yes | ||
| owned | No | ||
| read | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
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()