dw-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.
- dw_mcp-0.1.0/.github/workflows/publish.yml +20 -0
- dw_mcp-0.1.0/.github/workflows/registry.yml +61 -0
- dw_mcp-0.1.0/.github/workflows/smoke.yml +21 -0
- dw_mcp-0.1.0/LICENSE +21 -0
- dw_mcp-0.1.0/PKG-INFO +72 -0
- dw_mcp-0.1.0/README-de.md +51 -0
- dw_mcp-0.1.0/README-fa.md +51 -0
- dw_mcp-0.1.0/README.md +60 -0
- dw_mcp-0.1.0/pyproject.toml +25 -0
- dw_mcp-0.1.0/server.json +1 -0
- dw_mcp-0.1.0/src/dw_mcp/__init__.py +7 -0
- dw_mcp-0.1.0/src/dw_mcp/domain.py +157 -0
- dw_mcp-0.1.0/src/dw_mcp/http.py +99 -0
- dw_mcp-0.1.0/src/dw_mcp/server.py +163 -0
- dw_mcp-0.1.0/tests/__init__.py +0 -0
- dw_mcp-0.1.0/tests/fixtures/article-en.html +8 -0
- dw_mcp-0.1.0/tests/fixtures/articles-en.xml +243 -0
- dw_mcp-0.1.0/tests/fixtures/news-de.xml +483 -0
- dw_mcp-0.1.0/tests/fixtures/news-en.xml +899 -0
- dw_mcp-0.1.0/tests/fixtures/news-fa-ir.xml +243 -0
- dw_mcp-0.1.0/tests/fixtures/topics-en.xml +123 -0
- dw_mcp-0.1.0/tests/smoke_live.py +17 -0
- dw_mcp-0.1.0/tests/test_domain.py +123 -0
- dw_mcp-0.1.0/tests/test_live.py +64 -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
|
dw_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.
|
dw_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dw-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial read-only MCP server for Deutsche Welle news (dw.com) — headlines, search, articles & topics in 31 languages
|
|
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
|
+
# dw-mcp 📰
|
|
14
|
+
|
|
15
|
+
mcp-name: io.github.mohammad-abbasi-sh/dw-mcp
|
|
16
|
+
|
|
17
|
+
Unofficial **read-only** MCP server for **[dw.com](https://www.dw.com)** — Deutsche Welle news in 31 languages from DW's official sitemaps: latest headlines, keyword search over recent headlines, latest articles, full article text and topic pages. No key, no login. No key, no login.
|
|
18
|
+
|
|
19
|
+
> Built by Mohammad Abbasi as part of the "Germany MCP factory". Not affiliated with dw.com.
|
|
20
|
+
|
|
21
|
+
## For AI agents
|
|
22
|
+
|
|
23
|
+
Add to your MCP client config (stdio):
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"mcpServers": {
|
|
28
|
+
"dw": {
|
|
29
|
+
"command": "uvx",
|
|
30
|
+
"args": ["dw-mcp==0.1.0"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or run locally: `python -m dw_mcp.server` (needs `mcp<2`, `httpx`).
|
|
37
|
+
|
|
38
|
+
## Tools
|
|
39
|
+
|
|
40
|
+
| Tool | Description |
|
|
41
|
+
|------|-------------|
|
|
42
|
+
| `dw_headlines` | Latest DW headlines — `language` (e.g. "en", "de", "fa-ir"), `limit` 1..50 |
|
|
43
|
+
| `dw_search_news` | Keyword search over the latest DW headlines — `query`, `language`, `limit` 1..50 |
|
|
44
|
+
| `dw_latest_articles` | Latest DW articles by publication time — `language`, `limit` 1..50 |
|
|
45
|
+
| `dw_get_article` | Full text of one DW article — `url` (a dw.com article link) |
|
|
46
|
+
| `dw_topics` | DW topic pages matching a word — `query`, `language`, `limit` 1..50 |
|
|
47
|
+
| `dw_health` | Reachability probe (ok / blocked / error) — one polite request |
|
|
48
|
+
|
|
49
|
+
## Notes
|
|
50
|
+
|
|
51
|
+
- All data comes from **DW's official sitemaps** (free, no key, no login).
|
|
52
|
+
- DW has **no working RSS feeds any more** — every `/rss/` path returns 404 (verified 2026-11-10) — and its site search is gone, so headlines come from the news sitemaps and `dw_search_news` filters the latest ~50 headlines (not the full archive).
|
|
53
|
+
- Persian is two editions: `fa-ir` (Iran) and `fa-af` (Afghanistan/Dari); plain `fa` does not exist.
|
|
54
|
+
- Article bodies are extracted from DW's server-rendered pages (JSON-LD headline/date + cleaned `<p>` text); live blogs and video pages may return little or no body text.
|
|
55
|
+
|
|
56
|
+
Tests: 22/22 green (15 offline + 7 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
|
+
# dw-mcp 📰
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dw-mcp
|
|
4
|
+
|
|
5
|
+
Inoffizieller **nur lesender** MCP-Server für **[dw.com](https://www.dw.com)** — Deutsche-Welle-Nachrichten in 31 Sprachen über die offiziellen DW-Sitemaps: neueste Schlagzeilen, Stichwortsuche, neueste Artikel, Volltexte und Themenseiten. Kein Schlüssel, kein Login. Kein Schlüssel, keine Anmeldung.
|
|
6
|
+
|
|
7
|
+
> Gebaut von Mohammad Abbasi als Teil der "Germany MCP factory". Nicht mit dw.com verbunden.
|
|
8
|
+
|
|
9
|
+
## Für KI-Agenten
|
|
10
|
+
|
|
11
|
+
Zur MCP-Client-Konfiguration hinzufügen (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dw": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dw-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Oder lokal starten: `python -m dw_mcp.server` (benötigt `mcp<2`, `httpx`).
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | Beschreibung |
|
|
29
|
+
|------|-------------|
|
|
30
|
+
| `dw_headlines` | Neueste DW-Schlagzeilen in einer Sprache |
|
|
31
|
+
| `dw_search_news` | Neueste DW-Schlagzeilen nach Stichwort suchen |
|
|
32
|
+
| `dw_latest_articles` | Neueste DW-Artikel in einer Sprache |
|
|
33
|
+
| `dw_get_article` | Volltext eines DW-Artikels |
|
|
34
|
+
| `dw_topics` | DW-Themenseiten zu einem Stichwort |
|
|
35
|
+
| `dw_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
|
+
# dw-mcp 📰
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dw-mcp
|
|
4
|
+
|
|
5
|
+
سرور MCP غیررسمی و **فقطخواندنی** برای **[dw.com](https://www.dw.com)** — اخبار دویچهوله به ۳۱ زبان از سایتمپهای رسمی DW: تازهترین تیترها، جستوجوی کلیدواژه، تازهترین مقالهها، متن کامل مقاله و صفحههای موضوعی. بدون کلید، بدون ورود. بدون کلید، بدون ورود.
|
|
6
|
+
|
|
7
|
+
> ساختهٔ محمد عباسی، بخشی از «کارخانهٔ MCP آلمان». وابسته به dw.com نیست.
|
|
8
|
+
|
|
9
|
+
## برای ایجنتهای هوش مصنوعی
|
|
10
|
+
|
|
11
|
+
به پیکربندی MCP کلاینت اضافه کنید (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dw": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dw-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
یا بهصورت محلی اجرا کنید: `python -m dw_mcp.server` (نیازمند `mcp<2` و `httpx`).
|
|
25
|
+
|
|
26
|
+
## ابزارها
|
|
27
|
+
|
|
28
|
+
| ابزار | توضیح |
|
|
29
|
+
|------|-------|
|
|
30
|
+
| `dw_headlines` | تازهترین تیترهای DW به یک زبان |
|
|
31
|
+
| `dw_search_news` | جستوجوی تیترهای اخیر DW با کلیدواژه |
|
|
32
|
+
| `dw_latest_articles` | تازهترین مقالههای DW به یک زبان |
|
|
33
|
+
| `dw_get_article` | متن کامل یک مقالهٔ DW |
|
|
34
|
+
| `dw_topics` | صفحههای موضوعی DW برای یک واژه |
|
|
35
|
+
| `dw_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)
|
dw_mcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# dw-mcp 📰
|
|
2
|
+
|
|
3
|
+
mcp-name: io.github.mohammad-abbasi-sh/dw-mcp
|
|
4
|
+
|
|
5
|
+
Unofficial **read-only** MCP server for **[dw.com](https://www.dw.com)** — Deutsche Welle news in 31 languages from DW's official sitemaps: latest headlines, keyword search over recent headlines, latest articles, full article text and topic pages. No key, no login. No key, no login.
|
|
6
|
+
|
|
7
|
+
> Built by Mohammad Abbasi as part of the "Germany MCP factory". Not affiliated with dw.com.
|
|
8
|
+
|
|
9
|
+
## For AI agents
|
|
10
|
+
|
|
11
|
+
Add to your MCP client config (stdio):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"dw": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["dw-mcp==0.1.0"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or run locally: `python -m dw_mcp.server` (needs `mcp<2`, `httpx`).
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | Description |
|
|
29
|
+
|------|-------------|
|
|
30
|
+
| `dw_headlines` | Latest DW headlines — `language` (e.g. "en", "de", "fa-ir"), `limit` 1..50 |
|
|
31
|
+
| `dw_search_news` | Keyword search over the latest DW headlines — `query`, `language`, `limit` 1..50 |
|
|
32
|
+
| `dw_latest_articles` | Latest DW articles by publication time — `language`, `limit` 1..50 |
|
|
33
|
+
| `dw_get_article` | Full text of one DW article — `url` (a dw.com article link) |
|
|
34
|
+
| `dw_topics` | DW topic pages matching a word — `query`, `language`, `limit` 1..50 |
|
|
35
|
+
| `dw_health` | Reachability probe (ok / blocked / error) — one polite request |
|
|
36
|
+
|
|
37
|
+
## Notes
|
|
38
|
+
|
|
39
|
+
- All data comes from **DW's official sitemaps** (free, no key, no login).
|
|
40
|
+
- DW has **no working RSS feeds any more** — every `/rss/` path returns 404 (verified 2026-11-10) — and its site search is gone, so headlines come from the news sitemaps and `dw_search_news` filters the latest ~50 headlines (not the full archive).
|
|
41
|
+
- Persian is two editions: `fa-ir` (Iran) and `fa-af` (Afghanistan/Dari); plain `fa` does not exist.
|
|
42
|
+
- Article bodies are extracted from DW's server-rendered pages (JSON-LD headline/date + cleaned `<p>` text); live blogs and video pages may return little or no body text.
|
|
43
|
+
|
|
44
|
+
Tests: 22/22 green (15 offline + 7 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 = "dw-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Unofficial read-only MCP server for Deutsche Welle news (dw.com) — headlines, search, articles & topics in 31 languages"
|
|
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
|
+
dw-mcp = "dw_mcp.server:main"
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/dw_mcp"]
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
markers = ["live: tests that hit the real https://www.dw.com site"]
|
dw_mcp-0.1.0/server.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", "description": "Unofficial read-only MCP server for Deutsche Welle news — headlines, search & articles.", "name": "io.github.mohammad-abbasi-sh/dw-mcp", "packages": [{"identifier": "dw-mcp", "registryBaseUrl": "https://pypi.org", "registryType": "pypi", "transport": {"type": "stdio"}, "version": "0.1.0"}], "repository": {"source": "github", "url": "https://github.com/mohammad-abbasi-sh/dw-mcp"}, "title": "Deutsche Welle — DW news in 31 languages: headlines, search, articles & topics", "version": "0.1.0", "websiteUrl": "https://github.com/mohammad-abbasi-sh/dw-mcp"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""dw_mcp — unofficial read-only MCP server for dw.com.
|
|
2
|
+
|
|
3
|
+
Deutsche Welle news in 31 languages from DW's official sitemaps: latest headlines, keyword search over recent headlines, latest articles, full article text and topic pages. No key, no login.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Domain logic: shape Deutsche Welle sitemap XML + article HTML into
|
|
2
|
+
compact dicts (stdlib only).
|
|
3
|
+
|
|
4
|
+
Data source: DW's official sitemaps
|
|
5
|
+
(https://www.dw.com/{lang}/news-sitemap.xml,
|
|
6
|
+
/{lang}/article-sitemap.xml, /{lang}/auto-topic-sitemap.xml) and
|
|
7
|
+
dw.com article pages — free, no key, no login.
|
|
8
|
+
|
|
9
|
+
DW has NO working RSS feeds any more (all /rss/ paths 404, verified
|
|
10
|
+
2026-11-10) and its site search is gone too, so `dw_search_news`
|
|
11
|
+
filters the latest news-sitemap headlines by keyword — it searches
|
|
12
|
+
the ~last 50 headlines, not the full archive, and says so.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import html as _html
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import xml.etree.ElementTree as ET
|
|
20
|
+
|
|
21
|
+
BASE = "https://www.dw.com"
|
|
22
|
+
|
|
23
|
+
# Language editions with a news sitemap (from the DW sitemap index,
|
|
24
|
+
# verified 2026-11-10). Note: Persian is "fa-ir" (Iran) and "fa-af"
|
|
25
|
+
# (Afghanistan/Dari) — plain "fa" 400s.
|
|
26
|
+
LANGUAGES = {
|
|
27
|
+
"am", "ar", "bg", "bn", "bs", "de", "el", "en", "es", "fa-af",
|
|
28
|
+
"fa-ir", "fr", "ha", "hi", "hr", "id", "mk", "pl", "ps",
|
|
29
|
+
"pt-002", "pt-br", "ro", "ru", "sq", "sr", "sw", "tr", "uk",
|
|
30
|
+
"ur", "zh", "zh-hant",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_NS = {
|
|
34
|
+
"s": "http://www.sitemaps.org/schemas/sitemap/0.9",
|
|
35
|
+
"n": "http://www.google.com/schemas/sitemap-news/0.9",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_LD_RE = re.compile(r'<script[^>]*application/ld\+json[^>]*>(.*?)</script>', re.S)
|
|
39
|
+
_P_RE = re.compile(r'<p[^>]*>(.*?)</p>', re.S)
|
|
40
|
+
_TAG_RE = re.compile(r'<[^>]+>')
|
|
41
|
+
_SHORT_URL_RE = re.compile(r'^https?://p\.dw\.com/p/\S+?Prefer DW on Google\s*')
|
|
42
|
+
_SHORT_URL_BARE_RE = re.compile(r'^https?://p\.dw\.com/p/\S+\s+')
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def validate_language(language: str) -> str:
|
|
46
|
+
key = (language or "").strip().lower()
|
|
47
|
+
if key not in LANGUAGES:
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"unsupported language: {language!r} "
|
|
50
|
+
f"(use one of: {', '.join(sorted(LANGUAGES))})"
|
|
51
|
+
)
|
|
52
|
+
return key
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def validate_limit(limit: int) -> int:
|
|
56
|
+
if not 1 <= limit <= 50:
|
|
57
|
+
raise ValueError(f"limit out of range: {limit} (expected 1..50)")
|
|
58
|
+
return limit
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def news_sitemap_url(language: str) -> str:
|
|
62
|
+
return f"{BASE}/{language}/news-sitemap.xml"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def article_sitemap_url(language: str) -> str:
|
|
66
|
+
return f"{BASE}/{language}/article-sitemap.xml"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def topic_sitemap_url(language: str) -> str:
|
|
70
|
+
return f"{BASE}/{language}/auto-topic-sitemap.xml"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _parse_xml(text: str, what: str) -> ET.Element:
|
|
74
|
+
try:
|
|
75
|
+
return ET.fromstring(text)
|
|
76
|
+
except ET.ParseError as e:
|
|
77
|
+
raise ValueError(f"invalid {what}: {e}") from e
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def parse_news_sitemap(text: str) -> list[dict]:
|
|
81
|
+
"""[{title, url, published}] — newest first (sitemap order)."""
|
|
82
|
+
root = _parse_xml(text, "news sitemap")
|
|
83
|
+
out = []
|
|
84
|
+
for url in root.findall("s:url", _NS):
|
|
85
|
+
news = url.find("n:news", _NS)
|
|
86
|
+
if news is None:
|
|
87
|
+
continue
|
|
88
|
+
out.append({
|
|
89
|
+
"title": news.findtext("n:title", namespaces=_NS) or "",
|
|
90
|
+
"url": url.findtext("s:loc", namespaces=_NS) or "",
|
|
91
|
+
"published": news.findtext("n:publication_date", namespaces=_NS) or "",
|
|
92
|
+
})
|
|
93
|
+
return out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def parse_article_sitemap(text: str) -> list[dict]:
|
|
97
|
+
"""[{url, lastmod}] — sorted newest first by lastmod."""
|
|
98
|
+
root = _parse_xml(text, "article sitemap")
|
|
99
|
+
out = []
|
|
100
|
+
for url in root.findall("s:url", _NS):
|
|
101
|
+
out.append({
|
|
102
|
+
"url": url.findtext("s:loc", namespaces=_NS) or "",
|
|
103
|
+
"lastmod": url.findtext("s:lastmod", namespaces=_NS) or "",
|
|
104
|
+
})
|
|
105
|
+
out.sort(key=lambda e: e["lastmod"], reverse=True)
|
|
106
|
+
return out
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def parse_topic_sitemap(text: str) -> list[dict]:
|
|
110
|
+
"""[{name, url, lastmod}] — name derived from the topic slug."""
|
|
111
|
+
root = _parse_xml(text, "topic sitemap")
|
|
112
|
+
out = []
|
|
113
|
+
for url in root.findall("s:url", _NS):
|
|
114
|
+
loc = url.findtext("s:loc", namespaces=_NS) or ""
|
|
115
|
+
slug = loc.rstrip("/").split("/")[-2] if "/t-" in loc else ""
|
|
116
|
+
name = slug.replace("-", " ").strip().title() if slug else ""
|
|
117
|
+
out.append({
|
|
118
|
+
"name": name,
|
|
119
|
+
"url": loc,
|
|
120
|
+
"lastmod": url.findtext("s:lastmod", namespaces=_NS) or "",
|
|
121
|
+
})
|
|
122
|
+
out.sort(key=lambda e: e["lastmod"], reverse=True)
|
|
123
|
+
return out
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def parse_article(html_text: str) -> dict:
|
|
127
|
+
"""Extract headline/date (JSON-LD NewsArticle) + cleaned body <p>s.
|
|
128
|
+
|
|
129
|
+
DW article pages are server-rendered: the body is plain <p> tags.
|
|
130
|
+
The first <p> is navigation junk ("Skip to main menu...") and is
|
|
131
|
+
dropped; the intro paragraph carries a leading p.dw.com short URL
|
|
132
|
+
+ "Prefer DW on Google" prefix which is stripped.
|
|
133
|
+
"""
|
|
134
|
+
headline, published = "", ""
|
|
135
|
+
m = _LD_RE.search(html_text)
|
|
136
|
+
if m:
|
|
137
|
+
try:
|
|
138
|
+
ld = json.loads(m.group(1))
|
|
139
|
+
if isinstance(ld, dict) and ld.get("@type") == "NewsArticle":
|
|
140
|
+
headline = ld.get("headline") or ""
|
|
141
|
+
published = ld.get("datePublished") or ""
|
|
142
|
+
except json.JSONDecodeError:
|
|
143
|
+
pass
|
|
144
|
+
paras = []
|
|
145
|
+
for raw in _P_RE.findall(html_text):
|
|
146
|
+
txt = _html.unescape(_TAG_RE.sub("", raw)).replace("\u00a0", " ").strip()
|
|
147
|
+
if not txt:
|
|
148
|
+
continue
|
|
149
|
+
if txt.startswith("Skip to main menu"):
|
|
150
|
+
continue
|
|
151
|
+
txt = _SHORT_URL_RE.sub("", txt)
|
|
152
|
+
txt = _SHORT_URL_BARE_RE.sub("", txt)
|
|
153
|
+
txt = txt.strip()
|
|
154
|
+
if txt:
|
|
155
|
+
paras.append(txt)
|
|
156
|
+
body = "\n\n".join(paras)
|
|
157
|
+
return {"headline": headline, "published": published, "body": body}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""HTTP layer for dw_mcp — plain httpx GETs against dw.com.
|
|
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://www.dw.com/en/news-sitemap.xml"
|
|
19
|
+
SOURCE = "dw.com"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DwMcpError(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 DwMcpError(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 DwMcpError(
|
|
71
|
+
f"{SOURCE} returned HTTP 403 for {url} (bot wall) — try again later"
|
|
72
|
+
)
|
|
73
|
+
if r.status_code == 429:
|
|
74
|
+
raise DwMcpError(
|
|
75
|
+
f"{SOURCE} rate-limited the request (HTTP 429) — try again later"
|
|
76
|
+
)
|
|
77
|
+
if r.status_code != 200:
|
|
78
|
+
raise DwMcpError(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 DwMcpError 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}
|