"""Camera 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_camera_tool(mcp: FastMCP) -> None:
"""Register the camera tool with the MCP server."""
@mcp.tool()
def camera(ctx: Context) -> dict[str, Any]:
"""Capture an image from the robot's camera.
Returns a base64-encoded JPEG image that can be used for visual analysis.
Returns:
Status dict with:
- "status": "success" or "error"
- "image_base64": Base64-encoded JPEG image data (on success)
- "format": "jpeg" (on success)
- "error": Error message (on failure)
"""
robot_manager = ctx.request_context.lifespan_context.robot_manager
config = ctx.request_context.lifespan_context.config
if not config.enable_camera:
return {"status": "error", "error": "Camera not enabled. Set REACHY_MINI_ENABLE_CAMERA=true"}
if not robot_manager.is_connected():
return {"status": "error", "error": "Robot not connected"}
result = robot_manager.capture_image()
if result is None:
return {"status": "error", "error": "Failed to capture image"}
b64_data, fmt = result
logger.info("Captured camera image")
return {"status": "success", "image_base64": b64_data, "format": fmt}