Skip to main content
Glama
pointwise-mcp

pointwise-mcp

by Jash2012
README.md
# pointwise-mcp

An MCP server that lets Claude drive **Cadence Fidelity Pointwise** through Glyph.
It covers CAD import, automatic surface meshing, T-Rex boundary layers, the volume mesh,
quality checks and OpenFOAM export.

You need your own licensed installation of Fidelity Pointwise. This is an independent project, not
affiliated with or endorsed by Cadence; Fidelity Pointwise and Glyph are Cadence trademarks.

It has two backends:

- **batch** (default): each tool call writes a Glyph script into its own run folder, runs
  Pointwise's headless `tclsh.exe` on it with a timeout, and parses the structured result.
  State passes between steps through `.pw` project files.
- **live**: the same scripts go to a running Pointwise GUI through its Glyph Server
  (TCP, port 2807), so you can watch each step happen.

Tested on Windows 11 with Fidelity Pointwise 2023.2.2 (Glyph package 8.23.2, Tcl 8.5.7) and
Python 3.13.15. Other Pointwise versions have not been tested.

## Install

```powershell
cd pointwise-mcp
py -3.13 -m venv .venv
.venv\Scripts\python -m pip install -e ".[dev]"
.venv\Scripts\python -m pointwise_mcp --health
```

`--health` finds `tclsh.exe`, shows which `CDS_LIC_FILE` value it will pass and where that
value came from, and runs a small Glyph probe. It exits 1 if the probe fails.

### Finding Pointwise

The server looks for `tclsh.exe` in this order:

1. `POINTWISE_MCP_TCLSH`. This can also be a `.cmd`/`.bat` wrapper.
2. The registry key `HKLM\Software\Pointwise\<CurrentVersion>\tclsh`, which the installer writes.
3. `C:\Program Files\Cadence\FidelityPointwise2023.2.2\win64\bin\tclsh.exe`.

### Licence: `CDS_LIC_FILE`

Pointwise checks out its licence from your licence server, which it finds through `CDS_LIC_FILE`
(`port@host`, for example set as a machine-level Windows variable). A process only inherits the
variables that existed when it started. A Claude Desktop that was already running when the
variable was defined has no `CDS_LIC_FILE`, and neither does anything it launches. The server
therefore sets `CDS_LIC_FILE` on every `tclsh` it starts. It takes the value from the first of
these that is set:

1. `POINTWISE_MCP_CDS_LIC_FILE`, an explicit override.
2. `CDS_LIC_FILE` in the server's own environment, for example from the `env` block of the
   MCP config.
3. The user environment in the registry (`HKCU\Environment`).
4. The machine environment in the registry
   (`HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment`).

`pw_health` reports the value and its source (`cds_lic_file`, `cds_lic_file_source`). If the
checkout fails, Pointwise prints an `LMC-xxxxx` error and exits with code 127. Tools then fail
with `kind = "license"` and a message like this:

```
Pointwise licence check-out failed: ERROR (LMC-01902): License call failed. The license server
search path is defined as <none>. Can't find license file. ...
CDS_LIC_FILE passed to tclsh: <none> (source: not set). Check that lmgrd is running ...
```

### Claude Desktop entry

Open the config file from Claude Desktop (Settings → Developer → Edit Config), add this inside
`"mcpServers"` with your own paths and licence server, then quit Claude Desktop fully and reopen it:

```json
"pointwise": {
  "command": "C:\\path\\to\\pointwise-mcp\\.venv\\Scripts\\python.exe",
  "args": ["-m", "pointwise_mcp"],
  "env": {
    "CDS_LIC_FILE": "port@your-licence-server",
    "POINTWISE_MCP_WORKDIR": "C:\\path\\to\\pointwise_mcp_runs"
  }
}
```

### Settings (environment variables)

| Variable | Default | Meaning |
| --- | --- | --- |
| `CDS_LIC_FILE` / `POINTWISE_MCP_CDS_LIC_FILE` | from the registry | Licence server passed to tclsh |
| `POINTWISE_MCP_TCLSH` | from the registry | Path to Pointwise's `tclsh.exe` |
| `POINTWISE_MCP_WORKDIR` | `~\pointwise_mcp_runs` | Where run folders are created (`runs\<time>-<tool>-<id>`) |
| `POINTWISE_MCP_TIMEOUT` | `1800` | Default per-call timeout in seconds of awake time (see Timeouts); tools also take `timeout_seconds` |
| `POINTWISE_MCP_BACKEND` | `batch` | Default backend (`batch` or `live`) |
| `POINTWISE_MCP_MAX_PARALLEL` | `1` | Concurrent tclsh runs; each one checks out a licence seat |
| `PWI_GLYPH_SERVER_PORT` / `PWI_GLYPH_SERVER_AUTH` / `POINTWISE_MCP_GLYPH_HOST` | `2807` / empty / `localhost` | Live Glyph Server |
| `POINTWISE_MCP_WSL_DISTRO` | `Ubuntu-24.04` | WSL distro for `checkMesh` |
| `POINTWISE_MCP_OPENFOAM_BASHRC` | `/usr/lib/openfoam/openfoam2606/etc/bashrc` | OpenFOAM environment inside WSL |

## Tools

| Tool | What it does |
| --- | --- |
| `pw_health` | Finds tclsh, reports the licence value and its source, runs a probe (version, Glyph package, CAE solvers incl. OpenFOAM). `check_live` also pings the Glyph Server. |
| `pw_import_cad` | Imports STEP/IGES (or any format Pointwise reads) into a new `.pw`. Converts units (`units`) and can apply an extra `scale`. Assembles models if the file has none. Returns models, quilt names, extents and warnings. |
| `pw_surface_mesh` | Automatic Surface Mesh (`pw::DatabaseMesher`). Takes min/max edge spacing, curvature resolution angle, boundary growth rate, feature (hard) angle, refinement factor, max aspect ratio and algorithm. `quilt_spacing` sets a max spacing per quilt; `edge_refinement` adds boundary filters along the edges of matching quilts (spacing factor, optional 2D growth). Domains are named `<quilt>-dom`. |
| `pw_trex` | Sets up the boundary layer. If there is no block yet, it creates one: `farfield.mode="auto"` runs Automatic Volume Mesh (box/sphere/cylinder farfield plus symmetry planes); `"existing"` uses a closed set of domains. It then assigns T-Rex types by domain-name pattern (symmetry→Match, off→Off, adjacent_grid→AdjacentGrid, wall→Wall), sets `first_layer_height` on every Wall condition, and sets the block's T-Rex attributes: max/full layers, growth rate, collision buffer, skew criteria, cell type, push attributes. It does not create any cells. |
| `pw_volume` | Sets interior options (Delaunay or Voxel, decay, edge lengths, voxel sizes) and runs the unstructured solver's Initialize, which also grows the T-Rex layers. Returns cell counts by type and the number of T-Rex layers reached. |
| `pw_examine` | Runs Pointwise examine functions and reports min/max/average and the count outside limits. Defaults: max included angle >175°, equiangle skew >0.9, non-orthogonality >70°, volume ratio >20, aspect ratio, Jacobian <0, volume <0. Also reports per-block T-Rex counts. Does not change the project. |
| `pw_export_openfoam` | Sets the CAE solver to OpenFOAM, maps boundary domains to patches by pattern (first match wins) and exports to `<case_dir>/constant/polyMesh`. It can write a minimal `system/` and run `checkMesh` in WSL. It refuses to overwrite an existing polyMesh unless `overwrite=true`. |
| `pw_save` | Batch: re-saves a project under a new name. Live: saves the GUI session. |
| `pw_load` | Reports what a project contains: models and quilts, domains, blocks with T-Rex stats and solver attributes, BCs, T-Rex conditions and the CAE solver. Live: loads the project into the GUI. |
| `pw_run_glyph` | Guarded escape hatch: runs Glyph/Tcl and returns what it `puts` plus its result. See below. |

### How the tools behave

- **Projects.** Batch tools read `project` and write `save_as`. If `save_as` is omitted, the
  result replaces `project` in place. Pointwise first saves into the run folder, and the file
  is moved over `project` only after the step succeeds, so a failed step leaves the input
  unchanged. Use `save_as` whenever you want to keep the previous stage.
- **Live backend.** `project` is optional and the tools act on the open session. A tool that
  would replace that session (load or import) refuses if it has unsaved changes, unless you
  pass `discard_unsaved=true`.
- **Names and patterns.** Entity selection uses Tcl glob patterns on Pointwise names, e.g.
  `["wing*", "*-dom"]`. Naming after each step:
  - quilts keep the names of the CAD faces;
  - domains are `<quilt>-dom`;
  - Automatic Volume Mesh adds `farfield-xmin` … `farfield-zmax` and `symmetry-<side>`.
- **Run folders.** Every call keeps `script.glf`, `stdout.log`, `stderr.log`, `tclsh.pid` and
  `result.json` in its run folder (or `response.txt` for live calls). The response's `run_dir`
  points to it. `stdout.log` is written while Pointwise runs, so you can watch T-Rex layer
  progress there. `result.json` records the `outcome` (`ok` or the error kind), `elapsed_s`
  and `suspended_s` (time the computer was asleep).
- **Errors.** A failed call is an MCP tool error whose text starts with `kind=<kind>:`. The
  kinds are `license`, `timeout`, `cancelled`, `args`, `import`, `topology`, `init`, `export`,
  `unsaved`, `glyph`, `live`, `launch` and `crash`. The message includes Pointwise's last
  warnings or output and the run folder.

### Timeouts, sleep and leftover processes

- `timeout_seconds` limits one Pointwise run and counts **only time the computer is awake**.
  When it expires, Pointwise and everything it started are stopped, and the call fails with
  `kind=timeout`, the last lines Pointwise printed, and the run folder.
- **Sleep.** Nothing runs while the computer sleeps or hibernates, and that includes this
  server's timer. Closing a laptop lid suspends the run. When the machine wakes, the run carries
  on with the timeout budget it had left. The response (`suspended_s` and a warning) or the
  error says how long it slept. To have a long run progress unattended, keep the machine awake.
  Your MCP client may still have its own wall-clock limit.
- A call that is queued behind another run gives up after `timeout_seconds` too, saying it
  never started. Cancelling a call stops Pointwise.
- **No orphans.** Each batch `tclsh` is in a Windows Job Object with kill-on-close. If the
  server process is terminated or the client app restarts, Windows ends `tclsh` too, so it
  cannot keep holding a licence.
- **Live backend.** A timeout or cancel only stops the server waiting. The command keeps
  running in the Pointwise GUI until it finishes or you cancel it there.

### `pw_run_glyph` guard

The code runs in a Tcl **safe interpreter**. That means core Tcl only, with no `exec`, `open`,
`file`, `socket`, `load`, `source`, `cd`, `glob`, `exit` or `interp invokehidden`. Calls to
`pw::…`/`pwu::…` and Glyph object commands are forwarded to Pointwise, except `pw::Script` and
`pw::Application exit`, which are refused. In batch mode your `puts` lines are also echoed to
`stdout.log` as they happen (prefixed `| `), so a hung script shows how far it got. There is
no shell access. Pointwise's own file
commands still work, for example `pw::Database export`. Glyph options that write a caller
variable, such as `-reject var`, write into the Glyph interpreter, not your code.

## Example: half model with a y=0 symmetry plane, through OpenFOAM

Example input: a half aircraft STEP in mm, cut at y=0, with the body in +y. The settings below
aim at y+≈1 with a 25 µm first layer. They are a starting point, not a validated recipe: check the
quality for your own geometry. The same chain passes on the smoke-test half box (see Tests).

1. Import in metres:

   ```json
   pw_import_cad {"cad_file": "C:/cases/model/half.stp", "save_as": "C:/cases/model/stage_01_cad.pw", "units": "Meters"}
   ```

   Read `data.summary.models[].quilts` to get the quilt names used by the filters in step 2.

2. Surface mesh, with finer edges along the wing and tail edges:

   ```json
   pw_surface_mesh {"project": "C:/cases/model/stage_01_cad.pw", "save_as": "C:/cases/model/stage_02_surf.pw",
     "max_edge_spacing": 0.05, "min_edge_spacing": 0.0005, "curvature_resolution_angle": 10,
     "boundary_hard_angle": 30,
     "edge_refinement": [{"name": "lifting_edges", "quilts": ["*wing*", "*tail*"], "spacing_factor": 0.5}]}
   ```

3. Farfield plus symmetry plane plus T-Rex settings. `symmetry: "auto"` detects the open loop
   on y=0 and creates `symmetry-ymin`. `["ymin"]` forces it.

   ```json
   pw_trex {"project": "C:/cases/model/stage_02_surf.pw", "save_as": "C:/cases/model/stage_03_trex.pw",
     "first_layer_height": 2.5e-5, "growth_rate": 1.2, "max_layers": 40, "full_layers": 0,
     "collision_buffer": 2.0, "max_included_angle": 170, "cell_type": "TetPyramidPrismHex",
     "farfield": {"shape": "Box", "symmetry": "auto", "length": [40, 20], "width": [20, 20], "height": [20, 20]}}
   ```

   By default, `symmetry-*` domains become T-Rex Match, `farfield-*` become Off, and every
   other domain becomes Wall. Check `data.boundaries`.

4. Volume:

   ```json
   pw_volume {"project": "C:/cases/model/stage_03_trex.pw", "save_as": "C:/cases/model/stage_04_vol.pw", "timeout_seconds": 14400}
   ```

   `data.block.trex_layers`, `trex_prisms` and the other counts show what T-Rex reached.

5. Quality: `pw_examine {"project": "C:/cases/model/stage_04_vol.pw"}`. Look at `data.flagged`.

6. OpenFOAM:

   ```json
   pw_export_openfoam {"project": "C:/cases/model/stage_04_vol.pw", "case_dir": "C:/cases/model/of_case", "run_checkmesh": true}
   ```

   The default patches are `symmetry` (symmetryPlane), `farfield` (patch) and `wall` (wall).
   To split the walls into named patches, pass your own ordered list, e.g.
   `[{"name":"wing","type":"wall","domains":["*wing*"]}, {"name":"symmetry","type":"symmetryPlane","domains":["symmetry-*"]}, {"name":"farfield","type":"patch","domains":["farfield-*"]}, {"name":"fuselage","type":"wall","domains":["*"]}]`.
   `data.checkmesh` holds the verdict (`mesh_ok`, `failed_checks`), cell counts, the maximum
   non-orthogonality and skewness, and the path to `log.checkMesh`.

## Live backend (Glyph Server)

1. In the Pointwise GUI, open **Script → Glyph Server…**, choose **Active** and note the port
   (default 2807). Pointwise picks a random port if 2807 is busy. Set an authentication string
   if you like.
2. If those differ from the defaults, set `PWI_GLYPH_SERVER_PORT` and `PWI_GLYPH_SERVER_AUTH`
   in the MCP `env` block.
3. Call tools with `"backend": "live"`, or set `POINTWISE_MCP_BACKEND=live`. `pw_health` with
   `check_live: true` tests the connection.

Pointwise lets only one client connect at a time, and it runs commands only when no GUI task
panel is open. If a live call times out, the command may still be running in the GUI.

The wire protocol follows Cadence's GlyphClientPython (`glyph_client.py`): a 4-byte big-endian
length, an 8-byte space-padded message type, then the payload. The exchange is `AUTH` → `READY`,
`EVAL` → `OK`/`ERROR`, and `PING`. The automated tests drive a headless `tclsh` Glyph Server
(`pw::Script processServerMessages`). Against the 2023.2.2 GUI the live backend has been used by
hand for a full T-Rex mesh of a half aircraft model.

## Pointwise behaviour found while building this (2023.2.2)

- **Import units.** `FileUnits` is the unit the data ends up in. A mm STEP imported with
  `Meters` comes in with 0–1 m coordinates; `FromFile` keeps the file's numbers.
- **Symmetry plane names.** In Manual mode, `setSymmetryPlane1 -Y` put the plane on the body's
  *y-max* face. `+Y` put it at y=0 (the body's y-min side). Automatic mode reports that same
  correct plane as `-Y`. To avoid confusion, this server takes side names (`ymin`, …), which
  match the `symmetry-ymin` domain Pointwise creates.
- **Automatic Volume Mesh defaults.** It sets `TRexMaximumLayers=1000` (grow until isotropic),
  `TRexFullLayers=1` and cell type `AllAndReducePyramids`. `pw_trex` sets `full_layers=0` by
  default, which is Pointwise's own advice for symmetry planes and sharp edges.
- **Examine limits.** `pw::Examine` counts cells outside the range limits only if the limits
  are set *before* `examine`.
- **OpenFOAM in WSL.** `etc/bashrc` reads the caller's `"$@"` as config overrides, so the
  checkMesh wrapper clears the positional arguments before sourcing it. Otherwise bash crashes
  with exit code 139.
- **Smoke-test mesh quality.** The half box has sharp 90° edges. After 12 T-Rex layers, max
  non-orthogonality is 88° and about 7–8k faces are above 70°. checkMesh still reports
  "Mesh OK" because severe non-orthogonality is only a warning.
- **Automatic Surface Mesh crash.** On one aircraft model, `pw_surface_mesh`
  (`pw::DatabaseMesher`) ended in an access violation. Building the domains with
  `pw::DomainUnstructured createOnDatabase` through `pw_run_glyph` worked.
- **Refinement sources on the symmetry plane.** With T-Rex push attributes on (the default),
  initialising the volume re-meshes the Match domain without sources, so a wake box is lost there.
  What worked: `pw_trex` with `push_attributes: false`; set the symmetry domain's
  `TRexMaximumLayers` to the block's value; re-initialise just that domain
  (`pw::Application begin UnstructuredSolver`); then run `pw_volume`. Check the spacing after
  `pw_volume`, not before it.

## Tests

```powershell
.venv\Scripts\python -m pytest
```

The unit tests need no Pointwise. They use Python's own Tcl (tkinter) and a fake tclsh
(`tests/fake_tclsh.py`), and they cover:

- parameter quoting, round-tripped through a real Tcl parser with injection strings;
- the Glyph library run against `pw::` stubs, including the safe-interpreter guard;
- output parsing and licence-error detection;
- timeouts and cancellation: partial output, the whole process tree killed, no orphan when
  the server is terminated, sleep not counted, queued calls, and the live backend with a
  server that stalls or trickles;
- in-place saves that leave the input unchanged on failure;
- the Glyph Server protocol against an in-process fake server;
- checkMesh and boundary parsing;
- an end-to-end MCP stdio session.

The real smoke test needs licensed Pointwise. It also runs checkMesh when WSL OpenFOAM is
present:

```powershell
$env:POINTWISE_MCP_REAL = "1"
$env:POINTWISE_MCP_SMOKE_DIR = "$PWD\smoke_outputs"  # optional: keep files
.venv\Scripts\python -m pytest tests\test_smoke_real.py -v
```

It writes a 1 m × 0.25 m × 0.2 m box as STEP in mm, open at y=0
(`python -m pointwise_mcp.testgeom` writes such boxes), then:

1. imports it in metres;
2. surface-meshes it with an edge filter;
3. creates the farfield and the automatic y=0 symmetry plane;
4. grows 12 T-Rex layers from a 0.1 mm first layer;
5. builds the volume, examines it and exports to OpenFOAM;
6. runs checkMesh, which must report Mesh OK. Last run: about 507k cells, 186k prisms.

`tests\test_timeouts_real.py` checks, with real Pointwise, that a busy-loop through the stdio
server and a timeout inside a volume step both return `kind=timeout` and leave no `tclsh`, that
the project file is unchanged, and that terminating the server mid-run leaves nothing behind.

The smoke test also covers:

- IGES import;
- bad inputs;
- the live backend on a headless Glyph Server;
- the stdio server running against real Pointwise.

## Layout

```
src/pointwise_mcp/
  __main__.py        CLI: stdio server, --health, --describe
  tools.py           MCP tool definitions and parameter docs
  service.py         Tool logic: paths, saves, OpenFOAM post-steps
  backends.py        Batch (tclsh subprocess) and live (Glyph Server) runners, error mapping
  procs.py           Awake-time clock and the kill-on-close process group
  glyph/pwmcp.tcl    Glyph library: every tool's Tcl, JSON output, run_glyph sandbox
  tcl.py             Parameter quoting and script assembly
  output.py          Parses tagged output, Pointwise messages and LMC errors
  glyph_server.py    Glyph Server wire-protocol client
  openfoam.py        Case skeleton, boundary parser, checkMesh in WSL
  config.py          tclsh, licence and settings discovery
  testgeom.py        STEP box writer used by the smoke test
tests/               Unit tests, fake tclsh, real smoke test
```

## Acknowledgements

Project structure modelled on [openvsp-mcp](https://github.com/rhyne1012/openvsp-mcp) (MIT).
The Glyph Server client follows the wire format of Cadence's GlyphClientPython.

TDQS

A4.1/5.0

Scored across 10 tools

Disambiguation5/5

Each tool maps to a distinct stage or concern in the Pointwise workflow: health check, CAD import, surface meshing, T-Rex setup, volume generation, quality examination, export, save/load, and an explicitly scoped escape hatch. The closest pair, pw_trex and pw_volume, is clearly separated as setup versus cell generation, and pw_save versus pw_load is unambiguous. There is no realistic misselection risk.

Naming Consistency4/5

All tools use a consistent pw_ prefix and snake_case, making the family immediately recognizable. Most names are action-oriented, though a few (pw_health, pw_trex, pw_volume) are noun/domain labels rather than strict verb_noun forms. The overall convention is still highly predictable.

Tool Count5/5

Ten tools is well-scoped for an end-to-end meshing workflow, with one tool per major stage and no redundant variants. Each tool earns its place, and the escape hatch avoids needing many narrow one-off tools.

Completeness4/5

The surface covers the core lifecycle: health/license check, import, surface mesh, boundary layers, volume generation, quality examination, OpenFOAM export, save, and load. Gaps such as project deletion/cleanup, broader solver exporters, or richer boundary-condition editing are minor and can be worked around via pw_run_glyph.