RayCrafterdocumentation

Simple ray tracing with off-the-shelf optics. Very early software: expect rough edges.

AI agents

RayCrafter includes an MCP server, so an AI agent such as Claude can search for lenses, build and edit a design, and read back the optics.

How it works

1. Install the MCP extra

With pip:

pip install "raycrafter[mcp]"

Or with uv, which installs both raycrafter and raycrafter-mcp:

uv tool install "raycrafter[mcp]"

With uv you can also install nothing and let it fetch RayCrafter when needed (see below).

2. Tell your AI app where it is

Claude desktop app

Open Settings → Developer → Edit Config. This opens claude_desktop_config.json (in ~/Library/Application Support/Claude/ on macOS, %APPDATA%\Claude\ on Windows). Add RayCrafter under mcpServers, then quit and reopen the app:

{
  "mcpServers": {
    "raycrafter": {
      "command": "/full/path/to/raycrafter-mcp"
    }
  }
}

Write the path in full: the app does not expand ~ and may not see the same PATH as your terminal. Find it with which raycrafter-mcp (macOS, Linux) or where raycrafter-mcp (Windows).

If you use uv and installed nothing, use this instead (find the path with which uvx):

{
  "mcpServers": {
    "raycrafter": {
      "command": "/full/path/to/uvx",
      "args": ["--from", "raycrafter[mcp]", "raycrafter-mcp"]
    }
  }
}

Claude Code and other MCP clients

claude mcp add raycrafter -- raycrafter-mcp

Other clients take the same command.

3. Ask for something

Start RayCrafter, then ask in plain words, for example:

Check what it tells you. Agents make mistakes, and RayCrafter is pre-alpha. Save your work first.

What an agent can do

LookRead the design, search the catalogue, read spot sizes, focal lengths, magnification and any of the analyses (including collimation, transmission, pulse dispersion, wavefront, colour, vignetting, field of view and image simulation), find focal points and foci, get the teaching overlays, and see any plot as a picture
Lenses and aperturesAdd, insert, move, flip, delete and replace; set aperture diameters; put an element exactly on a focal point or focus
GapsSet and lock gaps and the source plane; optimise a gap to collimate or focus
AssembliesMake, split and flip assemblies and Plossl pairs; save, list and insert user parts
Light and focusAdd, change and remove fields; switch between beams and a finite object; choose field colours and rays per field; move the image plane; autofocus
Stop and detectorChoose the aperture stop and make the fields fill it; mark a back aperture; add, size and remove the detector, and read how much light lands on it
Named designsKeep, choose, rename, remove and compare variants of a design
FilesNew design (also from an example), save and open projects, import and export Zemax files, export STEP files

Agents cannot open the web report. Agents cannot undo. They can read and write design files anywhere your user account can. Starting, opening or importing a design is refused while there are unsaved changes, unless the agent says to discard them.

The link to the window

The window listens only on your own computer. So that the server can find it, it writes a file in ~/.raycrafter, readable only by you, holding the port and a random token. The Python API uses the same link. To turn it off, start RayCrafter with:

raycrafter --no-agent-link