zemax-mcp
Safety-first MCP server enabling AI assistants to drive Zemax OpticStudio sequential-mode optical design workflows, including a mock backend for validation.
README
Zemax MCP
A safety-first, stdio-only MCP server that lets Codex, Claude Code, or another MCP host drive constrained Ansys Zemax OpticStudio sequential-mode workflows. The project includes a deterministic mock backend so validation and protocol work can proceed without an OpticStudio installation.
Current status: the mock backend is implemented and testable. The ZOS-API adapter deliberately stops after read-only runtime discovery until its object names and connection sequence are checked against the samples installed with the target OpticStudio release. It has not been verified against a live licensed OpticStudio instance.
MCP host (Codex / Claude Code)
| stdio
v
Python FastMCP server
| typed, bounded operations
v
Mock backend or Windows ZOS-API adapter
|
v
Ansys Zemax OpticStudio (sequential mode)
Safety model
- The server uses stdio and does not listen on a network port.
- It exposes a small typed tool set—no shell, arbitrary Python, arbitrary ZOS-API, or unrestricted filesystem tool.
- All file targets are resolved below the existing writable
ZEMAX_WORKSPACE; absolute paths and traversal are rejected. - Focus changes, optimization, saves, and standalone-session closure require an explicit
confirm=trueinside the tool. - Save never overwrites an existing file.
- Tool calls are logged with status and exception type, but paths, tokens, credentials, and file contents are not logged.
- Simulation records are immutable and versioned. Git LFS stores large Zemax/binary artifacts.
Windows prerequisites
- Windows 10 or 11
- Python 3.11+
- Git and Git LFS
- For live mode: installed and licensed OpticStudio with ZOS-API samples
uv(recommended) or pip/venv
Do not assume an installation path. In OpticStudio documentation or its installation folders, locate the Programming/ZOS-API Python samples and ZOSAPI_NetHelper.dll, then use those exact local paths. Python architecture must match the installed API runtime.
Mock quick start
git lfs install
New-Item -ItemType Directory C:\zemax-workspace
Copy-Item .env.example .env
$env:ZEMAX_WORKSPACE = "C:\zemax-workspace"
$env:ZEMAX_BACKEND = "mock"
uv sync --extra dev
uv run pytest -q
uv run python server.py
Pip alternative:
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
$env:ZEMAX_WORKSPACE = "C:\zemax-workspace"
$env:ZEMAX_BACKEND = "mock"
python server.py
For interactive MCP inspection:
uv run mcp dev server.py
Expected zemax_health behavior in mock mode: connected is true, backend is mock, the resolved workspace is shown, no OpticStudio version is claimed, and analysis/optimization capabilities are marked estimated.
Live ZOS-API preparation
Install the optional bridge, run diagnostics, and only then start the server:
uv sync --extra zosapi --extra dev
$env:ZEMAX_WORKSPACE = "C:\path\to\approved-workspace"
$env:ZEMAX_BACKEND = "zosapi"
$env:ZEMAX_CONNECT_MODE = "extension"
$env:ZEMAX_ZOSAPI_NETHELPER_DLL = "C:\path\from\installed\samples\ZOSAPI_NetHelper.dll"
uv run python scripts\diagnose_zosapi.py
uv run python server.py
extension mode must never close a user-owned OpticStudio process. standalone closure still requires confirmation. Adapt backend/zosapi_backend.py only after comparing it to the local, version-matched Python samples. DLL load, license, and connection errors must remain diagnostic rather than being converted to apparent success.
MCP host configuration
Claude Code template (replace every placeholder):
claude mcp add --transport stdio zemax-opticstudio `
--env ZEMAX_BACKEND=zosapi `
--env ZEMAX_WORKSPACE="C:\path\to\approved-workspace" `
--env ZEMAX_CONNECT_MODE=extension `
-- "C:\path\to\python.exe" "C:\path\to\zemax-mcp\server.py"
Codex configuration entry points vary by client version. A standard stdio definition needs command, args, and env:
{
"mcpServers": {
"zemax-opticstudio": {
"command": "C:\\path\\to\\python.exe",
"args": ["C:\\path\\to\\zemax-mcp\\server.py"],
"env": {
"ZEMAX_BACKEND": "zosapi",
"ZEMAX_WORKSPACE": "C:\\path\\to\\approved-workspace",
"ZEMAX_CONNECT_MODE": "extension"
}
}
}
}
Recommended optical workflow
Ask for missing wavelength band, aperture or F-number, object condition, fields, sensor size, allowed materials, and optimization objective. Then:
- Call
new_sequential_design,create_singlet, andconfigure_system. - Call
quick_focus_previewandparaxial_summary. - Review EFL/BFL and assumptions; only then call
apply_quick_focus(confirm=true). - Call
spot_diagramandmtf, recognizing singlet spherical, chromatic, and off-axis aberrations. - Call
preview_optimization; callrun_optimization(..., confirm=true)only after reviewing variables, bounds, and cost. - Call
preview_save_design; callsave_design(..., confirm=true)only after reviewing the new path.
Example request: “Using N-BK7, model a 25 mm diameter plano-convex singlet targeting 75 mm EFL at Fraunhofer F/d/C wavelengths, object at infinity, 10 mm entrance pupil, and fields 0° and 5°. Preview focus before changing it, then report paraxial data, spot sizes, and MTF.”
Recording every experimental milestone
The repository is the experiment system of record. Copy experiments/templates/experiment.json, fill it with exact inputs and numeric outputs, then create a non-overwritable record:
python scripts\record_experiment.py exp-001-bk7-focus C:\path\to\completed-record.json
Place referenced .ZOS, .ZMX, plots, arrays, or archives below experiments/artifacts/<experiment-id>/, update EXPERIMENTS.md, run tests, inspect the diff, commit the milestone, and push. The included AGENTS.md tells future Codex sessions to follow this process after every meaningful run. Never commit credentials, license details, user-specific paths, or sensitive logs.
Tool limits
All length inputs are millimeters, wavelength inputs are micrometers, angles are degrees, and MTF frequencies are lp/mm. Lens diameter is 1–200 mm, center thickness 0.2–100 mm, curved radius magnitude 1–10,000 mm, wavelength 0.2–20 µm (up to 10), field magnitude up to 90° (up to 10), and MTF frequency 0–500 lp/mm (up to 20 samples). Optimization is bounded to 1–100 iterations and four whitelisted variables.
Troubleshooting
| Symptom | Action |
|---|---|
ZEMAX_WORKSPACE error |
Create the intended directory explicitly, verify it is writable, then set the variable. |
pythonnet unavailable |
Install .[zosapi] using the same Python architecture as OpticStudio. |
| NetHelper load failure | Use the DLL path from the installed, version-matched ZOS-API sample. |
| License/connection failure | Open OpticStudio, verify the license, connection mode, and sample code behavior. |
| Glass rejected in mock mode | Use N-BK7, N-SF11, or F_SILICA; live catalogs require ZOS-API verification. |
| Save refused | Use a relative .ZOS path below the workspace, an existing parent directory, and a new filename. |
| Optimization unsupported | Use a bounded manual parameter sweep; no backend may fabricate success. |
Repository layout
backend/ backend protocol, mock, and guarded ZOS-API adapter
experiments/runs/ immutable JSON experiment records
experiments/artifacts/ Git LFS-backed designs and large results
experiments/templates/ record template
scripts/ diagnostics and experiment recorder
tests/ validation, path, and mock-physics tests
server.py FastMCP stdio tools
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。