fix(calendar): TZID Europe/Berlin for timed events/tasks, resolve real resource href on delete/update, fix _report_tasks XML; sync deployed servers (owamail, openwearables, ghostfolio), docs and tests

This commit is contained in:
Stefan Lohmaier committed 2026-10-01 04:29:57 +02:00
1 parent 7c01e7be53
commit 75185ef2ba
41 files changed
+8834 -324

No files matched your search

+53 -14
View File
@@ -12,9 +12,10 @@ Alle Server lesen pro User aus `config.json`.
## Backends pro Dienst
- **Calendar/Contacts (Radicale):** User `mcptest` (htpasswd `/opt/radicale/config/htpasswd`,
bcrypt). Collections `/mcptest/calendar-test/` (VEVENT+VTODO) und `/mcptest/contacts-test/`
(VADDRESSBOOK, Test-Kontakt "Max Mustermann"). `calendar_paths/addressbook_paths[mcptest]=["/mcptest/"]`.
- **Calendar/Contacts (Baikal auf 1blu):** User `mcptest` (Baikal-auth via digesta1).
Collections im calendar-home `/dav.php/calendars/mcptest/`: `calendar-test` (VEVENT+VTODO)
und `calendar-test-second` (VEVENT). Addressbook `/dav.php/addressbooks/mcptest/contacts-test`
(VADDRESSBOOK). `calendar_paths/addressbook_paths[mcptest]=["/dav.php/calendars|addressbooks/mcptest/"]`.
- **Files (oCIS):** kompletter User `mcptest` (angelegt via Graph-API `POST /graph/v1.0/users`
als admin). `ocis_users[mcptest]`. Tests legen `/.mcp-tests` selbst an + raeumen auf.
- **Notes (Joplin):** lokales joplin-cli-Profil `/mnt/ssd/joplin-mcp/profiles/mcptest`
@@ -26,8 +27,9 @@ Alle Server lesen pro User aus `config.json`.
## Credentials
- Klartext-Backup: `/root/.mcptest-creds` (chmod 600).
- Aktiv genutzt: `config.json` (gitignored) — radicale/ocis Passwoerter, joplin Token.
- Klartext-Backup: `/root/.mcptest-creds` (chmod 600). Baikal-mcptest-Passwort zusaetzlich
unter `~/1bluapps/.secrets-mcptest/` (mcptest-baikal.password + .digesta1, chmod 600).
- Aktiv genutzt: `config.json` (gitignored) — baikal/ocis Passwoerter, joplin Token. Radicale-Keys sind entfernt.
- oCIS-Admin (fuer User-Anlage): `/mnt/ssd/ocis/auth.txt`.
## Tests laufen lassen
@@ -38,23 +40,47 @@ Alle Server lesen pro User aus `config.json`.
sudo /opt/mcp-servers/tests/run_tests.sh
```
## Testablauf und Selbstreinigung (Kalender/Kontakte)
- **Smoke (taeglich, read-only):** prueft, dass BEIDE Test-Kalender (calendar-test +
calendar-test-second) in `list_calendars` sichtbar sind. Kein Schreiben.
- **Full CRUD (`test_all.py`, on-demand):** erzeugt Events/Tasks/Kontakte via MCP
(`create_event` mit vollen Feldern inkl. Apple-Reise, `create_task`, `create_contact`),
aendert sie via `update_event`/`update_task`/`update_contact` (alle Felder, beide Kalender)
und **loescht am Ende alles wieder via `delete_event`/`delete_task`/`delete_contact`**
(try/finally je Testmethode). Nach dem Lauf ist der mcptest-Account wieder LEER
(Collections vorhanden, keine Objekte). Nur MCP-Methoden, kein direkter DAV-Zugriff.
## Neue MCP-Tools (Calendar/Contacts)
- `update_event(uid, ...)` — Feld-Overwrite wie `create_event`, auf bestehender UID.
- `update_task(uid, ...)` — wie `create_task` auf bestehender UID.
- `update_contact(uid, ...)` — wie `create_contact` auf bestehender UID.
- `delete_contact(uid)` — loescht Kontakt per UID.
- `create_event`/`update_event` unterstuetzen zusaetzlich `travel_mode`
(walking/driving/transit/biking) und `travel_advisory` (true = Apple berechnet die
Reise-Erinnerung dynamisch aus der Route via `X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC`).
- Bugfix: `_parse`/`_get_contacts` dekodieren jetzt XML-Entities per `html.unescape`
(zuvor brachen `"`-Werte wie `X-TITLE` das vobject-Roundtrip-Parsing).
## Als Dev-Sandbox nutzen
- Direkt gegen die Backends: Radicale `http://127.0.0.1:5232/mcptest/` (User mcptest),
Joplin Data API `http://127.0.0.1:41186` (Token aus config.json), Maildir s.o.
- Direkt gegen die Backends: Baikal `https://baikal.slohmaier.de/dav.php/calendars|addressbooks/mcptest/`
(User mcptest), Joplin Data API `http://127.0.0.1:41186` (Token aus config.json), Maildir s.o.
- Ueber die MCP-Server: mit dem `test`-OAuth-Client verbinden -> trifft automatisch mcptest.
- Testdaten zuruecksetzen: Collections/Notebooks neu seeden (siehe Provisioning unten).
## Provisioning (Recreate)
1. Radicale: `htpasswd -bB /opt/radicale/config/htpasswd mcptest <pw>`; dann MKCALENDAR
`/mcptest/calendar-test/` + extended-MKCOL `/mcptest/contacts-test/`.
1. Baikal (MySQL auf 1blu, `~/1bluapps/mysql-baikal`): principal `principals/mcptest`,
user mit `digesta1`=md5-hex("mcptest:BaikalDAV:<pw>"), zwei Kalender (`calendar-test` VEVENT+VTODO,
`calendar-test-second` VEVENT) + `calendarinstances` (access=1) + `addressbooks` `contacts-test`.
2. oCIS: `POST /graph/v1.0/users` als admin (onPremisesSamAccountName=mcptest, passwordProfile).
3. Joplin: Profil anlegen (`joplin --profile DIR config api.token ...; sync.target 0`),
`api.port=41186` in settings.json, `joplin-cli-mcptest.service` (Kopie von -stefan),
Notebooks/Notizen via Data API seeden.
4. Mail: `tests/testdata/maildir/` (im Repo) — Maildir-Konten mit cur/-Nachrichten.
5. `config.json`: mcptest in radicale_users, ocis_users, joplin_data_api, mail_roots,
5. `config.json`: mcptest in baikal_users, ocis_users, joplin_data_api, mail_roots,
calendar_paths, addressbook_paths.
6. `common.py`: `USER_ALIASES = {"test": "mcptest"}`.
@@ -111,8 +137,21 @@ Runtime-Deps: `pymupdf`, `pytesseract` + System `tesseract-ocr`/`-deu` (s. `requ
Drei Schichten, NUR Smoke laeuft naechtlich:
- **Smoke** (`test_smoke.py`, Marker `smoke`): NIGHTLY via `mcp-tests.timer` (05:00) ->
`run_tests.sh` -> `pytest test_smoke.py`. Pro Connector: Server up + OAuth + tools/list +
EIN read-only Call. Schnell (~0.5s), schreibt keine Testdaten. Faengt Totalausfaelle ab.
`run_tests.sh` -> `pytest test_smoke.py test_public_smoke.py test_search_smoke.py`. Pro Connector: Server up +
OAuth + tools/list + EIN read-only Call. Schnell (~0.5s), schreibt keine Testdaten. Faengt
Totalausfaelle ab.
- **Public-Smoke** (`test_public_smoke.py`, Marker `smoke`): NIGHTLY im selben Lauf. Prueft die
oeffentliche Route (DNS, nginx-vhost, TLS/Cert-SAN, Bearer) fuer alle 9 Server ueber
`https://<name>.mcp.slohmaier.de/mcp`: ohne Token -> 401, mit Token -> initialize (serverInfo)
+ tools/list. Nutzt das nicht-ablaufende Service-Token mit Label `smoketest` (User mcptest)
aus `service_tokens.json`; keine `/token`-Aufrufe, damit das nginx-Rate-Limit `mcp_auth`
(10/min) unberuehrt bleibt. Read-only, kein Datenzugriff.
- **SearXNG-Smoke** (`test_search_smoke.py`, Marker `smoke`): NIGHTLY im selben Lauf.
Prueft die interne SearXNG-Instanz ueber die lokale Host-Route `127.0.0.1:8888`
(`/search?q=...&format=json`, kein Token noetig, Token-Gate nur in nginx). Assert:
HTTP 200 + `results` ist eine Liste. Bewusst kein "nicht leer", da geratelimitete
Engines ein bekannter Degraded-Zustand sind. Ersetzt den frueheren searxng-Eintrag
im Dashboard-service-check (2026-09-17).
- **Edge** (`test_edge.py`, Marker `edge`): ON-DEMAND. Boese/ungewoehnliche Eingaben pro
Connector: Unicode/Emoji-Roundtrips, Sonderzeichen, riesige Limits/Bodies, kaputte
Datumsangaben, **Path-Traversal-Block** (Files). Muss graceful sein, nichts leaken/crashen.
@@ -155,13 +194,13 @@ Frage: verkraften die Connector "viel durchwuehlen" wie der Mail-Vollscan?
den single-threaded Server blockiert. **Fix:** `SEARCH_DEADLINE_S=20` + `SEARCH_MAX_DIRS=400`
+ Truncation-Hinweis ("Begriff praezisieren / 'path' enger"). Worst-Case jetzt ~20s gekappt.
Langfristig besser: oCIS server-seitige Suche (Graph/REPORT) statt Client-Rekursion.
- **Calendar (Radicale):** `get_events` ist server-seitig zeitgefiltert (gut). ABER bei
- **Calendar:** `get_events` ist server-seitig zeitgefiltert (gut). ABER bei
~6000 Test-Events gemessen: `search_events` 6-8s (vobject parst ALLE Events im ~15-Mon-
Fenster client-seitig), `get_events` lieferte **10939 Zeilen** (KEIN Result-Limit -> Token-
Explosion). Real schon 5s bei 29 Kalendern. **Fix:** `_parse` mit `PARSE_DEADLINE_S=12` +
`get_events`/`get_tasks` Output-Cap `MAX_RESULTS=300` + Hinweise; `search_events` Top-30 +
Deadline. Danach get_events 1501 statt 10939 Zeilen.
- **Contacts (Radicale):** `search_contacts` parst ALLE vCards client-seitig (real 0.2s, wenige
- **Contacts:** `search_contacts` parst ALLE vCards client-seitig (real 0.2s, wenige
Kontakte; skaliert linear). **Fix:** `PARSE_DEADLINE_S=12` in `_get_contacts` + Hinweis.
- Rest-Kosten = CalDAV/CardDAV-REPORT-Transfer selbst (kein Server-Result-Limit im Protokoll);
in der Praxis durch Datumsbereich/Begriff eingrenzbar. Langfristig: server-seitige Suche.
+5 -3
View File
@@ -1,7 +1,9 @@
#!/bin/bash
# MCP Smoke-Tests — laeuft taeglich via systemd timer (mcp-tests.timer 05:00).
# NUR Smoke (Server up + Auth + 1 Read/Connector). Stress/Edge/Funktional laufen
# NICHT naechtlich -> on-demand via run_full_tests.sh.
# NUR Smoke (Server up + Auth + 1 Read/Connector) plus SearXNG-Smoke
# (test_search_smoke.py, lokale Route 127.0.0.1:8888) plus oeffentlicher Smoke
# (test_public_smoke.py, Route/TLS/Bearer ueber https://<name>.mcp.slohmaier.de).
# Stress/Edge/Funktional laufen NICHT naechtlich -> on-demand via run_full_tests.sh.
set -uo pipefail
LOG="/var/log/mcp-tests.log"
@@ -10,7 +12,7 @@ VENV="/opt/mcp-servers/venv/bin"
echo "[$(date)] MCP Smoke-Tests gestartet" | tee -a "$LOG"
OUTPUT=$(cd /opt/mcp-servers/tests && $VENV/python -m pytest test_smoke.py -v --tb=short 2>&1)
OUTPUT=$(cd /opt/mcp-servers/tests && $VENV/python -m pytest test_smoke.py test_public_smoke.py test_search_smoke.py -v --tb=short 2>&1)
EXIT=$?
echo "$OUTPUT" | tee -a "$LOG"
+219 -97
View File
@@ -13,6 +13,7 @@ Run: /opt/mcp-servers/venv/bin/python -m pytest /opt/mcp-servers/tests/test_all.
import json
import hashlib
import base64
import re
import secrets
import time
@@ -59,11 +60,11 @@ def get_token_pkce(port):
return r2.json()["access_token"]
def mcp_call(port, token, method, params=None):
def mcp_call(port, token, method, params=None, timeout=60):
r = httpx.post(f"http://127.0.0.1:{port}/mcp",
json={"jsonrpc": "2.0", "id": 1, "method": method, "params": params or {}},
headers={"Authorization": f"Bearer {token}", "Accept": "application/json, text/event-stream"},
timeout=60)
timeout=timeout)
assert r.status_code == 200, f"MCP {r.status_code}: {r.text[:200]}"
for line in r.text.split("\n"):
if line.startswith("data: "):
@@ -71,8 +72,8 @@ def mcp_call(port, token, method, params=None):
return None
def tool_call(port, token, tool_name, arguments=None):
result = mcp_call(port, token, "tools/call", {"name": tool_name, "arguments": arguments or {}})
def tool_call(port, token, tool_name, arguments=None, timeout=60):
result = mcp_call(port, token, "tools/call", {"name": tool_name, "arguments": arguments or {}}, timeout=timeout)
assert result and "error" not in result, f"Error: {result}"
content = result["result"]["content"]
assert len(content) > 0
@@ -229,125 +230,203 @@ class TestMail:
# ============================================================
# Calendar Tests (CRUD on calendar-test)
# Calendar Tests (CRUD on calendar-test + calendar-test-second)
# Baikal mcptest-Backend. Nur MCP-Methoden, kein direkter DAV-Zugriff.
# Selbstreinigend: alle erzeugten Events/Tasks werden am Ende geloescht.
# ============================================================
import re as _re
def _extract_uids(text):
"""Alle UIDs (uuid-Format) aus einem MCP-Textauszug extrahieren."""
return _re.findall(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", text)
class TestCalendar:
PORT = SERVERS["calendar"]
TEST_CAL = "calendar-test"
CAL1 = "calendar-test"
CAL2 = "calendar-test-second"
def test_list_calendars(self):
def test_list_calendars_both(self):
"""Beide Test-Kalender muessen sichtbar sein (klares Fehlerbild, wenn Backend fehlt)."""
text = tool_call(self.PORT, get_token(self.PORT), "list_calendars")
assert "calendar-test" in text or "MCP Test" in text
missing = [c for c in (self.CAL1, self.CAL2) if c not in text]
assert not missing, (
f"mcptest-Backend unvollstaendig: Kalender {missing} nicht in list_calendars. "
f"Pruefe Baikal (baikal.slohmaier.de, User mcptest) und config.json.")
def test_list_task_lists(self):
def test_list_task_lists_contains(self):
"""calendar-test ist auch Task-Liste (VEVENT+VTODO)."""
text = tool_call(self.PORT, get_token(self.PORT), "list_task_lists")
assert len(text) > 0
assert self.CAL1 in text or self.CAL2 in text, f"Keine Task-Liste sichtbar: {text[:200]}"
def test_create_and_find_event(self):
def test_create_update_delete_event_full_fields(self):
token = get_token(self.PORT)
tag = f"mcptest-{int(time.time())}"
# Create
result = tool_call(self.PORT, token, "create_event", {
"calendar": self.TEST_CAL,
"title": f"Test Event {tag}",
"start": "2026-12-25T10:00",
"end": "2026-12-25T11:00",
"location": "Testort",
"description": "Automatischer Test",
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpFeldtest-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL1, "title": tag,
"start": "2026-12-25T10:00", "end": "2026-12-25T11:00",
"location": "Marienplatz 1, Muenchen", "description": "Export Test Beschreibung",
"travel_minutes": 30, "travel_mode": "driving",
"travel_advisory": True, "reminder_minutes": 15,
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2026-12-01", "date_to": "2026-12-31"})
assert tag in found, f"Event nach Create nicht auffindbar: {found[:300]}"
uids = _extract_uids(found)
assert uids, f"Keine UID im Create-Ergebnis: {found[:300]}"
uid = uids[0]
created.append((self.CAL1, uid))
# Search
found = tool_call(self.PORT, token, "search_events", {"query": tag})
assert tag in found, f"Event not found after create: {found[:200]}"
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_event", {
"calendar": self.CAL1, "uid": uid, "title": tag2,
"start": "2026-12-26T14:30", "end": "2026-12-26T15:30",
"location": "Hauptbahnhof Muenchen", "description": "Neue Beschreibung nach Update",
"travel_minutes": 45, "travel_mode": "transit",
"travel_advisory": True, "reminder_minutes": 30,
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_event failed: {r}"
found2 = tool_call(self.PORT, token, "search_events",
{"query": tag2, "date_from": "2026-12-01", "date_to": "2027-01-31"})
assert tag2 in found2, f"Event nach Update nicht auffindbar: {found2[:300]}"
assert "Hauptbahnhof" in found2, f"Ort nach Update fehlt: {found2[:300]}"
assert "Verkehrsmittel" in found2, f"travel_mode nach Update nicht angezeigt: {found2[:300]}"
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
def test_create_and_find_task(self):
def test_event_timezone_tzid(self):
"""Timed events muessen mit TZID (Europe/Berlin) gespeichert werden, nicht floating.
Regression 2026-09-30: floating DTSTART wurde von Baikal als UTC gelesen (+2h)."""
token = get_token(self.PORT)
tag = f"mcptask-{int(time.time())}"
result = tool_call(self.PORT, token, "create_task", {
"task_list": self.TEST_CAL,
"title": f"Test Task {tag}",
"due": "2026-12-31",
"priority": 5,
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpTz-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL1, "title": tag,
"start": "2026-12-25T17:30", "end": "2026-12-25T19:15",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2026-12-01", "date_to": "2026-12-31"})
uids = _extract_uids(found)
assert uids, f"Keine UID: {found[:300]}"
created.append((self.CAL1, uids[0]))
assert re.search(r"T17:30:00[+-]0[12]:00", found), (
f"Event ohne Berlin-Offset (floating?) gespeichert: {found[:300]}")
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
tasks = tool_call(self.PORT, token, "get_tasks", {"task_list": self.TEST_CAL, "include_completed": True})
assert tag in tasks, f"Task not found: {tasks[:200]}"
def test_create_event_second_calendar(self):
"""Event in zweitem Kalender anlegen (Wechsel/Mehrfach-Test)."""
token = get_token(self.PORT)
tag = f"McpZweiter-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL2, "title": tag,
"start": "2027-01-15T09:00", "end": "2027-01-15T10:00",
"location": "Marienplatz", "description": "Zweiter Kalender Test",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event(second) failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2027-01-01", "date_to": "2027-02-01"})
uids = _extract_uids(found)
assert uids, f"Event in zweitem Kalender nicht auffindbar: {found[:300]}"
created.append((self.CAL2, uids[0]))
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
def test_get_events_date_range(self):
text = tool_call(self.PORT, get_token(self.PORT), "get_events", {
"calendar": "calendar-test", "date_from": "2026-06-01", "date_to": "2026-06-30",
})
assert "Wann:" in text or "Keine Termine" in text
def test_create_update_delete_task(self):
"""Aufgabe in calendar-test (VTODO) anlegen, aendern, loeschen."""
token = get_token(self.PORT)
tag = f"McpAufgabe-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_task", {
"task_list": self.CAL1, "title": tag, "due": "2026-12-31", "priority": 5, "description": "Testbeschreibung",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_task failed: {r}"
tasks = tool_call(self.PORT, token, "get_tasks", {"task_list": self.CAL1, "include_completed": True})
assert tag in tasks, f"Task nach Create nicht auffindbar: {tasks[:300]}"
uids = _extract_uids(tasks)
assert uids, f"Keine UID bei Task: {tasks[:300]}"
uid = uids[0]
created.append(uid)
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_task", {
"task_list": self.CAL1, "uid": uid, "title": tag2, "due": "2026-12-30", "priority": 8, "description": "Update Notiz",
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_task failed: {r}"
tasks2 = tool_call(self.PORT, token, "get_tasks", {"task_list": self.CAL1, "include_completed": True})
assert tag2 in tasks2, f"Task nach Update nicht auffindbar: {tasks2[:300]}"
assert "Update Notiz" in tasks2, f"Task-Beschreibung nach Update fehlt: {tasks2[:300]}"
finally:
for uid in created:
try:
tool_call(self.PORT, token, "delete_task", {"task_list": self.CAL1, "uid": uid})
except Exception:
pass
# ============================================================
# Contacts Tests (CRUD on contacts-test)
# ============================================================
class TestContacts:
PORT = SERVERS["contacts"]
def test_search_real_contacts(self):
def test_search_contacts_read(self):
"""Read-only Smoke auf das Adressbuch (leer ok)."""
text = tool_call(self.PORT, get_token(self.PORT), "search_contacts", {"query": "Mustermann", "limit": 3})
assert "Mustermann" in text
assert isinstance(text, str), f"search_contacts Kaputt: {text}"
def test_search_empty(self):
text = tool_call(self.PORT, get_token(self.PORT), "search_contacts", {"query": "xyzzy_nobody_99"})
assert "Keine Kontakte" in text
def test_create_search_contact(self):
def test_create_update_delete_contact(self):
token = get_token(self.PORT)
tag = f"McpTest-{int(time.time())}"
result = tool_call(self.PORT, token, "create_contact", {
"name": f"{tag} Mustermann",
"email": f"{tag.lower()}@example.com",
"phone": "+49 170 0000000",
"organization": "MCP Tests GmbH",
"note": "Automatisch erstellt",
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpKontakt-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_contact", {
"name": f"{tag} Mustermann", "email": "max@example.com",
"phone": "+49 170 0000000", "organization": "MCP Tests GmbH", "note": "Automatisch erstellt",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_contact failed: {r}"
found = tool_call(self.PORT, token, "search_contacts", {"query": tag, "limit": 5})
assert tag in found, f"Kontakt nach Create nicht auffindbar: {found[:300]}"
uids = _extract_uids(found)
assert uids, f"Keine UID bei Kontakt: {found[:300]}"
uid = uids[0]
created.append(uid)
found = tool_call(self.PORT, token, "search_contacts", {"query": tag})
assert tag in found, f"Contact not found: {found[:200]}"
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_contact", {
"uid": uid, "name": f"{tag2} Mustermann", "email": "neu@example.org",
"phone": "+49 171 999999", "organization": "Andere Firma", "note": "Update-Notiz",
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_contact failed: {r}"
found2 = tool_call(self.PORT, token, "search_contacts", {"query": tag2, "limit": 5})
assert tag2 in found2, f"Kontakt nach Update nicht auffindbar: {found2[:300]}"
assert "Andere Firma" in found2, f"Organisation nach Update fehlt: {found2[:300]}"
finally:
for uid in created:
try:
tool_call(self.PORT, token, "delete_contact", {"uid": uid})
except Exception:
pass
def test_get_contact_details(self):
token = get_token(self.PORT)
search = tool_call(self.PORT, token, "search_contacts", {"query": "Mustermann", "limit": 1})
if "Keine" in search:
pytest.skip("No contacts")
uid = [l for l in search.split("\n") if "UID:" in l][0].split("UID: ")[1].strip()
# get_contact returns list content, first element is text
result = mcp_call(self.PORT, token, "tools/call", {"name": "get_contact", "arguments": {"uid": uid}})
text = result["result"]["content"][0]["text"]
assert "Mustermann" in text
assert "UID:" in text
def test_set_and_read_photo(self):
# Foto setzen + zuruecklesen (get_contact liefert dann ImageContent)
token = get_token(self.PORT)
tag = f"PhotoTest{int(time.time())}"
tool_call(self.PORT, token, "create_contact", {"name": f"{tag} Bildmann", "email": f"{tag.lower()}@example.com"})
search = tool_call(self.PORT, token, "search_contacts", {"query": tag, "limit": 1})
uid = [l for l in search.split("\n") if "UID:" in l][0].split("UID:")[1].strip()
# 1x1 PNG
png_b64 = ("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwC"
"AAAAC0lEQVR42mNk+M8AAAMCAYAAAS+ZkAAAAABJRU5ErkJggg==")
res = tool_call(self.PORT, token, "set_contact_photo",
{"uid": uid, "image_base64": png_b64, "image_type": "png"})
assert "esetzt" in res.lower() or "set" in res.lower()
content = mcp_call(self.PORT, token, "tools/call",
{"name": "get_contact", "arguments": {"uid": uid}})["result"]["content"]
imgs = [c for c in content if c.get("type") == "image"]
assert imgs, f"Kein Bild in get_contact: {[c.get('type') for c in content]}"
assert imgs[0].get("mimeType", "").startswith("image/")
# ============================================================
# Files Tests (CRUD on /mcp-tests/)
# ============================================================
class TestFiles:
PORT = SERVERS["files"]
@@ -497,6 +576,49 @@ class TestNotes:
result = tool_call(self.PORT, token, "delete_note", {"note_id": note_id, "permanent": True})
assert "ENDGUELTIG" in result, f"Delete failed: {result}"
def test_attachment_crud(self):
"""Anhang-Zyklus: add -> list -> read -> update (Inhalt+Props) -> delete (inkl. Link-Cleanup)."""
token = get_token(self.PORT)
tag = f"mcptest-att-{int(time.time())}"
result = tool_call(self.PORT, token, "create_note", {
"notebook": self.TEST_NOTEBOOK, "title": f"Att {tag}", "body": "anfang",
})
assert "erstellt" in result.lower(), f"Create failed: {result}"
note_id = result.split("id: ")[1].rstrip(")").strip()
content = base64.b64encode(f"Hallo {tag}\n".encode()).decode()
res = tool_call(self.PORT, token, "add_attachment", {
"note_id": note_id, "filename": f"{tag}.txt", "content_base64": content,
})
assert "hinzugefuegt" in res.lower(), f"Add failed: {res}"
rid = res.split("resource id: ")[1].split(",")[0].strip()
listing = tool_call(self.PORT, token, "list_note_resources", {"note_id": note_id})
assert rid in listing and f"{tag}.txt" in listing, f"Listing mismatch: {listing}"
body = tool_call(self.PORT, token, "read_note", {"note_id": note_id})
assert f":/{rid}" in body, f"Link missing in body: {body}"
text = tool_call(self.PORT, token, "read_resource", {"resource_id": rid})
assert tag in text, f"Content mismatch: {text}"
new_content = base64.b64encode(f"Neu {tag}\n".encode()).decode()
upd = tool_call(self.PORT, token, "update_attachment", {
"resource_id": rid, "content_base64": new_content, "title": f"{tag}-neu.txt",
})
assert "ersetzt" in upd.lower(), f"Content update failed: {upd}"
text = tool_call(self.PORT, token, "read_resource", {"resource_id": rid})
assert f"Neu {tag}" in text, f"Content update not applied: {text}"
upd2 = tool_call(self.PORT, token, "update_attachment", {"resource_id": rid, "mime": "text/plain"})
assert "aktualisiert" in upd2.lower(), f"Props update failed: {upd2}"
dele = tool_call(self.PORT, token, "delete_attachment", {"resource_id": rid, "note_id": note_id})
assert "geloescht" in dele.lower(), f"Delete failed: {dele}"
assert f":/{rid}" not in tool_call(self.PORT, token, "read_note", {"note_id": note_id})
tool_call(self.PORT, token, "delete_note", {"note_id": note_id, "permanent": True})
# ============================================================
# File Type Tests (read_file auf vorbereiteten /testdata-Dateien)
+15
View File
@@ -154,6 +154,21 @@ class TestFilesEdge:
assert "404" in text or "gefunden" in text.lower() or "not found" in text.lower()
_alive(self.PORT)
def test_url_special_chars_roundtrip(self):
# '#', '%' und '?' im Dateinamen duerfen die URL nicht zerlegen
# (Fix 2026-09-11: _enc_path() in files/server.py).
token = get_token(self.PORT)
tag = str(int(time.time()))
for fname in [f"edge{tag}#hash.txt", f"edge{tag}100%.txt", f"edge{tag}was?so.txt"]:
path = f"{self.DIR}/{fname}"
w = tool_call(self.PORT, token, "write_file", {"path": path, "content": "special"})
assert "geschrieben" in w, f"write fehlgeschlagen: {w}"
r = tool_call(self.PORT, token, "read_file", {"path": path})
assert "special" in r, f"read fehlgeschlagen: {r}"
d = tool_call(self.PORT, token, "delete_file", {"path": path})
assert "Geloescht" in d, f"delete fehlgeschlagen: {d}"
_alive(self.PORT)
# ============================================================
# Notes
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""Regression (2026-09-26): ungelesene Mails im Maildir `new/` muessen indexiert
werden. mbsync legt Gmail-Mails ohne \\Seen in <folder>/new/ ab; der Index scannte
frueher nur cur/ und jarvis sah diese Mails nicht.
Lauf: /opt/mcp-servers/venv/bin/python -m pytest test_mail_newdir.py -q
"""
import os
import sys
import pytest
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE)
sys.path.insert(0, os.path.join(BASE, "mail"))
from mail import mailindex # noqa: E402
pytestmark = pytest.mark.edge
MSG = (
"From: sender@example.com\r\n"
"To: rcpt@example.com\r\n"
"Subject: Newdir Regression {tag}\r\n"
"Date: Sat, 26 Sep 2026 13:58:32 +0200\r\n"
"Content-Type: text/plain; charset=utf-8\r\n"
"\r\n"
"unique-body-token-{tag}\r\n"
)
def _write_mail(path):
with open(path, "w", encoding="utf-8") as fh:
fh.write(MSG.format(tag=os.path.basename(path).split(":")[0]))
@pytest.fixture()
def newdir_index(tmp_path):
user = "newdir_test"
root = tmp_path / "maildir"
for sub, tag in (("cur", "curtoken"), ("new", "newtoken")):
d = root / "acct" / "INBOX" / sub
d.mkdir(parents=True)
_write_mail(str(d / f"1700000000.{tag}.polo,S:2,S"))
mailindex.update_user(user, str(root), log=lambda *a: None)
with open(mailindex._ready_path(user), "w") as fh:
fh.write("test")
yield user
for p in (mailindex.index_db_path(user), mailindex._ready_path(user)):
try:
os.remove(p)
except OSError:
pass
def test_new_dir_is_indexed(newdir_index):
hits = mailindex.search(newdir_index, "newtoken", limit=5)
assert hits is not None, "Index nicht nutzbar"
assert hits, "Mail aus new/ wurde nicht indexiert"
assert hits[0]["folder"] == "INBOX"
def test_cur_dir_still_indexed(newdir_index):
hits = mailindex.search(newdir_index, "curtoken", limit=5)
assert hits, "Mail aus cur/ wurde nicht indexiert"
+110
View File
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
"""Oeffentlicher MCP-Smoke-Test — NIGHTLY.
Prueft die oeffentliche Route (DNS, nginx-vhost, TLS/Cert-SAN, Bearer-Auth)
fuer alle oeffentlichen MCP-Server: https://<name>.mcp.slohmaier.de/mcp.
Nutzt ein dediziertes, nicht-ablaufendes Service-Token (Label `smoketest`,
User mcptest) aus /opt/mcp-servers/service_tokens.json. Dadurch entstehen
keine /token-Aufrufe und das nginx-Rate-Limit `mcp_auth` (10/min) wird nicht
belastet. Read-only: initialize + tools/list, kein Datenzugriff.
Lauf: /opt/mcp-servers/venv/bin/python -m pytest test_public_smoke.py -q
"""
import json
import httpx
import pytest
PUBLIC_HOSTS = {
"notes": "notes.mcp.slohmaier.de",
"calendar": "calendar.mcp.slohmaier.de",
"mail": "mail.mcp.slohmaier.de",
"contacts": "contacts.mcp.slohmaier.de",
"files": "files.mcp.slohmaier.de",
"openwearables": "openwearables.mcp.slohmaier.de",
"owamail": "owamail.mcp.slohmaier.de",
}
SERVICE_TOKENS = "/opt/mcp-servers/service_tokens.json"
INIT = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": {},
"clientInfo": {"name": "public-smoke", "version": "1"},
},
}
pytestmark = pytest.mark.smoke
def _token():
with open(SERVICE_TOKENS) as f:
data = json.load(f)
for tok, info in data.items():
if isinstance(info, dict) and info.get("label") == "smoketest":
return tok
pytest.skip("kein Service-Token mit Label 'smoketest' in service_tokens.json")
def _headers(token=None, session=None):
h = {
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
}
if token:
h["Authorization"] = f"Bearer {token}"
if session:
h["mcp-session-id"] = session
return h
def _jsonrpc(resp):
for line in resp.text.split("\n"):
if line.startswith("data: "):
return json.loads(line[6:])
try:
return resp.json()
except Exception:
return None
@pytest.mark.parametrize("svc,host", list(PUBLIC_HOSTS.items()))
def test_public_requires_auth(svc, host):
"""Ohne Bearer muss die oeffentliche Route 401 liefern (Route/TLS erreichbar)."""
r = httpx.post(f"https://{host}/mcp", json=INIT, headers=_headers(), timeout=30)
assert r.status_code == 401, f"{svc}: erwartet 401 ohne Token, bekam {r.status_code}"
@pytest.mark.parametrize("svc,host", list(PUBLIC_HOSTS.items()))
def test_public_initialize_and_tools(svc, host):
"""initialize + tools/list ueber die oeffentliche URL mit Service-Token."""
token = _token()
r = httpx.post(f"https://{host}/mcp", json=INIT, headers=_headers(token), timeout=30)
assert r.status_code == 200, f"{svc}: initialize HTTP {r.status_code}: {r.text[:200]}"
res = _jsonrpc(r)
assert res and res.get("result", {}).get("serverInfo"), f"{svc}: kein serverInfo"
session = r.headers.get("mcp-session-id")
# initialized-Notification (Server, die sie verlangen); Fehler ignorieren.
if session:
httpx.post(
f"https://{host}/mcp",
json={"jsonrpc": "2.0", "method": "notifications/initialized"},
headers=_headers(token, session),
timeout=30,
)
r2 = httpx.post(
f"https://{host}/mcp",
json={"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
headers=_headers(token, session),
timeout=30,
)
assert r2.status_code == 200, f"{svc}: tools/list HTTP {r2.status_code}: {r2.text[:200]}"
res2 = _jsonrpc(r2)
assert res2 and res2.get("result", {}).get("tools"), f"{svc}: tools/list leer"
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
"""SearXNG Smoke-Test — NIGHTLY.
Minimal, schnell, read-only. Prueft die interne SearXNG-Instanz auf Erreichbarkeit
und JSON-Antwort. Genutzt wird die lokale Host-Route 127.0.0.1:8888 (kein Token
noetig, das Token-Gate sitzt nur in nginx/oeffentlich); damit bleibt der Test ohne
Secret. Faengt Totalausfaelle (Container down, API kaputt) ueber Nacht ab.
Bewusst KEIN "results nicht leer"-Assert: geratelimitete Upstream-Engines liefern
leere results (bekannter Degraded-Zustand, siehe /opt/searxng/README.md), das ist
kein Ausfall.
Lauf: /opt/mcp-servers/venv/bin/python -m pytest test_search_smoke.py -q
"""
import httpx
import pytest
pytestmark = pytest.mark.smoke
BASE = "http://127.0.0.1:8888"
def test_searxng_json_alive():
"""SearXNG erreichbar und liefert eine JSON-Antwort mit results-Liste."""
r = httpx.get(f"{BASE}/search", params={"q": "polo smoke", "format": "json"}, timeout=30)
assert r.status_code == 200, f"SearXNG HTTP {r.status_code}"
data = r.json()
assert isinstance(data.get("results"), list), "SearXNG JSON ohne results-Liste"
+6 -1
View File
@@ -32,8 +32,12 @@ def test_mail_read():
def test_calendar_read():
"""Beide Test-Kalender des mcptest-Backends muessen sichtbar sein (read-only)."""
text = tool_call(SERVERS["calendar"], get_token(SERVERS["calendar"]), "list_calendars")
assert "calendar-test" in text or "MCP Test" in text
missing = [c for c in ("calendar-test", "calendar-test-second") if c not in text]
assert not missing, (
f"mcptest-Backend unvollstaendig: Kalender {missing} fehlen in list_calendars. "
f"Pruefe Baikal (baikal.slohmaier.de, User mcptest) und config.json.")
def test_contacts_read():
@@ -51,3 +55,4 @@ def test_files_read():
def test_notes_read():
text = tool_call(SERVERS["notes"], get_token(SERVERS["notes"]), "list_notebooks")
assert "id:" in text