Files
legal-shield/butler/notify_server.py
T

44 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""MCP-Server `notify`: kurze Push-Nachricht aufs Handy der Person, die gerade fragt (ntfy, butler/notify.py).
LibreChat schickt je Anfrage die Nutzer-ID (Kopfzeile X-User-Id); daraus wird der persönliche Kanal abgeleitet.
Start: python -m butler.notify_server (NTFY_SECRET; optional NTFY_URL, NTFY_TOKEN, NTFY_CLICK_URL)
"""
from __future__ import annotations
from mcp.server.mcpserver import Context, MCPServer
from . import notify as push
from .mcp_run import erwartet, starten
server = MCPServer("notify", instructions=(
"Push-Nachricht aufs Handy der Person, die fragt. Nur kurze Hinweise ohne Inhalte, Beträge, Namen oder "
"Aktenzeichen (z. B. „Tagescheck: 1 dringend, 2 neu“) – Details stehen im Chat. Einmalig: notify_setup zeigt, "
"wie die App eingerichtet wird."))
def _nutzer_id(ctx: Context | None) -> str | None:
try:
return (ctx.headers or {}).get("x-user-id")
except (AttributeError, ValueError, RuntimeError): # außerhalb einer HTTP-Anfrage
return None
@server.tool()
@erwartet
def notify_setup(ctx: Context | None = None) -> dict:
"""Wie die Person Push-Nachrichten aufs Handy bekommt: persönlicher Kanal und Anleitung für die ntfy-App."""
return push.einrichtung(_nutzer_id(ctx))
@server.tool()
@erwartet
def notify(message: str, title: str = "", priority: str = "default", ctx: Context | None = None) -> dict:
"""Kurze Push-Nachricht (max. 300 Zeichen) an die Person, die fragt. priority: min, low, default, high, urgent
(high/urgent nur bei Fristen in den nächsten Tagen). Keine Inhalte, Beträge oder Namen."""
return push.senden(_nutzer_id(ctx), message, title, priority)
if __name__ == "__main__":
starten(server)