"""Stop motion tool for Reachy Mini MCP server."""
from __future__ import annotations
import logging
from typing import Any
from mcp.server.fastmcp import Context, FastMCP
logger = logging.getLogger(__name__)
def register_stop_motion_tool(mcp: FastMCP) -> None:
"""Register the stop_motion tool with the MCP server."""
@mcp.tool()
def stop_motion(ctx: Context) -> dict[str, Any]:
"""Stop all current and queued motions immediately.
Clears the move queue and stops any currently playing dance,
emotion, or head movement. The robot will return to breathing
mode after a short delay.
Returns:
Status dict with "status" and "queue_cleared" keys.
"""
robot_manager = ctx.request_context.lifespan_context.robot_manager
if not robot_manager.is_connected():
return {"status": "error", "error": "Robot not connected"}
queue_size = robot_manager.clear_queue()
logger.info(f"Stopped motion, cleared {queue_size} queued moves")
return {"status": "success", "queue_cleared": queue_size}