search_books
Search for books by title or ISBN to find and manage reading materials in your personal library database.
Instructions
Searches for books by name or ISBN.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- server.py:116-127 (handler)The `search_books` tool handler implements a database search functionality using SQL 'LIKE' queries on both the book 'name' and 'isbn' columns. It is decorated with `@mcp.tool()` which handles the registration with the MCP framework.
@mcp.tool() def search_books(query: str) -> str: """Searches for books by name or ISBN.""" conn = get_db_connection() cursor = conn.cursor() cursor.execute("SELECT isbn, name FROM books WHERE name LIKE ? OR isbn LIKE ?", (f"%{query}%", f"%{query}%")) results = [dict(row) for row in cursor.fetchall()] conn.close() if results: return json.dumps(results, indent=2) return "No matches found."