图书馆目录搜索服务

一个为Wake County公共图书馆提供目录搜索功能的MCP服务器,支持本地和NC Cardinal图书馆的搜索,返回包括标题、作者、格式、出版年份、可用状态等详细信息。

  • by jfposton
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 jfposton/mcp-wcpl-

使用说明

威克县公共图书馆MCP服务器

一种模型上下文协议(MCP)服务器,为威克县公共图书馆目录提供搜索功能。

使用官方MCP Python SDK和uv进行依赖管理,使用Python构建。

特性

  • 搜索威克县公共图书馆目录
  • 搜索当地威克县目录或所有北卡罗来纳州Cardinal图书馆
  • 返回详细信息,包括:
    • 标题
    • 作者
    • 格式(书籍、DVD、有声读物等)
    • 出版年份
    • 可用性状态
    • 直接链接到目录条目
    • 封面图片

先决条件

  • Python 3.12或更高版本
  • 紫外线 -快速Python包管理器

安装uv

# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# Or with pip
pip install uv

安装

# Clone the repository
git clone <repository-url>
cd mcp-wcpl

# Install dependencies
uv sync

用法

使用克劳德桌面

将此添加到您的Claude Desktop配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

视窗: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "wake-county-library": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/mcp-wcpl",
        "run",
        "python",
        "-m",
        "mcp_wcpl"
      ]
    }
  }
}

替换 /absolute/path/to/mcp-wcpl 带有此项目目录的实际路径。

直接运行

您也可以直接运行服务器进行测试:

# Using uv (recommended)
uv run python -m mcp_wcpl

# Or activate the virtual environment first
source .venv/bin/activate  # Unix/macOS
.venv\Scripts\activate     # Windows
python -m mcp_wcpl

可用工具

search_library

搜索威克县公共图书馆目录。

参数:

  • query (字符串,必填):搜索词(书名、作者、关键字等)
  • searchSource (字符串,可选):
    • "local" (默认)-仅搜索威克县目录
    • "all" -搜索所有NC Cardinal库
  • limit (number,可选):返回的最大结果数(默认值:10)

例子:

{
  "query": "Foundation Isaac Asimov",
  "searchSource": "local",
  "limit": 5
}

答复:

返回具有以下结构的搜索结果数组:

[
  {
    "title": "Foundation",
    "author": "Asimov, Isaac",
    "format": "Book",
    "publicationYear": "2004",
    "availability": "Available",
    "url": "https://catalog.wake.gov/Union/Record/...",
    "coverImage": "https://..."
  }
]

发展

测试

运行测试套件:

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run with coverage report
uv run pytest --cov=src/mcp_wcpl --cov-report=html

# Run specific test file
uv run pytest tests/test_server.py

测试套件将包括:

  • HTML解析逻辑的单元测试
  • 使用模拟HTTP请求进行搜索功能的集成测试
  • MCP服务器工具接口测试
  • 错误处理测试

添加依赖关系

# Add a runtime dependency
uv add <package-name>

# Add a development dependency
uv add --dev <package-name>

项目结构

mcp-wcpl/
├── src/
│   └── mcp_wcpl/             # Main package
│       ├── __init__.py       # Package initialization
│       ├── __main__.py       # Entry point
│       └── server.py         # MCP server implementation
├── tests/                    # Test files
│   ├── __init__.py
│   └── test_server.py
├── .venv/                    # Virtual environment (created by uv)
├── pyproject.toml            # Project configuration
├── uv.lock                   # Dependency lock file
├── .gitignore
├── README.md
└── CLAUDE.md                 # Instructions for Claude Code

运作原理

服务器将:

  1. 为威克县图书馆目录构建搜索URL
  2. 使用带有适当HTTP标头的httpx获取搜索结果
  3. 使用BeautifulSoup4解析HTML响应
  4. 从结果中提取相关书籍信息
  5. 通过MCP协议返回结构化JSON数据

许可证

麻省理工学院

链接