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
- With a RayCrafter window open, the agent controls that window. You watch its changes happen, you can move lenses yourself and ask the agent about the result, and you can undo its edits (but not its starting or opening of another design). The status bar shows AI agent link on and names each action.
- With no window open, the agent works on a design of its own, with no picture.
- Every result says which of the two it came from.
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:
- “Build a 2:1 beam reducer from 1 inch achromats and tell me how good the output is.”
- “Which way round should this plano-convex lens go?”
- “I have moved the second lens. What happened to the spot size?”
- “Replace these paraxial lenses with real ones and tell me what got worse.”
- “How much of the light lands on a 3 mm detector?”
- “Keep this as one design, try a better scan lens as another, and compare them.”
- “How long will a 100 fs pulse at 920 nm be after these lenses?”
Check what it tells you. Agents make mistakes, and RayCrafter is pre-alpha. Save your work first.
What an agent can do
| Look | Read 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 apertures | Add, insert, move, flip, delete and replace; set aperture diameters; put an element exactly on a focal point or focus |
| Gaps | Set and lock gaps and the source plane; optimise a gap to collimate or focus |
| Assemblies | Make, split and flip assemblies and Plossl pairs; save, list and insert user parts |
| Light and focus | Add, 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 detector | Choose 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 designs | Keep, choose, rename, remove and compare variants of a design |
| Files | New 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