PyLumericalMCP#
- class ansys.lumerical.mcp.server.PyLumericalMCP(config: ansys.lumerical.mcp.config.Config | None = None, python_executable: str | None = None, working_directory: str | None = None, **kwargs)#
Bases:
ansys.common.mcp.PyAnsysBaseMCPMCP server exposing Ansys Lumerical (via PyLumerical) to LLM agents.
Hosts a single
PersistentPythonSessionsubprocess that owns all live Lumerical handles. Multiple named sessions of any product type (FDTD/MODE/DEVICE/INTERCONNECT) live in that subprocess as_lumerical_sessions[name]. The MCP server only tracks metadata.
Overview#
Build the typed app context with the Lumerical-aware subprocess. |
|
Run framework startup logging after subprocess launch. |
|
Close Lumerical handles before tearing down the subprocess. |
|
No-op: Lumerical handle cleanup happens in |
|
Lifespan wrapper that keeps the event loop responsive on shutdown. |
Import detail#
from ansys.lumerical.mcp.server import PyLumericalMCP
Method detail#
- PyLumericalMCP.create_context() ansys.lumerical.mcp.context.PyLumericalContext#
Build the typed app context with the Lumerical-aware subprocess.
Uses
LumericalPersistentPythonSessionso that long, silent Lumerical startup phases (FDTD()/MODE()/ …). Don’t trip the framework’s 0.5 s no-data safety break and lose their output.
- PyLumericalMCP.cleanup_python_session() None#
Close Lumerical handles before tearing down the subprocess.
_lum_close_all()must run while the subprocess is still alive. It is flushed here (best-effort, bounded by_CLOSE_ALL_JOIN_TIMEOUT_Svia a daemon thread) before delegating to the base teardown. Running it inproduct_cleanupwould be too late. The subprocess is gone by then, and lumapi’s child processes are left orphaned.Stays synchronous so direct unit tests work without an event loop;
product_lifespan()offloads the call viaasyncio.to_thread().
- PyLumericalMCP.product_cleanup() None#
No-op: Lumerical handle cleanup happens in
cleanup_python_session.
- async PyLumericalMCP.product_lifespan(server: fastmcp.FastMCP) AsyncIterator[ansys.lumerical.mcp.context.PyLumericalContext]#
Lifespan wrapper that keeps the event loop responsive on shutdown.
Identical to the base
PyAnsysBaseMCP.product_lifespan()except that the potentially slowcleanup_python_session()(which runs_lum_close_all()against the live subprocess) is dispatched viaasyncio.to_thread(), so the synchronous teardown can’t freeze the event loop and block the STDIO transport from flushing its final JSON-RPC writes. Startup stays on the loop – it’s fast and runs before any tool traffic.