Skip to content

Viewer Controls

Functions for controlling the camera, navigation, and display settings.

reset_view

MCP Tool Interface

Reset the camera view to fit data.

Source code in src/napari_mcp/server.py
async def reset_view() -> dict[str, Any]:
    """Reset the camera view to fit data."""
    return await NapariMCPTools.reset_view()

Implementation

Reset the camera view to fit data.

Source code in src/napari_mcp/server.py
@staticmethod
async def reset_view() -> dict[str, Any]:
    """Reset the camera view to fit data."""
    async with _viewer_lock:

        def _reset():
            v = _ensure_viewer()
            v.reset_view()
            _process_events()
            return {"status": "ok"}

        return _gui_execute(_reset)

set_camera

MCP Tool Interface

Set camera properties: center, zoom, and/or angle.

Source code in src/napari_mcp/server.py
async def set_camera(
    center: list[float] | None = None,
    zoom: float | str | None = None,
    angle: float | str | None = None,
) -> dict[str, Any]:
    """Set camera properties: center, zoom, and/or angle."""
    return await NapariMCPTools.set_camera(center=center, zoom=zoom, angle=angle)

Implementation

Set camera properties: center, zoom, and/or angle.

Source code in src/napari_mcp/server.py
@staticmethod
async def set_camera(
    center: list[float] | None = None,
    zoom: float | str | None = None,
    angle: float | str | None = None,
) -> dict[str, Any]:
    """Set camera properties: center, zoom, and/or angle."""
    async with _viewer_lock:

        def _set_cam():
            v = _ensure_viewer()
            if center is not None:
                v.camera.center = list(map(float, center))
            if zoom is not None:
                v.camera.zoom = float(zoom)
            if angle is not None:
                v.camera.angles = (float(angle),)
            _process_events()
            return {
                "status": "ok",
                "center": list(map(float, v.camera.center)),
                "zoom": float(v.camera.zoom),
            }

        return _gui_execute(_set_cam)

set_ndisplay

MCP Tool Interface

Set number of displayed dimensions (2 or 3).

Source code in src/napari_mcp/server.py
async def set_ndisplay(ndisplay: int | str) -> dict[str, Any]:
    """Set number of displayed dimensions (2 or 3)."""
    return await NapariMCPTools.set_ndisplay(ndisplay)

Implementation

Set number of displayed dimensions (2 or 3).

Source code in src/napari_mcp/server.py
@staticmethod
async def set_ndisplay(ndisplay: int | str) -> dict[str, Any]:
    """Set number of displayed dimensions (2 or 3)."""
    async with _viewer_lock:

        def _set():
            v = _ensure_viewer()
            v.dims.ndisplay = int(ndisplay)
            _process_events()
            return {"status": "ok", "ndisplay": int(v.dims.ndisplay)}

        return _gui_execute(_set)

set_dims_current_step

MCP Tool Interface

Set the current step (slider position) for a specific axis.

Source code in src/napari_mcp/server.py
async def set_dims_current_step(axis: int | str, value: int | str) -> dict[str, Any]:
    """Set the current step (slider position) for a specific axis."""
    return await NapariMCPTools.set_dims_current_step(axis, value)

Implementation

Set the current step (slider position) for a specific axis.

Source code in src/napari_mcp/server.py
@staticmethod
async def set_dims_current_step(
    axis: int | str, value: int | str
) -> dict[str, Any]:
    """Set the current step (slider position) for a specific axis."""
    async with _viewer_lock:

        def _set():
            v = _ensure_viewer()
            v.dims.set_current_step(int(axis), int(value))
            _process_events()
            return {"status": "ok", "axis": int(axis), "value": int(value)}

        return _gui_execute(_set)

set_grid

MCP Tool Interface

Enable or disable grid view.

Source code in src/napari_mcp/server.py
async def set_grid(enabled: bool | str = True) -> dict[str, Any]:
    """Enable or disable grid view."""
    return await NapariMCPTools.set_grid(enabled)

Implementation

Enable or disable grid view.

Source code in src/napari_mcp/server.py
@staticmethod
async def set_grid(enabled: bool | str = True) -> dict[str, Any]:
    """Enable or disable grid view."""
    async with _viewer_lock:

        def _set():
            v = _ensure_viewer()
            v.grid.enabled = _parse_bool(enabled)
            _process_events()
            return {"status": "ok", "grid": _parse_bool(v.grid.enabled)}

        return _gui_execute(_set)