The ``visualization_tools.py`` module ===================================== .. py:module:: ansys.geometry.mcp.tools.visualization_tools Summary ------- .. py:currentmodule:: visualization_tools .. tab-set:: .. tab-item:: Functions .. list-table:: :header-rows: 0 :widths: auto * - :py:obj:`~read_image_in_base64` - Read an image file and return its contents as a base64-encoded string. * - :py:obj:`~visualize` - Open a 3D view of the active design or save an image when requested. .. tab-item:: Attributes .. list-table:: :header-rows: 0 :widths: auto * - :py:obj:`~logger` - Description ----------- MCP visualization tools for PyAnsys Geometry-MCP. Tools that render the active design or read the resulting images. Each function decorated with ``@app.tool()`` is exposed as an MCP tool. The ``ctx`` parameter provides access to the application context (and thus to the live product instance and command history). How to add a tool ----------------- 1. Define a Python function with type-annotated parameters. 2. Add a NumPy-style docstring. The summary line becomes the tool description. visible to the AI assistant. 3. Decorate it with ``@app.tool()``. 4. Access the product instance:: app_context = get_geometry_ctx(ctx) instance = app_context.product_instance Notes ----- Import this module in ``__main__.py`` (already done) to register all tools with the server before it starts. Module detail ------------- .. py:function:: read_image_in_base64(ctx: fastmcp.server.Context, image_path: str) -> dict[str, str] Read an image file and return its contents as a base64-encoded string. Parameters ---------- ctx : Context MCP request context (injected automatically). image_path : str Path to the image file to read. Returns ------- dict of str A dictionary with a single key "base64" containing the base64-encoded contents of the image, or an error message if reading fails. .. py:function:: visualize(ctx: fastmcp.server.Context, path: str | None = None, save: bool = False, use_service_colors: bool = False) -> str Open a 3D view of the active design or save an image when requested. Parameters ---------- ctx : Context MCP request context (injected automatically). path : str, default: None Path to save the image to. Providing a path saves the image there. save : bool, default: False Whether to save an image using a timestamped filename if no path is provided. use_service_colors : bool, default: False Whether to plot using service colors. Set to ``True`` when the design's colors convey essential information or the user requests a full-color plot. Returns ------- str Result message, or an error message if the operation fails. .. py:data:: logger