Skip to content

Session & Viewer Controls

Functions for managing the napari viewer lifecycle, GUI state, and session information.

init_viewer

async def init_viewer(title: str | None = None, width: int | str | None = None, height: int | str | None = None, port: int | str | None = None, detect_only: bool = False) -> dict[str, Any]

Create or return the napari viewer, with viewer detection.

When detect_only=True, reports available viewers (local and external) without creating or modifying anything.

Parameters

title : str, optional Optional window title (only for local viewer). width : int, optional Optional initial canvas width (only for local viewer). height : int, optional Optional initial canvas height (only for local viewer). port : int, optional If provided, attempt to connect to an external napari-mcp bridge on this port (default is taken from NAPARI_MCP_BRIDGE_PORT or 9999). detect_only : bool, default=False If True, only detect available viewers without initialising.

Source: server.py:147

close_viewer

async def close_viewer() -> dict[str, Any]

Close the viewer window and clear all layers.

Source: server.py:248

session_information

async def session_information() -> dict[str, Any]

Get comprehensive information about the current napari session.

Source: server.py:278