Calibre图书管理员MCP服务器

模型上下文协议(MCP)服务器,通过xmcp向Claude显示Calibre目录。
需求
- Node.js:
v24.13.0(如果使用,则自动管理nvm use). - pnpm:版本
10.28.0或更新。 - Calibre CLI工具:
calibredb和ebook-convert必须安装在PATH上。 - 环境变量:
- CALIBRE_LIBRARY_PATH –Calibre库目录的绝对路径。 - CALIBRE_DB_COMMAND –位置 calibredb 可执行(例如。, /opt/homebrew/bin/calibredb). - FAVORITE_SEARCH_ENGINE_URL –服务器提供外部图书查找时使用的基本URL(默认为DuckDuckGo: https://duckduckgo.com/?q=).
设置
- 克隆并进入仓库:
git clone https://github.com/chepetime/calibre-librarian-mcp.git
cd calibre-librarian-mcp- 使用pnpm安装依赖项:
pnpm install- 复制示例环境文件并填写路径:
cp .env.example .env更新变量,以便服务器可以访问您的Calibre库。
环境变量仅用于本地开发。对于Claude Desktop,您需要在Claude Desktop设置中配置服务器。
本地开发工作流程
在本地迭代时使用这些脚本:
pnpm run dev–通过stdio监视文件并为MCP服务器提供服务。pnpm run lint–类型检查和lints项目。pnpm test–运行一次完整的单元测试套件。pnpm test:watch–每当源文件发生更改时,都会重新运行测试。
为Claude桌面构建(无Docker)
当您希望Claude Desktop(或任何MCP客户端)直接运行编译后的服务器时,请遵循以下流程:
- 这样构建项目
dist/stdio.js存在:
pnpm run build- (可选)在本地运行内置输出以进行快速烟雾测试:
pnpm start # equivalent to: node dist/stdio.js- 通过编辑配置Claude Desktop
~/Library/Application Support/Claude/claude_desktop_config.json(或通过应用内UI)。集command到node,包括绝对路径dist/stdio.js作为第一args输入并提供所需的环境变量:
{
"globalShortcut": "",
"mcpServers": {
"calibre-librarian": {
"command": "node",
"args": ["/Users/you/path/to/calibre-librarian-mcp/dist/stdio.js"],
"env": {
"CALIBRE_LIBRARY_PATH": "/Calibre",
"CALIBRE_DB_COMMAND": "/opt/homebrew/bin/calibredb",
"FAVORITE_SEARCH_ENGINE_URL": "https://duckduckgo.com/?q="
}
}
},
"preferences": {
"quickEntryShortcut": "off",
"menuBarEnabled": false
}
}Claude Desktop重新加载后,它将列出 优秀图书管理员 每当启用MCP的对话开始时,作为可用的MCP服务器。
Docker部署
当您喜欢隔离环境时,请在预装了Calibre的容器中运行服务器。
快速开始
# Build the image
docker build -t calibre-librarian-mcp .
# Run with your Calibre library mounted
docker run -it \
-v /path/to/your/calibre/library:/library:ro \
-e CALIBRE_LIBRARY_PATH=/library \
calibre-librarian-mcpDocker Compose
- 复制和自定义
docker-compose.yml.
- 设置库路径并启动堆栈:
export CALIBRE_LIBRARY_PATH=/path/to/your/calibre/library
docker compose up --buildClaude桌面与Docker
要让Claude Desktop直接运行容器,请将其指向 docker run:
{
"mcpServers": {
"calibre-librarian": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/your/calibre/library:/library:ro",
"-e",
"CALIBRE_LIBRARY_PATH=/library",
"calibre-librarian-mcp"
]
}
}
}注: 移除 :ro 从卷装载并添加 -e CALIBRE_ENABLE_WRITE_OPERATIONS=true 以启用写入操作。
工具目录和示例
安装MCP CLI
以下示例使用 mcp CLI由Anthropic发布。使用以下任何选项安装(或运行)它:
- 全局安装(如果您经常调用MCP工具,建议使用):
npm install -g @anthropic-ai/mcp-cli
# now `mcp --help` should work- 无需全局安装即可一次性执行:
npx @anthropic-ai/mcp-cli --help
# or
pnpm dlx @anthropic-ai/mcp-cli --helpCLI使用情况
所有工具都可以从MCP检查器或CLI调用:
mcp call calibre-librarian ''提示(例如。, merge_duplicates, library_cleanup, search_library)使用伴随命令:
mcp prompt calibre-librarian library_cleanup '{"focus":"missing covers"}'交换 library_cleanup 对于下面列出的任何提示,请进行替换 calibre-librarian 使用您在中配置的服务器名称 mcp.json.
库概述和元数据
| 工具 | 示例 |
|---|---|
list_sample_books | mcp call calibre-librarian list_sample_books '{"limit":5}' |
get_book_details | mcp call calibre-librarian get_book_details '{"bookId":42}' |
get_library_stats | mcp call calibre-librarian get_library_stats '{}' |
get_all_tags | mcp call calibre-librarian get_all_tags '{"sortBy":"count","minCount":5}' |
get_custom_columns | mcp call calibre-librarian get_custom_columns '{"includeDisplay":true}' |
搜索与发现
| 工具 | 示例 |
|---|---|
search_books | mcp call calibre-librarian search_books '{"query":"author:Sanderson and tag:fantasy","limit":10}' |
search_books_by_title | mcp call calibre-librarian search_books_by_title '{"title":"stormlight","exact":false}' |
search_authors_by_name | mcp call calibre-librarian search_authors_by_name '{"name":"ng","sortBy":"count"}' |
get_books_by_author | mcp call calibre-librarian get_books_by_author '{"author":"Robin Hobb","sortBy":"series","ascending":true}' |
get_books_by_author_id | mcp call calibre-librarian get_books_by_author_id '{"authorId":17}' |
get_books_by_series | mcp call calibre-librarian get_books_by_series '{"series":"The Expanse","exact":true}' |
get_books_by_tag | mcp call calibre-librarian get_books_by_tag '{"tag":"cozy mystery","limit":25}' |
search_books_by_tag_pattern | mcp call calibre-librarian search_books_by_tag_pattern '{"pattern":"*punk","limit":10}' |
全文和内容访问
| 工具 | 示例 |
|---|---|
full_text_search | mcp call calibre-librarian full_text_search '{"query":"\"winter is coming\"","matchAll":false}' |
search_book_content | mcp call calibre-librarian search_book_content '{"bookId":12,"query":"quantum","contextChars":120}' |
fetch_excerpt | mcp call calibre-librarian fetch_excerpt '{"bookId":8,"maxChars":1500}' |
清理和复制工作台
| 工具 | 示例 |
|---|---|
find_duplicates | mcp call calibre-librarian find_duplicates '{"mode":"author_title","threshold":0.85}' |
compare_books | mcp call calibre-librarian compare_books '{"bookIds":[101,205],"fields":["title","series","formats"]}' |
quality_report | mcp call calibre-librarian quality_report '{"checks":["missing_cover","missing_tags"],"limit":20}' |
merge_duplicates 提示 | mcp prompt calibre-librarian merge_duplicates '{"bookIds":[101,205]}' |
library_cleanup 提示 | mcp prompt calibre-librarian library_cleanup '{"focus":"missing covers"}' |
search_library 提示 | mcp prompt calibre-librarian search_library '{"query":"hopepunk","searchType":"tag"}' |
智能维护食谱
| 工具 | 示例 |
|---|---|
normalize_author_sort | mcp call calibre-librarian normalize_author_sort '{"preview":true,"limit":25}' |
bulk_retag | mcp call calibre-librarian bulk_retag '{"query":"author:Sanderson","action":"add","tags":"cosmere","preview":true}' |
library_maintenance | mcp call calibre-librarian library_maintenance '{"operation":"check"}' |
missing_book_scout | mcp call calibre-librarian missing_book_scout '{"readingList":"Dune\n1984\nThe Hobbit","searchEngine":"annas_archive"}' |
元数据编辑和自定义列
需要 CALIBRE_ENABLE_WRITE_OPERATIONS=true| 工具 | 示例 |
|---|---|
set_custom_column | mcp call calibre-librarian set_custom_column '{"bookId":42,"column":"#reading_status","value":"Started"}' |
set_metadata | mcp call calibre-librarian set_metadata '{"bookId":42,"title":"The Final Empire (Revised)","tags":["cosmere","favorite"]}' |
设置和配置工具
| 工具 | 示例 |
|---|---|
generate_claude_config | mcp call calibre-librarian generate_claude_config '{"enableWrites":false}' |
环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
CALIBRE_LIBRARY_PATH | 是 | -- | Calibre库目录的绝对路径 |
CALIBRE_DB_COMMAND | 没有 | calibredb | 通往 calibredb 可执行文件 |
CALIBRE_COMMAND_TIMEOUT_MS | 没有 | 15000 | calibredb命令超时(毫秒) |
CALIBRE_ENABLE_WRITE_OPERATIONS | 没有 | false | 启用元数据编辑工具(set_metadata等等) |
FAVORITE_SEARCH_ENGINE_URL | 没有 | https://duckduckgo.com/?q= | 外部图书搜索链接的基本URL |
MCP_SERVER_NAME | 没有 | Calibre Librarian MCP | MCP客户端中显示的服务器名称 |
资源
服务器公开这些MCP资源:
| URI | 描述 |
|---|---|
calibre://library/info | 库配置和统计 |
calibre://library/custom-columns | 自定义列定义 |
calibre://docs/inspector-guide | MCP检查员验证指南 |
故障排除
“calibredb:找不到命令”
服务器找不到Calibre CLI工具。解决:
- macOS(自制):
brew install calibre或设置CALIBRE_DB_COMMAND=/Applications/calibre.app/Contents/MacOS/calibredb - macOS(应用程序):
CALIBRE_DB_COMMAND=/Applications/calibre.app/Contents/MacOS/calibredb - 视窗:
CALIBRE_DB_COMMAND=C:\Program Files\Calibre2\calibredb.exe - Linux:通过包管理器安装Calibre,通常会添加
calibredb前往PATH
“库路径不存在”
验证您的 CALIBRE_LIBRARY_PATH:
# Check the path contains metadata.db
ls "$CALIBRE_LIBRARY_PATH/metadata.db"“写入操作已禁用”
编写工具(set_metadata, set_custom_column, bulk_retag 随着 preview:false等等)要求:
CALIBRE_ENABLE_WRITE_OPERATIONS=true将此添加到您的 .env 文件或Claude桌面配置。
“命令超时”
对于大型库,请增加超时时间:
CALIBRE_COMMAND_TIMEOUT_MS=60000 # 60 seconds“全文搜索不返回结果”
必须启用Calibre FTS:
- 打开口径
- 首选 偏好→ 搜索
- 启用 全文搜索
- 点击 重新索引所有书籍
服务器未出现在Claude Desktop中
- 验证配置文件路径:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 窗户: %APPDATA%\Claude\claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json
- 检查JSON语法是否有效
- 完全重新启动克劳德桌面
- 检查Claude Desktop日志是否有错误
MCP检验员测试
使用内置验证指南:
# Start dev server
npm run dev
# In another terminal, run inspector
npx @anthropic/mcp-inspector或者使用 generate_claude_config 工具来获取您的配置。
许可证
麻省理工学院
