feat: add get_activities tool via wallget endpoint (v0.3.0)

This commit is contained in:
2026-04-15 14:15:20 +02:00
parent f680633b59
commit 8276647fcf
4 changed files with 104 additions and 2 deletions
+70
View File
@@ -269,6 +269,76 @@ def get_tasks(list_id: str, only_open: bool = True) -> str:
return json.dumps(result, ensure_ascii=False, indent=2)
# ---------------------------------------------------------------------------
# Tool: get_activities
# ---------------------------------------------------------------------------
@mcp.tool()
def get_activities(limit: int = 20) -> str:
"""Return recent Family Wall wall activities (posts, comments, photos, …).
Uses the wallget endpoint. Response structure is not yet verified against
a live API call — the raw response is returned when no known pattern is
matched, so the structure can be inspected on the first real call.
Args:
limit: Maximum number of activities to return (default 20).
Returns:
JSON string — list of objects with keys:
id, type, text, date, author.
Falls back to raw API response when the structure is unrecognised.
"""
try:
email, password = get_credentials()
except RuntimeError as exc:
return f"Error: {exc}"
try:
with FamilyWallClient() as client:
client.login(email, password)
data = client.call("wallget", {"nb": str(limit)})
client.logout()
except FamilyWallError as exc:
return f"Error: {exc}"
except Exception as exc:
return f"Connection error: {exc}"
# Try known response patterns; fall back to raw JSON for verification.
raw_activities: list[dict[str, Any]] | None = None
try:
candidate = data["a00"]["r"]["r"]
if isinstance(candidate, list):
raw_activities = candidate
elif isinstance(candidate, dict) and isinstance(candidate.get("updatedCreated"), list):
raw_activities = candidate["updatedCreated"]
except (KeyError, TypeError):
pass
if raw_activities is None:
# Response structure not yet verified — return raw JSON for inspection.
return json.dumps(
{"warning": "Unexpected wallget response structure", "raw": data},
ensure_ascii=False,
indent=2,
)
result = []
for item in raw_activities:
result.append(
{
"id": item.get("metaId"),
"type": item.get("type"),
"text": item.get("text") or item.get("comment"),
"date": item.get("date") or item.get("createdDate"),
"author": item.get("authorName") or item.get("author"),
}
)
return json.dumps(result, ensure_ascii=False, indent=2)
# ---------------------------------------------------------------------------
# Factory
# ---------------------------------------------------------------------------