Heuristic:8beeeaaat Touchdesigner mcp OP Type Reference Compatibility
| Knowledge Sources | |
|---|---|
| Domains | Cross_Version_Compatibility, Node_Graph |
| Last Updated | 2026-10-28 22:13 GMT |
Overview
Reference TouchDesigner OP type constants via `td.<TypeName>` (e.g. `td.resolutionTOP`) instead of bare globals (e.g. `resolutionTOP`) to ensure compatibility with both older and newer deployed `.tox` packages.
Description
TouchDesigner injects OP type names (`noiseTOP`, `resolutionTOP`, `moviefileinTOP`, etc.) as bare globals into the script execution namespace. However, this injection only happens in newer `mcp_webserver_base.tox` packages that include the fix from issue #185. Older deployed packages do not inject these globals, so a script that references `resolutionTOP` directly will fail with `NameError` on those deployments.
The fix is to reference OP types via the `td` module: `td.resolutionTOP`. The `td` module is always available (imported at the top of the script), and it exposes all OP type constants regardless of the `.tox` package version. This makes the generated script work against both older and newer deployed components.
Usage
Use this heuristic when:
- Writing Python scripts that will be executed via `exec_python_script` or `execute_python_script`.
- Creating nodes dynamically where the OP type is needed as a constant (e.g. `parent.create(td.resolutionTOP, name)`).
- Targeting compatibility with multiple versions of the `mcp_webserver_base.tox` component.
The Insight (Rule of Thumb)
- Action: Replace bare OP type globals (`resolutionTOP`) with `td.resolutionTOP` (or `td.<TypeName>` generally).
- Value: Prefix all OP type references with `td.` — the `td` module is always imported and always exposes these constants.
- Trade-off: Slightly more verbose, but eliminates a `NameError` on older `.tox` deployments. No functional difference on newer deployments.
- Compatibility: Works on all `mcp_webserver_base.tox` versions. The bare global approach only works on packages with the #185 fix.
Reasoning
The `exec_python_script` implementation in `api_service.py` merges the `__main__` module namespace (which contains TD globals) into the script's execution namespace. However, this merge only includes globals that already exist in `__main__`. On older `.tox` packages, the OP type constants were not injected into `__main__` at component startup, so they are absent from the merged namespace.
The `td` module, by contrast, is a built-in that TouchDesigner always provides. It exposes OP type constants as module attributes. Referencing `td.resolutionTOP` therefore works regardless of whether the bare global injection fix is present.
This was discovered during development of the `get_top_image` tool, which creates a temporary `resolutionTOP`. The initial implementation used the bare `resolutionTOP` global, which worked in the development environment but failed on older deployed components. The fix (issue #185) was to use `td.resolutionTOP` instead.
Code Evidence
The `buildGetTopImageScript` function documents this heuristic in its JSDoc:
From `src/features/tools/pythonScripts/getTopImageScript.ts:24-29`:
/**
* OP type constants are referenced via `td.resolutionTOP` (not the bare
* `resolutionTOP` global) because the bare global is only injected into the
* exec namespace by TD-side packages that include #185's global injection
* fix; `import td` + `td.resolutionTOP` works against both older and newer
* deployed `mcp_webserver_base.tox` packages.
*/
The generated Python script uses `td.resolutionTOP`:
From `src/features/tools/pythonScripts/getTopImageScript.ts:72`:
tmp_top = parent.create(td.resolutionTOP, tmp_name)
The script imports `td` at the top:
From `src/features/tools/pythonScripts/getTopImageScript.ts:41`:
import td