search-books
Search for books in the NeoDB catalog using queries to find specific titles, authors, or topics.
Instructions
Search items in catalog
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query for books |
Implementation Reference
- src/neodb/server.py:155-195 (handler)Handler for the 'search-books' tool: validates input query, performs HTTP GET to NeoDB /api/catalog/search endpoint with query param, processes response, formats books using helper, returns TextContent.elif name == "search-books": """ https://neodb.social/developer/#/catalog/catalog_api_search_item #TBD category and page parameters not supported """ query = arguments.get("query") if not query: raise ValueError("Missing query parameter") async with httpx.AsyncClient() as client: search_data, status_code = await make_neodb_request( client, access_token, f"/api/catalog/search?query={query}&page=1", api_base ) if status_code != 200: error_message = { 400: "Bad request", }.get(status_code, f"Request failed with status code: {status_code}") return [types.TextContent(type="text", text=error_message)] if not search_data: return [types.TextContent(type="text", text=f"Failed to search books")] books = search_data.get("data", []) if not books: return [types.TextContent(type="text", text=f"No books found for query: {query}")] # Format each book into a concise string formatted_books = [format_book(book) for book in books] books_text = f"Search results for '{query}':\n\n" + "\n".join(formatted_books) return [ types.TextContent( type="text", text=books_text ) ]
- src/neodb/server.py:29-42 (registration)Registers the 'search-books' tool with MCP server via list_tools(), including description and inputSchema.types.Tool( name="search-books", description="Search items in catalog", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "Search query for books", } }, "required": ["query"], }, ),
- src/neodb/server.py:91-99 (helper)Utility function to format individual book data into a multi-line string representation, called by search-books handler.def format_book(book: dict) -> str: """Format a book into a concise string.""" return ( f"Title: {book.get('title', 'Unknown')}\n" f"Author: {book.get('author', 'Unknown')}\n" f"Rating: {book.get('rating', 'N/A')}\n" f"Description: {book.get('description', 'No description available')}\n" "---" )