mcp-open-library

by 8enSmith
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Referenced in the repository URL for cloning the project.

  • Used for package management and running scripts.

  • Used for code formatting in the development workflow.

MCP开放图书馆

开放图书馆 API 的模型上下文协议 (MCP) 服务器,使 AI 助手能够搜索书籍和作者信息。

概述

该项目实现了一个 MCP 服务器,为 AI 助手提供与开放图书馆交互的工具。它支持按书名搜索图书信息、按姓名搜索作者、使用开放图书馆密钥检索作者详细信息,以及使用开放图书馆 ID (OLID) 获取作者照片的 URL。服务器返回图书和作者信息的结构化数据。

特征

  • 按标题搜索书籍:使用标题搜索书籍并获取详细信息
  • 按姓名搜索作者:使用姓名搜索作者并获取相关详细信息
  • 结构化响应格式:以一致的 JSON 结构返回书籍和作者信息
  • 错误处理:正确的验证和错误报告
  • 测试:使用 Vitest 进行全面测试

安装

# Clone the repository git clone https://github.com/your-username/mcp-open-library.git cd mcp-open-library # Install dependencies npm install # Build the project npm run build

用法

运行服务器

您可以使用 MCP 检查器来测试服务器:

npm run inspector

访问 MCP 检查器,然后测试该工具,例如

与 MCP 客户端一起使用

该服务器实现了模型上下文协议 (MCP),这意味着它可以被任何兼容 MCP 的 AI 助手或客户端(例如Claude Desktop)使用。该服务器公开以下工具:

  • get_book_by_title :按标题搜索书籍信息
  • get_authors_by_name :按姓名搜索作者信息
  • get_author_info :使用开放图书馆作者密钥获取特定作者的详细信息
  • get_author_photo :使用开放图书馆作者 ID (OLID) 获取作者照片的 URL

get_book_by_title输入示例:

{ "title": "The Hobbit" }

get_book_by_title输出示例:

[ { "title": "The Hobbit", "authors": [ "J. R. R. Tolkien" ], "first_publish_year": 1937, "open_library_work_key": "/works/OL45883W", "edition_count": 120, "cover_url": "https://covers.openlibrary.org/b/id/10581294-M.jpg" } ]

get_authors_by_name输入示例:

{ "name": "J.R.R. Tolkien" }

get_authors_by_name输出示例:

[ { "key": "OL26320A", "name": "J. R. R. Tolkien", "alternate_names": [ "John Ronald Reuel Tolkien" ], "birth_date": "3 January 1892", "top_work": "The Hobbit", "work_count": 648 } ]

get_author_info输入示例:

{ "author_key": "OL26320A" }

get_author_info输出示例:

{ "name": "J. R. R. Tolkien", "personal_name": "John Ronald Reuel Tolkien", "birth_date": "3 January 1892", "death_date": "2 September 1973", "bio": "John Ronald Reuel Tolkien (1892-1973) was a major scholar of the English language, specializing in Old and Middle English. He served as the Rawlinson and Bosworth Professor of Anglo-Saxon and later the Merton Professor of English Language and Literature at Oxford University.", "alternate_names": ["John Ronald Reuel Tolkien"], "photos": [6791763], "key": "/authors/OL26320A", "remote_ids": { "viaf": "95218067", "wikidata": "Q892" }, "revision": 43, "last_modified": { "type": "/type/datetime", "value": "2023-02-12T05:50:22.881" } }

get_author_photo输入示例:

{ "olid": "OL26320A" }

get_author_photo输出示例:

https://covers.openlibrary.org/a/olid/OL26320A-L.jpg

您可以在此处看到 Claude Desktop 中使用此工具的示例:

Docker

你可以使用 Docker 测试这个 MCP 服务器。首先运行以下命令:

docker build -t mcp-open-library . docker run -p 8080:8080 mcp-open-library

然后,您可以通过检查器测试 Docker 中运行的服务器,例如

pnpm run inspector http://localhost:8080

发展

项目结构

  • src/index.ts - 主服务器实现
  • src/types.ts - TypeScript 类型定义
  • src/index.test.ts - 测试套件

可用脚本

  • npm run build构建 TypeScript 代码
  • npm run watch - 观察变化并重建
  • npm test运行测试套件
  • npm run format - 使用 Prettier 格式化代码
  • npm run inspector - 在服务器上运行 MCP 检查器

运行测试

npm test

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

致谢

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

开放图书馆 API 的模型上下文协议 (MCP) 服务器,使 AI 助手能够搜索书籍信息。

  1. Overview
    1. Features
      1. Installation
        1. Usage
          1. Running the Server
          2. Using with an MCP Client
          3. Docker
        2. Development
          1. Project Structure
          2. Available Scripts
          3. Running Tests
        3. Contributing
          1. Acknowledgments
            ID: qhkblspta2