uysalserkan/books-mcp
If you are the rightful owner of books-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A book search application that provides access to the OpenLibrary API through both FastAPI and MCP (Model Context Protocol) servers.
search_books
Search for books using OpenLibrary API.
Books MCP
A book search application that provides access to the OpenLibrary API through both FastAPI and MCP (Model Context Protocol) servers.
๐ Features
- Book Search: Search for books using the OpenLibrary API
- Dual Server Support: Available as both FastAPI web server and MCP server
- Data Validation: Robust Pydantic models with proper validation
- Error Handling: Graceful handling of incomplete API responses
- Comprehensive Logging: Detailed logging for monitoring and debugging
- Code Quality: Pre-commit hooks for maintaining code standards
๐ฆ Installation
Prerequisites
- Python 3.11+
- Poetry (recommended) or pip
Using Poetry (Recommended)
# Clone the repository
git clone <repository-url>
cd books_mcp
# Install dependencies
poetry install
# Install pre-commit hooks
poetry run pre-commit install
# Activate virtual environment
poetry shell
Using pip
# Clone the repository
git clone <repository-url>
cd books_mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
๐ ๏ธ Usage
FastAPI Server
Start the FastAPI web server:
python -m books_mcp.fastapi_server
The server will be available at http://localhost:8000
API Endpoints
GET /search?query=<search_term>
- Search for booksGET /health
- Health check endpointGET /
- API informationGET /docs
- Interactive API documentation
Example:
curl "http://localhost:8000/search?query=python+programming"
MCP Server
The MCP server provides tool-based access for AI assistants:
python -m books_mcp.mcp_server
Or use the installed command:
books-mcp
๐ค Using with Claude Desktop
This MCP server can be easily integrated with Claude Desktop to provide book search capabilities directly in your conversations with Claude.
๐ Prerequisites
- Claude Desktop application installed
- This books_mcp project installed and working
- Poetry or Python environment set up
โ๏ธ Setup Instructions
1. Locate Claude Desktop Config
Find your Claude Desktop configuration file:
macOS:
~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
Linux:
~/.config/Claude/claude_desktop_config.json
2. Add Books MCP Server
Edit the claude_desktop_config.json
file and add the books-mcp server:
{
"mcpServers": {
"books-search": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/uysalserkan/books-mcp",
"books-mcp"
]
},
...
}
}
3. Restart Claude Desktop
Close and restart Claude Desktop for the changes to take effect.
๐ฏ Using the Book Search Tool
Once configured, you can use the book search functionality in Claude Desktop:
Example Conversations:
You: "Can you help me find books about Python programming?"
Claude: I'll search for Python programming books for you.
[Claude uses the search_books tool]
Claude: I found several Python programming books:
-
"Learning Python" by Mark Lutz (2013)
- 5 editions available
- Language: English
-
"Python Crash Course" by Eric Matthes (2019)
- 3 editions available
- Language: English
[...more results...]
Other Example Queries:
- "Find books by J.R.R. Tolkien"
- "Search for books about machine learning"
- "Look up George Orwell's 1984"
- "Find cookbooks published after 2020"
๐ง Tool Details
The MCP server provides one tool:
search_books(query: str)
- Purpose: Search for books using OpenLibrary API
- Input: Search query string
- Output: Structured book data including titles, authors, publication years, and more
- Examples:
"python programming"
"tolkien lord of the rings"
"george orwell 1984"
โ Verification
After setup, you should see:
- In Claude Desktop: The books-mcp server listed in available tools
- In Conversations: Ability to ask Claude to search for books
- In Logs: MCP server startup messages when Claude Desktop starts
The integration allows Claude to seamlessly search for books and provide detailed information about authors, publication years, editions, and more, making it a powerful research and discovery tool!
๐ง Development
Pre-commit Hooks
This project uses pre-commit hooks to ensure code quality and consistency. The following tools are configured:
๐ก๏ธ Code Quality Tools
- Black: Code formatting (line length: 88)
- isort: Import sorting with black compatibility
- Ruff: Fast Python linter (replaces flake8)
- mypy: Static type checking
- Bandit: Security vulnerability scanner
๐ General Checks
- Trailing whitespace: Automatically removes trailing spaces
- End of file: Ensures files end with newline
- YAML/TOML validation: Validates configuration files
- Large files: Prevents committing large files
- Merge conflicts: Detects merge conflict markers
- Debug statements: Finds debug statements in code
๐ Running Pre-commit
# Install hooks (run once)
poetry run pre-commit install
# Run on all files
poetry run pre-commit run --all-files
# Run on specific files
poetry run pre-commit run --files books_mcp/models.py
# Skip hooks for a commit (not recommended)
git commit -m "message" --no-verify
โ๏ธ Tool Configuration
All tools are configured in pyproject.toml
:
[tool.black]
line-length = 88
target-version = ['py311']
[tool.isort]
profile = "black"
line_length = 88
[tool.ruff.lint]
select = ["E", "W", "F", "I", "B", "C4", "UP"]
[tool.mypy]
python_version = "3.11"
disallow_untyped_defs = true
๐ API Response Format
{
"num_found": 1234,
"q": "python programming",
"docs": [
{
"author_name": "John Doe",
"edition_count": 5,
"first_publish_year": 2020,
"language": "en",
"title": "Python Programming Guide"
}
]
}
๐๏ธ Project Structure
books_mcp/
โโโ books_mcp/ # Main package directory
โ โโโ __init__.py # Package initialization
โ โโโ fastapi_server.py # FastAPI web server
โ โโโ mcp_server.py # MCP server implementation
โ โโโ models.py # Pydantic data models
โ โโโ providers.py # OpenLibrary API provider
โโโ .pre-commit-config.yaml # Pre-commit configuration
โโโ claude_desktop_config.json # Sample Claude Desktop configuration
โโโ pyproject.toml # Project configuration
โโโ poetry.lock # Dependency lock file
โโโ README.md # This file
โโโ dist/ # Built packages
๐ง Dependencies
- FastAPI: Web framework for building APIs
- FastMCP: MCP server implementation
- Pydantic: Data validation and settings management
- Uvicorn: ASGI server for FastAPI
- HTTPX: Async HTTP client for API calls
- Requests: HTTP library for synchronous requests
Development Dependencies
- pre-commit: Git hooks for code quality
- black: Code formatter
- isort: Import sorter
- ruff: Fast Python linter
- mypy: Static type checker
- bandit: Security linter
๐ Data Models
BookDetails
Represents individual book information with optional fields to handle incomplete API responses:
author_name
: Author's nameedition_count
: Number of available editionsfirst_publish_year
: Year of first publicationlanguage
: Book language(s)title
: Book title
OpenLibrary
Represents the complete API response:
num_found
: Total number of books foundq
: Search querydocs
: List of book details
๐ Logging
The application includes comprehensive logging to help with monitoring and debugging:
๐ฏ Key Logging Features:
- API Calls: Track OpenLibrary API requests, responses, and timing
- Data Validation: Monitor model validation, data cleaning, and incomplete records
- Server Activity: Log server startup, endpoint access, and request processing
- Error Handling: Detailed error logging with context
๐ Log Levels:
- INFO: General application flow and important events
- DEBUG: Detailed validation steps and data processing
- WARNING: Non-critical issues (empty queries, missing fields)
- ERROR: Failures and exceptions with full context
๐ง Log Format:
2025-07-15 16:57:40,733 - books_mcp.providers - INFO - ๐ Starting book search for query: 'python'
2025-07-15 16:57:40,734 - books_mcp.models - INFO - โ ๏ธ 1/3 books have missing critical fields
๐ Example Log Messages:
๐ง OpenLibraryProvider initialized with base_url: https://openlibrary.org
๐ Starting book search for query: 'python programming'
๐ก API Response: 200 | Content-Length: 12345
โ
Search completed: 1234 total books found, 20 returned in response
๐ฏ Successfully processed 20 book records
๐ MCP tool called: search_books with query='python'
๐ GET /search - Query: {'query': 'python'}
๐ Response: 200 | Time: 0.523s
๐งช Testing
Run a quick test to verify the installation:
# Test FastAPI server
python -c "from books_mcp.providers import OpenLibraryProvider; print('โ
OpenLibrary provider works!')"
# Test models
python -c "from books_mcp.models import BookDetails, OpenLibrary; print('โ
Models imported successfully!')"
# Test pre-commit hooks
poetry run pre-commit run --all-files
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Ensure pre-commit hooks pass:
poetry run pre-commit run --all-files
- Add tests if applicable
- Submit a pull request
Code Quality Standards
- Type hints: All functions must have proper type annotations
- Documentation: Use docstrings for all public functions and classes
- Error handling: Use proper exception chaining with
raise ... from e
- Security: Avoid binding to all interfaces (
0.0.0.0
) in production - Logging: Include meaningful log messages with appropriate levels
๐ License
This project is open source and available under the .
๐ Related Links
- OpenLibrary API Documentation
- FastAPI Documentation
- MCP Documentation
- Pydantic Documentation
- Pre-commit Documentation
๐ Issues
If you encounter any issues, please create an issue on the GitHub repository with:
- Description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Your environment details