"""Head tracking 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_head_tracking_tool(mcp: FastMCP) -> None:
"""Register the head_tracking tool with the MCP server."""
@mcp.tool()
def head_tracking(
ctx: Context,
enabled: bool,
) -> dict[str, Any]:
"""Enable or disable head tracking mode.
When enabled, the robot will apply face tracking offsets to follow
detected faces. This requires external face tracking data to be
provided via the set_head_tracking_offsets API.
Args:
enabled: True to enable head tracking, False to disable.
Returns:
Status dict with "status" and "enabled" keys.
"""
robot_manager = ctx.request_context.lifespan_context.robot_manager
if not robot_manager.is_connected():
return {"status": "error", "error": "Robot not connected"}
robot_manager.set_head_tracking(enabled)
status = "enabled" if enabled else "disabled"
logger.info(f"Head tracking {status}")
return {"status": "success", "enabled": enabled}