dnb-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dnb_mcp-0.1.0/.github/workflows/publish.yml +20 -0
- dnb_mcp-0.1.0/.github/workflows/registry.yml +61 -0
- dnb_mcp-0.1.0/.github/workflows/smoke.yml +21 -0
- dnb_mcp-0.1.0/LICENSE +21 -0
- dnb_mcp-0.1.0/PKG-INFO +72 -0
- dnb_mcp-0.1.0/README-de.md +51 -0
- dnb_mcp-0.1.0/README-fa.md +51 -0
- dnb_mcp-0.1.0/README.md +60 -0
- dnb_mcp-0.1.0/pyproject.toml +25 -0
- dnb_mcp-0.1.0/server.json +1 -0
- dnb_mcp-0.1.0/src/dnb_mcp/__init__.py +7 -0
- dnb_mcp-0.1.0/src/dnb_mcp/domain.py +119 -0
- dnb_mcp-0.1.0/src/dnb_mcp/http.py +99 -0
- dnb_mcp-0.1.0/src/dnb_mcp/server.py +145 -0
- dnb_mcp-0.1.0/tests/__init__.py +0 -0
- dnb_mcp-0.1.0/tests/fixtures/by-isbn.xml +202 -0
- dnb_mcp-0.1.0/tests/fixtures/get-record.xml +202 -0
- dnb_mcp-0.1.0/tests/fixtures/search-per-kafka.xml +399 -0
- dnb_mcp-0.1.0/tests/fixtures/search-tit-kafka.xml +399 -0
- dnb_mcp-0.1.0/tests/fixtures/search-woe-kafka.xml +202 -0
- dnb_mcp-0.1.0/tests/smoke_live.py +17 -0
- dnb_mcp-0.1.0/tests/test_domain.py +119 -0
- dnb_mcp-0.1.0/tests/test_live.py +55 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write # required for PyPI trusted publishing (OIDC)
|
|
12
|
+
contents: read
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- run: pip install build
|
|
19
|
+
- run: python -m build
|
|
20
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Publish to MCP Registry
|
|
2
|
+
|
|
3
|
+
# Official MCP Registry (registry.modelcontextprotocol.io) via GitHub OIDC.
|
|
4
|
+
# No secret, no interactive login: the runner's OIDC token proves ownership
|
|
5
|
+
# of the io.github.mohammad-abbasi-sh/* namespace.
|
|
6
|
+
# Refs: https://github.com/modelcontextprotocol/registry
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags: ["v*"]
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
publish:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write # required for OIDC -> MCP Registry
|
|
18
|
+
contents: read
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Sync server.json version to tag
|
|
23
|
+
# Only sync when running on a version tag (v*). On workflow_dispatch
|
|
24
|
+
# (ref = refs/heads/main) keep the version committed in server.json.
|
|
25
|
+
run: |
|
|
26
|
+
VER=""
|
|
27
|
+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
|
28
|
+
TAG="${GITHUB_REF#refs/tags/}"
|
|
29
|
+
VER="${TAG#v}"
|
|
30
|
+
fi
|
|
31
|
+
if [ -n "$VER" ]; then
|
|
32
|
+
python3 - "$VER" << 'EOF'
|
|
33
|
+
import json, sys
|
|
34
|
+
ver = sys.argv[1]
|
|
35
|
+
d = json.load(open('server.json'))
|
|
36
|
+
d['version'] = ver
|
|
37
|
+
for pkg in d.get('packages', []):
|
|
38
|
+
pkg['version'] = ver
|
|
39
|
+
json.dump(d, open('server.json', 'w'), indent=2, ensure_ascii=False)
|
|
40
|
+
print('server.json version ->', ver)
|
|
41
|
+
EOF
|
|
42
|
+
else
|
|
43
|
+
echo "No version tag ($GITHUB_REF); keeping server.json version as-is"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
- name: Install mcp-publisher
|
|
47
|
+
run: |
|
|
48
|
+
curl -sL "https://github.com/modelcontextprotocol/registry/releases/download/v1.8.7/mcp-publisher_linux_amd64.tar.gz" -o /tmp/mcp-publisher.tar.gz
|
|
49
|
+
tar -xzf /tmp/mcp-publisher.tar.gz -C /tmp
|
|
50
|
+
sudo mv /tmp/mcp-publisher /usr/local/bin/mcp-publisher
|
|
51
|
+
mcp-publisher --version
|
|
52
|
+
|
|
53
|
+
- name: Validate server.json
|
|
54
|
+
run: mcp-publisher validate server.json
|
|
55
|
+
|
|
56
|
+
- name: Publish to MCP Registry (OIDC)
|
|
57
|
+
run: |
|
|
58
|
+
mcp-publisher login github-oidc
|
|
59
|
+
mcp-publisher publish server.json
|
|
60
|
+
# A registry outage must never break the release; re-run from Actions if needed.
|
|
61
|
+
continue-on-error: true
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Daily live smoke
|
|
2
|
+
|
|
3
|
+
# One fixed probe per day: catches fingerprint rot / bot-wall changes
|
|
4
|
+
# before users hit them. Fails visibly on 403/timeout.
|
|
5
|
+
on:
|
|
6
|
+
schedule:
|
|
7
|
+
- cron: "0 6 * * *"
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
smoke:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install
|
|
19
|
+
run: pip install -e .
|
|
20
|
+
- name: Smoke probe
|
|
21
|
+
run: python tests/smoke_live.py
|
dnb_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohammad Abbasi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dnb_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dnb-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial read-only MCP server for the Deutsche Nationalbibliothek catalogue (DNB SRU) — books, authors, ISBN
|
|
5
|
+
Author: Mohammad Abbasi
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Requires-Dist: mcp<2
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# dnb-mcp 📚
|
|
14
|
+
|
|
15
|
+
mcp-name: io.github.mohammad-abbasi-sh/dnb-mcp
|
|
16
|
+
|
|
17
|
+
Unofficial **read-only** MCP server for **[services.dnb.de](https://www.dnb.de)** — Deutsche Nationalbibliothek catalogue via its official SRU API: keyword, title and author search, ISBN and DNB-ID lookup. No key, no login. No key, no login.
|
|
18
|
+
|
|
19
|
+
> Built by Mohammad Abbasi as part of the "Germany MCP factory". Not affiliated with services.dnb.de.
|
|
20
|
+
|
|
21
|
+
## For AI agents
|
|
22
|
+
|
|
23
|
+
Add to your MCP client config (stdio):
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"mcpServers": {
|
|
28
|
+
"dnb": {
|
|
29
|
+
"command": "uvx",
|
|
30
|
+
"args": ["dnb-mcp==0.1.0"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or run locally: `python -m dnb_mcp.server` (needs `mcp<2`, `httpx`).
|
|
37
|
+
|
|
38
|
+
## Tools
|
|
39
|
+
|
|
40
|
+
| Tool | Description |
|
|
41
|
+
|------|-------------|
|
|
42
|
+
| `dnb_search_books` | Keyword search across the DNB catalogue — `query`, `limit` 1..50 |
|
|
43
|
+
| `dnb_search_by_title` | Title search — `title`, `limit` 1..50 |
|
|
44
|
+
| `dnb_search_by_author` | Author search — `author` (e.g. "Kafka, Franz"), `limit` 1..50 |
|
|
45
|
+
| `dnb_by_isbn` | Look up one book by ISBN — `isbn` (13 or 10 digits, with or without dashes) |
|
|
46
|
+
| `dnb_get_record` | Full record by DNB identifier — `dnb_id` (e.g. "1306459214") |
|
|
47
|
+
| `dnb_health` | Reachability probe (ok / blocked / error) — one polite request |
|
|
48
|
+
|
|
49
|
+
## Notes
|
|
50
|
+
|
|
51
|
+
- All data comes from the **Deutsche Nationalbibliothek SRU API** (free, no key, no login).
|
|
52
|
+
- Indexes used (from the API's own explain response): `woe` (all terms), `tit` (title), `per` (person/author), `num` (number incl. ISBN), `idn` (DNB identifier).
|
|
53
|
+
- There is **no newspapers-only filter**: the `mat` (material type) index returns 0 for every German value tried (Bücher, Zeitschriften, Zeitung, Zeitungen, Online-Ressource), so no newspapers-only tool is offered; newspapers are still found by the keyword and title searches.
|
|
54
|
+
- Dublin Core recordSchema is unsupported by the API — MARC21-xml only.
|
|
55
|
+
|
|
56
|
+
Tests: 20/20 green (14 offline + 6 live, 2026-11-10).
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python3 -m venv .venv && .venv/bin/pip install "mcp<2" httpx pytest
|
|
62
|
+
.venv/bin/pip install -e .
|
|
63
|
+
.venv/bin/python -m pytest tests/ -q
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
Built by [Mohammad Abbasi](https://github.com/mohammad-abbasi-sh) — [Almanibama](https://almanibama.ir) · [mabbasi.ir](https://mabbasi.ir)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# dnb-mcp 📚
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dnb-mcp
|
|
4
|
+
|
|
5
|
+
Inoffizieller **nur lesender** MCP-Server für **[services.dnb.de](https://www.dnb.de)** — Katalog der Deutschen Nationalbibliothek über die offizielle SRU-API: Stichwort-, Titel- und Autorensuche, ISBN- und DNB-ID-Abfrage. Kein Schlüssel, kein Login. Kein Schlüssel, keine Anmeldung.
|
|
6
|
+
|
|
7
|
+
> Gebaut von Mohammad Abbasi als Teil der "Germany MCP factory". Nicht mit services.dnb.de verbunden.
|
|
8
|
+
|
|
9
|
+
## Für KI-Agenten
|
|
10
|
+
|
|
11
|
+
Zur MCP-Client-Konfiguration hinzufügen (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dnb": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dnb-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Oder lokal starten: `python -m dnb_mcp.server` (benötigt `mcp<2`, `httpx`).
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | Beschreibung |
|
|
29
|
+
|------|-------------|
|
|
30
|
+
| `dnb_search_books` | Stichwortsuche im DNB-Katalog |
|
|
31
|
+
| `dnb_search_by_title` | Titelsuche im DNB-Katalog |
|
|
32
|
+
| `dnb_search_by_author` | Autorensuche im DNB-Katalog |
|
|
33
|
+
| `dnb_by_isbn` | Ein Buch per ISBN nachschlagen |
|
|
34
|
+
| `dnb_get_record` | Vollständiger Datensatz per DNB-ID |
|
|
35
|
+
| `dnb_health` | Erreichbarkeitsprüfung (ok / blocked / error) — eine höfliche Anfrage |
|
|
36
|
+
|
|
37
|
+
## Entwicklung
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python3 -m venv .venv && .venv/bin/pip install "mcp<2" httpx pytest
|
|
41
|
+
.venv/bin/pip install -e .
|
|
42
|
+
.venv/bin/python -m pytest tests/ -q
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Lizenz
|
|
46
|
+
|
|
47
|
+
MIT
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
Built by [Mohammad Abbasi](https://github.com/mohammad-abbasi-sh) — [Almanibama](https://almanibama.ir) · [mabbasi.ir](https://mabbasi.ir)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# dnb-mcp 📚
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dnb-mcp
|
|
4
|
+
|
|
5
|
+
سرور MCP غیررسمی و **فقطخواندنی** برای **[services.dnb.de](https://www.dnb.de)** — کاتالوگ کتابخانه ملی آلمان از طریق API رسمی SRU: جستوجوی کلیدواژه، عنوان و نویسنده، جستوجو با ISBN و شناسهٔ DNB. بدون کلید، بدون ورود. بدون کلید، بدون ورود.
|
|
6
|
+
|
|
7
|
+
> ساختهٔ محمد عباسی، بخشی از «کارخانهٔ MCP آلمان». وابسته به services.dnb.de نیست.
|
|
8
|
+
|
|
9
|
+
## برای ایجنتهای هوش مصنوعی
|
|
10
|
+
|
|
11
|
+
به پیکربندی MCP کلاینت اضافه کنید (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dnb": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dnb-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
یا بهصورت محلی اجرا کنید: `python -m dnb_mcp.server` (نیازمند `mcp<2` و `httpx`).
|
|
25
|
+
|
|
26
|
+
## ابزارها
|
|
27
|
+
|
|
28
|
+
| ابزار | توضیح |
|
|
29
|
+
|------|-------|
|
|
30
|
+
| `dnb_search_books` | جستوجوی کلیدواژه در کاتالوگ DNB |
|
|
31
|
+
| `dnb_search_by_title` | جستوجو در کاتالوگ DNB با عنوان |
|
|
32
|
+
| `dnb_search_by_author` | جستوجو در کاتالوگ DNB با نویسنده |
|
|
33
|
+
| `dnb_by_isbn` | یافتن یک کتاب با ISBN |
|
|
34
|
+
| `dnb_get_record` | رکورد کامل با شناسهٔ DNB |
|
|
35
|
+
| `dnb_health` | بررسی دسترسپذیری (ok / blocked / error) — یک درخواست مؤدبانه |
|
|
36
|
+
|
|
37
|
+
## توسعه
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python3 -m venv .venv && .venv/bin/pip install "mcp<2" httpx pytest
|
|
41
|
+
.venv/bin/pip install -e .
|
|
42
|
+
.venv/bin/python -m pytest tests/ -q
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## لایسنس
|
|
46
|
+
|
|
47
|
+
MIT
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
Built by [Mohammad Abbasi](https://github.com/mohammad-abbasi-sh) — [Almanibama](https://almanibama.ir) · [mabbasi.ir](https://mabbasi.ir)
|
dnb_mcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# dnb-mcp 📚
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dnb-mcp
|
|
4
|
+
|
|
5
|
+
Unofficial **read-only** MCP server for **[services.dnb.de](https://www.dnb.de)** — Deutsche Nationalbibliothek catalogue via its official SRU API: keyword, title and author search, ISBN and DNB-ID lookup. No key, no login. No key, no login.
|
|
6
|
+
|
|
7
|
+
> Built by Mohammad Abbasi as part of the "Germany MCP factory". Not affiliated with services.dnb.de.
|
|
8
|
+
|
|
9
|
+
## For AI agents
|
|
10
|
+
|
|
11
|
+
Add to your MCP client config (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dnb": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dnb-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or run locally: `python -m dnb_mcp.server` (needs `mcp<2`, `httpx`).
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | Description |
|
|
29
|
+
|------|-------------|
|
|
30
|
+
| `dnb_search_books` | Keyword search across the DNB catalogue — `query`, `limit` 1..50 |
|
|
31
|
+
| `dnb_search_by_title` | Title search — `title`, `limit` 1..50 |
|
|
32
|
+
| `dnb_search_by_author` | Author search — `author` (e.g. "Kafka, Franz"), `limit` 1..50 |
|
|
33
|
+
| `dnb_by_isbn` | Look up one book by ISBN — `isbn` (13 or 10 digits, with or without dashes) |
|
|
34
|
+
| `dnb_get_record` | Full record by DNB identifier — `dnb_id` (e.g. "1306459214") |
|
|
35
|
+
| `dnb_health` | Reachability probe (ok / blocked / error) — one polite request |
|
|
36
|
+
|
|
37
|
+
## Notes
|
|
38
|
+
|
|
39
|
+
- All data comes from the **Deutsche Nationalbibliothek SRU API** (free, no key, no login).
|
|
40
|
+
- Indexes used (from the API's own explain response): `woe` (all terms), `tit` (title), `per` (person/author), `num` (number incl. ISBN), `idn` (DNB identifier).
|
|
41
|
+
- There is **no newspapers-only filter**: the `mat` (material type) index returns 0 for every German value tried (Bücher, Zeitschriften, Zeitung, Zeitungen, Online-Ressource), so no newspapers-only tool is offered; newspapers are still found by the keyword and title searches.
|
|
42
|
+
- Dublin Core recordSchema is unsupported by the API — MARC21-xml only.
|
|
43
|
+
|
|
44
|
+
Tests: 20/20 green (14 offline + 6 live, 2026-11-10).
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python3 -m venv .venv && .venv/bin/pip install "mcp<2" httpx pytest
|
|
50
|
+
.venv/bin/pip install -e .
|
|
51
|
+
.venv/bin/python -m pytest tests/ -q
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
Built by [Mohammad Abbasi](https://github.com/mohammad-abbasi-sh) — [Almanibama](https://almanibama.ir) · [mabbasi.ir](https://mabbasi.ir)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dnb-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Unofficial read-only MCP server for the Deutsche Nationalbibliothek catalogue (DNB SRU) — books, authors, ISBN"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"mcp<2",
|
|
14
|
+
"httpx>=0.27",
|
|
15
|
+
]
|
|
16
|
+
authors = [{ name = "Mohammad Abbasi" }]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
dnb-mcp = "dnb_mcp.server:main"
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/dnb_mcp"]
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
markers = ["live: tests that hit the real https://www.dnb.de site"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", "description": "Unofficial read-only MCP server for the Deutsche Nationalbibliothek catalogue (DNB SRU).", "name": "io.github.mohammad-abbasi-sh/dnb-mcp", "packages": [{"identifier": "dnb-mcp", "registryBaseUrl": "https://pypi.org", "registryType": "pypi", "transport": {"type": "stdio"}, "version": "0.1.0"}], "repository": {"source": "github", "url": "https://github.com/mohammad-abbasi-sh/dnb-mcp"}, "title": "DNB — Deutsche Nationalbibliothek catalogue: books, authors & ISBN lookup", "version": "0.1.0", "websiteUrl": "https://github.com/mohammad-abbasi-sh/dnb-mcp"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""dnb_mcp — unofficial read-only MCP server for services.dnb.de.
|
|
2
|
+
|
|
3
|
+
Deutsche Nationalbibliothek catalogue via its official SRU API: keyword, title and author search, ISBN and DNB-ID lookup. No key, no login.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Domain logic: shape DNB SRU (MARC21-xml) responses into compact
|
|
2
|
+
dicts (stdlib only).
|
|
3
|
+
|
|
4
|
+
Data source: the Deutsche Nationalbibliothek SRU API
|
|
5
|
+
(https://services.dnb.de/sru/dnb) — free, no key, no login.
|
|
6
|
+
CQL indexes used (from the API's own explain response, verified
|
|
7
|
+
2026-11-10): woe (all terms), tit (title), per (person/author),
|
|
8
|
+
num (number — incl. ISBN), idn (DNB identifier).
|
|
9
|
+
|
|
10
|
+
NOT offered: a newspapers-only search — the `mat` (material type)
|
|
11
|
+
index returns 0 for every German value tried (Bücher, Zeitschriften,
|
|
12
|
+
Zeitung, Zeitungen, Online-Ressource), so no reliable newspaper
|
|
13
|
+
filter exists; newspapers are still found by the keyword/title
|
|
14
|
+
searches. Dublin Core recordSchema is unsupported ("Unknown schema
|
|
15
|
+
for retrieval") — MARC21-xml only.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import re
|
|
20
|
+
import urllib.parse
|
|
21
|
+
import xml.etree.ElementTree as ET
|
|
22
|
+
|
|
23
|
+
BASE = "https://services.dnb.de/sru/dnb"
|
|
24
|
+
|
|
25
|
+
SRW = "{http://www.loc.gov/zing/srw/}"
|
|
26
|
+
M = "{http://www.loc.gov/MARC21/slim}"
|
|
27
|
+
|
|
28
|
+
_ISBN_RE = re.compile(r"^[\d-]{10,17}[0-9Xx]$")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def validate_limit(limit: int) -> int:
|
|
32
|
+
if not 1 <= limit <= 50:
|
|
33
|
+
raise ValueError(f"limit out of range: {limit} (expected 1..50)")
|
|
34
|
+
return limit
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def validate_isbn(isbn: str) -> str:
|
|
38
|
+
key = (isbn or "").strip().replace(" ", "")
|
|
39
|
+
if not _ISBN_RE.match(key) or not 10 <= len(key.replace("-", "")) <= 13:
|
|
40
|
+
raise ValueError(f"invalid ISBN: {isbn!r} "
|
|
41
|
+
"(expected 10 or 13 digits, dashes allowed)")
|
|
42
|
+
return key
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def validate_dnb_id(dnb_id: str) -> str:
|
|
46
|
+
key = (dnb_id or "").strip()
|
|
47
|
+
if not key.isdigit():
|
|
48
|
+
raise ValueError(f"invalid DNB identifier: {dnb_id!r} "
|
|
49
|
+
"(expected digits, e.g. \"1306459214\")")
|
|
50
|
+
return key
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def search_url(query: str, maximum_records: int = 10) -> str:
|
|
54
|
+
params = {
|
|
55
|
+
"operation": "searchRetrieve",
|
|
56
|
+
"version": "1.1",
|
|
57
|
+
"query": query,
|
|
58
|
+
"recordSchema": "MARC21-xml",
|
|
59
|
+
"maximumRecords": str(maximum_records),
|
|
60
|
+
}
|
|
61
|
+
return BASE + "?" + urllib.parse.urlencode(params)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _subs(record, tag, code):
|
|
65
|
+
return [s.text.strip() for df in record.findall(f"{M}datafield[@tag='{tag}']")
|
|
66
|
+
for s in df.findall(f"{M}subfield[@code='{code}']")
|
|
67
|
+
if (s.text or "").strip()]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _first(record, tag, code):
|
|
71
|
+
vals = _subs(record, tag, code)
|
|
72
|
+
return vals[0] if vals else ""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _compact(record) -> dict:
|
|
76
|
+
title = _first(record, "245", "a")
|
|
77
|
+
subtitle = _first(record, "245", "b")
|
|
78
|
+
if subtitle:
|
|
79
|
+
title = f"{title} : {subtitle}"
|
|
80
|
+
author = _first(record, "100", "a") or _first(record, "110", "a")
|
|
81
|
+
return {
|
|
82
|
+
"dnb_id": (record.findtext(f"{M}controlfield[@tag='001']") or "").strip(),
|
|
83
|
+
"title": title,
|
|
84
|
+
"author": author,
|
|
85
|
+
"contributors": _subs(record, "700", "a")[:3],
|
|
86
|
+
"year": _first(record, "264", "c"),
|
|
87
|
+
"publisher": _first(record, "264", "b"),
|
|
88
|
+
"place": _first(record, "264", "a"),
|
|
89
|
+
"edition": _first(record, "250", "a"),
|
|
90
|
+
"isbn": _first(record, "020", "a"),
|
|
91
|
+
"language": _first(record, "041", "a"),
|
|
92
|
+
"pages": _first(record, "300", "a"),
|
|
93
|
+
"subjects": _subs(record, "653", "a")[:5],
|
|
94
|
+
"url": _first(record, "856", "u"),
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def parse_search(text: str) -> dict:
|
|
99
|
+
"""Parse an SRU searchRetrieve response -> {total_results, items}."""
|
|
100
|
+
try:
|
|
101
|
+
root = ET.fromstring(text)
|
|
102
|
+
except ET.ParseError as e:
|
|
103
|
+
raise ValueError(f"invalid SRU response: {e}") from e
|
|
104
|
+
diag = root.find(f"{SRW}diagnostics")
|
|
105
|
+
if diag is not None:
|
|
106
|
+
details = diag.findtext(".//{http://www.loc.gov/zing/srw/diagnostic/}details") or ""
|
|
107
|
+
msg = diag.findtext(".//{http://www.loc.gov/zing/srw/diagnostic/}message") or ""
|
|
108
|
+
raise ValueError(f"DNB SRU error: {details} ({msg})".strip())
|
|
109
|
+
total = root.findtext(f"{SRW}numberOfRecords")
|
|
110
|
+
try:
|
|
111
|
+
total_n = int(total or "0")
|
|
112
|
+
except ValueError:
|
|
113
|
+
total_n = 0
|
|
114
|
+
items = []
|
|
115
|
+
for rec in root.findall(f"{SRW}records/{SRW}record"):
|
|
116
|
+
data = rec.find(f"{SRW}recordData/{M}record")
|
|
117
|
+
if data is not None:
|
|
118
|
+
items.append(_compact(data))
|
|
119
|
+
return {"total_results": total_n, "items": items}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""HTTP layer for dnb_mcp — plain httpx GETs against services.dnb.de.
|
|
2
|
+
|
|
3
|
+
No key, no login. One retry on 429/5xx; error taxonomy (403/429/other).
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import ssl
|
|
9
|
+
import time
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
|
|
13
|
+
UA = (
|
|
14
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
15
|
+
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
16
|
+
)
|
|
17
|
+
TIMEOUT = 25.0
|
|
18
|
+
PROBE_URL = "https://services.dnb.de/sru/dnb?operation=searchRetrieve&version=1.1&query=woe%3DKafka&recordSchema=MARC21-xml&maximumRecords=1"
|
|
19
|
+
SOURCE = "services.dnb.de"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DnbMcpError(RuntimeError):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _verify():
|
|
27
|
+
"""TLS trust store: the OS bundle when present, else httpx/certifi."""
|
|
28
|
+
for path in (
|
|
29
|
+
"/etc/ssl/certs/ca-certificates.crt",
|
|
30
|
+
ssl.get_default_verify_paths().openssl_cafile,
|
|
31
|
+
):
|
|
32
|
+
if path and os.path.exists(path):
|
|
33
|
+
return ssl.create_default_context(cafile=path)
|
|
34
|
+
return True
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _client() -> httpx.Client:
|
|
38
|
+
# NOTE: we read the proxy URL from the environment but never log it.
|
|
39
|
+
proxy = os.environ.get("https_proxy") or os.environ.get("HTTPS_PROXY")
|
|
40
|
+
return httpx.Client(
|
|
41
|
+
headers={"User-Agent": UA, "Accept": "application/json, application/xml, text/html, */*"},
|
|
42
|
+
timeout=TIMEOUT,
|
|
43
|
+
proxy=proxy or None,
|
|
44
|
+
trust_env=False,
|
|
45
|
+
verify=_verify(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def fetch_text(url: str) -> str:
|
|
50
|
+
"""GET one URL and return its text. One retry on 429/5xx."""
|
|
51
|
+
last_exc: Exception | None = None
|
|
52
|
+
r: httpx.Response | None = None
|
|
53
|
+
for attempt in range(2):
|
|
54
|
+
try:
|
|
55
|
+
with _client() as c:
|
|
56
|
+
r = c.get(url)
|
|
57
|
+
except httpx.HTTPError as e:
|
|
58
|
+
last_exc = e
|
|
59
|
+
if attempt == 0:
|
|
60
|
+
time.sleep(1.0)
|
|
61
|
+
continue
|
|
62
|
+
raise DnbMcpError(f"network error fetching {url}: {e}") from e
|
|
63
|
+
if r.status_code in (429, 500, 502, 503):
|
|
64
|
+
if attempt == 0:
|
|
65
|
+
time.sleep(1.0)
|
|
66
|
+
continue
|
|
67
|
+
break
|
|
68
|
+
assert r is not None # loop always assigns r or raises
|
|
69
|
+
if r.status_code == 403:
|
|
70
|
+
raise DnbMcpError(
|
|
71
|
+
f"{SOURCE} returned HTTP 403 for {url} (bot wall) — try again later"
|
|
72
|
+
)
|
|
73
|
+
if r.status_code == 429:
|
|
74
|
+
raise DnbMcpError(
|
|
75
|
+
f"{SOURCE} rate-limited the request (HTTP 429) — try again later"
|
|
76
|
+
)
|
|
77
|
+
if r.status_code != 200:
|
|
78
|
+
raise DnbMcpError(f"{SOURCE} returned HTTP {r.status_code} for {url}")
|
|
79
|
+
return r.text
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def health_check() -> dict:
|
|
83
|
+
"""One polite probe of the source site.
|
|
84
|
+
|
|
85
|
+
Returns {"status": "ok"|"blocked"|"error", "http_status": int|None,
|
|
86
|
+
"url": ..., "detail": ...}. Used by the `<prefix>_health` tool
|
|
87
|
+
and the daily smoke CI.
|
|
88
|
+
"""
|
|
89
|
+
url = PROBE_URL
|
|
90
|
+
try:
|
|
91
|
+
fetch_text(url)
|
|
92
|
+
except DnbMcpError as e:
|
|
93
|
+
msg = str(e)
|
|
94
|
+
if "403" in msg:
|
|
95
|
+
return {"status": "blocked", "http_status": 403, "url": url, "detail": msg}
|
|
96
|
+
if "429" in msg:
|
|
97
|
+
return {"status": "blocked", "http_status": 429, "url": url, "detail": msg}
|
|
98
|
+
return {"status": "error", "http_status": None, "url": url, "detail": msg}
|
|
99
|
+
return {"status": "ok", "http_status": 200, "url": url}
|