sim-tools-mcp 1.0.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.
Files changed (32) hide show
  1. sim_tools_mcp-1.0.0/LICENSE +21 -0
  2. sim_tools_mcp-1.0.0/PKG-INFO +241 -0
  3. sim_tools_mcp-1.0.0/README.md +214 -0
  4. sim_tools_mcp-1.0.0/pyproject.toml +139 -0
  5. sim_tools_mcp-1.0.0/setup.cfg +4 -0
  6. sim_tools_mcp-1.0.0/src/cooling_surrogate/LICENSE +21 -0
  7. sim_tools_mcp-1.0.0/src/cooling_surrogate/__init__.py +0 -0
  8. sim_tools_mcp-1.0.0/src/cooling_surrogate/checks.py +60 -0
  9. sim_tools_mcp-1.0.0/src/cooling_surrogate/data.py +176 -0
  10. sim_tools_mcp-1.0.0/src/cooling_surrogate/metrics.py +60 -0
  11. sim_tools_mcp-1.0.0/src/cooling_surrogate/model.py +138 -0
  12. sim_tools_mcp-1.0.0/src/cooling_surrogate/monitor.py +87 -0
  13. sim_tools_mcp-1.0.0/src/cooling_surrogate/physics.py +299 -0
  14. sim_tools_mcp-1.0.0/src/cooling_surrogate/service.py +149 -0
  15. sim_tools_mcp-1.0.0/src/sim_tools_mcp/__init__.py +1 -0
  16. sim_tools_mcp-1.0.0/src/sim_tools_mcp/__main__.py +3 -0
  17. sim_tools_mcp-1.0.0/src/sim_tools_mcp/model_v1/bundle.json +12 -0
  18. sim_tools_mcp-1.0.0/src/sim_tools_mcp/model_v1/model/model.json +24 -0
  19. sim_tools_mcp-1.0.0/src/sim_tools_mcp/model_v1/model/weights.pt +0 -0
  20. sim_tools_mcp-1.0.0/src/sim_tools_mcp/py.typed +0 -0
  21. sim_tools_mcp-1.0.0/src/sim_tools_mcp/server.py +160 -0
  22. sim_tools_mcp-1.0.0/src/sim_tools_mcp/tools.py +703 -0
  23. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/PKG-INFO +241 -0
  24. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/SOURCES.txt +30 -0
  25. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/dependency_links.txt +1 -0
  26. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/entry_points.txt +2 -0
  27. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/requires.txt +5 -0
  28. sim_tools_mcp-1.0.0/src/sim_tools_mcp.egg-info/top_level.txt +2 -0
  29. sim_tools_mcp-1.0.0/tests/test_mcp.py +89 -0
  30. sim_tools_mcp-1.0.0/tests/test_results.py +30 -0
  31. sim_tools_mcp-1.0.0/tests/test_tools.py +150 -0
  32. sim_tools_mcp-1.0.0/tests/test_vendored.py +31 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zuhal Karadavut
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.
@@ -0,0 +1,241 @@
1
+ Metadata-Version: 2.4
2
+ Name: sim-tools-mcp
3
+ Version: 1.0.0
4
+ Summary: MCP tools that let an AI agent run and query a verified cooling simulation and its surrogate safely.
5
+ Author: Zuhal Karadavut
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://zuhalsicimkaradavut.com/projects/cooling-surrogate/
8
+ Project-URL: Repository, https://github.com/zuhalsicim/sim-tools-mcp
9
+ Project-URL: Issues, https://github.com/zuhalsicim/sim-tools-mcp/issues
10
+ Keywords: mcp,model-context-protocol,ai-agents,physics-simulation,surrogate-model,safety
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy>=2.0
22
+ Requires-Dist: scipy>=1.14
23
+ Requires-Dist: torch>=2.5
24
+ Requires-Dist: pydantic>=2.10
25
+ Requires-Dist: mcp>=1.2
26
+ Dynamic: license-file
27
+
28
+ # sim-tools-mcp
29
+
30
+ [![ci](https://github.com/zuhalsicim/sim-tools-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/zuhalsicim/sim-tools-mcp/actions/workflows/ci.yml)
31
+
32
+ **Solver & surrogate:** [cooling-surrogate](https://zuhalsicimkaradavut.com/projects/cooling-surrogate/) · **Portfolio & proof:** [zuhalsicimkaradavut.com](https://zuhalsicimkaradavut.com) · **Author:** [Zuhal Karadavut (Zuhal Sicim · @zuhalsicim)](https://zuhalsicimkaradavut.com)
33
+
34
+ An MCP server that lets an AI agent use my [cooling-surrogate](https://github.com/zuhalsicim/cooling-surrogate)
35
+ pipeline: run the finite-volume solver, ask the surrogate, sweep one input, check an answer against
36
+ physics, and compare surrogate and solver. I built it to answer one question.
37
+
38
+ Can an agent use a simulation and its fast surrogate through tool calls without ever getting a surrogate number it should not trust?
39
+ Here, yes. Of 694 calls the surrogate must not answer (invalid, malformed, outside the training box, or failing a physics check), it answered 0. With the int8 copy that the gate in cooling-surrogate blocked loaded on purpose, 71 of 200 answers failed a physics check, all 71 went to the solver, and no answer that fails a check reached the agent.
40
+ A scripted agent found the warmest mould temperature for an 8 s cooling time in 7 tool calls and 475 ms, 0.032 K below the solver's own answer; the solver alone took 13 calls and 2.59 s. A surrogate call over stdio takes 2.30 ms at the median.
41
+ The numbers are in [`results/`](results/), and CI checks on every push that the results section below matches them.
42
+
43
+ To reproduce: `pip install -r requirements-dev.txt && pip install -e . --no-deps`, then `python -m bench.run_all` and `python -m bench.readme` (CPU only; the whole measurement took 239 s on one AMD CPU under Windows 11). Details under [Run it](#run-it).
44
+
45
+ ## The question
46
+
47
+ Can an agent work with a simulation and its fast surrogate through tool calls, without ever getting a
48
+ surrogate number it should not trust, and what does each call cost?
49
+
50
+ The surrogate in cooling-surrogate is much faster than the solver, but it is only valid inside the box of
51
+ inputs it was trained on, and only when its answer passes the physics checks. A person reads that in the
52
+ README. An agent only sees the tool list and what the calls return, so the tools have to
53
+ carry those rules themselves.
54
+
55
+ ## What I measured
56
+
57
+ Every number in this section is written by `python -m bench.readme` from the files in `results/`, which
58
+ `python -m bench.run_all` produces. CI fails if the two disagree.
59
+
60
+ <!-- results:begin -->
61
+ I asked the scripted agent for the warmest mould temperature that keeps a 2 mm part at or under 8 s of cooling. It answered 44.00 °C after 7 tool calls. The solver's own answer, found by bisection without the tools, is 44.032 °C, so the agent is 0.032 K below it, inside the 0.05 K step it searched with. Its last calls ran the solver on both sides of the answer to confirm it. On this run the surrogate put the crossing one step too high and the solver check moved it down. With one predict_cooling call per bisection step it took 17 calls. The solver alone took 13 calls and 2.59 s, where the sweep plan took 475 ms.
62
+
63
+ With a 12 s budget the answer lies above 60 °C, where the surrogate was never trained. The same plan answered 76.15 °C (solver: 76.156 °C) in 6 calls; 56 of its 97 sweep points were answered by the solver, each one marked as such. It still took only 1.37 s, against 3.01 s for the solver alone, because a sweep hands all its out-of-box points to the solver as one batch.
64
+
65
+ Of 694 calls the surrogate must not answer (invalid, malformed, outside the training box, or failing a physics check), it answered 0. 74 hand-written calls of that kind were all handled as planned (74 of 74): 59 refused with a code, a reason and a hint, the rest answered by the solver. 1,000 random calls matched an independent check of the limits every time (0 mismatches). With a broken model loaded on purpose, the int8 copy my gate in cooling-surrogate blocked, 71 of 200 answers inside the box failed a physics check and went to the solver; 0 answers that fail a check came back.
66
+
67
+ Every tool answer equals the direct library call: 134 of 134 comparisons on 22 fixed cases, exact float equality after the JSON round trip, including against cooling-surrogate's own HTTP service, with MKL on one thread as the service is configured (see Limits). A second server process gave byte-identical answers and result ids (45 of 45), and repeated calls came from the result store (45 of 45, 0 solver runs).
68
+
69
+ Over stdio a surrogate call takes 2.30 ms at the median against 0.31 ms for the bare library call, so the protocol and the guards add about 1.99 ms. A solver call takes 221 ms (library 221 ms). Starting the server takes 4.01 s.
70
+
71
+ ### 1. The agent session
72
+
73
+ A deterministic client follows a fixed plan, no language model. One fresh server per run. Time is what the client waited for tool calls, without server start.
74
+
75
+ **A 2 mm wall, melt 230 °C: what is the warmest mould temperature between 20 and 60 °C that keeps the cooling time at or below 8 s?** Solver answer: 44.0317 °C.
76
+
77
+ | plan | tool calls | solver runs | time | answer | off by | confirmed by the solver |
78
+ |---|---:|---:|---:|---:|---:|---|
79
+ | two sweeps, then check | 7 | 2 | 475 ms | 44.0000 °C | -0.0317 K | yes (stepped down) |
80
+ | one point per call | 17 | 2 | 474 ms | 44.0234 °C | -0.0082 K | yes (stepped down) |
81
+ | solver only | 13 | 12 | 2.59 s | 44.0234 °C | -0.0082 K | yes |
82
+
83
+ **The same part with a 12 s cycle budget: what is the warmest mould temperature between 20 and 95 °C that keeps the cooling time at or below 12 s? The surrogate was trained up to 60 °C only.** Solver answer: 76.1559 °C.
84
+
85
+ | plan | tool calls | solver runs | time | answer | off by | confirmed by the solver |
86
+ |---|---:|---:|---:|---:|---:|---|
87
+ | two sweeps, then check | 6 | 58 | 1.37 s | 76.1500 °C | -0.0059 K | yes |
88
+ | one point per call | 17 | 13 | 3.08 s | 76.1401 °C | -0.0158 K | yes |
89
+ | solver only | 14 | 13 | 3.01 s | 76.1401 °C | -0.0158 K | yes |
90
+
91
+ ### 2. Safety
92
+
93
+ Hand-written bad calls, by kind. The surrogate column must be zero everywhere.
94
+
95
+ | kind | calls | as planned | refused | solver | surrogate |
96
+ |---|---:|---:|---:|---:|---:|
97
+ | physically meaningless numbers | 35 | 35 | 35 | 0 | 0 |
98
+ | wrong types, missing or extra fields, bad ids | 21 | 21 | 21 | 0 | 0 |
99
+ | valid, outside the training box | 16 | 16 | 2 | 14 | 0 |
100
+ | inside the box, surrogate answer fails a check | 1 | 1 | 0 | 1 | 0 |
101
+ | valid, but the wall never cools enough | 1 | 1 | 1 | 0 | 0 |
102
+
103
+ Random calls to predict_cooling (seed 7): each input in the box, outside it, physically invalid, malformed or missing, at fixed odds.
104
+
105
+ | outcome | calls |
106
+ |---|---:|
107
+ | refused, invalid_input | 395 |
108
+ | surrogate | 380 |
109
+ | solver, out_of_box | 225 |
110
+
111
+ Physics guard, inside the box only, every answer then put through check_physics:
112
+
113
+ | model served | calls | surrogate answers failing a check | sent to the solver | answers returned failing a check |
114
+ |---|---:|---:|---:|---:|
115
+ | version 1, promoted | 200 | 1 | 1 | 0 |
116
+ | int8 copy, blocked by the gate | 200 | 71 | 71 | 0 |
117
+
118
+ ### 3. Correctness
119
+
120
+ | comparison | checked | equal |
121
+ |---|---:|---:|
122
+ | run_solver = physics.solve | 22 | 22 |
123
+ | predict_cooling = library guard and fallback | 22 | 22 |
124
+ | predict_cooling = cooling-surrogate HTTP service | 22 | 22 |
125
+ | compare_with_solver = metrics.errors | 22 | 22 |
126
+ | check_physics = checks.run_all | 44 | 44 |
127
+ | sweep_parameter = library guard on the batch | 2 | 2 |
128
+
129
+ A sweep answers in one batch, and batching changes the floating-point path a little: sweep points differ from the same points asked one by one by at most 2.9e-07 relative.
130
+
131
+ ### 4. Latency
132
+
133
+ Median and 95th percentile over 200 calls (15 for the solver rows), new inputs on every call. Library is cooling_surrogate called directly; tool layer is the same call through ToolBox in-process; MCP is the client's wait for the answer from the server subprocess over stdio.
134
+
135
+ | call | library | tool layer | MCP, median | MCP, p95 | answer size |
136
+ |---|---:|---:|---:|---:|---:|
137
+ | describe_model | - | 0.01 ms | 1.57 ms | 1.96 ms | 3,236 chars |
138
+ | predict_cooling, inside the box | 0.31 ms | 0.40 ms | 2.30 ms | 3.48 ms | 609 chars |
139
+ | predict_cooling, same call again (result store) | - | 0.02 ms | 1.59 ms | 2.28 ms | 605 chars |
140
+ | sweep_parameter, 41 points inside the box | 0.94 ms | 1.29 ms | 4.35 ms | 6.00 ms | 2,481 chars |
141
+ | check_physics on a stored answer | 0.11 ms | 0.15 ms | 2.12 ms | 3.00 ms | 1,151 chars |
142
+ | predict_cooling, outside the box (solver) | 220 ms | 221 ms | 230 ms | 249 ms | 649 chars |
143
+ | run_solver | 221 ms | 217 ms | 221 ms | 249 ms | 507 chars |
144
+ | compare_with_solver | 222 ms | 217 ms | 224 ms | 256 ms | 921 chars |
145
+
146
+ Server start, three runs: 3.93 s, 4.01 s, 4.04 s. Machine: AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD, Windows 11, Python 3.12.16, mcp 2.3.0, torch 2.15.0+cpu, numpy 2.5.5, one torch thread. Whole measurement: 239 s.
147
+ <!-- results:end -->
148
+
149
+ ## How it works
150
+
151
+ | tool | what it does | runs the solver |
152
+ |---|---|---|
153
+ | `describe_model` | every input with unit, allowed range and training box; model version and hashes; the checks | no |
154
+ | `predict_cooling` | cooling time and heat removed for one case, surrogate with solver fallback | only when needed |
155
+ | `sweep_parameter` | the same over a grid of one input, in one call | for the points that need it, in one batch |
156
+ | `run_solver` | the finite-volume solver, verified against the exact series in cooling-surrogate | yes |
157
+ | `check_physics` | the five physics checks on an earlier answer, by its `result_id`, with the worst value of each | no |
158
+ | `compare_with_solver` | surrogate and solver on one case, and the surrogate's error | yes |
159
+
160
+ Every input carries its unit in its name (`melt_temp_c`, `thickness_mm`, `htc_w_m2k`, ...), and the JSON
161
+ schema the agent sees gives its allowed range and the training box. Types are strict: `"230"` or `true`
162
+ for a temperature is refused, not converted. A refused call comes back with `ok: false`, MCP's `is_error`
163
+ flag, a code, a reason that names the field and what is allowed, and a hint for the next call. For an
164
+ invalid call nothing is computed.
165
+
166
+ `predict_cooling` and `sweep_parameter` use the same guard as cooling-surrogate's HTTP service, in the same
167
+ order. If any input is outside the training box, the solver answers. If the surrogate's answer fails one of
168
+ the five physics checks, the solver answers. The answer says which one answered and why (`source`,
169
+ `fallback_reason`, `outside_training_box`, `surrogate_failed_checks`). With `on_out_of_box: "refuse"` an
170
+ agent that cannot wait for the solver gets a refusal instead, and still no surrogate number.
171
+
172
+ Each answer reports its `cost`: wall time, solver runs, surrogate evaluations, and whether it came from the
173
+ result store. Answers depend only on the arguments and the model, so each one gets a `result_id`, a hash
174
+ of the tool, the arguments, the weights and the library commit. The same call again returns the same id
175
+ and the same answer from the store without running anything. `check_physics` takes that id, so an agent
176
+ never has to send profiles back.
177
+
178
+ I wrote the server on the SDK's low-level `Server`, not the decorator layer. That way the schemas the agent
179
+ sees are exactly the ones in `tools.py`, and a bad argument comes back as a refusal the agent can read,
180
+ not as a protocol error. All tools are marked read-only and idempotent.
181
+
182
+ `src/cooling_surrogate` is an unchanged copy of eight files of cooling-surrogate at commit `58b7397` (MIT
183
+ licence, copied with it). It is copied, not installed, because that repository is not packaged for pip.
184
+ `UPSTREAM.json` holds the SHA-256 of every file, a test checks them, and CI compares them with a fresh
185
+ clone of that commit. The model in `src/sim_tools_mcp/model_v1` is version 1 of cooling-surrogate's full
186
+ run, the one its gate promoted. The server refuses to start if the weights' hash is not the registered one.
187
+
188
+ The measurements live in `bench/`: `correctness.py`, `safety.py` (with the bad calls in `cases.py`),
189
+ `latency.py`, and `agent.py` with `session.py` for the scripted agent.
190
+
191
+ ## Run it
192
+
193
+ Python 3.12, CPU only.
194
+
195
+ ```sh
196
+ python -m venv .venv
197
+ .venv/bin/pip install -r requirements-dev.txt # Windows: .venv\Scripts\pip
198
+ .venv/bin/pip install -e . --no-deps
199
+ .venv/bin/python -m pytest -q
200
+ .venv/bin/python -m bench.run_all # writes results/
201
+ .venv/bin/python -m bench.readme # rewrites the results part of this README
202
+ ```
203
+
204
+ To use it from an MCP host, start it over stdio:
205
+
206
+ ```json
207
+ {
208
+ "mcpServers": {
209
+ "cooling": { "command": "/path/to/sim-tools-mcp/.venv/bin/python", "args": ["-m", "sim_tools_mcp"] }
210
+ }
211
+ }
212
+ ```
213
+
214
+ CI (`.github/workflows/ci.yml`) runs lint, the tests, the README check, the comparison of the copied files
215
+ with cooling-surrogate, and a small version of the whole measurement.
216
+
217
+ ## Limits
218
+
219
+ - The agent is a script, not a language model. It shows that the tools are enough to answer the question
220
+ and how many calls each plan needs. It says nothing about how well a model would choose a plan. I did
221
+ not run it with a model.
222
+ - I ran the server only with the SDK's own client, not inside a desktop host.
223
+ - The physics is cooling-surrogate's: a one-dimensional wall with constant properties. Its README lists
224
+ what that leaves out.
225
+ - The latency numbers come from one machine, one torch thread and stdio. Over HTTP or on other hardware
226
+ they will differ.
227
+ - cooling-surrogate's HTTP service sets one torch thread when it starts, but torch passes that to MKL
228
+ only for the thread that starts it. The service answers in request threads, where MKL then uses every
229
+ core, and on some Intel CPUs (CI's Xeon 8370C runners) heat removed differs from the library call in
230
+ its last digits. The measurement and the tests set `MKL_NUM_THREADS=1` before torch loads
231
+ (`bench/__init__.py`), so the service is compared as it is configured. Started without that setting
232
+ on such a CPU, it can differ in those digits.
233
+ - The result store lives in the server process. It is lost on restart, and `check_physics` only knows ids
234
+ from the same process. It keeps the last 4,096 answers.
235
+ - The guard checks each input against its own range, as in cooling-surrogate. A combination that is rare
236
+ inside the box is not flagged.
237
+ - The physical limits are those of cooling-surrogate's HTTP service. A wall that loses heat very slowly
238
+ passes them, and the solver then runs to its time limit before the tool refuses with `solver_failed`.
239
+ - The bad calls and the fuzz odds are mine. They cover the mistakes I could think of, not every input.
240
+
241
+ MIT licence.
@@ -0,0 +1,214 @@
1
+ # sim-tools-mcp
2
+
3
+ [![ci](https://github.com/zuhalsicim/sim-tools-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/zuhalsicim/sim-tools-mcp/actions/workflows/ci.yml)
4
+
5
+ **Solver & surrogate:** [cooling-surrogate](https://zuhalsicimkaradavut.com/projects/cooling-surrogate/) · **Portfolio & proof:** [zuhalsicimkaradavut.com](https://zuhalsicimkaradavut.com) · **Author:** [Zuhal Karadavut (Zuhal Sicim · @zuhalsicim)](https://zuhalsicimkaradavut.com)
6
+
7
+ An MCP server that lets an AI agent use my [cooling-surrogate](https://github.com/zuhalsicim/cooling-surrogate)
8
+ pipeline: run the finite-volume solver, ask the surrogate, sweep one input, check an answer against
9
+ physics, and compare surrogate and solver. I built it to answer one question.
10
+
11
+ Can an agent use a simulation and its fast surrogate through tool calls without ever getting a surrogate number it should not trust?
12
+ Here, yes. Of 694 calls the surrogate must not answer (invalid, malformed, outside the training box, or failing a physics check), it answered 0. With the int8 copy that the gate in cooling-surrogate blocked loaded on purpose, 71 of 200 answers failed a physics check, all 71 went to the solver, and no answer that fails a check reached the agent.
13
+ A scripted agent found the warmest mould temperature for an 8 s cooling time in 7 tool calls and 475 ms, 0.032 K below the solver's own answer; the solver alone took 13 calls and 2.59 s. A surrogate call over stdio takes 2.30 ms at the median.
14
+ The numbers are in [`results/`](results/), and CI checks on every push that the results section below matches them.
15
+
16
+ To reproduce: `pip install -r requirements-dev.txt && pip install -e . --no-deps`, then `python -m bench.run_all` and `python -m bench.readme` (CPU only; the whole measurement took 239 s on one AMD CPU under Windows 11). Details under [Run it](#run-it).
17
+
18
+ ## The question
19
+
20
+ Can an agent work with a simulation and its fast surrogate through tool calls, without ever getting a
21
+ surrogate number it should not trust, and what does each call cost?
22
+
23
+ The surrogate in cooling-surrogate is much faster than the solver, but it is only valid inside the box of
24
+ inputs it was trained on, and only when its answer passes the physics checks. A person reads that in the
25
+ README. An agent only sees the tool list and what the calls return, so the tools have to
26
+ carry those rules themselves.
27
+
28
+ ## What I measured
29
+
30
+ Every number in this section is written by `python -m bench.readme` from the files in `results/`, which
31
+ `python -m bench.run_all` produces. CI fails if the two disagree.
32
+
33
+ <!-- results:begin -->
34
+ I asked the scripted agent for the warmest mould temperature that keeps a 2 mm part at or under 8 s of cooling. It answered 44.00 °C after 7 tool calls. The solver's own answer, found by bisection without the tools, is 44.032 °C, so the agent is 0.032 K below it, inside the 0.05 K step it searched with. Its last calls ran the solver on both sides of the answer to confirm it. On this run the surrogate put the crossing one step too high and the solver check moved it down. With one predict_cooling call per bisection step it took 17 calls. The solver alone took 13 calls and 2.59 s, where the sweep plan took 475 ms.
35
+
36
+ With a 12 s budget the answer lies above 60 °C, where the surrogate was never trained. The same plan answered 76.15 °C (solver: 76.156 °C) in 6 calls; 56 of its 97 sweep points were answered by the solver, each one marked as such. It still took only 1.37 s, against 3.01 s for the solver alone, because a sweep hands all its out-of-box points to the solver as one batch.
37
+
38
+ Of 694 calls the surrogate must not answer (invalid, malformed, outside the training box, or failing a physics check), it answered 0. 74 hand-written calls of that kind were all handled as planned (74 of 74): 59 refused with a code, a reason and a hint, the rest answered by the solver. 1,000 random calls matched an independent check of the limits every time (0 mismatches). With a broken model loaded on purpose, the int8 copy my gate in cooling-surrogate blocked, 71 of 200 answers inside the box failed a physics check and went to the solver; 0 answers that fail a check came back.
39
+
40
+ Every tool answer equals the direct library call: 134 of 134 comparisons on 22 fixed cases, exact float equality after the JSON round trip, including against cooling-surrogate's own HTTP service, with MKL on one thread as the service is configured (see Limits). A second server process gave byte-identical answers and result ids (45 of 45), and repeated calls came from the result store (45 of 45, 0 solver runs).
41
+
42
+ Over stdio a surrogate call takes 2.30 ms at the median against 0.31 ms for the bare library call, so the protocol and the guards add about 1.99 ms. A solver call takes 221 ms (library 221 ms). Starting the server takes 4.01 s.
43
+
44
+ ### 1. The agent session
45
+
46
+ A deterministic client follows a fixed plan, no language model. One fresh server per run. Time is what the client waited for tool calls, without server start.
47
+
48
+ **A 2 mm wall, melt 230 °C: what is the warmest mould temperature between 20 and 60 °C that keeps the cooling time at or below 8 s?** Solver answer: 44.0317 °C.
49
+
50
+ | plan | tool calls | solver runs | time | answer | off by | confirmed by the solver |
51
+ |---|---:|---:|---:|---:|---:|---|
52
+ | two sweeps, then check | 7 | 2 | 475 ms | 44.0000 °C | -0.0317 K | yes (stepped down) |
53
+ | one point per call | 17 | 2 | 474 ms | 44.0234 °C | -0.0082 K | yes (stepped down) |
54
+ | solver only | 13 | 12 | 2.59 s | 44.0234 °C | -0.0082 K | yes |
55
+
56
+ **The same part with a 12 s cycle budget: what is the warmest mould temperature between 20 and 95 °C that keeps the cooling time at or below 12 s? The surrogate was trained up to 60 °C only.** Solver answer: 76.1559 °C.
57
+
58
+ | plan | tool calls | solver runs | time | answer | off by | confirmed by the solver |
59
+ |---|---:|---:|---:|---:|---:|---|
60
+ | two sweeps, then check | 6 | 58 | 1.37 s | 76.1500 °C | -0.0059 K | yes |
61
+ | one point per call | 17 | 13 | 3.08 s | 76.1401 °C | -0.0158 K | yes |
62
+ | solver only | 14 | 13 | 3.01 s | 76.1401 °C | -0.0158 K | yes |
63
+
64
+ ### 2. Safety
65
+
66
+ Hand-written bad calls, by kind. The surrogate column must be zero everywhere.
67
+
68
+ | kind | calls | as planned | refused | solver | surrogate |
69
+ |---|---:|---:|---:|---:|---:|
70
+ | physically meaningless numbers | 35 | 35 | 35 | 0 | 0 |
71
+ | wrong types, missing or extra fields, bad ids | 21 | 21 | 21 | 0 | 0 |
72
+ | valid, outside the training box | 16 | 16 | 2 | 14 | 0 |
73
+ | inside the box, surrogate answer fails a check | 1 | 1 | 0 | 1 | 0 |
74
+ | valid, but the wall never cools enough | 1 | 1 | 1 | 0 | 0 |
75
+
76
+ Random calls to predict_cooling (seed 7): each input in the box, outside it, physically invalid, malformed or missing, at fixed odds.
77
+
78
+ | outcome | calls |
79
+ |---|---:|
80
+ | refused, invalid_input | 395 |
81
+ | surrogate | 380 |
82
+ | solver, out_of_box | 225 |
83
+
84
+ Physics guard, inside the box only, every answer then put through check_physics:
85
+
86
+ | model served | calls | surrogate answers failing a check | sent to the solver | answers returned failing a check |
87
+ |---|---:|---:|---:|---:|
88
+ | version 1, promoted | 200 | 1 | 1 | 0 |
89
+ | int8 copy, blocked by the gate | 200 | 71 | 71 | 0 |
90
+
91
+ ### 3. Correctness
92
+
93
+ | comparison | checked | equal |
94
+ |---|---:|---:|
95
+ | run_solver = physics.solve | 22 | 22 |
96
+ | predict_cooling = library guard and fallback | 22 | 22 |
97
+ | predict_cooling = cooling-surrogate HTTP service | 22 | 22 |
98
+ | compare_with_solver = metrics.errors | 22 | 22 |
99
+ | check_physics = checks.run_all | 44 | 44 |
100
+ | sweep_parameter = library guard on the batch | 2 | 2 |
101
+
102
+ A sweep answers in one batch, and batching changes the floating-point path a little: sweep points differ from the same points asked one by one by at most 2.9e-07 relative.
103
+
104
+ ### 4. Latency
105
+
106
+ Median and 95th percentile over 200 calls (15 for the solver rows), new inputs on every call. Library is cooling_surrogate called directly; tool layer is the same call through ToolBox in-process; MCP is the client's wait for the answer from the server subprocess over stdio.
107
+
108
+ | call | library | tool layer | MCP, median | MCP, p95 | answer size |
109
+ |---|---:|---:|---:|---:|---:|
110
+ | describe_model | - | 0.01 ms | 1.57 ms | 1.96 ms | 3,236 chars |
111
+ | predict_cooling, inside the box | 0.31 ms | 0.40 ms | 2.30 ms | 3.48 ms | 609 chars |
112
+ | predict_cooling, same call again (result store) | - | 0.02 ms | 1.59 ms | 2.28 ms | 605 chars |
113
+ | sweep_parameter, 41 points inside the box | 0.94 ms | 1.29 ms | 4.35 ms | 6.00 ms | 2,481 chars |
114
+ | check_physics on a stored answer | 0.11 ms | 0.15 ms | 2.12 ms | 3.00 ms | 1,151 chars |
115
+ | predict_cooling, outside the box (solver) | 220 ms | 221 ms | 230 ms | 249 ms | 649 chars |
116
+ | run_solver | 221 ms | 217 ms | 221 ms | 249 ms | 507 chars |
117
+ | compare_with_solver | 222 ms | 217 ms | 224 ms | 256 ms | 921 chars |
118
+
119
+ Server start, three runs: 3.93 s, 4.01 s, 4.04 s. Machine: AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD, Windows 11, Python 3.12.16, mcp 2.3.0, torch 2.15.0+cpu, numpy 2.5.5, one torch thread. Whole measurement: 239 s.
120
+ <!-- results:end -->
121
+
122
+ ## How it works
123
+
124
+ | tool | what it does | runs the solver |
125
+ |---|---|---|
126
+ | `describe_model` | every input with unit, allowed range and training box; model version and hashes; the checks | no |
127
+ | `predict_cooling` | cooling time and heat removed for one case, surrogate with solver fallback | only when needed |
128
+ | `sweep_parameter` | the same over a grid of one input, in one call | for the points that need it, in one batch |
129
+ | `run_solver` | the finite-volume solver, verified against the exact series in cooling-surrogate | yes |
130
+ | `check_physics` | the five physics checks on an earlier answer, by its `result_id`, with the worst value of each | no |
131
+ | `compare_with_solver` | surrogate and solver on one case, and the surrogate's error | yes |
132
+
133
+ Every input carries its unit in its name (`melt_temp_c`, `thickness_mm`, `htc_w_m2k`, ...), and the JSON
134
+ schema the agent sees gives its allowed range and the training box. Types are strict: `"230"` or `true`
135
+ for a temperature is refused, not converted. A refused call comes back with `ok: false`, MCP's `is_error`
136
+ flag, a code, a reason that names the field and what is allowed, and a hint for the next call. For an
137
+ invalid call nothing is computed.
138
+
139
+ `predict_cooling` and `sweep_parameter` use the same guard as cooling-surrogate's HTTP service, in the same
140
+ order. If any input is outside the training box, the solver answers. If the surrogate's answer fails one of
141
+ the five physics checks, the solver answers. The answer says which one answered and why (`source`,
142
+ `fallback_reason`, `outside_training_box`, `surrogate_failed_checks`). With `on_out_of_box: "refuse"` an
143
+ agent that cannot wait for the solver gets a refusal instead, and still no surrogate number.
144
+
145
+ Each answer reports its `cost`: wall time, solver runs, surrogate evaluations, and whether it came from the
146
+ result store. Answers depend only on the arguments and the model, so each one gets a `result_id`, a hash
147
+ of the tool, the arguments, the weights and the library commit. The same call again returns the same id
148
+ and the same answer from the store without running anything. `check_physics` takes that id, so an agent
149
+ never has to send profiles back.
150
+
151
+ I wrote the server on the SDK's low-level `Server`, not the decorator layer. That way the schemas the agent
152
+ sees are exactly the ones in `tools.py`, and a bad argument comes back as a refusal the agent can read,
153
+ not as a protocol error. All tools are marked read-only and idempotent.
154
+
155
+ `src/cooling_surrogate` is an unchanged copy of eight files of cooling-surrogate at commit `58b7397` (MIT
156
+ licence, copied with it). It is copied, not installed, because that repository is not packaged for pip.
157
+ `UPSTREAM.json` holds the SHA-256 of every file, a test checks them, and CI compares them with a fresh
158
+ clone of that commit. The model in `src/sim_tools_mcp/model_v1` is version 1 of cooling-surrogate's full
159
+ run, the one its gate promoted. The server refuses to start if the weights' hash is not the registered one.
160
+
161
+ The measurements live in `bench/`: `correctness.py`, `safety.py` (with the bad calls in `cases.py`),
162
+ `latency.py`, and `agent.py` with `session.py` for the scripted agent.
163
+
164
+ ## Run it
165
+
166
+ Python 3.12, CPU only.
167
+
168
+ ```sh
169
+ python -m venv .venv
170
+ .venv/bin/pip install -r requirements-dev.txt # Windows: .venv\Scripts\pip
171
+ .venv/bin/pip install -e . --no-deps
172
+ .venv/bin/python -m pytest -q
173
+ .venv/bin/python -m bench.run_all # writes results/
174
+ .venv/bin/python -m bench.readme # rewrites the results part of this README
175
+ ```
176
+
177
+ To use it from an MCP host, start it over stdio:
178
+
179
+ ```json
180
+ {
181
+ "mcpServers": {
182
+ "cooling": { "command": "/path/to/sim-tools-mcp/.venv/bin/python", "args": ["-m", "sim_tools_mcp"] }
183
+ }
184
+ }
185
+ ```
186
+
187
+ CI (`.github/workflows/ci.yml`) runs lint, the tests, the README check, the comparison of the copied files
188
+ with cooling-surrogate, and a small version of the whole measurement.
189
+
190
+ ## Limits
191
+
192
+ - The agent is a script, not a language model. It shows that the tools are enough to answer the question
193
+ and how many calls each plan needs. It says nothing about how well a model would choose a plan. I did
194
+ not run it with a model.
195
+ - I ran the server only with the SDK's own client, not inside a desktop host.
196
+ - The physics is cooling-surrogate's: a one-dimensional wall with constant properties. Its README lists
197
+ what that leaves out.
198
+ - The latency numbers come from one machine, one torch thread and stdio. Over HTTP or on other hardware
199
+ they will differ.
200
+ - cooling-surrogate's HTTP service sets one torch thread when it starts, but torch passes that to MKL
201
+ only for the thread that starts it. The service answers in request threads, where MKL then uses every
202
+ core, and on some Intel CPUs (CI's Xeon 8370C runners) heat removed differs from the library call in
203
+ its last digits. The measurement and the tests set `MKL_NUM_THREADS=1` before torch loads
204
+ (`bench/__init__.py`), so the service is compared as it is configured. Started without that setting
205
+ on such a CPU, it can differ in those digits.
206
+ - The result store lives in the server process. It is lost on restart, and `check_physics` only knows ids
207
+ from the same process. It keeps the last 4,096 answers.
208
+ - The guard checks each input against its own range, as in cooling-surrogate. A combination that is rare
209
+ inside the box is not flagged.
210
+ - The physical limits are those of cooling-surrogate's HTTP service. A wall that loses heat very slowly
211
+ passes them, and the solver then runs to its time limit before the tool refuses with `solver_failed`.
212
+ - The bad calls and the fuzz odds are mine. They cover the mistakes I could think of, not every input.
213
+
214
+ MIT licence.
@@ -0,0 +1,139 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sim-tools-mcp"
7
+ version = "1.0.0"
8
+ description = "MCP tools that let an AI agent run and query a verified cooling simulation and its surrogate safely."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Zuhal Karadavut" }]
14
+ keywords = ["mcp", "model-context-protocol", "ai-agents", "physics-simulation", "surrogate-model", "safety"]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
23
+ ]
24
+ dependencies = [
25
+ "numpy>=2.0",
26
+ "scipy>=1.14",
27
+ "torch>=2.5",
28
+ "pydantic>=2.10",
29
+ "mcp>=1.2",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://zuhalsicimkaradavut.com/projects/cooling-surrogate/"
34
+ Repository = "https://github.com/zuhalsicim/sim-tools-mcp"
35
+ Issues = "https://github.com/zuhalsicim/sim-tools-mcp/issues"
36
+
37
+ [project.scripts]
38
+ sim-tools-mcp = "sim_tools_mcp.server:main"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.setuptools.package-data]
44
+ sim_tools_mcp = ["py.typed", "model_v1/*.json", "model_v1/model/*"]
45
+ cooling_surrogate = ["LICENSE"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+ pythonpath = ["."]
50
+ filterwarnings = [
51
+ "ignore::DeprecationWarning:starlette.*",
52
+ "ignore::DeprecationWarning:fastapi.*",
53
+ "ignore:Using `httpx` with `starlette.testclient`",
54
+ ]
55
+
56
+ [tool.ruff]
57
+ line-length = 120
58
+ target-version = "py312"
59
+ extend-exclude = ["src/cooling_surrogate"]
60
+
61
+ [tool.ruff.lint]
62
+ select = ["E", "F", "W", "I", "B", "UP", "SIM", "C90", "PL", "RUF"]
63
+ ignore = [
64
+ "PLC0415", # deferred imports in optional HTTP/environment helpers
65
+ "PLR0913", # explicit benchmark/question parameters are clearer than wrapper dicts
66
+ "PLR0914", # benchmark and report functions assemble multiple summary columns in one scope
67
+ "PLR0915", # bench/readme.py renders the full Markdown report in one linear function
68
+ "PLR0917", # positional helper parameters match call sites
69
+ "PLR2004", # domain thresholds and grid counts
70
+ ]
71
+
72
+ [tool.ruff.lint.mccabe]
73
+ max-complexity = 15
74
+
75
+ [tool.ruff.lint.per-file-ignores]
76
+ "bench/readme.py" = ["E501"] # sentences of the README
77
+
78
+ [tool.mypy]
79
+ python_version = "3.12"
80
+ mypy_path = "src"
81
+ files = ["src/sim_tools_mcp", "bench", "tests"]
82
+ strict = true
83
+
84
+ [[tool.mypy.overrides]]
85
+ module = ["cooling_surrogate.*"]
86
+ follow_imports = "silent"
87
+ ignore_missing_imports = true
88
+
89
+ [[tool.mypy.overrides]]
90
+ module = ["anyio.*", "fastapi.*", "mcp.*", "scipy.*", "torch.*"]
91
+ ignore_missing_imports = true
92
+
93
+ [[tool.mypy.overrides]]
94
+ module = [
95
+ "conftest",
96
+ "test_mcp",
97
+ "test_results",
98
+ "test_tools",
99
+ "test_vendored",
100
+ ]
101
+ disallow_untyped_defs = false
102
+ disallow_incomplete_defs = false
103
+ disallow_untyped_calls = false
104
+
105
+ [tool.vulture]
106
+ paths = ["src/sim_tools_mcp", "bench"]
107
+ min_confidence = 80
108
+
109
+ [tool.importlinter]
110
+ root_package = "sim_tools_mcp"
111
+ include_external_packages = true
112
+
113
+ [[tool.importlinter.contracts]]
114
+ name = "Plain-Python tool layer never imports MCP transport"
115
+ type = "forbidden"
116
+ source_modules = ["sim_tools_mcp.tools"]
117
+ forbidden_modules = ["mcp"]
118
+
119
+ [[tool.importlinter.contracts]]
120
+ name = "CLI entrypoint -> MCP server -> plain-Python tools"
121
+ type = "layers"
122
+ layers = [
123
+ "sim_tools_mcp.__main__",
124
+ "sim_tools_mcp.server",
125
+ "sim_tools_mcp.tools",
126
+ ]
127
+
128
+ [tool.typos.default]
129
+ extend-ignore-re = ['\b[0-9a-f]{12,}\b'] # content hashes such as ds-b17ba686b995
130
+
131
+ [tool.coverage.run]
132
+ branch = true
133
+ source = ["sim_tools_mcp"]
134
+
135
+ [tool.coverage.report]
136
+ # 96.4 % on 29 Nov 2026. The floor is the multiple of 5 at least one point below,
137
+ # so that a small difference between Linux and Windows runs cannot fail it.
138
+ # Raise it when tests are added; never lower it.
139
+ fail_under = 95
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zuhal Karadavut
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.
File without changes