PyMechanicalAppContext#

class ansys.mechanical.mcp.server.PyMechanicalAppContext#

Bases: ansys.common.mcp.context.PyAnsysBaseAppContext

Application context with typed dependencies and CLI options.

Attributes:
mechanicalOptional[Any]

Mechanical instance connection.

owns_mechanicalbool

Whether this server launched the connected Mechanical instance. Only owned instances are shut down on disconnect or server exit; attached instances are released and left running.

lifecycle_lockasyncio.Lock

Serializes launch, connect, and disconnect operations.

session_jobOptional[Any]

Launch or connect operation that is still in progress, if any.

change_previewsdict

Pending property change previews by token. Each token is single use and expires after a few minutes.

transport_typestr

Transport type for PyMechanical-MCP. Options are 'stdio' and 'http'.

mechanical_ipOptional[str]

IP address or hostname for Mechanical connection.

mechanical_portOptional[int]

Port number for Mechanical connection.

connect_on_startupbool

Whether to attempt Mechanical connection on PyMechanical-MCP startup.

static_toolsbool

Whether to expose all tools from startup instead of dynamically hiding tools that require an active Mechanical connection. When False (default), tools tagged requires_mechanical stay hidden until launch_mechanical or connect_to_mechanical succeeds.

http_hoststr

Host address for HTTP transport.

http_portint

Port number for HTTP transport.

cors_originsOptional[list[str]]

List of allowed CORS origins for HTTP transport.

grpc_transport_modeOptional[str]

gRPC transport mode for Mechanical connections. Options are 'auto', 'insecure', 'mtls', and 'wnua'. When set to 'auto' (default), the mode is determined automatically based on the platform and certificate availability.

certs_dirOptional[str]

Path to directory containing mTLS certificate files (ca.crt, client.crt, and client.key). Used when grpc_transport_mode is 'mtls'.

Overview#

Import detail#

from ansys.mechanical.mcp.server import PyMechanicalAppContext

Property detail#

property PyMechanicalAppContext.product_instance: Any | None#

Returns the Mechanical instance for backward compatibility.

Returns:
Optional[Any]

Mechanical instance or None if not connected.

Attribute detail#

PyMechanicalAppContext.mechanical: Any | None = None#
PyMechanicalAppContext.owns_mechanical: bool = False#
PyMechanicalAppContext.lifecycle_lock: asyncio.Lock#
PyMechanicalAppContext.session_job: Any | None = None#
PyMechanicalAppContext.change_previews: dict[str, dict[str, Any]]#
PyMechanicalAppContext.transport_type: str = 'stdio'#
PyMechanicalAppContext.mechanical_ip: str | None = None#
PyMechanicalAppContext.mechanical_port: int | None = None#
PyMechanicalAppContext.connect_on_startup: bool = False#
PyMechanicalAppContext.static_tools: bool = False#
PyMechanicalAppContext.http_host: str = '127.0.0.1'#
PyMechanicalAppContext.http_port: int = 8080#
PyMechanicalAppContext.cors_origins: list[str] | None = None#
PyMechanicalAppContext.grpc_transport_mode: str | None = None#
PyMechanicalAppContext.certs_dir: str | None = None#