feat: add like_post tool via wallmood endpoint (v0.4.2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-15 15:32:12 +02:00
parent 61e0d63931
commit c412c24c86
4 changed files with 73 additions and 3 deletions
+50
View File
@@ -471,6 +471,56 @@ def delete_task(task_id: str) -> str:
return json.dumps({"deleted": True, "id": task_id}, ensure_ascii=False, indent=2)
# ---------------------------------------------------------------------------
# Tool: like_post
# ---------------------------------------------------------------------------
@mcp.tool()
def like_post(post_id: str, like: bool = True) -> str:
"""Like or unlike a wall post/activity.
Args:
post_id: Wall post ID from get_activities (e.g. ``wall/23431854_31119189``).
like: ``True`` to like the post, ``False`` to unlike.
Returns:
JSON success indicator or an error message.
"""
# wallmood is a toggle endpoint — same endpoint for like and unlike.
# The 'like' parameter controls the intended state; since the endpoint
# toggles server-side state, it is sent as 'moodType' to allow the server
# to differentiate. Exact parameter names to be verified via FW_DEBUG=1.
params: dict[str, Any] = {
"wallId": post_id,
"moodType": "LIKE" if like else "NONE",
}
try:
data = _authenticated_call("wallmood", params)
except RuntimeError as exc:
return f"Error: {exc}"
# The response structure is not yet fully verified — return raw JSON
# if the expected shape is absent so the caller can inspect it.
try:
result_data = data["a00"]["r"]["r"]
if result_data is None:
raise KeyError("empty result")
except (KeyError, TypeError):
return json.dumps(
{"warning": "Unexpected wallmood response structure", "raw": data},
ensure_ascii=False,
indent=2,
)
return json.dumps(
{"liked": like, "id": post_id},
ensure_ascii=False,
indent=2,
)
# ---------------------------------------------------------------------------
# Factory
# ---------------------------------------------------------------------------