zaymcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zaymcp-0.1.0/LICENSE +21 -0
- zaymcp-0.1.0/PKG-INFO +172 -0
- zaymcp-0.1.0/README.md +149 -0
- zaymcp-0.1.0/pyproject.toml +49 -0
- zaymcp-0.1.0/setup.cfg +4 -0
- zaymcp-0.1.0/src/zaymcp/__init__.py +1 -0
- zaymcp-0.1.0/src/zaymcp/__main__.py +3 -0
- zaymcp-0.1.0/src/zaymcp/dev.py +16 -0
- zaymcp-0.1.0/src/zaymcp/server.py +142 -0
- zaymcp-0.1.0/src/zaymcp/tools/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/analyze/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/analyze/image_quality/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/analyze/image_quality/rays_and_spots/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/analyze/image_quality/rays_and_spots/single_ray_trace.py +60 -0
- zaymcp-0.1.0/src/zaymcp/tools/analyze/others.py +34 -0
- zaymcp-0.1.0/src/zaymcp/tools/file/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/file/lens/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/file/lens/new.py +33 -0
- zaymcp-0.1.0/src/zaymcp/tools/file/lens/save.py +57 -0
- zaymcp-0.1.0/src/zaymcp/tools/optimize/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/optimize/automatic_optimization/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/optimize/automatic_optimization/local_optimization.py +64 -0
- zaymcp-0.1.0/src/zaymcp/tools/optimize/automatic_optimization/merit_function.py +105 -0
- zaymcp-0.1.0/src/zaymcp/tools/optimize/automatic_optimization/optimization_wizard.py +201 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/editors/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/editors/lens_data.py +105 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/editors/multi_configuration.py +88 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/system/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/tools/setup/system/explorer.py +241 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/analyze/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/analyze/image_quality/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/analyze/image_quality/rays_and_spots/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/analyze/image_quality/rays_and_spots/single_ray_trace.py +188 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/analyze/others.py +35 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/errors.py +9 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/file/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/file/lens/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/file/lens/new.py +26 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/file/lens/save.py +42 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/model/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/model/cells.py +333 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/model/fields.py +467 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/optimize/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/optimize/automatic_optimization/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/optimize/automatic_optimization/local_optimization.py +109 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/optimize/automatic_optimization/merit_function.py +454 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/optimize/automatic_optimization/optimization_wizard.py +256 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/session.py +697 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/editors/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/editors/lens_data.py +606 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/editors/multi_configuration.py +460 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/system/__init__.py +0 -0
- zaymcp-0.1.0/src/zaymcp/zosapi/setup/system/explorer.py +185 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/PKG-INFO +172 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/SOURCES.txt +60 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/dependency_links.txt +1 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/entry_points.txt +2 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/requires.txt +2 -0
- zaymcp-0.1.0/src/zaymcp.egg-info/top_level.txt +1 -0
zaymcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jiaqi Guo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
zaymcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zaymcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An MCP server for Ansys Zemax OpticStudio.
|
|
5
|
+
Author: Jiaqi Guo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/GjQAQ/ZayMCP
|
|
8
|
+
Project-URL: Documentation, https://gjqaq.github.io/ZayMCP/
|
|
9
|
+
Project-URL: Repository, https://github.com/GjQAQ/ZayMCP
|
|
10
|
+
Project-URL: Issues, https://github.com/GjQAQ/ZayMCP/issues
|
|
11
|
+
Keywords: mcp,opticstudio,zemax
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: mcp>=2.3.0
|
|
21
|
+
Requires-Dist: pythonnet>=3.2.1
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# ZayMCP
|
|
25
|
+
|
|
26
|
+
An MCP server for Ansys Zemax OpticStudio 2024 R2.
|
|
27
|
+
|
|
28
|
+
[](https://www.python.org/downloads/)
|
|
29
|
+
[](LICENSE)
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
> **Unofficial project.** ZayMCP is an independent project. It is **not** developed, maintained, endorsed, or affiliated with Ansys or Zemax, and it does **not** represent Ansys Zemax OpticStudio or its publisher. “Ansys”, “Zemax”, and “OpticStudio” are trademarks of their respective owners, used here only to identify the product this server connects to.
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- Windows
|
|
37
|
+
- Ansys Zemax OpticStudio 2024 R2
|
|
38
|
+
- Python 3.12 or newer
|
|
39
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
### Configure the MCP server
|
|
44
|
+
|
|
45
|
+
Register the server with the host. `OPTICSTUDIO_DIRECTORY` is the directory that contains `OpticStudio.exe`. The server uses it when Zemax's helper cannot find the installation.
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"mcpServers": {
|
|
50
|
+
"zaymcp": {
|
|
51
|
+
"command": "uvx",
|
|
52
|
+
"args": ["zaymcp"],
|
|
53
|
+
"env": {
|
|
54
|
+
"OPTICSTUDIO_DIRECTORY": "<path-to-OpticStudio>"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Open Interactive Extension
|
|
62
|
+
|
|
63
|
+
In OpticStudio, open **Programming → ZOS-API.NET Applications → Interactive Extension**. A dialog opens and OpticStudio waits for this server. Only one external program can be connected at a time. Leave the dialog open before the host starts the server.
|
|
64
|
+
|
|
65
|
+
## Example
|
|
66
|
+
|
|
67
|
+
[examples/001-simple-singlet.md](examples/001-simple-singlet.md) is a complete task: design a positive N-BK7 singlet, from a new lens through local optimization.
|
|
68
|
+
|
|
69
|
+
## Tools
|
|
70
|
+
|
|
71
|
+
Each tool's arguments and return fields travel with the tool schema the host receives.
|
|
72
|
+
|
|
73
|
+
<details>
|
|
74
|
+
<summary>Session</summary>
|
|
75
|
+
|
|
76
|
+
| Tool | Description |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `get_opticstudio_version` | Return the product version, license, and connection details. |
|
|
79
|
+
|
|
80
|
+
</details>
|
|
81
|
+
|
|
82
|
+
<details>
|
|
83
|
+
<summary>File</summary>
|
|
84
|
+
|
|
85
|
+
| Tool | Description |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `new_lens` | Replace the open lens with a new lens. Unsaved changes stay unless you discard them. |
|
|
88
|
+
| `get_lens_metadata` | Return the lens path, title, mode, and whether the window has unsaved changes. |
|
|
89
|
+
| `save_lens` | Save the current file, or save it to a new path. |
|
|
90
|
+
|
|
91
|
+
</details>
|
|
92
|
+
|
|
93
|
+
<details>
|
|
94
|
+
<summary>Setup</summary>
|
|
95
|
+
|
|
96
|
+
| Tool | Description |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `get_system_settings` | Read one System Explorer group: units, aperture, fields, wavelengths, environment, polarization, or ray aiming. |
|
|
99
|
+
| `set_system_settings` | Change keys in one of those groups. |
|
|
100
|
+
| `set_system_rows` | Change, add, or remove a field point or wavelength, or choose the primary wavelength. |
|
|
101
|
+
| `get_lens_data` | Read the Lens Data Editor, or one surface. |
|
|
102
|
+
| `set_lens_rows` | Change, insert, or remove one surface. |
|
|
103
|
+
| `get_multi_configuration` | Read the Multi-Configuration Editor, or one operand. |
|
|
104
|
+
| `set_multi_configuration_rows` | Change an operand or a configuration, including which configuration is current. |
|
|
105
|
+
|
|
106
|
+
</details>
|
|
107
|
+
|
|
108
|
+
<details>
|
|
109
|
+
<summary>Optimize</summary>
|
|
110
|
+
|
|
111
|
+
| Tool | Description |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| `get_merit_function` | Read the Merit Function Editor, or one operand. |
|
|
114
|
+
| `set_merit_rows` | Change, insert, or remove one operand. |
|
|
115
|
+
| `calculate_merit_function` | Calculate the merit function. |
|
|
116
|
+
| `apply_optimization_wizard` | Apply the Optimization Wizard and return the operands it creates. |
|
|
117
|
+
| `run_local_optimization` | Run local optimization and return the merit function before and after. |
|
|
118
|
+
|
|
119
|
+
</details>
|
|
120
|
+
|
|
121
|
+
<details>
|
|
122
|
+
<summary>Analyze</summary>
|
|
123
|
+
|
|
124
|
+
| Tool | Description |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `get_first_order` | Return effective focal length, entrance pupil diameter, F-numbers, and total length. |
|
|
127
|
+
| `get_single_ray_trace` | Trace one ray and return the Single Ray Trace table. |
|
|
128
|
+
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
## Connection
|
|
132
|
+
|
|
133
|
+
A host launches this server against the OpticStudio window that is waiting on Interactive Extension. The tools work on the lens open in that window, and the window stays on screen. The connection lasts for the life of the server process.
|
|
134
|
+
|
|
135
|
+
When OpticStudio cannot answer a call, the server closes the connection. The next call opens a new one, which needs the Interactive Extension dialog to be waiting again. **Auto Close on Disconnect** is on by default, so the dialog closes when the connection ends. Open Interactive Extension again before the next session. Stopping the host closes the connection the same way.
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
Clone the repository and create the environment:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone https://github.com/GjQAQ/ZayMCP.git
|
|
143
|
+
cd ZayMCP
|
|
144
|
+
uv sync
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
To run this checkout instead of the published package, point the host at it:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"mcpServers": {
|
|
152
|
+
"zaymcp-dev": {
|
|
153
|
+
"command": "uv",
|
|
154
|
+
"args": [
|
|
155
|
+
"run",
|
|
156
|
+
"--project",
|
|
157
|
+
"<path-to-checkout>",
|
|
158
|
+
"zaymcp"
|
|
159
|
+
],
|
|
160
|
+
"env": {
|
|
161
|
+
"OPTICSTUDIO_DIRECTORY": "<path-to-OpticStudio>"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Development conventions are in [CONTRIBUTING.md](CONTRIBUTING.md). Lasting decisions are recorded in [docs/adr](docs/adr).
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
[MIT](LICENSE) © 2026 Jiaqi Guo
|
zaymcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# ZayMCP
|
|
2
|
+
|
|
3
|
+
An MCP server for Ansys Zemax OpticStudio 2024 R2.
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
> **Unofficial project.** ZayMCP is an independent project. It is **not** developed, maintained, endorsed, or affiliated with Ansys or Zemax, and it does **not** represent Ansys Zemax OpticStudio or its publisher. “Ansys”, “Zemax”, and “OpticStudio” are trademarks of their respective owners, used here only to identify the product this server connects to.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Windows
|
|
14
|
+
- Ansys Zemax OpticStudio 2024 R2
|
|
15
|
+
- Python 3.12 or newer
|
|
16
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
### Configure the MCP server
|
|
21
|
+
|
|
22
|
+
Register the server with the host. `OPTICSTUDIO_DIRECTORY` is the directory that contains `OpticStudio.exe`. The server uses it when Zemax's helper cannot find the installation.
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"mcpServers": {
|
|
27
|
+
"zaymcp": {
|
|
28
|
+
"command": "uvx",
|
|
29
|
+
"args": ["zaymcp"],
|
|
30
|
+
"env": {
|
|
31
|
+
"OPTICSTUDIO_DIRECTORY": "<path-to-OpticStudio>"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Open Interactive Extension
|
|
39
|
+
|
|
40
|
+
In OpticStudio, open **Programming → ZOS-API.NET Applications → Interactive Extension**. A dialog opens and OpticStudio waits for this server. Only one external program can be connected at a time. Leave the dialog open before the host starts the server.
|
|
41
|
+
|
|
42
|
+
## Example
|
|
43
|
+
|
|
44
|
+
[examples/001-simple-singlet.md](examples/001-simple-singlet.md) is a complete task: design a positive N-BK7 singlet, from a new lens through local optimization.
|
|
45
|
+
|
|
46
|
+
## Tools
|
|
47
|
+
|
|
48
|
+
Each tool's arguments and return fields travel with the tool schema the host receives.
|
|
49
|
+
|
|
50
|
+
<details>
|
|
51
|
+
<summary>Session</summary>
|
|
52
|
+
|
|
53
|
+
| Tool | Description |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `get_opticstudio_version` | Return the product version, license, and connection details. |
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>File</summary>
|
|
61
|
+
|
|
62
|
+
| Tool | Description |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `new_lens` | Replace the open lens with a new lens. Unsaved changes stay unless you discard them. |
|
|
65
|
+
| `get_lens_metadata` | Return the lens path, title, mode, and whether the window has unsaved changes. |
|
|
66
|
+
| `save_lens` | Save the current file, or save it to a new path. |
|
|
67
|
+
|
|
68
|
+
</details>
|
|
69
|
+
|
|
70
|
+
<details>
|
|
71
|
+
<summary>Setup</summary>
|
|
72
|
+
|
|
73
|
+
| Tool | Description |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `get_system_settings` | Read one System Explorer group: units, aperture, fields, wavelengths, environment, polarization, or ray aiming. |
|
|
76
|
+
| `set_system_settings` | Change keys in one of those groups. |
|
|
77
|
+
| `set_system_rows` | Change, add, or remove a field point or wavelength, or choose the primary wavelength. |
|
|
78
|
+
| `get_lens_data` | Read the Lens Data Editor, or one surface. |
|
|
79
|
+
| `set_lens_rows` | Change, insert, or remove one surface. |
|
|
80
|
+
| `get_multi_configuration` | Read the Multi-Configuration Editor, or one operand. |
|
|
81
|
+
| `set_multi_configuration_rows` | Change an operand or a configuration, including which configuration is current. |
|
|
82
|
+
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
<details>
|
|
86
|
+
<summary>Optimize</summary>
|
|
87
|
+
|
|
88
|
+
| Tool | Description |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `get_merit_function` | Read the Merit Function Editor, or one operand. |
|
|
91
|
+
| `set_merit_rows` | Change, insert, or remove one operand. |
|
|
92
|
+
| `calculate_merit_function` | Calculate the merit function. |
|
|
93
|
+
| `apply_optimization_wizard` | Apply the Optimization Wizard and return the operands it creates. |
|
|
94
|
+
| `run_local_optimization` | Run local optimization and return the merit function before and after. |
|
|
95
|
+
|
|
96
|
+
</details>
|
|
97
|
+
|
|
98
|
+
<details>
|
|
99
|
+
<summary>Analyze</summary>
|
|
100
|
+
|
|
101
|
+
| Tool | Description |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| `get_first_order` | Return effective focal length, entrance pupil diameter, F-numbers, and total length. |
|
|
104
|
+
| `get_single_ray_trace` | Trace one ray and return the Single Ray Trace table. |
|
|
105
|
+
|
|
106
|
+
</details>
|
|
107
|
+
|
|
108
|
+
## Connection
|
|
109
|
+
|
|
110
|
+
A host launches this server against the OpticStudio window that is waiting on Interactive Extension. The tools work on the lens open in that window, and the window stays on screen. The connection lasts for the life of the server process.
|
|
111
|
+
|
|
112
|
+
When OpticStudio cannot answer a call, the server closes the connection. The next call opens a new one, which needs the Interactive Extension dialog to be waiting again. **Auto Close on Disconnect** is on by default, so the dialog closes when the connection ends. Open Interactive Extension again before the next session. Stopping the host closes the connection the same way.
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
Clone the repository and create the environment:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
git clone https://github.com/GjQAQ/ZayMCP.git
|
|
120
|
+
cd ZayMCP
|
|
121
|
+
uv sync
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
To run this checkout instead of the published package, point the host at it:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"mcpServers": {
|
|
129
|
+
"zaymcp-dev": {
|
|
130
|
+
"command": "uv",
|
|
131
|
+
"args": [
|
|
132
|
+
"run",
|
|
133
|
+
"--project",
|
|
134
|
+
"<path-to-checkout>",
|
|
135
|
+
"zaymcp"
|
|
136
|
+
],
|
|
137
|
+
"env": {
|
|
138
|
+
"OPTICSTUDIO_DIRECTORY": "<path-to-OpticStudio>"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Development conventions are in [CONTRIBUTING.md](CONTRIBUTING.md). Lasting decisions are recorded in [docs/adr](docs/adr).
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
[MIT](LICENSE) © 2026 Jiaqi Guo
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "zaymcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An MCP server for Ansys Zemax OpticStudio."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Jiaqi Guo" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["mcp", "opticstudio", "zemax"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Operating System :: Microsoft :: Windows",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"mcp>=2.3.0",
|
|
26
|
+
"pythonnet>=3.2.1",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/GjQAQ/ZayMCP"
|
|
31
|
+
Documentation = "https://gjqaq.github.io/ZayMCP/"
|
|
32
|
+
Repository = "https://github.com/GjQAQ/ZayMCP"
|
|
33
|
+
Issues = "https://github.com/GjQAQ/ZayMCP/issues"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
zaymcp = "zaymcp.server:main"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.uv]
|
|
42
|
+
default-groups = "all"
|
|
43
|
+
package = true
|
|
44
|
+
|
|
45
|
+
[dependency-groups]
|
|
46
|
+
docs = [
|
|
47
|
+
"furo>=2025.12.19",
|
|
48
|
+
"sphinx>=9.1.1",
|
|
49
|
+
]
|
zaymcp-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""MCP server for Ansys Zemax OpticStudio."""
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Entry point for ``mcp dev``.
|
|
2
|
+
|
|
3
|
+
The CLI loads this file by path. Tool modules import ``zaymcp.server``, so
|
|
4
|
+
this file re-exports that module's server instead of creating a second one.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import mcp.server
|
|
8
|
+
|
|
9
|
+
import zaymcp.server
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
'server',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
#: MCP server loaded by ``mcp dev``.
|
|
16
|
+
server: mcp.server.MCPServer = zaymcp.server.server
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Stdio MCP server."""
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
|
|
5
|
+
import mcp.server
|
|
6
|
+
import mcp.server.mcpserver
|
|
7
|
+
import mcp.server.mcpserver.exceptions
|
|
8
|
+
|
|
9
|
+
import zaymcp.zosapi.session
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
'SERVER_NAME',
|
|
13
|
+
'main',
|
|
14
|
+
'read',
|
|
15
|
+
'server',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
#: Name announced to an MCP host.
|
|
19
|
+
SERVER_NAME: str = "zaymcp"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class OpticStudioConnection:
|
|
23
|
+
"""Keep one Interactive Extension session for this server process."""
|
|
24
|
+
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
#: The shared OpticStudio session. ``None`` before the first tool call and after a failed call.
|
|
27
|
+
self.session: zaymcp.zosapi.session.OpticStudioSession | None = None
|
|
28
|
+
|
|
29
|
+
def open(self) -> zaymcp.zosapi.session.OpticStudioSession:
|
|
30
|
+
"""
|
|
31
|
+
Return the shared session, connecting on first use.
|
|
32
|
+
|
|
33
|
+
:returns: The Interactive Extension session.
|
|
34
|
+
:rtype: zaymcp.zosapi.session.OpticStudioSession
|
|
35
|
+
:raises zaymcp.zosapi.session.OpticStudioError: OpticStudio cannot be connected.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
if self.session is None:
|
|
39
|
+
self.session = zaymcp.zosapi.session.OpticStudioSession()
|
|
40
|
+
|
|
41
|
+
return self.session
|
|
42
|
+
|
|
43
|
+
def close(self) -> None:
|
|
44
|
+
"""Disconnect the shared session.
|
|
45
|
+
|
|
46
|
+
Calling this again does nothing.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
session = self.session
|
|
50
|
+
self.session = None
|
|
51
|
+
|
|
52
|
+
if session is not None:
|
|
53
|
+
session.close()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@contextlib.asynccontextmanager
|
|
57
|
+
async def lifespan(server: mcp.server.MCPServer):
|
|
58
|
+
"""
|
|
59
|
+
Keep one OpticStudio connection for the life of this server process.
|
|
60
|
+
|
|
61
|
+
:param mcp.server.MCPServer server: The server being started.
|
|
62
|
+
:returns: The connection yielded to each request.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
# Close the OpticStudio connection when the host stops this process.
|
|
66
|
+
connection = OpticStudioConnection()
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
yield connection
|
|
70
|
+
finally:
|
|
71
|
+
connection.close()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
server = mcp.server.MCPServer(SERVER_NAME, lifespan=lifespan)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def read(ctx, load):
|
|
78
|
+
"""
|
|
79
|
+
Run one read against the shared session.
|
|
80
|
+
|
|
81
|
+
The session is dropped when OpticStudio cannot answer, so the next call can reconnect.
|
|
82
|
+
|
|
83
|
+
:param ctx: Tool context for this request.
|
|
84
|
+
:param load: Called with the open session.
|
|
85
|
+
:returns: The value returned by ``load``.
|
|
86
|
+
:raises mcp.server.mcpserver.exceptions.ToolError: OpticStudio cannot answer.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
# Drop the shared session when OpticStudio cannot answer, so the next call can reconnect.
|
|
90
|
+
connection = ctx.request_context.lifespan_context
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
return load(connection.open())
|
|
94
|
+
except zaymcp.zosapi.session.OpticStudioError as exc:
|
|
95
|
+
connection.close()
|
|
96
|
+
raise mcp.server.mcpserver.exceptions.ToolError(str(exc)) from exc
|
|
97
|
+
except ValueError as exc:
|
|
98
|
+
# ValueError is an anticipated tool failure. Left as ValueError, the host only sees "Error executing tool".
|
|
99
|
+
raise mcp.server.mcpserver.exceptions.ToolError(str(exc)) from exc
|
|
100
|
+
|
|
101
|
+
@server.tool(
|
|
102
|
+
description='Return version, license, and connection details for the OpticStudio window.',
|
|
103
|
+
)
|
|
104
|
+
def get_opticstudio_version(ctx: mcp.server.mcpserver.Context) -> dict[str, str | int]:
|
|
105
|
+
"""
|
|
106
|
+
Return version details for the OpticStudio window waiting on Interactive Extension.
|
|
107
|
+
|
|
108
|
+
:returns:
|
|
109
|
+
* **product_name** -- Product name from ``OpticStudio.exe``.
|
|
110
|
+
* **product_version** -- Product version, such as ``24.2.00.0``. The first two parts identify the release, so 24.2 is 2024 R2.
|
|
111
|
+
* **file_version** -- File version of ``OpticStudio.exe``.
|
|
112
|
+
* **file_description** -- File description of ``OpticStudio.exe``.
|
|
113
|
+
* **opticstudio_version** -- Integer version reported by ZOS-API.
|
|
114
|
+
* **zos_major_version** -- ZOS-API major version.
|
|
115
|
+
* **zos_minor_version** -- ZOS-API minor version.
|
|
116
|
+
* **zos_service_pack** -- ZOS-API service pack number. 0 means no service pack.
|
|
117
|
+
* **license_status** -- License type, such as ``PremiumEdition``.
|
|
118
|
+
* **mode** -- Connection mode. Interactive Extension reports ``Plugin``.
|
|
119
|
+
* **installation_directory** -- Directory that contains ``OpticStudio.exe``.
|
|
120
|
+
* **supported_release** -- Release this server supports. This value is fixed by the server.
|
|
121
|
+
:rtype: dict[str, str | int]
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
return read(ctx, lambda session: session.version())
|
|
125
|
+
|
|
126
|
+
def main() -> None:
|
|
127
|
+
"""Serve MCP over stdio until the host closes the connection."""
|
|
128
|
+
|
|
129
|
+
server.run()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# Importing a tool module registers its tools on server.
|
|
133
|
+
import zaymcp.tools.file.lens.new
|
|
134
|
+
import zaymcp.tools.file.lens.save
|
|
135
|
+
import zaymcp.tools.setup.system.explorer
|
|
136
|
+
import zaymcp.tools.setup.editors.lens_data
|
|
137
|
+
import zaymcp.tools.setup.editors.multi_configuration
|
|
138
|
+
import zaymcp.tools.optimize.automatic_optimization.local_optimization
|
|
139
|
+
import zaymcp.tools.optimize.automatic_optimization.merit_function
|
|
140
|
+
import zaymcp.tools.optimize.automatic_optimization.optimization_wizard
|
|
141
|
+
import zaymcp.tools.analyze.image_quality.rays_and_spots.single_ray_trace
|
|
142
|
+
import zaymcp.tools.analyze.others
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Single Ray Trace tool."""
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import mcp.server.mcpserver
|
|
6
|
+
|
|
7
|
+
import zaymcp.server as mcp_server
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
'get_single_ray_trace',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
@mcp_server.server.tool(
|
|
14
|
+
description=(
|
|
15
|
+
'Return the Single Ray Trace table for one ray. '
|
|
16
|
+
'`hx` and `hy` are the normalized field coordinates. '
|
|
17
|
+
'`px` and `py` are the normalized pupil coordinates. '
|
|
18
|
+
'`trace_type` is `DirectionCosines`, `TangentAngle`, or `YmUmYcUc`.'
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
def get_single_ray_trace(
|
|
22
|
+
ctx: mcp.server.mcpserver.Context,
|
|
23
|
+
wavelength: int = 1,
|
|
24
|
+
hx: float = 0,
|
|
25
|
+
hy: float = 0,
|
|
26
|
+
px: float = 0,
|
|
27
|
+
py: float = 0,
|
|
28
|
+
trace_type: typing.Literal['DirectionCosines', 'TangentAngle', 'YmUmYcUc'] = 'DirectionCosines',
|
|
29
|
+
) -> dict[str, object]:
|
|
30
|
+
"""
|
|
31
|
+
Return the Single Ray Trace table for one ray in the open lens.
|
|
32
|
+
|
|
33
|
+
``hx`` and ``hy`` are the normalized field coordinates. ``px`` and ``py`` are the normalized pupil coordinates. ``trace_type`` selects Direction Cosines, Tangential Angle, or ``Ym, Um, Yc, Uc``.
|
|
34
|
+
|
|
35
|
+
:param wavelength: 1-based wavelength number.
|
|
36
|
+
:param hx: Normalized field coordinate X.
|
|
37
|
+
:param hy: Normalized field coordinate Y.
|
|
38
|
+
:param px: Normalized pupil coordinate X.
|
|
39
|
+
:param py: Normalized pupil coordinate Y.
|
|
40
|
+
:param trace_type: ``DirectionCosines``, ``TangentAngle``, or ``YmUmYcUc``.
|
|
41
|
+
:returns:
|
|
42
|
+
* **wavelength** -- Wavelength number used for the ray.
|
|
43
|
+
* **hx** -- Normalized field coordinate X.
|
|
44
|
+
* **hy** -- Normalized field coordinate Y.
|
|
45
|
+
* **px** -- Normalized pupil coordinate X.
|
|
46
|
+
* **py** -- Normalized pupil coordinate Y.
|
|
47
|
+
* **type** -- Table format.
|
|
48
|
+
* **columns** -- Headings of the Single Ray Trace table, after the surface column.
|
|
49
|
+
* **surfaces** -- One entry per surface, in the order shown in the window.
|
|
50
|
+
* **surfaces[].surface** -- Surface label from the table, such as ``OBJ``, a surface number, or ``IMA``.
|
|
51
|
+
* **surfaces[].values** -- One number per heading. ``None`` where the table has no finite number.
|
|
52
|
+
* **message** -- Error line under the table. Empty when the table has none.
|
|
53
|
+
:rtype: dict[str, object]
|
|
54
|
+
:raises ValueError: The ray settings or the table cannot be used.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
return mcp_server.read(
|
|
58
|
+
ctx,
|
|
59
|
+
lambda session: session.single_ray_trace(wavelength, hx, hy, px, py, trace_type),
|
|
60
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Analyze results that are not their own window."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import mcp.server.mcpserver
|
|
5
|
+
|
|
6
|
+
import zaymcp.server as mcp_server
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'get_first_order',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
@mcp_server.server.tool(
|
|
13
|
+
description=(
|
|
14
|
+
'Return effective focal length, entrance pupil diameter, F-numbers, and total length for the open lens. '
|
|
15
|
+
'Lengths are in lens units.'
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
def get_first_order(ctx: mcp.server.mcpserver.Context) -> dict[str, float | str | None]:
|
|
19
|
+
"""
|
|
20
|
+
Return first-order values for the lens open in the OpticStudio window.
|
|
21
|
+
|
|
22
|
+
The system is updated before the values are read. ``working_f_number`` is on axis at the primary wavelength. A number is ``None`` when OpticStudio does not return a finite value.
|
|
23
|
+
|
|
24
|
+
:returns:
|
|
25
|
+
* **effective_focal_length** -- Effective focal length, in lens units.
|
|
26
|
+
* **entrance_pupil_diameter** -- Entrance pupil diameter, in lens units.
|
|
27
|
+
* **image_space_f_number** -- Paraxial image-space F-number.
|
|
28
|
+
* **working_f_number** -- Working F-number on axis at the primary wavelength.
|
|
29
|
+
* **total_length** -- Thickness from surface 1 to the image surface, in lens units.
|
|
30
|
+
* **status** -- Text reported while updating the system. Empty when the update reports nothing.
|
|
31
|
+
:rtype: dict[str, float | str | None]
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
return mcp_server.read(ctx, lambda session: session.first_order())
|
|
File without changes
|
|
File without changes
|