OpticStudio MCP Server 标志

OpticStudio MCP Server

社区
jaruiz6363

An MCP (Model Context Protocol) server that enables AI assistants to interact with Zemax OpticStudio for optical design tasks. Works with Claude Desktop, Claude Code, and Ollama (local LLMs).

发布者jaruiz6363
代码仓库OpticStudioMCPServer
语言C#
复刻数
13
星标数
58
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    OpticStudio MCP Server 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 58 个星标和 13 个复刻。

OpticStudio MCP Server

An MCP (Model Context Protocol) server that enables AI assistants to interact with Zemax OpticStudio for optical design tasks. Works with Claude Desktop, Claude Code, and Ollama (local LLMs).

Table of Contents


Prerequisites

  • Windows (required - OpticStudio is Windows-only)
  • .NET Framework 4.8 (included with Windows 10/11)
  • Zemax OpticStudio with a valid license (any recent version)
  • One of the following AI clients:

Quick Start

  1. Build the solution in Visual Studio or via command line
  2. Run FixBinaries to point the project at your OpticStudio installation
  3. Run ConfigureClaudeMCP to automatically set up Claude Desktop and/or Claude Code
  4. Start using OpticStudio through your AI assistant

Step 1: Build the Solution

Open a Developer Command Prompt or terminal and run:

cd C:\GIT\OpticStudioMCPServer
dotnet build

Or open OpticStudioMCPServer.sln in Visual Studio and build the solution (Ctrl+Shift+B).

This builds all projects:

  • ZemaxMCP.Server - The MCP server (main executable)
  • ZemaxMCP.Core - Core library (session management, models)
  • ZemaxMCP.Documentation - Operand reference database
  • FixBinaries - ZOS-API path configuration tool
  • ConfigureClaudeMCP - Claude Desktop/Code setup tool
  • ConfigureOllama - Ollama bridge setup tool
  • ZemaxMCP.OllamaBridge - Ollama-to-MCP bridge

Step 2: Fix Binaries (Configure ZOS-API Path)

The MCP server needs to reference three DLLs from your OpticStudio installation: ZOSAPI.dll, ZOSAPI_Interfaces.dll, and ZOSAPI_NetHelper.dll. The FixBinaries tool configures this automatically.

Using the FixBinaries GUI

  1. Run FixBinaries.exe from src\FixBinaries\bin\Debug\ (or Release)
  2. The tool automatically scans for OpticStudio installations in:
    • C:\Program Files\Ansys Zemax OpticStudio*
    • C:\Program Files\Zemax OpticStudio*
    • C:\Program Files\OpticStudio*
  3. Select your installation from the list (or click Browse to locate it manually)
  4. Verify all three DLLs show green checkmarks:
    • ZOSAPI.dll
    • ZOSAPI_Interfaces.dll
    • ZOSAPI_NetHelper.dll
  5. Click Generate ZemaxPaths.props

This creates a ZemaxPaths.props file at the repository root that tells MSBuild where to find the ZOS-API DLLs. After generating, rebuild the solution so the references resolve correctly.

Manual Alternative

If you prefer, create ZemaxPaths.props in the repository root manually:

xml
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ZEMAX_ROOT>C:\Program Files\Ansys Zemax OpticStudio 2024 R1\</ZEMAX_ROOT>
  </PropertyGroup>
</Project>

Replace the path with your actual OpticStudio installation directory (include trailing backslash).

Building distributable .exe file

To build a distributable .exe file using Costura that packs all of the .dll files (except OpticStudio's and .NET itself) into the .exe for easy distribution, build in release mode (after generating ZemaxPaths.props):

powershell
dotnet build -c Release

The file src/ZemaxMCP.Server/bin/Release/net48/ZemaxMCP.Server.exe will run as-is on any machine with OpticStudio and .NET installed.


Step 3: Configure Your AI Client

Claude Desktop Setup

New to Claude Desktop? See the full Claude Desktop Installation Guide for step-by-step instructions including account creation, downloading, and installation.

Using the ConfigureClaudeMCP GUI (Recommended)

  1. Run ConfigureClaudeMCP.exe from src\ConfigureClaudeMCP\bin\Debug\
  2. The tool auto-detects ZemaxMCP.Server.exe (or click Browse to locate it)
  3. Click Configure Claude Desktop
  4. Restart Claude Desktop

The tool edits %APPDATA%\Claude\claude_desktop_config.json to add the zemax-mcp server entry.

ConfigureClaudeMCP GUI

Manual Configuration

Edit %APPDATA%\Claude\claude_desktop_config.json:

json
{
  "mcpServers": {
    "zemax-mcp": {
      "command": "C:\\GIT\\OpticStudioMCPServer\\src\\ZemaxMCP.Server\\bin\\Debug\\net48\\ZemaxMCP.Server.exe",
      "args": []
    }
  }
}

Restart Claude Desktop after saving.


Claude Code Setup

New to Claude Code? See the full Claude Code Installation Guide for step-by-step instructions including installing Node.js, setting up Claude Code, and signing in.

Using the ConfigureClaudeMCP GUI (Recommended)

  1. Run ConfigureClaudeMCP.exe from src\ConfigureClaudeMCP\bin\Debug\
  2. Click Configure Claude Code
  3. The tool runs: claude mcp add --transport stdio --scope user zemax-mcp -- "path\to\ZemaxMCP.Server.exe"

Manual Configuration (CLI)

claude mcp add --transport stdio --scope user zemax-mcp -- "C:\GIT\OpticStudioMCPServer\src\ZemaxMCP.Server\bin\Debug\net48\ZemaxMCP.Server.exe"

To verify the server is registered:

claude mcp list

To remove:

claude mcp remove --scope user zemax-mcp

Skipping Tool Permissions

By default, Claude Code will prompt you to approve each MCP tool call. To skip these prompts and allow all tool calls automatically, start Claude Code with:

claude --dangerously-skip-permissions

Warning: This bypasses all permission checks. Only use this in trusted environments where you are comfortable with the AI calling OpticStudio tools without confirmation.


Ollama Setup (Local LLMs)

The Ollama Bridge lets you use OpticStudio with local LLMs running on your machine via Ollama. No cloud API keys needed.

Prerequisites

  1. Install Ollama
  2. Pull a model with tool-calling support:
    ollama pull llama3.1
    Other recommended models: mistral, qwen2.5-coder
  3. Make sure Ollama is running: ollama serve

Using the ConfigureOllama GUI (Recommended)

ConfigureOllama GUI

  1. Run ConfigureOllama.exe from src\ConfigureOllama\bin\Debug\
  2. The tool auto-detects:
    • ZemaxMCP.Server.exe path
    • ZemaxMCP.OllamaBridge.exe path
    • Running Ollama instance and available models
  3. Select a model from the dropdown (or pull a new one)
  4. Choose an action:
    • Launch Bridge - Start an interactive chat session immediately
    • Create Desktop Shortcut - Make a shortcut for quick access
    • Create Batch File - Save a .bat file to launch later

Manual Launch (CLI)

Set environment variables and run the bridge:

set OLLAMA_MODEL=llama3.1
set OLLAMA_URL=http://localhost:11434
ZemaxMCP.OllamaBridge.exe "path\to\ZemaxMCP.Server.exe"

Or pass the server path as a command line argument:

ZemaxMCP.OllamaBridge.exe C:\GIT\OpticStudioMCPServer\src\ZemaxMCP.Server\bin\Debug\net48\ZemaxMCP.Server.exe

If no model is specified, the bridge will list available models and let you pick one interactively.

How the Ollama Bridge Works

The bridge acts as an intermediary:

  1. Starts the MCP server as a subprocess (stdio transport)
  2. Discovers all available tools from the MCP server
  3. Auto-connects to OpticStudio in standalone mode
  4. Converts MCP tools to Ollama's tool-calling format
  5. Provides an interactive chat loop where the LLM can call OpticStudio tools

Type tools during a chat session to list all available tools, or quit to exit.


Connection Modes

The MCP server supports two connection modes:

ModeDescriptionUse Case
Standalone (default)Launches a new OpticStudio instance without UIAutomated workflows, scripting, headless operation
ExtensionConnects to an already-running OpticStudio instanceInteractive use alongside the OpticStudio GUI

To use Extension mode:

  1. Open OpticStudio
  2. Go to Programming > Interactive Extension
  3. Tell the AI to connect in extension mode: "Connect to OpticStudio in extension mode"

The AI defaults to standalone mode unless you explicitly request extension mode.


Non-Sequential (NSC) Mode

In addition to classic sequential ray tracing, the MCP server supports non-sequential simulation through the Non-sequential Component Editor (NCE). Non-sequential mode is used for problems where rays can hit objects in any order and may split, scatter, or reflect — such as illumination design, photometry, stray-light analysis, light pipes, and other non-imaging optics.

The system operates in one of two modes:

ModeDescriptionUse Case
Sequential (default)Surfaces are traced in a fixed order (the Lens Data Editor)Imaging systems: lenses, mirrors, MTF, spot size, optimization
Non-SequentialObjects are placed in 3D and rays propagate freely (the NCE)Illumination, detectors, sources, stray light, non-imaging optics

Switch modes by telling the AI, e.g. "Switch to non-sequential mode", which calls zemax_set_system_mode. Once in non-sequential mode you build the system from objects (sources, detectors, lenses, reflectors, etc.) rather than surfaces, run a non-sequential ray trace, and read results back from detector objects.

To discover the exact object type names available in your OpticStudio installation, ask the AI to list them (zemax_nsc_list_object_types) and use the returned names verbatim when adding objects.

A typical non-sequential interaction with the AI assistant looks like:

  1. Connect: "Connect to OpticStudio" (uses standalone mode by default)
  2. Switch mode: "Switch to non-sequential mode"
  3. Discover types: "List the available source and detector object types"
  4. Add a source: "Add a Source Point at z = 0"
  5. Add a detector: "Add a Detector Rectangle 50mm downstream"
  6. Configure: "Set the source to 1,000,000 analysis rays"
  7. Trace: "Run a non-sequential ray trace with 4 cores"
  8. Read results: "Show me the total flux and irradiance on the detector"
  9. Save: "Save the file"

See the Non-Sequential Tools table below for the full list of available tools and their parameters.


Tool Reference

System Tools

ToolDescriptionParameters
zemax_connectConnect to OpticStudiomode (opt, default: "standalone"): "standalone" or "extension" · instanceId (opt, default: 0): Instance ID for extension mode
zemax_disconnectDisconnect from OpticStudionone
zemax_restartRestart the OpticStudio connectionnone
zemax_statusGet connection statusnone
zemax_new_systemCreate a new blank optical systemnone
zemax_open_fileOpen a .zmx or .zos lens filefilePath (required): Full path to the lens file
zemax_save_fileSave the current systemfilePath (opt): File path; uses current file if omitted

Lens Data Tools

ToolDescriptionParameters
zemax_get_systemGet system data (surfaces, fields, wavelengths)includeSurfaces (opt, default: true) · includeFields (opt, default: true) · includeWavelengths (opt, default: true)
zemax_get_surfaceGet detailed data for a surfacesurfaceNumber (required): Surface number (0=object, -1=image)
zemax_set_surfaceModify surface propertiessurfaceNumber (required) · radius (opt) · thickness (opt) · material (opt) · semiDiameter (opt) · conic (opt) · comment (opt) · isStop (opt) · radiusVariable (opt) · thicknessVariable (opt) · conicVariable (opt) · coating (opt)
zemax_add_surfaceAdd a new surfaceinsertAt (opt, default: 0 = before image) · radius (opt) · thickness (opt) · material (opt) · comment (opt)
zemax_get_aspheric_surfaceGet aspheric surface data with Even Asphere coefficientssurfaceNumber (required)
zemax_set_aspheric_surfaceSet Even Asphere coefficientssurfaceNumber (required) · conic (opt) · conicVariable (opt) · alpha1-alpha8 (opt): Coefficients · alpha1Variable-alpha8Variable (opt)
zemax_get_surface_solvesGet solve/variable/pickup status for a surfacesurfaceNumber (required)
zemax_set_surface_solveSet solve type for a surface propertysurfaceNumber (required) · property (required): radius, thickness, conic, semiDiameter, material, param1-param8 · solveType (required): Fixed, Variable, Pickup, MarginalRayHeight, etc. · Various solve-specific params (opt)
zemax_set_fieldsSet field pointsfields (required): Array of {x, y, weight} · fieldType (opt, default: "Angle"): Angle, ObjectHeight, ParaxialImageHeight, RealImageHeight
zemax_set_wavelengthsSet wavelengthswavelengths (required): Array of {wavelength (um), weight} · primaryWavelength (opt, default: 1)
zemax_set_apertureSet system aperturevalue (required): Aperture value · apertureType (opt, default: "EPD"): EPD, FNumber, ObjectNA, FloatByStop

Analysis Tools

ToolDescriptionParameters
zemax_spot_diagramGet spot size analysisfield (opt, default: 1) · wavelength (opt, default: 0 = polychromatic) · rings (opt, default: 3)
zemax_fft_mtfCalculate FFT MTF for all fieldsfrequency (required): Max spatial frequency (cycles/mm) · wavelength (opt, default: 0) · sampling (opt, default: 3, range 1-6)
zemax_geometric_mtfCalculate Geometric MTF for all fieldsmaxFrequency (opt, default: 100) · wavelength (opt, default: 0) · multiplyByDiffractionLimit (opt, default: false)
zemax_fft_mtf_vs_fieldFFT MTF vs. Y field height for up to 6 frequenciesfrequency1-frequency6 (opt, defaults: 10,0,0,0,0,0) · sampling (opt, default: 3)
zemax_geometric_mtf_vs_fieldGeometric MTF vs. Y field heightfrequency1-frequency6 (opt, defaults: 10,0,0,0,0,0)
zemax_ray_traceTrace a ray through the systemhx, hy (opt, default: 0): Normalized field coords · px, py (opt, default: 0): Normalized pupil coords · wavelength (opt, default: 1) · surface (opt, default: 0 = image)
zemax_rms_spotCalculate RMS spot sizehx, hy (opt, default: 0) · wavelength (opt, default: 0) · reference (opt, default: "centroid"): centroid or chief · sampling (opt, default: 4) · useGrid (opt, default: false)
zemax_cardinal_pointsGet focal lengths, principal planes, etc.wavelength (opt, default: 1)
zemax_seidel_coefficientsGet 3rd-order Seidel aberration coefficientswavelength (opt, default: 0 = primary)
zemax_ray_fanTransverse ray aberration fan for all fields/wavelengthsnone
zemax_opd_fanOptical path difference fan for all fields/wavelengthsnone
zemax_pupil_aberration_fanEntrance pupil aberration fannone
zemax_chromatic_focal_shiftChromatic focal shift vs. wavelengthnone
zemax_lateral_colorLateral color vs. fieldnone
zemax_longitudinal_aberrationLongitudinal aberration vs. pupil positionnone
zemax_field_curvature_distortionField curvature and distortion vs. fielddistortionType (opt, default: "f_tan_theta"): f_tan_theta or f_theta
zemax_relative_illuminationRelative illumination vs. field anglenone
zemax_diffraction_encircled_energyFFT diffraction encircled energysampling (opt, default: 3) · useDashes (opt, default: false)
zemax_geometric_encircled_energyGeometric encircled energy (ray-based)sampling (opt, default: 4) · showDiffractionLimit (opt, default: true) · scaleByDiffractionLimit (opt, default: false) · scatterRays (opt, default: false) · useDashes (opt, default: false)

Optimization Tools

ToolDescriptionParameters
zemax_get_merit_functionGet current merit functionincludeValues (opt, default: true) · startRow (opt, default: 0 = all) · endRow (opt, default: 0 = all)
zemax_add_operandAdd operand to merit functionoperandType (required): e.g. EFFL, MTFT, RSCE · target (opt, default: 0) · weight (opt, default: 1) · insertAt (opt, default: 0 = append) · int1, int2 (opt) · data1-data6 (opt)
zemax_remove_operandRemove a merit function operandrow (required): Row number (1-indexed)
zemax_optimizeRun local optimizationalgorithm (opt, default: "DLS"): DLS or Orthogonal · cycles (opt, default: 0 = automatic)
zemax_hammerRun Hammer optimizationalgorithm (opt, default: "DLS") · cores (opt, default: 0 = all) · targetRuntimeMinutes (opt, default: 1) · timeoutSeconds (opt, default: 120) · automatic (opt, default: true)
zemax_global_searchRun global optimizationalgorithm (opt, default: "DLS") · cores (opt, default: 0 = all) · solutionsToSave (opt, default: 10) · timeoutSeconds (opt, default: 60)
zemax_optimization_wizardAuto-construct merit functioncriterion (opt, default: "RMSSpotRadius") · reference (opt, default: "Centroid") · pupilIntegration (opt, default: "GaussianQuadrature") · rings (opt, default: 3) · gridSize (opt, default: 6) · arms (opt, default: 6) · includeAllFields (opt, default: true) · wavelength (opt, default: 0) · and more
zemax_forbes_merit_functionForbes 1988 Gaussian quadrature OPD merit functionoperandType (opt, default: "OPDX"): OPDX, OPDC, or OPDM · rings (opt, default: 3) · arms (opt, default: 6) · includeAllWavelengths (opt, default: true) · clearExisting (opt, default: true) · and more
zemax_operand_helpGet help for a specific operandoperandType (required): e.g. EFFL
zemax_search_operandsSearch operands by name/descriptionquery (required) · maxResults (opt, default: 10) · category (opt)
zemax_save_merit_function_fileSave merit function to .MF filefilePath (required)
zemax_load_merit_function_fileLoad merit function from .MF filefilePath (required)

Constrained Optimization Tools

Custom MCP-implemented optimization algorithms that run entirely in the MCP server. These are not built-in Zemax optimizers — they use ZOSAPI only to get/set variable values and evaluate the merit function, while the optimization logic (Levenberg-Marquardt with bound constraints) runs server-side.

Workflow

  1. Identify variables — Use zemax_get_variables to scan the system for all Variable solves and get their variable numbers.
  2. Set constraints — Use zemax_set_variable_constraints to define min/max bounds on variables. Constraints are persisted alongside the .zmx file in a sidecar .constraints file and are automatically reloaded when the file is opened.
  3. Optimize — Run either:
    • zemax_constrained_optimize for a single local optimization (blocking), or
    • zemax_multistart_optimize for a randomized multistart search (non-blocking).
  4. Monitor (multistart only) — Poll with zemax_multistart_status and cancel with zemax_multistart_stop.

Tool Reference

ToolDescriptionParameters
zemax_get_variablesScan system for all Variable solves and their constraint statusnone
zemax_set_variable_constraintsSet min/max bounds on variablesconstraints (required): JSON array of [{VariableNumber, Constraint, Min, Max}]. Constraint types: Unconstrained, MinAndMax, MinOnly, MaxOnly
zemax_constrained_optimizeBound-constrained Levenberg-Marquardt optimization (blocking)maxIterations (opt, default: 200) · initialMu (opt, default: 1e-3) · delta (opt, default: 1e-7) · useBroydenUpdate (opt, default: true) · maxRestarts (opt, default: 2)
zemax_multistart_optimizeNon-blocking multistart optimization with randomized restartsmaxTrials (opt, default: 100) · lmIterationsPerTrial (opt, default: 50) · initialLmIterations (opt, default: 200) · randomizationPercent (opt, default: 5.0) · constrainedOnly (opt, default: false) · glassSubstitutionProbability (opt, default: 0.5) · progressInterval (opt, default: 0) · resume (opt, default: false) · initialMu (opt, default: 1e-3) · delta (opt, default: 1e-7) · useBroydenUpdate (opt, default: true) · maxRestarts (opt, default: 0)
zemax_multistart_statusPoll progress of a running multistart optimizationnone
zemax_multistart_stopCancel a running multistart optimizationnone

Local Optimization (zemax_constrained_optimize)

Runs a bound-constrained Levenberg-Marquardt (LM) optimizer. Variables are clamped to their min/max bounds at each iteration. Optionally uses Broyden rank-1 Jacobian updates to reduce the number of merit function evaluations. When Broyden converges early, the optimizer can auto-restart with a fresh Jacobian (controlled by maxRestarts).

Key features:

  • Finite-difference Jacobian with configurable step size (delta)
  • Broyden rank-1 updates between full Jacobian rebuilds
  • Automatic restarts when convergence stalls
  • Bound clamping at every iteration

Multistart Optimization (zemax_multistart_optimize)

Launches a non-blocking multistart search that returns immediately. Each trial randomizes continuous variables within their bound ranges (by randomizationPercent of the bound width), optionally substitutes glasses on surfaces with Material Substitute solves, then runs a short LM optimization. The best result across all trials is kept.

Key features:

  • Non-blocking — returns immediately; use zemax_multistart_status to poll progress
  • Initial LM phase — runs a full LM optimization from the current starting point before trials begin
  • Auto-save — saves improving solutions to a <filename>_multistart/ folder alongside the original file
  • Constrained-only mode (constrainedOnly) — only randomize variables that have constraints, leaving unconstrained variables at their current best values
  • Glass substitution — randomly swaps glasses on surfaces with Material Substitute solves at a configurable probability
  • Resume — continue accumulating trials from a previous run, skipping the initial LM phase
  • Cancellation — use zemax_multistart_stop to gracefully cancel; the optimizer finishes the current trial and restores the best state

Configuration Tools

ToolDescriptionParameters
zemax_get_configurationGet number/current configurationnone
zemax_set_number_of_configurationsSet number of configurationsnumberOfConfigurations (required)
zemax_set_current_configurationSet active configurationconfigurationNumber (required, 1-indexed)
zemax_add_configuration_operandAdd MCE operandoperandType (required): e.g. THIC, CURV, CONI, PRAM · insertAt (opt, default: 0) · param1-param3 (opt)
zemax_delete_configuration_operandDelete MCE operandrow (required, 1-indexed)
zemax_get_configuration_operandsGet all MCE operandsstartRow (opt, default: 1) · endRow (opt, default: 0 = all)
zemax_set_configuration_operand_valueSet MCE operand value or pickupoperandRow (required) · configurationNumber (required) · value (opt) · pickupConfig (opt) · scaleFactor (opt) · offset (opt)

System Settings Tools

ToolDescriptionParameters
zemax_get_ray_aimingGet ray aiming settingnone
zemax_set_ray_aimingSet ray aimingrayAiming (required): Off, Paraxial, or Real
zemax_get_afocal_modeGet afocal mode settingnone
zemax_set_afocal_modeSet afocal modeafocalMode (required): true or false

Glass Catalog Tools

ToolDescriptionParameters
zemax_get_glass_catalogsList available glass catalog namesnone
zemax_get_glassesList glasses with properties (Nd, Vd, dPgF, etc.)catalogs (required): Comma-separated catalog names, e.g. "SCHOTT,OHARA"
zemax_filter_glassesFilter glasses by criteriacatalogs (required) · preferredOnly (opt) · ndMin/ndMax (opt) · vdMin/vdMax (opt) · dpgfMin/dpgfMax (opt) · maxCost (opt) · tceMin/tceMax (opt) · distanceRadius (opt): Max weighted distance from target · ndTarget/vdTarget/dpgfTarget (opt) · wn/wa/wp (opt): Weights for distance calc
zemax_export_glass_catalogExport filtered glasses to a new .agf filecatalogName (required) · sourceCatalogs (required) · overwrite (opt, default: false) · Plus all filter params from zemax_filter_glasses
zemax_add_material_catalogAdd a glass/material catalog to the current project's list of catalogs in use (System Explorer > Material Catalogs)catalogName (required)

Non-Sequential Tools

Tools for building and simulating non-sequential systems via the Non-sequential Component Editor (NCE) — illumination, photometry, stray light, and non-imaging optics. Switch the system to non-sequential mode first with zemax_set_system_mode.

ToolDescriptionParameters
zemax_set_system_modeSwitch between sequential and non-sequential mode, or report the current modemode (opt): "sequential" or "nonsequential". Omit to just report the current mode
zemax_nsc_list_object_typesList object type names available in this installation (use the names verbatim in zemax_nsc_add_object)filter (opt, default: "all"): "all", "sources", "detectors", or "objects"
zemax_nsc_get_objectsList all NCE objects with type, comment, position, tilt, material, and reference linksnone
zemax_nsc_get_objectGet one object's full detail, including type-specific parameter columns (Par1..ParN) paired with their labelsobjectNumber (required, 1-based)
zemax_nsc_add_objectAdd an object and set its typeobjectType (required): e.g. "Source Point", "Detector Rectangle" · insertAt (opt, default: 0 = append) · x/y/z (opt) · material (opt) · comment (opt)
zemax_nsc_set_objectModify an object's position, tilt, material, comment, references, and parameter columnsobjectNumber (required) · x/y/z (opt) · tiltX/tiltY/tiltZ (opt) · material (opt) · comment (opt) · refObject/insideOf (opt) · parameters (opt): list of { index, value } or { index, text }
zemax_nsc_remove_objectRemove an object from the NCEobjectNumber (required, 1-based)
zemax_nsc_ray_traceRun a non-sequential ray trace (blocks until complete)splitRays (opt, default: false) · scatterRays (opt, default: false) · usePolarization (opt, default: false) · ignoreErrors (opt, default: true) · clearDetectors (opt, default: true) · cores (opt, default: 0 = auto)
zemax_nsc_get_detector_dataRead detector results after a trace (total flux + per-pixel stats, optional grid)objectNumber (required) · dataType (opt, default: 0): 0=flux/pixel, 1=irradiance, 2=intensity · includeGrid (opt, default: false) · maxGridPixels (opt, default: 4096)

Resources

MCP resources provide read-only access to system state:

ResourceDescription
zemax://systemCurrent optical system state
zemax://merit-functionCurrent merit function
zemax://docs/operandsOperand documentation

Prompts

Built-in prompt templates for common workflows:

PromptDescription
design_singletGuide for designing a singlet lens
design_doubletGuide for designing an achromatic doublet
optimize_mtfGuide for MTF optimization
optimize_distortionGuide for distortion optimization
optimize_spot_sizeGuide for spot size optimization
analyze_systemComprehensive system analysis guide
troubleshoot_designDesign troubleshooting guide

Example Workflow

Here is a typical interaction with the AI assistant:

  1. Connect: "Connect to OpticStudio" (uses standalone mode by default)
  2. Open a file: "Open C:\Lenses\MyDoublet.zmx"
  3. Review: "Show me the system data"
  4. Analyze: "Run a spot diagram" or "Calculate the MTF at 100 cycles/mm"
  5. Modify: "Set surface 2 radius to 50mm and make it variable"
  6. Optimize: "Build an RMS spot merit function and optimize"
  7. Evaluate: "Show me Seidel coefficients and spot size"
  8. Save: "Save the file"

Screenshots

Connecting to OpticStudio from Claude Code:

Connecting to OpticStudio

Opening a Zemax file and querying the merit function:

Opening a Zemax file

Hammer optimization results:

Hammer optimization


Project Structure

OpticStudioMCPServer/
|-- src/
|   |-- ZemaxMCP.Server/          # MCP server (main executable)
|   |-- ZemaxMCP.Core/            # Core library (session, models, services)
|   |-- ZemaxMCP.Documentation/   # Operand reference database
|   |-- FixBinaries/              # GUI tool to configure ZOS-API DLL paths
|   |-- ConfigureClaudeMCP/       # GUI tool to set up Claude Desktop/Code
|   |-- ConfigureOllama/          # GUI tool to set up Ollama bridge
|   |-- ZemaxMCP.OllamaBridge/    # Ollama-to-MCP bridge (console app)
|-- Directory.Build.props         # Shared build properties
|-- ZemaxPaths.props              # ZOS-API path (generated by FixBinaries)
|-- OpticStudioMCPServer.sln      # Visual Studio solution
|-- README.md

Troubleshooting

"ZOSAPI.dll not found" or build errors

Run FixBinaries to generate ZemaxPaths.props, then rebuild the solution.

Tools not loading in Claude

  1. Verify the server is registered: claude mcp list (for Claude Code)
  2. Check %APPDATA%\Claude\claude_desktop_config.json (for Claude Desktop)
  3. Restart your AI client after configuration changes
  4. Check the server log at src\ZemaxMCP.Server\bin\Debug\net48\logs\

"Connection failed" when connecting to OpticStudio

  • Standalone mode: Make sure OpticStudio is installed and licensed
  • Extension mode: Open OpticStudio first, then go to Programming > Interactive Extension before connecting

Ollama bridge cannot find the MCP server

Set the MCP_SERVER_PATH environment variable to the full path of ZemaxMCP.Server.exe, or pass it as the first command-line argument.

Known Issues

  • zemax_optimization_wizard: May not work correctly in all cases. Use zemax_forbes_merit_function or zemax_add_operand as alternatives.

License

MIT License - Copyright (c) 2026 Javier A Ruiz. See LICENSE for details. Note: A valid Zemax OpticStudio license is required for operation.

安装

TypingMind
{
  "mcpServers": {
    "opticstudiomcpserver": {
      "command": "ZemaxMCP.Server.exe",
      "args": []
    }
  }
}

将 OpticStudio MCP Server MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 OpticStudio MCP Server 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 OpticStudio MCP Server 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 OpticStudio MCP Server MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "opticstudiomcpserver": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 OpticStudio MCP Server MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 OpticStudio MCP Server MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 OpticStudio MCP Server 帮我完成这项任务吗?
OpticStudio MCP Server
当然,我看过了。
以下是我使用 OpticStudio MCP Server 得到的结果。

常见问题

OpticStudio MCP Server MCP 服务器有什么用途?

OpticStudio MCP Server 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 OpticStudio MCP Server MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 OpticStudio MCP Server。

为什么在 TypingMind 中使用 OpticStudio MCP Server MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 OpticStudio MCP Server 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 OpticStudio MCP Server MCP 连接到 TypingMind?

OpticStudio MCP Server 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

OpticStudio MCP Server MCP 在 TypingMind 中提供哪些工具?

OpticStudio MCP Server 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 OpticStudio MCP Server MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 OpticStudio MCP Server 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇