:class:`FluentLeafMCP` ====================== .. py:class:: ansys.fluent.mcp.common.base.FluentLeafMCP(*, backends: dict[str, ansys.fluent.mcp.common.backend.Backend], expose_tools: Iterable[str] = ALL_TOOLS, name: Optional[str] = None, **fastmcp_kwargs: Any) Bases: :py:obj:`ansys.common.mcp.server.PyAnsysBaseMCP` Base MCP server class that exposes one or more :class:`Backend` instances. .. !! processed by numpydoc !! .. py:currentmodule:: FluentLeafMCP Overview -------- .. tab-set:: .. tab-item:: Methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~run` - Start the MCP server via the parent implementation when available. * - :py:attr:`~tool_annotations_for` - Return the MCP behavior hints for one of this server's tools. * - :py:attr:`~tool` - Register a tool with behavior hints and the host contract applied. * - :py:attr:`~product_startup` - No persistent product session at startup. Backends connect lazily. * - :py:attr:`~product_cleanup` - Disconnect any active backend at shutdown. * - :py:attr:`~owning_product` - Return the product that owns ``tool_name`` on this server. * - :py:attr:`~connect_recovery` - Return the reconnect instruction valid for THIS server's ``connect``. * - :py:attr:`~extra_recovery` - Return extra recovery fields for a ``not_connected`` result. * - :py:attr:`~toolset_catalogue` - Return the toolset catalog used by :meth:`build_toolsets`. * - :py:attr:`~build_toolsets` - Build toolset definitions filtered to the tools this leaf exposes. * - :py:attr:`~register_run_code_observer` - Register a callable invoked after every ``run_code`` tool call. .. tab-item:: Properties .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~backend` - Return the active backend instance. * - :py:attr:`~exposed_tools` - Names of the tools this server was asked to expose. .. tab-item:: Attributes .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~leaf_name` - * - :py:attr:`~default_backend_kind` - * - :py:attr:`~cache_ttl_seconds` - * - :py:attr:`~host_contract` - Import detail ------------- .. code-block:: python from ansys.fluent.mcp.common.base import FluentLeafMCP Property detail --------------- .. py:property:: backend :type: ansys.fluent.mcp.common.backend.Backend Return the active backend instance. :Returns: :obj:`Backend` Backend produced by the operation. .. !! processed by numpydoc !! .. py:property:: exposed_tools :type: frozenset[str] Names of the tools this server was asked to expose. .. !! processed by numpydoc !! Attribute detail ---------------- .. py:attribute:: leaf_name :type: str :value: 'fluent' .. py:attribute:: default_backend_kind :type: Optional[str] :value: None .. py:attribute:: cache_ttl_seconds :type: float :value: 30.0 .. py:attribute:: host_contract :type: bool :value: True Method detail ------------- .. py:method:: run(transport: str = 'stdio', host: str | None = None, port: int | None = None) -> None Start the MCP server via the parent implementation when available. :Parameters: **transport** : :class:`python:str` Transport name used to run the MCP server. **host** : :class:`python:str` | :data:`python:None` Host interface used by the server transport. **port** : :class:`python:int` | :data:`python:None` Port used by the selected server transport. :Returns: :data:`python:None` The function completes through its side effects. .. !! processed by numpydoc !! .. py:method:: tool_annotations_for(tool_name: str | None) -> dict[str, bool] | None Return the MCP behavior hints for one of this server's tools. Subclasses that register extra tools override this to add their own classifications and fall back to ``super()``. :Parameters: **tool_name** : :class:`python:str` | :data:`python:None` Registered tool name. :Returns: :class:`python:dict`\[:class:`python:str`, :ref:`bool `] | :data:`python:None` ``readOnlyHint`` / ``destructiveHint`` / ``idempotentHint``, or ``None`` when the tool is unclassified. .. !! processed by numpydoc !! .. py:method:: tool(name_or_fn: Any = None, *args: Any, **kwargs: Any) -> Any Register a tool with behavior hints and the host contract applied. Accepts every ``FastMCP.tool`` call form (direct function, positional or keyword name, bare decorator). Explicit ``annotations=`` win. :Parameters: **name_or_fn** : :obj:`Any` Tool name or function, as accepted by ``FastMCP.tool``. **args** : :obj:`Any` Positional arguments forwarded to ``FastMCP.tool``. **kwargs** : :obj:`Any` Keyword arguments forwarded to ``FastMCP.tool``. :Returns: :obj:`Any` Whatever ``FastMCP.tool`` returns (a decorator or a tool). .. !! processed by numpydoc !! .. py:method:: product_startup() -> None No persistent product session at startup. Backends connect lazily. :Returns: :data:`python:None` The function completes through its side effects. .. !! processed by numpydoc !! .. py:method:: product_cleanup() -> None Disconnect any active backend at shutdown. :Returns: :data:`python:None` The function completes through its side effects. .. !! processed by numpydoc !! .. py:method:: owning_product(tool_name: str) -> Optional[str] Return the product that owns ``tool_name`` on this server. A single-product server owns all of its tools and reports its ``leaf_name``. A server that routes tools to several backends must override this so recovery guidance names the tool's real owner. :Parameters: **tool_name** : :class:`python:str` Registered tool name. :Returns: :obj:`Optional`\[:class:`python:str`] The owning product name, or ``None`` when this server cannot tell. .. !! processed by numpydoc !! .. py:method:: connect_recovery(product: Optional[str]) -> dict[str, Any] Return the reconnect instruction valid for THIS server's ``connect``. The base ``connect`` tool accepts ``backend_kind`` and ``connect_kwargs``; it has no ``product`` argument. Servers that register a different ``connect`` signature must override this. :Parameters: **product** : :obj:`Optional`\[:class:`python:str`] Product that owns the failing tool (unused by the base leaf, whose ``connect`` is already product-scoped). :Returns: :class:`python:dict`\[:class:`python:str`, :obj:`Any`] ``next_tool`` plus either ``next_tool_args`` or ``next_tool_choices``. .. !! processed by numpydoc !! .. py:method:: extra_recovery(product: Optional[str]) -> dict[str, Any] Return extra recovery fields for a ``not_connected`` result. Extension point for embedding applications that need another step before a reconnect works (for example starting the solver in their own environment). Return ``{}`` when there is none. :Parameters: **product** : :obj:`Optional`\[:class:`python:str`] Value returned by :meth:`owning_product` for the failing tool. :Returns: :class:`python:dict`\[:class:`python:str`, :obj:`Any`] Extra keyword fields for the ``not_connected`` payload. .. !! processed by numpydoc !! .. py:method:: toolset_catalogue() -> dict[str, dict[str, Any]] Return the toolset catalog used by :meth:`build_toolsets`. Subclasses that register extra tools override this and merge their own groups into ``super().toolset_catalogue()``. :Returns: :class:`python:dict`\[:class:`python:str`, :class:`python:dict`\[:class:`python:str`, :obj:`Any`]] Toolset name to ``description`` / ``skill`` / ``tools``. .. !! processed by numpydoc !! .. py:method:: build_toolsets() -> list[dict[str, Any]] Build toolset definitions filtered to the tools this leaf exposes. Returns a list of toolset dicts conforming to the PyAnsysMCPService conductor contract. :Returns: :class:`python:list`\[:class:`python:dict`\[:class:`python:str`, :obj:`Any`]] Mapping containing the operation result. .. !! processed by numpydoc !! .. py:method:: register_run_code_observer(observer: Callable[..., Awaitable[None] | None]) -> None Register a callable invoked after every ``run_code`` tool call. The observer is called as ``observer(code=..., result=..., error=...)``. ``result`` is the backend's :class:`RunCodeResult` on success (and ``None`` on exception); ``error`` is the raised exception on failure (and ``None`` on success). Observers may be sync or async. Exceptions raised by an observer are logged and swallowed so the original tool result is preserved. :Parameters: **observer** : :obj:`Callable`\[..., :obj:`Awaitable`\[:data:`python:None`] | :data:`python:None`] Observer callback invoked after run-code execution. :Returns: :data:`python:None` The function completes through its side effects. .. !! processed by numpydoc !!