Backend#

class ansys.cfx.mcp.common.backend.Backend#

Bases: abc.ABC

Common interface for all backends.

Concrete subclasses override only the methods their product supports. Default implementations raise a BackendUnavailable error.

Overview#

connect

Connect this backend to a CFX runtime or service.

is_connected

Whether the backend is currently connected.

disconnect

Disconnect this backend from its active CFX runtime or service.

status

Return a structured status summary for the active CFX backend or session manager.

codegen

Generate CFX Python code or return a clarification request.

clarify

Continue code generation after a clarification answer.

error_remediation

Return recovery guidance for a failed backend operation.

list_named_objects

List named objects available in the active context.

select_named_objects

Return the subset of requested named objects that are available.

get_help

Return help information for a backend-specific API path.

solver_status

Return solver status information for the backend.

get_named_object_names

Return named object names for the active CFX context.

find_named_object

Find named object matching the request.

get_state

Get the state for the active CFX context.

get_active_status

Get the active/inactive status for a CFX path or component.

get_allowed_values

Get allowed values for a CFX path from live state or schema metadata.

get_node_attrs

Get selected attributes for one or more backend nodes.

get_node_attrs_bulk

Get selected attributes for children under a parent backend node.

probe_path

Check whether a backend path can be resolved.

get_command_arguments

Get argument metadata for a command-like CFX path.

describe_named_object_template

Describe the fields used when creating a named CFX object.

list_fields

List fields available for a backend object or schema scope.

get_targeted_context

Return a compact context slice for the requested CFX paths or objects.

mesh_adjacency_probe

Return mesh adjacency information for candidate boundary locations.

find_api

Find the API matching the request.

run_code

Execute Python code against the active CFX backend namespace.

validate_code

Validate Python code without mutating the active backend.

mesh_counts

Return mesh entity counts reported by the backend.

mesh_quality

Return mesh quality metrics reported by the backend.

mesh_check

Run backend mesh checks and return their diagnostics.

activate_component

Activate a backend component for later operations.

deactivate_component

Deactivate a backend component that should no longer receive operations.

update_component

Update backend component state with new data.

refresh_component

Refresh backend component state from the active session.

screenshot

Capture a screenshot from the active backend, when supported.

invalidate_cache

Clear cached backend data that may no longer reflect the active CFX session.

invalidate_live_caches

Clear live CFX session caches after the model or session state changes.

Import detail#

from ansys.cfx.mcp.common.backend import Backend

Attribute detail#

Backend.kind: str = 'unknown'#
Backend.label: str = 'Unknown backend'#

Method detail#

abstractmethod Backend.connect(**kwargs: Any) ansys.cfx.mcp.common.models.ConnectResult#
Async:

Connect this backend to a CFX runtime or service.

Parameters:
kwargsAny

Keyword arguments forwarded to the wrapped callable.

Returns:
ConnectResult

Connection result describing the selected backend session.

async Backend.disconnect() None#

Disconnect this backend from its active CFX runtime or service.

Returns:
None

No value is returned. Side effects are applied to the relevant cache, session, or server.

abstractmethod Backend.is_connected() bool#

Whether the backend is currently connected.

Returns:
bool

Whether the backend currently has an active CFX connection.

Backend.status(leaf: str) ansys.cfx.mcp.common.models.SessionStatus#

Return a structured status summary for the active CFX backend or session manager.

Parameters:
leafstr

Leaf server or backend name associated with the status payload.

Returns:
dict[str, Any]

Structured status payload for the active backend or session manager.

async Backend.codegen(prompt: str, *, session_id: str | None = None, context: dict[str, Any] | None = None) ansys.cfx.mcp.common.models.CodegenResult#

Generate CFX Python code or return a clarification request.

Parameters:
promptstr

Natural-language user request to process.

session_idOptional[str], default: None

Conversation identifier to use to retrieve or continue context.

contextOptional[dict[str, Any]], default: None

Additional context supplied by the caller.

Returns:
CodegenResult

Generated-code response or clarification request.

async Backend.clarify(session_id: str, clarification_id: str, answer: str) ansys.cfx.mcp.common.models.CodegenResult#

Continue code generation after a clarification answer.

Parameters:
session_idstr

Conversation identifier used to retrieve or continue context.

clarification_idstr

Identifier of the clarification being answered or checked.

answerstr

User answer to the clarification prompt.

Returns:
CodegenResult

Generated-code response or clarification request.

async Backend.error_remediation(remediation_request: str, *, context: dict[str, Any] | None = None) ansys.cfx.mcp.common.models.RemediationResult#

Return recovery guidance for a failed backend operation.

Parameters:
remediation_requeststr

Error text, failing code, or diagnostic request to explain and remediate.

contextOptional[dict[str, Any]], default: None

Optional backend status, validation result, or MCP tool context.

Returns:
RemediationResult

Structured remediation advice from the backend.

async Backend.list_named_objects() dict[str, Any]#

List named objects available in the active context.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.select_named_objects(names: list[str]) list[str]#

Return the subset of requested named objects that are available.

Parameters:
nameslist[str]

Candidate named-object names.

Returns:
list[str]

Matching named-object names.

async Backend.get_help(path: str) dict[str, Any]#

Return help information for a backend-specific API path.

Parameters:
pathstr

API path to describe.

Returns:
dict[str, Any]

Structured help payload.

async Backend.solver_status() dict[str, Any]#

Return solver status information for the backend.

Returns:
dict[str, Any]

Structured solver-status payload.

async Backend.get_named_object_names(collection_path: str) list[str]#

Return named object names for the active CFX context.

Parameters:
collection_pathstr

Named-object collection path to read, such as a boundary or domain collection.

Returns:
list[str]

Names in the requested collection, or an empty list when named objects are not available.

async Backend.find_named_object(name: str) list[dict[str, Any]]#

Find named object matching the request.

Parameters:
namestr

Name of the object, resource, or field to process.

Returns:
list[dict[str, Any]]

List of structured records matching the request.

async Backend.get_state(paths: list[str] | None = None) dict[str, Any]#

Get the state for the active CFX context.

Parameters:
pathslist[str] | None, default: None

Backend paths to inspect.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.get_active_status(paths: list[str]) dict[str, bool]#

Get the active/inactive status for a CFX path or component.

Parameters:
pathslist[str]

Backend paths to inspect.

Returns:
dict[str, Any]

Structured active-status payload for the requested path or component.

async Backend.get_allowed_values(paths: list[str]) dict[str, list[Any]]#

Get allowed values for a CFX path from live state or schema metadata.

Parameters:
pathslist[str]

Backend paths to inspect.

Returns:
dict[str, list[Any]]

Structured allowed-values payload for the requested path.

async Backend.get_node_attrs(paths: list[str], attrs: list[str]) dict[str, dict[str, Any]]#

Get selected attributes for one or more backend nodes.

Parameters:
pathslist[str]

Backend node paths whose attributes should be retrieved.

attrslist[str]

Attributes to retrieve from a backend node.

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

Mapping from each requested path to its available attribute values.

async Backend.get_node_attrs_bulk(parent_path: str, attrs: list[str]) dict[str, dict[str, Any]]#

Get selected attributes for children under a parent backend node.

Parameters:
parent_pathstr

Parent CFX path that owns the requested child fields.

attrslist[str]

Attributes to retrieve from a backend node.

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

Mapping from child path to the requested attribute values.

async Backend.probe_path(paths: list[str]) dict[str, dict[str, Any]]#

Check whether a backend path can be resolved.

Parameters:
pathslist[str]

Backend paths to resolve against the live state or schema metadata.

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

Resolution details for each requested path.

async Backend.get_command_arguments(path: str) dict[str, Any] | None#

Get argument metadata for a command-like CFX path.

Parameters:
pathstr

Command-like backend path whose arguments should be described.

Returns:
dict[str, Any] | None

Argument metadata when the backend can describe the command. Otherwise, None is returned.

async Backend.describe_named_object_template(path: str) dict[str, Any] | None#

Describe the fields used when creating a named CFX object.

Parameters:
pathstr

Named-object collection or type path to describe.

Returns:
dict[str, Any] | None

Template metadata for creating the object, or None when unavailable.

async Backend.list_fields(*, scope: str = 'any') dict[str, Any] | None#

List fields available for a backend object or schema scope.

Parameters:
scopestr, default:'any'

Scope used to filter available fields.

Returns:
dict[str, Any] | None

Requested CFX data or metadata for the active session.

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 a compact context slice for the requested CFX paths or objects.

Parameters:
paths_to_checklist[str]

CFX paths to check against the live state or schema metadata.

named_object_typeslist[str] | None, default: None

Named-object categories to include in context output.

instance_state_fetchlist[str] | None, default: None

Optional callback used to fetch the live instance state.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.mesh_adjacency_probe(cellzones: list[str], *, bc_filter: tuple[str, Ellipsis] | None = None) dict[str, list[str]]#

Return mesh adjacency information for candidate boundary locations.

Parameters:
cellzoneslist[str]

Mesh cell zones used for adjacency probing.

bc_filtertuple[str, …] | None, default: None

Optional boundary-condition filter for adjacency output.

Returns:
dict[str, list[str]]

Value computed by the helper for the requested CFX workflow.

async Backend.find_api(query: str, *, top_k: int = 10, kinds: list[str] | None = None, under: str | None = None) list[dict[str, Any]]#

Find the API matching the request.

Parameters:
querystr

Search query for ranking CFX API or object matches.

top_kint, default: 10

Maximum number of matches to return.

kindslist[str] | None, default: None

Optional result categories for narrowing the search.

understr | None, default: None

Optional CFX path prefix for scoping the search.

Returns:
list[dict[str, Any]]

List of structured records matching the request.

async Backend.run_code(code: str, *, namespace: dict[str, Any] | None = None, filename: str = '') ansys.cfx.mcp.common.models.RunCodeResult#

Execute Python code against the active CFX backend namespace.

Parameters:
codestr

Python source code submitted for validation, grounding, or execution.

namespacedict[str, Any] | None, default: None

Execution namespace containing safe builtins and active CFX objects.

filenamestr, default: ""

Synthetic filename used in compile diagnostics.

Returns:
RunCodeResult

Execution or validation result returned to the MCP caller.

async Backend.validate_code(code: str) ansys.cfx.mcp.common.models.RunCodeResult#

Validate Python code without mutating the active backend.

Parameters:
codestr

Python source code submitted for validation, grounding, or execution.

Returns:
RunCodeResult

Execution or validation result returned to the MCP caller.

async Backend.mesh_counts() dict[str, int | None]#

Return mesh entity counts reported by the backend.

Returns:
dict[str, int | None]

Value computed by the helper for the requested CFX workflow.

async Backend.mesh_quality() dict[str, float | None]#

Return mesh quality metrics reported by the backend.

Returns:
dict[str, float | None]

Value computed by the helper for the requested CFX workflow.

async Backend.mesh_check() dict[str, Any]#

Run backend mesh checks and return their diagnostics.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.activate_component() dict[str, Any]#

Activate a backend component for later operations.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.deactivate_component() dict[str, Any]#

Deactivate a backend component that should no longer receive operations.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.update_component() dict[str, Any]#

Update backend component state with new data.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.refresh_component() dict[str, Any]#

Refresh backend component state from the active session.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

async Backend.screenshot(*, view: str | None = None) dict[str, Any]#

Capture a screenshot from the active backend, when supported.

Parameters:
viewOptional[str], default: None

Optional view name for the screenshot capture.

Returns:
dict[str, Any]

Structured response payload for the requested operation.

Backend.invalidate_cache() None#

Clear cached backend data that may no longer reflect the active CFX session.

Returns:
None

No value is returned. Side effects are applied to the relevant cache, session, or server.

Backend.invalidate_live_caches() None#

Clear live CFX session caches after the model or session state changes.

Returns:
None

No value is returned. Side effects are applied to the relevant cache, session, or server.