The html_window.py module#

Summary#

WindowResult

Outcome of an attempt to open a detached HTML window.

build_window_document

Build the wrapper page that sandboxes the supplied HTML.

find_app_browser

Find Microsoft Edge or Google Chrome to open --app windows.

display_unavailable_reason

Return why a local window cannot be shown, or None if it can.

open_html_window

Open HTML in a detached window on the machine running the MCP server.

BROWSER_ENV_VAR

Environment variable with the path of the Edge or Chrome executable to use.

VIEW_DIR_NAME

CONTENT_POLICY

Description#

Detached HTML window for clients without MCP Apps support.

The HTML is written to a temporary wrapper file and opened in a chromeless application window of an installed Microsoft Edge or Google Chrome browser. If neither is found, the default browser is used. Only the Python standard library is required.

The supplied HTML runs inside an iframe sandbox with an opaque origin and a Content Security Policy that blocks network access, external resources, forms, popups, and access to local files.

Module detail#

html_window.build_window_document(html: str, title: str, width: int | None = None, height: int | None = None) → str#

Build the wrapper page that sandboxes the supplied HTML.

The wrapper resizes its window to fit the rendered content. Dimensions given explicitly are kept fixed instead of being fitted.

Parameters:
htmlstr

HTML document or fragment to display.

titlestr

Window title.

widthint, optional

Fixed content width in pixels. Fitted to the content if None.

heightint, optional

Fixed content height in pixels. Fitted to the content if None.

Returns:
str

Complete HTML wrapper document.

html_window.find_app_browser() → str | None#

Find Microsoft Edge or Google Chrome to open --app windows.

The PYAEDT_MCP_HTML_BROWSER environment variable takes precedence.

Returns:
str | None

Path of the browser executable, or None if none was found.

html_window.display_unavailable_reason() → str | None#

Return why a local window cannot be shown, or None if it can.

Returns:
str | None

Reason a window cannot be displayed on this machine.

html_window.open_html_window(html: str, title: str, width: int | None = None, height: int | None = None) → WindowResult#

Open HTML in a detached window on the machine running the MCP server.

The window adjusts to the size of the rendered HTML, limited to the available screen area. Explicit dimensions override the fitted ones.

Parameters:
htmlstr

HTML document or fragment to display.

titlestr

Window title.

widthint, optional

Content width in pixels. Fitted to the HTML if None.

heightint, optional

Content height in pixels. Fitted to the HTML if None.

Returns:
WindowResult

How the HTML was opened, or why it could not be.

html_window.BROWSER_ENV_VAR = 'PYAEDT_MCP_HTML_BROWSER'#

Environment variable with the path of the Edge or Chrome executable to use.

html_window.VIEW_DIR_NAME = 'pyaedt-mcp-html-views'#
html_window.CONTENT_POLICY = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:;...#
html_window.logger#