Skip to main content

MCP server for searching library catalogs over Z39.50 and retrieving MARC 21 records.

Project description

z3950-mcp

CI License: MIT

An MCP server that lets an AI assistant search library catalogs over Z39.50 and get back structured MARC 21 records.

It talks to catalogs through YAZ (yaz-client) and parses the returned records with pymarc, so you get clean, standards-based bibliographic data — not scraped HTML.

Why

Most Polish (and international) library OPACs — Prolib/Integro, Virtua, Aleph, Alma, Koha — expose a Z39.50 server, the decades-old library-standard search protocol. It returns MARC 21, which is far more reliable to consume than scraping a web catalog. This server puts that behind two simple MCP tools.

Requirements

  • Python ≥ 3.10
  • The YAZ toolkit on your PATH (yaz-client):
    • macOS: brew install yaz
    • Debian/Ubuntu: apt-get install yaz

Install

git clone https://github.com/mpasternak/z3950-mcp
cd z3950-mcp
uv sync

Tools

list_targets()

Lists the preconfigured catalogs — see Public Z39.50 resources below. Each entry's key can be passed to search.

search(target, query, by="any", start=1, count=5, include_raw_marc=false)

Searches a catalog and returns parsed MARC records.

  • target — a registry key above, or an ad-hoc host:port/database string.
  • by — index to search: any, title, author, subject, isbn, issn, publisher, year, lccn, id, or pqf to pass query through as a raw PQF query.
  • count — how many records to return (max 50). Use count=1 with a narrow query (e.g. by ISBN) to fetch a single full record.
  • include_raw_marc — also include the full MARC record as text.

Example result for search("bn", "Pan Tadeusz", by="title", count=1):

{
  "target": "bn-nl.alma.exlibrisgroup.com:1921/48OMNIS_NLOP",
  "query": "@attr 1=4 \"Pan Tadeusz\"",
  "hits": 1406,
  "returned": 1,
  "records": [
    {
      "control_number": "991000041299705066",
      "title": "Pan Tadeusz czyli Ostatni zajazd na Litwie : historia szlachecka...",
      "author": "Mickiewicz, Adam (1798-1855)",
      "year": "1994",
      "isbn": ["8370010938"],
      "publisher": "\"Alfa-Wero\"",
      "language": "pol",
      "subjects": ["Poezja polska -- 19 w."]
    }
  ]
}

Public Z39.50 resources

Catalogs below were verified reachable (2026-07) — they return live MARC 21. Ones with a key are built in (search("bn", …)); the rest you pass as an ad-hoc host:port/database.

Polish

key library connection
bn Biblioteka Narodowa bn-nl.alma.exlibrisgroup.com:1921/48OMNIS_NLOP

The National Library has the broadest Polish holdings. Most other Polish libraries expose Z39.50 only through the KaRo federation and don't publish their host/port openly — to find more:

English / international

key library connection
loc Library of Congress (Voyager) z3950.loc.gov:7090/VOYAGER
loc-lcdb Library of Congress (LCDB) lx2.loc.gov:210/LCDB
nkc Národní knihovna ČR aleph.nkp.cz:9991/NKC
demo Index Data demo (test) z3950.indexdata.com:210/marc

The Library of Congress also serves a MARC-8 database at lx2.loc.gov:210/LCDB_MARC8 (pymarc transcodes it to Unicode). The Index Data server is a tiny demo database, handy for testing this MCP without hitting a real library.

Examples

search("demo", "computer")                           # tiny test database — smoke test
search("bn", "Lem Solaris")                          # Polish National Library
search("loc", "9780262033848", by="isbn")            # Library of Congress, by ISBN
search("nkc", "Kafka", by="author", count=3)         # Czech National Library
search("aleph.nkp.cz:9991/NKC", "Švejk")             # same, as an ad-hoc target

Use with Claude Code / Claude Desktop

Claude Code (CLI)

Register the server with claude mcp add. The -s user scope makes it available in all your projects; drop it for the current project only.

Straight from the public repo (no clone needed):

claude mcp add z3950 -s user -- uvx --from git+https://github.com/mpasternak/z3950-mcp z3950-mcp

From PyPI once released:

claude mcp add z3950 -s user -- uvx z3950-mcp

From a local checkout (for development):

claude mcp add z3950 -s user -- uv run --directory /path/to/z3950-mcp z3950-mcp

Remove it again with claude mcp remove z3950 -s user.

Claude Desktop (JSON config)

Add to claude_desktop_config.json (stdio transport):

{
  "mcpServers": {
    "z3950": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/mpasternak/z3950-mcp", "z3950-mcp"]
    }
  }
}

Adding catalogs

Append a Target(...) to _TARGETS in src/z3950_mcp/targets.py, or just pass an ad-hoc host:port/database to search. Finding a library's Z39.50 coordinates: the IRSpy registry lists many; some (e.g. NUKAT) provide them on request.

Development

uv run pytest              # unit tests (offline)
uv run pytest -m integration   # live tests against BN + LoC (network + yaz)
uv run ruff check .

Releasing

Releases publish to PyPI via Trusted Publishing (OIDC — no API tokens). Publishing a GitHub Release (or pushing a v* tag) triggers .github/workflows/publish.yml, which builds and uploads from the pypi environment. The PyPI project must have a matching trusted publisher (repo mpasternak/z3950-mcp, workflow publish.yml, environment pypi).

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z3950_mcp-0.1.1.tar.gz (81.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

z3950_mcp-0.1.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file z3950_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: z3950_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 81.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for z3950_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 210de77d76349d980eee4c771ec6387c856e1ee509447b965ed86d3121fa05a7
MD5 4d7c2e5c588231ae05adb2c692ee7e36
BLAKE2b-256 3af6c4b5f955242a2d3bd8ae692c43de07a361c7481beb621d6c3c37518a624d

See more details on using hashes here.

Provenance

The following attestation bundles were made for z3950_mcp-0.1.1.tar.gz:

Publisher: publish.yml on mpasternak/z3950-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file z3950_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: z3950_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for z3950_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5e2d7b9cfcc5f066e6df596d09d7c6f60e715258ac6b36da9b41da0835bf116
MD5 b4f32891cc5e0f76946f3f5cf72d9333
BLAKE2b-256 19ea4835bbcf9c17bd91435c976595cf954e5f20fc011348583807a4e0479106

See more details on using hashes here.

Provenance

The following attestation bundles were made for z3950_mcp-0.1.1-py3-none-any.whl:

Publisher: publish.yml on mpasternak/z3950-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page