restock_book
Add inventory to books by specifying book ID and quantity. This tool manages stock levels for bookstore operations.
Instructions
Add stock to a book.
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": {
"book_id": "<book_id>",
"quantity": "<quantity>"
},
"name": "restock_book"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| book_id | Yes | ||
| quantity | Yes |
Implementation Reference
- src/bookstore_mcp/server.py:103-123 (handler)The handler function for the 'restock_book' tool. It adds the specified quantity to the book's stock if the book exists and quantity > 0, then saves the updated books list. Returns success or error message.
@mcp.tool() def restock_book(book_id: int, quantity: int): """Add stock to a book.""" if quantity <= 0: return {"success": False, "error": "Quantity must be > 0"} books = load_books() book = next((b for b in books if b["id"] == book_id), None) if not book: return {"success": False, "error": f"Book {book_id} not found"} book["count"] += quantity if save_books(books): return { "success": True, "message": f"Restocked {quantity} of '{book['title']}'", } else: return {"success": False, "error": "Save failed"}