Backend#
- class ansys.fluent.mcp.common.backend.Backend#
Bases:
abc.ABCCommon interface for all backends.
Concrete subclasses override only the methods their product supports. Default implementations raise BackendUnavailableError.
Overview#
Connect to the configured backend or service. |
|
Return whether connected. |
Override if the backend holds a persistent resource. |
|
Return backend status information. |
|
List named objects entries. |
|
Return the instance names for a single named-object collection. |
|
Resolve a symbolic name across every named-object collection. |
|
Return the state. |
|
Return the active status. |
|
Return the allowed values. |
|
Batched per-node settings-attribute fetch. |
|
Recursively fetch attributes for all children of |
|
Cheap pre-flight probe for a batch of settings paths. |
|
Return the keyword-argument signature of a command path. |
|
Return the help. |
|
Return solver status information from the backend. |
|
Describe the field shape of a fresh child of a named-object collection. |
|
Enumerate solver field/variable names available for reports/post. |
|
Return the targeted context. |
|
Return |
|
Retrieve candidate Fluent settings APIs for |
|
Execute Python code through the backend runtime. |
|
Default validation: AST parse + forbidden-call scan. |
|
Return live mesh element totals. |
|
Return live mesh-quality summary statistics. |
|
Return Fluent’s full |
|
Start or resume the managed Fluids One component. |
|
Stop the managed Fluids One component. |
|
Update the managed Fluids One component. |
|
Refresh the managed Fluids One component. |
|
Capture a screenshot from the backend runtime. |
|
Drop cached mesh-probe results. |
|
Drop the mesh cache when |
|
Clear cached backend state. |
|
Drop caches that depend on solver state. |
Import detail#
from ansys.fluent.mcp.common.backend import Backend
Attribute detail#
Method detail#
- abstractmethod Backend.connect(**kwargs: Any) ansys.fluent.mcp.common.models.ConnectResult#
- Async:
Connect to the configured backend or service.
- Parameters:
- kwargs
Any Keyword arguments forwarded to the callable.
- kwargs
- Returns:
ConnectResultConnectResult produced by the operation.
- async Backend.disconnect() None#
Override if the backend holds a persistent resource.
- Returns:
NoneThe function completes through its side effects.
- abstractmethod Backend.is_connected() bool#
Return whether connected.
- Returns:
- bool
Boolean result of the operation.
- Backend.status(leaf: str) ansys.fluent.mcp.common.models.SessionStatus#
Return backend status information.
- Parameters:
- leaf
str Leaf MCP server instance under test.
- leaf
- Returns:
SessionStatusSessionStatus produced by the operation.
- async Backend.get_named_object_names(collection_path: str) list[str]#
Return the instance names for a single named-object collection.
Default implementation calls
list_named_objects()and filters. Backends with a directget_object_names()accessor (e.g. PyFluent) should override this for a cheaper single-node round-trip.
- async Backend.find_named_object(name: str) list[dict[str, Any]]#
Resolve a symbolic name across every named-object collection.
Accepts:
Literal identifiers (
"inlet-1") — exact and substring matches are returned, exact first.Glob patterns (
"wall-*","*bar*|*tabzone*") — every live name matching the pattern is returned with"exact": True(the pattern itself stands in for an exact intent against the matched key) and an"is_pattern": Trueflag on each entry plus a top-levelpattern_sourcepayload so callers know the source query was a pattern.
Default implementation calls
list_named_objects()and filters; backends with a faster index may override.
- async Backend.get_node_attrs(paths: list[str], attrs: list[str]) dict[str, dict[str, Any]]#
Batched per-node settings-attribute fetch.
Returns
{path: {attr: value}}. Backends with a live solver session should override; the default raisesBackendUnavailableErrorso callers can fall back to the per-attr accessors (get_active_status,get_allowed_values).
- async Backend.get_node_attrs_bulk(parent_path: str, attrs: list[str]) dict[str, dict[str, Any]]#
Recursively fetch attributes for all children of
parent_path.Calls
node.get_attrs(attrs, recursive=True)in a single Scheme RPC, replacing N per-field round-trips when the caller needs metadata for a whole subtree (e.g. validating every field in aset_namedvalue dict).Returns
{relative_child_path: {attr: value}}. Attr spellings follow the Scheme convention ("min","max","units-quantity","allowed-values","active?").The default returns
{}so callers can fall back gracefully to per-pathget_node_attrscalls.
- async Backend.probe_path(paths: list[str]) dict[str, dict[str, Any]]#
Cheap pre-flight probe for a batch of settings paths.
Returns
{path: {exists, is_active, is_user_creatable, kind}}in a single batched RPC. Live backends should override; the default raisesBackendUnavailableError.
- async Backend.get_command_arguments(path: str) dict[str, Any] | None#
Return the keyword-argument signature of a command path.
Returns
Noneif the backend cannot introspect commands or the path is not a command. The result shape is:{"argument_names": ["type", "name"], "arguments": {"type": {...}, ...}}
Backends with a live solver session should override.
- async Backend.describe_named_object_template(path: str) dict[str, Any] | None#
Describe the field shape of a fresh child of a named-object collection.
Returns
Nonewhen the backend cannot introspect templates. Live backends should override.
- async Backend.list_fields(*, scope: str = 'any') dict[str, Any] | None#
Enumerate solver field/variable names available for reports/post.
Returns
Nonewhen unavailable.
- async Backend.get_targeted_context(*, paths_to_check: list[str], named_object_types: list[str] | None = None, instance_state_fetch: list[str] | None = None) dict[str, Any]#
Return the targeted context.
- Parameters:
- Returns:
- async Backend.mesh_adjacency_probe(cellzones: list[str], *, bc_filter: tuple[str, Ellipsis] | None = None) dict[str, list[str]]#
Return
{cellzone -> [adjacent_face_zone_names]}.Implementations walk every BC family that exposes
adjacent_cell_zone(wall, velocity_inlet, pressure_outlet, mass_flow_inlet, …) and invert the mapping. Coupled-wallshadow_face_zoneentries are added to BOTH sides so cellzone↔cellzone neighbour queries (set-intersection on shared face names) find CHT solid–fluid pairs.bc_filterrestricts the walk to the listed BC families (e.g.("wall",)to answer “walls adjacent to X”,("velocity_inlet", "pressure_inlet")for inlets, …).None(default) walks every supported family. The shadow traversal only contributes when"wall"is in scope (or the filter is None) — interior families have no shadow concept.Limitation: interior face zones are not enumerated — they are gated INACTIVE on
boundary_conditions.interior[*]and themesh.adjacencyCommand’s argument-binding side-channel is broken on Fluent ≥ 27.1. Callers needing interior coverage must supplement withrun_code.Backends without a live solver session must raise
BackendUnavailableError.
- async Backend.find_api(query: str, *, top_k: int = 10, kinds: list[str] | None = None, under: str | None = None) list[dict[str, Any]]#
Retrieve candidate Fluent settings APIs for
query.Uses the configured lexical
ApiRetriever, which performs BM25 ranking over the bundled Fluent API catalog and PyFluent class docstrings.Returns a list of
{path, kind, score, ...}hits. Backends may override to add live cross-checks (e.g. filter out paths whose immediate parent does not exist on the connected solver).- Parameters:
- Returns:
-
async Backend.run_code(code: str, *, namespace: dict[str, Any] | None = None, filename: str = '
' ) ansys.fluent.mcp.common.models.RunCodeResult# Execute Python code through the backend runtime.
- async Backend.validate_code(code: str) ansys.fluent.mcp.common.models.RunCodeResult#
Default validation: AST parse + forbidden-call scan.
Backends with a live solver session can override to add semantic checks against the connected model.
- Parameters:
- code
str Python code snippet to validate or execute.
- code
- Returns:
RunCodeResultResult produced by the function.
- async Backend.mesh_counts() dict[str, int | None]#
Return live mesh element totals.
Output shape:
{"cell_count", "face_count", "node_count"}— each value is anintwhen the underlying solver exposes the count, orNonewhen the count is unavailable (no mesh loaded, partition pending, or the backend has no introspection path to mesh totals). Callers MUST treatNoneasunknown— never as zero.The default raises
BackendUnavailableErrorso backends that have no live solver (Fluids One geometry / mesh / post leaves) decline the probe; the smart-defaults wrapper catches this and falls back to an all-Nonepayload. Solve backends override this to query Fluent (e.g. via the Scheme variablestinfo/n-cellsetc.).
- async Backend.mesh_quality() dict[str, float | None]#
Return live mesh-quality summary statistics.
Output shape:
{"min_orthogonal_quality", "max_ortho_skew", "max_aspect_ratio"}— each value is afloatin its native Fluent range (orthogonal quality 0..1 where higher is better; ortho skew 0..1 where lower is better; aspect ratio ≥ 1) orNonewhen the metric is not available (no mesh loaded,mesh.qualityfailed, or the report wording on the connected Fluent build doesn’t match the parser).Callers MUST treat
Noneasunknown— never as a passing score. Backends should cache the result (mesh quality is invariant between mutations) and invalidate on mesh-modifying operations (case load, scale, translate, rotate, adapt, repair).The default raises
BackendUnavailableError. Solve backends override this to invoke Fluent’smesh.qualitysettings command and parse the captured transcript.
- async Backend.mesh_check() dict[str, Any]#
Return Fluent’s full
mesh.checkreport as structured data.Output shape (all keys optional — a value is
Nonewhen the corresponding line was not present in the captured transcript):{ "domain_extents": {"x": (min, max), "y": (min, max), "z": (min, max)}, "volume_min": float | None, "volume_max": float | None, "volume_total": float | None, "face_area_min": float | None, "face_area_max": float | None, "errors": list[str], # lines preceded by "Error:" "warnings": list[str], # lines preceded by "Warning:" "raw": str, # the verbatim transcript chunk }
mesh.checkis the right pre-flight diagnostic — it covers topology (left-handed cells, non-positive volumes, face handedness, periodic / boundary-pair sanity) on top of the bulk statistics. It does NOT print quality numbers in modern Fluent builds (seemesh_quality()for those).The default raises
BackendUnavailableError.
- async Backend.activate_component() dict[str, Any]#
Start or resume the managed Fluids One component.
Sends POST
/api/session/components/. Returns a status dict. Backends that do not talk to Fluids One raise/activate BackendUnavailableError.
- async Backend.deactivate_component() dict[str, Any]#
Stop the managed Fluids One component.
Sends POST
/api/session/components/. Returns a status dict. Backends that do not talk to Fluids One raise/deactivate BackendUnavailableError.
- async Backend.update_component() dict[str, Any]#
Update the managed Fluids One component.
Sends POST
/api/session/components/. Returns a status dict. Backends that do not talk to Fluids One raise/update BackendUnavailableError.
- async Backend.refresh_component() dict[str, Any]#
Refresh the managed Fluids One component.
Sends POST
/api/session/components/. Returns a status dict. Backends that do not talk to Fluids One raise/refresh BackendUnavailableError.
- async Backend.screenshot(*, view: str | None = None) dict[str, Any]#
Capture a screenshot from the backend runtime.
- Backend.invalidate_mesh_cache() None#
Drop cached mesh-probe results.
- Returns:
NoneThe function completes through its side effects.
- Backend.maybe_invalidate_mesh_cache(code: str) bool#
Drop the mesh cache when
codematches a mutation marker.
- Backend.invalidate_cache() None#
Clear cached backend state.
- Returns:
NoneThe function completes through its side effects.
- Backend.invalidate_live_caches() None#
Drop caches that depend on solver state.
Called by the framework after every
run_codeand afterconnect. The mesh-probe cache is preserved; useinvalidate_mesh_cache()ormaybe_invalidate_mesh_cache()to drop it explicitly.- Returns:
NoneThe function completes through its side effects.