The proxy.py module#
Summary#
Routing state of one proxy process. |
Return the MCP endpoint URL of a lane. |
|
Check whether an exception is, or wraps, a |
|
Return a recovery hint if a tool output reveals a broken AEDT connection. |
|
Classify a lane |
|
Return a lane |
|
Return the AEDT gRPC port a lane is attached to, within a time bound. |
|
Build a tool that forwards |
|
List the tools a lane started with |
|
Return the proxy instructions: the regular system prompt plus lane guidance. |
|
Add the lane management and recovery tools to |
|
Build the routing proxy server. |
Seconds between progress notifications while a routed call is pending. |
|
Backend arguments the proxy cannot support. |
|
Description#
Stdio routing proxy that multiplexes AEDT sessions (“lanes”).
The proxy is what an MCP client starts with ansys-aedt-mcp --lanes. It:
Lists the regular PyAEDT-MCP tools in-process, applying the same tag filters as the regular CLI. No backend is spawned at startup.
Registers one routing wrapper per tool. Each wrapper forwards the call to the lane selected in this proxy process, or fails fast when none is.
Adds lane management tools (
spawn_lane,switch_lane, and so on) plus health and recovery helpers.
The selected lane is per proxy process, so every client window gets an independent view of the same machine-wide fleet.
Module detail#
- proxy.is_auth_rejection(exc: BaseException) bool#
Check whether an exception is, or wraps, a
BackendAuthError.- Parameters:
- exc
BaseException Exception to inspect, including exception groups and chained causes.
- exc
- Returns:
- bool
Trueif a lane rejected the token.
- proxy.broken_connection_hint(text: str) str | None#
Return a recovery hint if a tool output reveals a broken AEDT connection.
- proxy.diagnose_status(status: dict[str, Any]) dict[str, Any]#
Classify a lane
check_aedt_statuspayload.The AEDT process view comes from the backend’s own
available_sessionsscan; the client view comes from its PyAEDTDesktop.
- async proxy.probe_lane_status(host: str, port: int, timeout: float | None = DEFAULT_PROBE_TIMEOUT, auth_token: str | None = None) dict[str, Any]#
Return a lane
check_aedt_statuspayload within a time bound.
- async proxy.probe_lane_aedt_port(host: str, port: int, timeout: float | None = DEFAULT_PROBE_TIMEOUT, auth_token: str | None = None) int | None#
Return the AEDT gRPC port a lane is attached to, within a time bound.
- proxy.make_routing_tool(upstream_tool: mcp.types.Tool, state: ProxyState) fastmcp.tools.Tool#
Build a tool that forwards
upstream_toolto the selected lane.The routed tool keeps the upstream name, description, schemas, title, annotations, and tags, so clients see the same tool surface as with the regular server.
- Parameters:
- upstream_tool
mcp.types.Tool Upstream tool definition.
- state
ProxyState Routing state shared by every tool of the proxy.
- upstream_tool
- Returns:
fastmcp.tools.ToolRouting tool.
- async proxy.list_upstream_tools(backend_args: list[str]) list[mcp.types.Tool]#
List the tools a lane started with
backend_argswould serve.The regular server is imported in-process and the same tag filters as its CLI are applied:
--connecthides the connection tools and--include-contextadds the context helpers.
- proxy.build_instructions() str#
Return the proxy instructions: the regular system prompt plus lane guidance.
- Returns:
strServer instructions.
- proxy.register_management_tools(server: fastmcp.FastMCP, state: ProxyState) None#
Add the lane management and recovery tools to
server.Every tool returns an
{"ok": False, "error": ...}payload instead of raising.- Parameters:
- server
fastmcp.FastMCP Proxy server.
- state
ProxyState Routing state shared with the routing tools.
- server
- async proxy.build_proxy(host: str = spawner.DEFAULT_HOST, startup_timeout: float = spawner.DEFAULT_STARTUP_TIMEOUT, backend_args: list[str] | None = None, probe_timeout: float | None = DEFAULT_PROBE_TIMEOUT, handshake_timeout: float = DEFAULT_HANDSHAKE_TIMEOUT) fastmcp.FastMCP#
Build the routing proxy server.
Nothing is spawned: the upstream tools are listed in-process and no lane is selected until the client calls
spawn_laneorswitch_lane.- Parameters:
- host
str, default: “127.0.0.1” Host lanes listen on.
- startup_timeout
float, default: 60.0 Seconds a new lane gets to bind its port.
- backend_args
list[str],optional Additional
ansys-aedt-mcparguments for spawned lanes.- probe_timeout
float, default: 10.0 Seconds a lane gets to answer a status probe.
- handshake_timeout
float, default: 5.0 Seconds a lane gets to answer the MCP handshake of a routed call.
- host
- Returns:
fastmcp.FastMCPProxy server ready to run over stdio.
- Raises:
ValueErrorIf
backend_argscontains an unsupported option.
- proxy.DEFAULT_SHUTDOWN_TIMEOUT = 10.0#
- proxy.DEFAULT_PROBE_TIMEOUT = 10.0#
- proxy.DEFAULT_HANDSHAKE_TIMEOUT = 5.0#
- proxy.DEFAULT_RECONNECT_TIMEOUT = 180.0#
- proxy.HEARTBEAT_INTERVAL = 10.0#
Seconds between progress notifications while a routed call is pending.
- proxy.ROUTED_TAG = 'routed'#
- proxy.LANES_TOOLSET = 'lanes'#
- proxy.UNSUPPORTED_BACKEND_ARGS = ('--dynamic-tool-discovery',)#
Backend arguments the proxy cannot support.
The proxy opens a new MCP session per routed call, so per-session tool gating would hide the AEDT-only tools forever.
- proxy.LANE_INSTRUCTIONS = Multiline-String#
Show Value
"""## Lanes This server routes AEDT tool calls through "lanes". Every AEDT tool call is forwarded to the lane currently selected. - A lane is an isolated backend that owns at most one AEDT session. Independent lanes let you run parallel work (e.g. baseline vs. experiment) without projects interfering. - No lane is selected when this server starts, so AEDT tools fail with "No lane selected" until you pick one. Start with list_lanes: switch_lane to continue on an existing lane (lanes are shared by every client on this machine), or spawn_lane to create one. - Name lanes like git branches, after the work ("patch-antenna", "filter-tuning"), never generic ("default", "main", "test") and never ports or numeric ids. - "AEDT session" means a running ansysedt process, as reported by check_aedt_status. It is not the same as a lane. One lane owns one AEDT session. Typical flow: 1. list_lanes() # anything to reuse? then switch_lane("
") and skip 2-3 2. spawn_lane("patch-antenna") # ~5s: creates the lane and routes to it 3. launch_aedt(...) # ~30-90s: runs INSIDE patch-antenna 4. ... use any AEDT tool normally ... 5. stop_lane("patch-antenna") # when the work is finished and nobody else uses it Rules: - spawn_lane does NOT launch AEDT. Call launch_aedt (or connect_to_aedt) next. - Use switch_lane to change where subsequent AEDT tool calls land. - current_lane / list_lanes tell you where you are and what exists. - stop_lane shuts a lane down; if it was the selected one, no lane is selected afterwards. - If AEDT calls on a lane start failing oddly (e.g. after an external PyAEDT script or toolkit used the same AEDT, or "[WinError 127]"), run check_lane. recycle_lane restarts the lane's backend and re-attaches it to the same AEDT without closing AEDT. - If things get wedged: reap_lanes (soft), reset_lanes (harder), unlock_registry_files. - "Lane ... is busy" means that lane's backend is blocked in a long AEDT call and your call was NOT sent. Don't retry in a tight loop: wait, check current_lane (in_flight), ask the user whether AEDT shows a dialog or is solving, or continue on another lane. """
- proxy.logger#