Books API MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Books API MCP Serverlist all books"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Books API MCP Server
A Model Context Protocol (MCP) server that exposes book management tools for AI assistants. This server provides a bridge between AI applications and a .NET Books API, enabling seamless book collection management through standardized MCP tool calls.
The .NET Book API backend that this MCP server interacts with is available at: https://github.com/0x1D-1983/book-api.
Features
MCP Protocol Support: Implements Model Context Protocol for tool discovery and execution
RESTful API Integration: Connects to a .NET Books API backend
Comprehensive CRUD Operations: Full Create, Read, Update, and Delete functionality for books
FastAPI Framework: Modern, fast, and easy-to-maintain Python web framework
Type-Safe Models: Uses Pydantic for robust data validation
Error Handling: Comprehensive error handling with clear error messages
Related MCP server: bookstore-mcp-server
Available Tools
The MCP server exposes the following tools:
1. list_books
Retrieve all books from the database.
Parameters:
None
Returns:
Array of book objects with the following fields:
id(integer): Unique book identifiertitle(string): Book titleauthor(string): Book authorisbn(string): International Standard Book NumberpublishedDate(string): Publication date in ISO 8601 formatcreatedAt(string): Record creation timestamp
Example Usage:
result = BookService.list_books()
# Returns: List of all books in the database2. get_book
Retrieve a specific book by its ID.
Parameters:
book_id(integer, required): The unique identifier of the book to retrieve
Returns:
Book object with full details, or error if book not found
Example Usage:
result = BookService.get_book(1)
# Returns: Book with ID 13. create_book
Create a new book in the database.
Parameters:
book_data(object, required): Book information object containing:id(integer, optional): Unique identifier for the booktitle(string, required): Title of the bookauthor(string, required): Author of the bookisbn(string, optional): ISBN of the bookpublishedDate(string, optional): Publication date in ISO 8601 UTC format (must end with 'Z', e.g.,2024-04-11T00:00:00Z)
Returns:
Created book object with all fields including generated
createdAttimestamp
Example Usage:
book_data = {
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"isbn": "978-0743273565",
"publishedDate": "1925-04-10T00:00:00Z"
}
result = BookService.create_book(book_data)Important: The publishedDate field must be in ISO 8601 UTC format ending with 'Z' to ensure PostgreSQL compatibility.
4. update_book
Update an existing book's information.
Parameters:
book_id(integer, required): The unique identifier of the book to updatebook_data(object, required): Updated book information object containing:id(integer): ID of the book (must matchbook_id)title(string, optional): New titleauthor(string, optional): New authorisbn(string, optional): New ISBNpublishedDate(string, optional): New publication date in ISO 8601 UTC format (must end with 'Z')
Returns:
Success message if update was successful, or error if book not found
Example Usage:
book_data = {
"id": 1,
"title": "Updated Title",
"author": "Updated Author",
"isbn": "978-1234567890",
"publishedDate": "2023-01-01T00:00:00Z"
}
result = BookService.update_book(1, book_data)5. delete_book
Delete a book from the database.
Parameters:
book_id(integer, required): The unique identifier of the book to delete
Returns:
Success message if deletion was successful, or error if book not found
Example Usage:
result = BookService.delete_book(1)
# Returns: Success message confirming deletionSetup Instructions
Prerequisites
Python 3.8 or higher
Access to a running Books API instance (default:
http://localhost:5288)Virtual environment (recommended)
Installation
Clone or navigate to the project directory:
cd book-api-mcp-serverCreate and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activateInstall dependencies:
pip install fastapi uvicorn requests pydanticOr if you have a
requirements.txtfile:pip install -r requirements.txtConfigure the Books API URL:
Edit
services.pyand update theBOOKS_API_URLconstant if your Books API is running on a different host/port:BOOKS_API_URL = "http://localhost:5288" # Update as neededRun the server:
python run.pyThe server will start on
http://0.0.0.0:8080by default.You can customize the host and port using environment variables:
export MCP_SERVER_HOST=localhost export MCP_SERVER_PORT=8080 python run.py
Testing the Server
Check server health:
curl http://localhost:8080/healthList available tools:
curl http://localhost:8080/toolsRun the test suite:
python test_tools.py
Configuration
Environment Variables
MCP_SERVER_HOST: Server host address (default:0.0.0.0)MCP_SERVER_PORT: Server port number (default:8080)BOOKS_API_URL: Base URL of the Books API (configured inservices.py, default:http://localhost:5288)
Cursor Integration
To use this MCP server with Cursor, add the following to your ~/.cursor/mcp.json:
{
"mcpServers": {
"books-api": {
"command": "python3",
"args": ["/path/to/book-api-mcp-server/run.py"]
}
}
}Note: Restart Cursor after updating the MCP configuration for changes to take effect.
API Endpoints
The MCP server exposes the following HTTP endpoints:
GET /: Root endpoint with server informationGET /tools: List all available MCP toolsPOST /tool-calls: Execute one or more tool callsGET /health: Health check endpointGET /docs: Interactive API documentation (FastAPI Swagger UI)
Usage Examples
Using Python Client
from services import BookService
import json
# List all books
books = BookService.list_books()
print(json.dumps(books.result, indent=2))
# Get a specific book
book = BookService.get_book(1)
print(json.dumps(book.result, indent=2))
# Create a new book
new_book = {
"title": "1984",
"author": "George Orwell",
"isbn": "978-0451524935",
"publishedDate": "1949-06-08T00:00:00Z"
}
result = BookService.create_book(new_book)
print(json.dumps(result.result, indent=2))
# Update a book
updated_data = {
"id": 1,
"title": "Nineteen Eighty-Four",
"author": "George Orwell"
}
result = BookService.update_book(1, updated_data)
# Delete a book
result = BookService.delete_book(1)Using HTTP API
# List all tools
curl http://localhost:8080/tools
# Call a tool
curl -X POST http://localhost:8080/tool-calls \
-H "Content-Type: application/json" \
-d '{
"tool_calls": [
{
"name": "list_books",
"parameters": {}
}
]
}'Project Structure
book-api-mcp-server/
├── main.py # FastAPI application and server setup
├── routes.py # API route handlers for MCP endpoints
├── tools.py # Tool definitions and schemas
├── services.py # Business logic and Books API integration
├── models.py # Pydantic models for data validation
├── config.py # Configuration settings
├── run.py # Server entry point
├── test_tools.py # Test suite for validating tools
├── requirements.txt # Python dependencies
└── README.md # This fileDate Format Requirements
Important: All date fields (publishedDate) must be provided in ISO 8601 UTC format ending with 'Z'. This is required for PostgreSQL compatibility.
Correct Format:
2024-04-11T00:00:00Z2023-05-11T12:30:45Z
Incorrect Formats (will cause errors):
2024-04-11T00:00:00(missing 'Z')2024-04-11(not full ISO 8601)04/11/2024(not ISO 8601)
Technologies
Python 3.8+: Programming language
FastAPI: Modern web framework for building APIs
Uvicorn: ASGI server for running FastAPI
Pydantic: Data validation using Python type annotations
Requests: HTTP library for making API calls to the Books API
Error Handling
All tools return a ToolCallResult object with the following structure:
{
"result": <data> | None, # Result data if successful
"error": <string> | None # Error message if operation failed
}Common error scenarios:
404 Not Found: Book with specified ID does not exist
400 Bad Request: Invalid input data (e.g., missing required fields, invalid date format)
500 Server Error: Database or API connection issues
Connection Error: Books API is not accessible
Troubleshooting
Server won't start
Check if port 8080 is already in use
Verify Python version (3.8+)
Ensure all dependencies are installed
Tools return connection errors
Verify the Books API is running and accessible
Check the
BOOKS_API_URLinservices.pyTest the Books API directly:
curl http://localhost:5288/books
Date format errors
Ensure all dates end with 'Z' for UTC timezone
Use full ISO 8601 format:
YYYY-MM-DDTHH:MM:SSZ
License
This project is part of a book management system demonstration.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/0x1D-1983/book-api-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server