FluentLeafMCP#

class ansys.fluent.mcp.common.base.FluentLeafMCP(*, backends: dict[str, ansys.fluent.mcp.common.backend.Backend], expose_tools: Iterable[str] = ALL_TOOLS, name: str | None = None, **fastmcp_kwargs: Any)#

Bases: ansys.common.mcp.server.PyAnsysBaseMCP

Base MCP server class that exposes one or more Backend instances.

Overview#

run

Start the MCP server via the parent implementation when available.

tool_annotations_for

Return the MCP behavior hints for one of this server’s tools.

tool

Register a tool with behavior hints and the host contract applied.

product_startup

No persistent product session at startup. Backends connect lazily.

product_cleanup

Disconnect any active backend at shutdown.

owning_product

Return the product that owns tool_name on this server.

connect_recovery

Return the reconnect instruction valid for THIS server’s connect.

extra_recovery

Return extra recovery fields for a not_connected result.

toolset_catalogue

Return the toolset catalog used by build_toolsets().

build_toolsets

Build toolset definitions filtered to the tools this leaf exposes.

register_run_code_observer

Register a callable invoked after every run_code tool call.

backend

Return the active backend instance.

exposed_tools

Names of the tools this server was asked to expose.

Import detail#

from ansys.fluent.mcp.common.base import FluentLeafMCP

Property detail#

property FluentLeafMCP.backend: ansys.fluent.mcp.common.backend.Backend#

Return the active backend instance.

Returns:
Backend

Backend produced by the operation.

property FluentLeafMCP.exposed_tools: frozenset[str]#

Names of the tools this server was asked to expose.

Attribute detail#

FluentLeafMCP.leaf_name: str = 'fluent'#
FluentLeafMCP.default_backend_kind: str | None = None#
FluentLeafMCP.cache_ttl_seconds: float = 30.0#
FluentLeafMCP.host_contract: bool = True#

Method detail#

FluentLeafMCP.run(transport: str = 'stdio', host: str | None = None, port: int | None = None) → None#

Start the MCP server via the parent implementation when available.

Parameters:
transportstr

Transport name used to run the MCP server.

hoststr | None

Host interface used by the server transport.

portint | None

Port used by the selected server transport.

Returns:
None

The function completes through its side effects.

FluentLeafMCP.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_namestr | None

Registered tool name.

Returns:
dict[str, bool] | None

readOnlyHint / destructiveHint / idempotentHint, or None when the tool is unclassified.

FluentLeafMCP.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_fnAny

Tool name or function, as accepted by FastMCP.tool.

argsAny

Positional arguments forwarded to FastMCP.tool.

kwargsAny

Keyword arguments forwarded to FastMCP.tool.

Returns:
Any

Whatever FastMCP.tool returns (a decorator or a tool).

FluentLeafMCP.product_startup() → None#

No persistent product session at startup. Backends connect lazily.

Returns:
None

The function completes through its side effects.

FluentLeafMCP.product_cleanup() → None#

Disconnect any active backend at shutdown.

Returns:
None

The function completes through its side effects.

FluentLeafMCP.owning_product(tool_name: str) → str | None#

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_namestr

Registered tool name.

Returns:
Optional[str]

The owning product name, or None when this server cannot tell.

FluentLeafMCP.connect_recovery(product: str | None) → 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:
productOptional[str]

Product that owns the failing tool (unused by the base leaf, whose connect is already product-scoped).

Returns:
dict[str, Any]

next_tool plus either next_tool_args or next_tool_choices.

FluentLeafMCP.extra_recovery(product: str | None) → 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:
productOptional[str]

Value returned by owning_product() for the failing tool.

Returns:
dict[str, Any]

Extra keyword fields for the not_connected payload.

FluentLeafMCP.toolset_catalogue() → dict[str, dict[str, Any]]#

Return the toolset catalog used by build_toolsets().

Subclasses that register extra tools override this and merge their own groups into super().toolset_catalogue().

Returns:
dict[str, dict[str, Any]]

Toolset name to description / skill / tools.

FluentLeafMCP.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:
list[dict[str, Any]]

Mapping containing the operation result.

FluentLeafMCP.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 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:
observerCallable[…, Awaitable[None] | None]

Observer callback invoked after run-code execution.

Returns:
None

The function completes through its side effects.