LibraryMCP
A library management MCP server supporting book search, member management, and loan operations through natural language commands.
README
LibraryMCP
Demo project — Intended for local development and learning purposes only. Do not expose it to the public internet or use it to store real data.
LibraryMCP is a FastAPI-based backend server designed to serve as a Model Context Protocol (MCP) tool invocation source for library management. It provides a set of API endpoints to manage books, members, and loans in a library system.
Features
- Books Management: Full CRUD with filtering by title, author, genre, and availability.
- Members Management: Register, list (with filters), view details with loan history and fines, update, and delete with business rules.
- Loans Management: Borrow/return workflows, active loans listing, and fine calculations.
- JWT Authentication: All API endpoints (except
/auth/token) require a Bearer token. Credentials are configurable via environment variables. - SQLite Database: Lightweight storage using SQLAlchemy ORM.
- FastAPI: High-performance web framework for building APIs with Python.
- CORS Enabled: Open CORS for easy local development and browser demos.
- Simple Frontend Demo: Minimal HTML page to add/list books and members.
- Seeding Tool: Built-in script to populate the database with initial sample data.
Project Structure
libraryMCP/
├── backend/ # Application source code
│ ├── routers/ # API route handlers
│ │ ├── auth.py # Authentication endpoint (token issuance)
│ │ ├── books.py # Book-related endpoints
│ │ ├── loans.py # Loan-related endpoints
│ │ └── members.py # Member-related endpoints
│ ├── auth.py # JWT creation, verification, and get_current_user dependency
│ ├── crud.py # CRUD operations
│ ├── database.py # Database configuration and session management
│ ├── main.py # FastAPI application entry point (CORS + routers)
│ ├── models.py # SQLAlchemy database models
│ ├── schemas.py # Pydantic models for request/response validation
│ └── seed.py # Database seeding script
├── frontend/
│ └── index.html # Simple browser demo (books/members)
├── library.db # SQLite database file
├── openapi.json # Generated OpenAPI schema snapshot
├── pyproject.toml # Project dependencies and configuration
├── uv.lock # Lock file for dependencies
└── README.md # Project documentation
Prerequisites
Installation
-
Clone the repository:
git clone <repository-url> cd libraryMCP -
Install dependencies:
uv sync -
Configure credentials in
.env(copy from.envand fill in your values):ADMIN_USERNAME="admin" ADMIN_PASSWORD="your-password" SECRET_KEY="your-secret-key" BACKEND_URL=http://localhost:8000
Usage
Running the Server
Start the FastAPI server using uvicorn:
uv run uvicorn backend.main:app --reload
The API will be available at http://127.0.0.1:8000.
Authentication
All endpoints except POST /auth/token require a JWT Bearer token.
Obtain a token:
curl -X POST http://127.0.0.1:8000/auth/token \
-d "username=admin&password=your-password"
Response:
{ "access_token": "<token>", "token_type": "bearer" }
Use the token:
curl http://127.0.0.1:8000/books/ \
-H "Authorization: Bearer <token>"
Tokens expire after 30 minutes. Configure credentials via ADMIN_USERNAME, ADMIN_PASSWORD, and SECRET_KEY environment variables (or in .env).
API Documentation
Once the server is running, you can access the interactive API documentation:
- Swagger UI: http://127.0.0.1:8000/docs — click Authorize, call
POST /auth/tokenfirst to get a token, then paste it in the Bearer field - ReDoc: http://127.0.0.1:8000/redoc
- OpenAPI JSON: http://127.0.0.1:8000/openapi.json (a snapshot also lives at
openapi.json)
Seeding the Database
To populate the database with sample data, run the seed script:
uv run python backend/seed.py
Simple Frontend Demo (optional)
You can interact with the API using a tiny frontend:
- Open
frontend/index.htmlin your browser - Ensure the backend runs at
http://localhost:8000(CORS is enabled) - Use the UI to add/list books and members
MCP Server
The MCP server exposes the library's functionality as tools that AI assistants (Claude, etc.) can call directly.
Running the MCP Server
The MCP server communicates over stdio. Start the FastAPI backend first, then run:
uv run python mcp_server/main_stdio.py
The server reads BACKEND_URL, ADMIN_USERNAME, and ADMIN_PASSWORD from the environment (or .env). It obtains a JWT token automatically on first use and refreshes it when it expires.
Connecting to Claude Desktop
Add the following to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"library": {
"command": "uv",
"args": ["run", "python", "mcp_server/main_stdio.py"],
"env": {
"PYTHONPATH": "/absolute/path/to/libraryMCP"
}
}
}
}
Available MCP Tools
| Tool | Description |
|---|---|
search_books |
Search books by title, author, or genre |
get_book |
Get full details of a book by ID |
add_book |
Add a new book to the catalog |
update_book |
Update book metadata or copy count |
delete_book |
Remove a book (blocked if active loans exist) |
list_members |
List members with optional filters |
register_member |
Register a new library member |
get_member |
Get member profile, loan history, and fines |
delete_member |
Delete a member (blocked if active loans or unpaid fines) |
borrow_book |
Borrow a book for a member |
return_book |
Return a borrowed book, calculating any overdue fine |
get_loans |
List all active loans for a member |
check_fines |
Get total outstanding fines for a member |
API Endpoints Overview
Authentication
POST /auth/token— Obtain a JWT Bearer token (form fields:username,password).
Books
GET /books/— List books with optional filters.- Query:
title,author,genre,available_only
- Query:
GET /books/{id}— Get a single book by ID.POST /books/— Create a book (initialavailable_copies = total_copies).PUT /books/{id}— Update a book.DELETE /books/{id}— Delete a book (blocked if there are active loans).
Members
GET /members/— List members with filters and pagination.- Query:
skip,limit,name,email,is_active
- Query:
GET /members/{id}— Get member details with loan history, active loans count, and total fines.POST /members/— Register a new member (unique email required).PUT /members/{id}— Update member (cannot deactivate with active loans; email must be unique/valid).DELETE /members/{id}— Delete member (blocked if active loans or unpaid fines).
Loans
POST /loans/borrow— Borrow a book (member must be active; book must have available copies; no duplicate active loan).POST /loans/return— Return a book (increments availability; computes fine if overdue: $0.50/day).GET /loans/{member_id}— List active loans for a member.GET /loans/{member_id}/fines— Calculate and return fine breakdown for a member.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。