misclosure 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.
Files changed (55) hide show
  1. misclosure-0.1.0/.github/workflows/ci.yml +58 -0
  2. misclosure-0.1.0/.gitignore +9 -0
  3. misclosure-0.1.0/DESIGN.md +68 -0
  4. misclosure-0.1.0/LICENSE +202 -0
  5. misclosure-0.1.0/PKG-INFO +295 -0
  6. misclosure-0.1.0/README.md +272 -0
  7. misclosure-0.1.0/encoders/julia/MisclosureEncode.jl +123 -0
  8. misclosure-0.1.0/encoders/julia/test_encode.jl +52 -0
  9. misclosure-0.1.0/encoders/r/misclosure_encode.R +59 -0
  10. misclosure-0.1.0/encoders/r/test_encode.R +46 -0
  11. misclosure-0.1.0/examples/kite/cases.yaml +226 -0
  12. misclosure-0.1.0/examples/kite/compare_results.py +49 -0
  13. misclosure-0.1.0/examples/kite/convert_questions.py +62 -0
  14. misclosure-0.1.0/examples/kite/eval-heldout.yaml +43 -0
  15. misclosure-0.1.0/examples/kite/eval.yaml +55 -0
  16. misclosure-0.1.0/examples/kite/kite_traps.py +65 -0
  17. misclosure-0.1.0/examples/kite/questions-heldout.yaml +54 -0
  18. misclosure-0.1.0/examples/kite/questions.yaml +113 -0
  19. misclosure-0.1.0/examples/kite/reference.R +125 -0
  20. misclosure-0.1.0/examples/testserver/cases.yaml +29 -0
  21. misclosure-0.1.0/pyproject.toml +63 -0
  22. misclosure-0.1.0/src/misclosure/__init__.py +3 -0
  23. misclosure-0.1.0/src/misclosure/cli.py +132 -0
  24. misclosure-0.1.0/src/misclosure/client.py +362 -0
  25. misclosure-0.1.0/src/misclosure/conform/__init__.py +1 -0
  26. misclosure-0.1.0/src/misclosure/conform/compare.py +387 -0
  27. misclosure-0.1.0/src/misclosure/conform/report.py +176 -0
  28. misclosure-0.1.0/src/misclosure/conform/runner.py +506 -0
  29. misclosure-0.1.0/src/misclosure/encoding.py +174 -0
  30. misclosure-0.1.0/src/misclosure/jsonlit.py +61 -0
  31. misclosure-0.1.0/src/misclosure/reference.py +107 -0
  32. misclosure-0.1.0/src/misclosure/score/__init__.py +1 -0
  33. misclosure-0.1.0/src/misclosure/score/numbers.py +122 -0
  34. misclosure-0.1.0/src/misclosure/score/scorer.py +255 -0
  35. misclosure-0.1.0/src/misclosure/score/support.py +200 -0
  36. misclosure-0.1.0/src/misclosure/score/transcript.py +151 -0
  37. misclosure-0.1.0/src/misclosure/score/traps.py +98 -0
  38. misclosure-0.1.0/src/misclosure/selectors.py +159 -0
  39. misclosure-0.1.0/tests/fixtures/eval/claude/g01.jsonl +4 -0
  40. misclosure-0.1.0/tests/fixtures/eval/eval.yaml +27 -0
  41. misclosure-0.1.0/tests/fixtures/eval/questions.yaml +23 -0
  42. misclosure-0.1.0/tests/fixtures/eval/reference.json +136 -0
  43. misclosure-0.1.0/tests/fixtures/eval/transcripts/g01.jsonl +4 -0
  44. misclosure-0.1.0/tests/fixtures/eval/transcripts/g02.jsonl +2 -0
  45. misclosure-0.1.0/tests/fixtures/eval/transcripts/g03.jsonl +6 -0
  46. misclosure-0.1.0/tests/fixtures/faults.yaml +40 -0
  47. misclosure-0.1.0/tests/server/growth_server.py +70 -0
  48. misclosure-0.1.0/tests/server/reference.py +39 -0
  49. misclosure-0.1.0/tests/test_compare.py +123 -0
  50. misclosure-0.1.0/tests/test_encoding.py +135 -0
  51. misclosure-0.1.0/tests/test_growth_server.py +92 -0
  52. misclosure-0.1.0/tests/test_jsonlit_selectors.py +73 -0
  53. misclosure-0.1.0/tests/test_kite.py +66 -0
  54. misclosure-0.1.0/tests/test_scorer.py +119 -0
  55. misclosure-0.1.0/uv.lock +958 -0
@@ -0,0 +1,58 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ name: Tests, ruff, and the encoders in R and Julia
10
+ runs-on: ubuntu-24.04
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: astral-sh/setup-uv@v6
14
+ - uses: r-lib/actions/setup-r@v2
15
+ with:
16
+ use-public-rspm: true
17
+ - name: Install jsonlite
18
+ run: Rscript -e 'install.packages("jsonlite")'
19
+ - uses: julia-actions/setup-julia@v2
20
+ with:
21
+ version: "1.11"
22
+ - run: uv sync --locked -p 3.11
23
+ - run: uv run ruff check .
24
+ - run: uv run ruff format --check .
25
+ - name: Unit tests, the growth server over stdio and HTTP, and the encoders
26
+ run: MISCLOSURE_JULIA=julia uv run pytest -v
27
+
28
+ kite:
29
+ # The proof against kite-mcp needs R, KITE at its pinned commit and a
30
+ # kite-mcp build. It runs when the repository variable MISCLOSURE_KITE is 1.
31
+ name: Proof against kite-mcp
32
+ if: vars.MISCLOSURE_KITE == '1'
33
+ runs-on: ubuntu-24.04
34
+ env:
35
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: actions/checkout@v4
39
+ with:
40
+ repository: ldocallaghan/kite-mcp
41
+ path: kite-mcp
42
+ - uses: astral-sh/setup-uv@v6
43
+ - uses: dtolnay/rust-toolchain@stable
44
+ - uses: r-lib/actions/setup-r@v2
45
+ with:
46
+ r-version: "4.6.2"
47
+ use-public-rspm: true
48
+ - name: Install R packages and KITE at kite-mcp's pinned commit
49
+ run: Rscript kite-mcp/scripts/install-r-deps.R
50
+ - name: Build kite-mcp
51
+ run: cargo build --release --manifest-path kite-mcp/Cargo.toml
52
+ - run: uv sync --locked -p 3.11
53
+ - name: Conformance and scoring against kite-mcp
54
+ run: |
55
+ export KITE_MCP_DIR="$GITHUB_WORKSPACE/kite-mcp"
56
+ export KITE_MCP_BIN="$KITE_MCP_DIR/target/release/kite-mcp"
57
+ MISCLOSURE_KITE=1 uv run pytest -v tests/test_kite.py
58
+ uv run misclosure conform examples/kite/cases.yaml --junit conformance-junit.xml
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ misclosure-out/
@@ -0,0 +1,68 @@
1
+ # Design notes
2
+
3
+ ## Two checks against one reference
4
+
5
+ Both checks start from reference values: the results of the model called directly, with no server code in the path, written in a format that keeps every bit. Conformance asks whether the server returns those values. The answer evaluation asks whether a language model, given the server, quotes only those values and numbers derived from them in declared ways. The first check is about the server; the second is about the server, its tool descriptions and the model together.
6
+
7
+ ## Why the default is exact bits
8
+
9
+ A server that wraps a numerical model should return the model's numbers. When it does, the comparison with a direct run is equality of bit patterns, and any other result is a fault somewhere: in the server's call of the model, in its encoding, in the JSON it writes or in the client. A tolerance would hide faults of the size it allows, and the size of a fault says little about its cause. So a tolerance is an exception a case must declare, with a reason, and the report lists every one with the number of values it let through.
10
+
11
+ There are honest reasons for a tolerance: a server that computes in a different order from the reference, or on other hardware. misclosure accepts them when declared. It does not accept a tolerance without a reason.
12
+
13
+ ## Comparison rules
14
+
15
+ - A double compares by its 64-bit pattern. -0.0 and 0.0 differ, and so do two NaNs of different class.
16
+ - JSON has no NaN or infinity. A server writes them as strings, and misclosure reads `"NA"`, `"NaN"`, `"Inf"` and `"-Inf"` by default. NaNs compare by class: R's NA (a NaN whose low 32 bits are 1954) or any other NaN. JSON cannot carry a payload beyond that.
17
+ - Integers, logicals and strings compare exactly. An integer must be a JSON integer: `22.0` does not equal the integer 22.
18
+ - A table is a list of row objects. Rows match by key columns, in any order; by default the keys are the reference columns that are not doubles. A missing row, an extra row, a duplicate key, a missing column and an unexpected column each fail. Columns that hold the server's own additions, such as display strings, are listed in `ignore_columns`.
19
+ - A tolerance applies only to finite doubles. It never lets a NaN or an infinity through.
20
+
21
+ ## Bits lost in JSON
22
+
23
+ A server can compute the right double and write too few digits of it. To tell this apart from a wrong value, misclosure keeps the text of every number the server wrote. When a double differs from the reference, the runner rounds the reference to the number of significant digits in the server's text. If that gives the server's number, the failure is `json_precision`: the value was right and the JSON lost bits. Seventeen significant digits are always enough, so a literal with 17 or more digits is never put in this class.
24
+
25
+ ## Reading numbers as the server wrote them
26
+
27
+ The MCP Python SDK parses each message with pydantic. misclosure uses the SDK's `Client` for the protocol, and its own transports for stdio and streamable HTTP, which pass every message through unchanged and keep a copy of the text. The runner parses that copy with Python's `json` module, which rounds a decimal literal to the nearest double, and compares each number with the SDK's parse. A difference is a `client` failure, a fault on misclosure's side of the wire. A unit test checks the SDK's parser against Python's on about 80,000 literals: random doubles in shortest, 17-digit and 26-digit forms, and decimals with exponents from -330 to 310.
28
+
29
+ The copy also records what each side said about the protocol version, from the `server/discover` result or the `initialize` exchange.
30
+
31
+ ## Reference values from any language
32
+
33
+ A reference is a JSON file or a command that writes one. Doubles are hexadecimal bit patterns, which every language can write without a decimal conversion, so a reference written in R, Julia or Python carries the same bits. The R encoder is about 60 lines and uses `writeBin`, the Julia encoder uses `reinterpret`, and the Python encoder uses `struct`. A file may carry the model name, version and commit, and a declaration may give its SHA-256, so a recorded reference can be tied to the run that made it.
34
+
35
+ ## The derivations model
36
+
37
+ Language models rarely quote a result as returned. They give percentages, differences between scenarios, ratios and converted units. The scorer accepts these only when the evaluation file declares them:
38
+
39
+ - `each_value` derivations apply to every reference value: `x`, `(x - 1) * 100` for a percentage change from a ratio, `x * 1000` for a unit conversion;
40
+ - `comparisons` derivations apply between two named cases of a question, row by row, for the tables their patterns match: `b - a`, `b / a`;
41
+ - each comparison value also goes through the `each_value` derivations, so the percentage change of a ratio between two scenarios is covered by `b / a` and `(x - 1) * 100`.
42
+
43
+ Derivations are arithmetic expressions, parsed with Python's `ast` and evaluated without `eval`. What is declared is what is accepted; there is no built-in list. kite-mcp's rules are one such declaration, in `examples/kite/eval.yaml`.
44
+
45
+ A number matches a value when the value rounds to it: within half a unit in the last place the answer shows. By default the sign is ignored, because prose often states a negative change as "2.3 % lower".
46
+
47
+ ## The transcript schema
48
+
49
+ The scorer needs three things from a run: the tool calls, their results and the final answer. The misclosure transcript format holds these and nothing else, one JSON record per line, in the order they happened, so any harness can write it. The adapter for Claude Code's `stream-json` output reads tool calls from assistant messages, tool results from user messages and the answer from the `result` record, and removes the `mcp__<server>__` prefix from tool names.
50
+
51
+ ## Choices in the number reader
52
+
53
+ kite-mcp's reader was the starting point. misclosure changes it in two ways, and neither changes a count on kite-mcp's 15 transcripts:
54
+
55
+ - It skips fenced code blocks of every language by default; kite-mcp skips R blocks only, and `skip_code_blocks: [r]` restores that.
56
+ - It reads a hyphen between two decimals as a range (0.5-0.8 gives 0.5 and 0.8). Without a decimal point on both sides the hyphen is left alone, so a date such as 2026-11-15 gives 2026 only, as before. `hyphen_ranges: false` turns this off.
57
+
58
+ The code-block rule, the hyphen ranges and `ignore_sign` are settings in the evaluation file.
59
+
60
+ ## How misclosure was built
61
+
62
+ misclosure was written on 23 November 2026 by Claude Code 2.1.322, Anthropic's coding agent, running the model Claude Opus 5.5 (`claude-opus-5-5`). It worked from a build specification by the repository's author, who set the scope and the acceptance tests. The work ran on Windows 11 with WSL 2 (Ubuntu 22.04), Python 3.11.15 with uv 0.11.8, the MCP Python SDK 2.3.0 (protocol 2026-07-28), pydantic 2.14.4, PyYAML 6.0.4, pytest 9.2.0, ruff 0.17.6, R 4.6.2 with jsonlite 2.0.0 and KITE 26.10 at commit `5995dd1`, and Julia 1.11.7.
63
+
64
+ The order was: a check of the SDK (its protocol version, its connection to kite-mcp, and the rounding of its JSON parser); the encoders and their round-trip tests; the conformance runner; the proof against kite-mcp's conformance cases; the scorer and the proof against kite-mcp's evaluation; the Python test server and its fault tests; the documentation.
65
+
66
+ The proofs found two faults in misclosure during the build. The first conformance run against kite-mcp failed ten checks: the server's headline holds two of the three columns of the welfare table, and the table check compared all three. The check gained `reference_columns`. The first scoring run of the test fixture failed because comparisons read tables from a fixed `tables` key, the layout of kite-mcp's reference; a comparison now names its table with a selector.
67
+
68
+ What the results do not show: the kite-mcp proof covers one server, one model family and one harness. The growth server is the only other server misclosure has run against.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,295 @@
1
+ Metadata-Version: 2.5
2
+ Name: misclosure
3
+ Version: 0.1.0
4
+ Summary: Conformance tests and answer scoring for MCP servers of scientific models
5
+ Project-URL: Repository, https://github.com/ldocallaghan/misclosure
6
+ Project-URL: Issues, https://github.com/ldocallaghan/misclosure/issues
7
+ Author: Liam O'Callaghan
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: conformance,ieee-754,llm-evaluation,mcp,model-context-protocol,numerical-models,scientific-computing,testing
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: mcp<3,>=2.3
21
+ Requires-Dist: pyyaml>=6
22
+ Description-Content-Type: text/markdown
23
+
24
+ # misclosure
25
+
26
+ misclosure tests an MCP server that runs a scientific or engineering model. It makes two checks, both against reference values from direct runs of the model:
27
+
28
+ - **Conformance.** Every number the server returns must equal the reference bit for bit, unless a case declares a tolerance and gives a reason.
29
+ - **Answer evaluation.** A language model answers questions through the server. Every number in each answer must be a reference value, a value from a declared derivation, a number given in the question or a declared constant, within the rounding the answer shows.
30
+
31
+ It works with any MCP server, over stdio or streamable HTTP, and with any model that can write its results to JSON. It was extracted from the tests of [kite-mcp](https://github.com/ldocallaghan/kite-mcp), and it reproduces kite-mcp's results: see [Worked example: kite-mcp](#worked-example-kite-mcp).
32
+
33
+ ## Why
34
+
35
+ A server between a language model and a numerical model has several places to change a number: the code that calls the model, the encoding of the results, the JSON it writes, and the client that reads it. A test that compares to six decimal places hides a change in the seventh, and a server that writes 15 significant digits loses the last bits of most doubles. misclosure compares bit patterns, so any change shows, and reports a server that loses bits in JSON as its own class of failure.
36
+
37
+ The answer evaluation checks a different thing: whether the numbers a language model quotes came from the model's results. It does not check whether the prose around them is right.
38
+
39
+ ## Install
40
+
41
+ misclosure needs Python 3.11 or later. In a clone of this repository:
42
+
43
+ ```
44
+ uv sync
45
+ uv run misclosure --help
46
+ ```
47
+
48
+ or `pip install .` in a virtual environment. Its dependencies are the official MCP Python SDK (`mcp`) and PyYAML.
49
+
50
+ ## Quick start
51
+
52
+ `tests/server/growth_server.py` is a small MCP server in Python. It wraps compound growth: the value of a principal after each year at a fixed rate, and the doubling time. `tests/server/reference.py` computes the same function directly and writes the reference file.
53
+
54
+ ```
55
+ uv run misclosure conform examples/testserver/cases.yaml
56
+ ```
57
+
58
+ ```
59
+ PASS: 2 cases, 86 values compared (84 table cells, 2 scalars, 0 other checks), 0 failures
60
+ protocol 2026-07-28; reports in misclosure-out
61
+ ```
62
+
63
+ The server has two more tools with faults: `grow_faulty` returns one value 1 ulp too high, and `grow_short_json` writes 15 significant digits. `tests/fixtures/faults.yaml` runs them:
64
+
65
+ ```
66
+ uv run misclosure conform tests/fixtures/faults.yaml
67
+ ```
68
+
69
+ The 1-ulp error fails, with both bit patterns in the report (`405cf0cccccccccf` against `405cf0ccccccccce`). The same output passes in the case that declares a relative tolerance of 1e-15, and the report lists that tolerance with its reason. The 15-digit tool fails with 30 values reported as bits lost in JSON.
70
+
71
+ ## Conformance
72
+
73
+ ```
74
+ misclosure conform CASES.yaml [--server "COMMAND"] [--url URL] [--mode auto|legacy|VERSION]
75
+ [--out DIR] [--junit FILE] [--case ID] [--reference FILE]
76
+ ```
77
+
78
+ `--server` and `--url` override the server the case file names. `--mode` sets the SDK's protocol negotiation: `auto` (the default) asks the server with `server/discover` and falls back to the `initialize` handshake; `legacy` uses the handshake. `--reference` uses a recorded reference file in place of the declared one. The exit status is 0 when every case passes, 1 on any failure and 2 when the reference or the server cannot be started.
79
+
80
+ The runner writes three files to `--out` (default `misclosure-out`):
81
+
82
+ - `conformance.json`: every case, every failure with both bit patterns, the tolerances used, the reference's model and SHA-256, and the protocol version each side gave;
83
+ - `conformance.md`: a summary table and the first 50 failures;
84
+ - `conformance-junit.xml`: one test case per case, for CI.
85
+
86
+ ### Case files
87
+
88
+ A case file is YAML or JSON:
89
+
90
+ ```yaml
91
+ misclosure: 1
92
+
93
+ reference:
94
+ command: ["${python}", make_reference.py, "${out}"] # or file: recorded.json
95
+
96
+ server:
97
+ command: ["${python}", my_server.py] # or url: http://127.0.0.1:8000/mcp
98
+
99
+ cases:
100
+ - id: five_percent
101
+ steps:
102
+ - call: grow
103
+ arguments: {principal: 100.0, rate: 0.05, years: 10}
104
+ save: run
105
+ checks:
106
+ - table: {output: rows, reference: five_percent.rows, keys: [year]}
107
+ - value: {output: doubling_time, reference: five_percent.doubling_time}
108
+ ```
109
+
110
+ Each case is a list of steps. A step calls a tool (`call` with `arguments`) or reads a resource (`read` with a URI, whose text is the output's `text`). `save: name` keeps the output for later steps, which refer to it as `${name.field}`. `error: true` says the call is expected to fail. `each: {keys_of: SELECTOR, as: name}` repeats a step for every key of a reference object, and `each: {values: [...], as: name}` for every value in a list. `setup` holds steps that run once before the cases; a case's `vars` are names its steps can use.
111
+
112
+ Selectors are dotted paths into the output or the reference: `info.criterion`, `rows[0].value`, `rows[*].flag`, `tables["a.b"]`. Strings may hold templates: `${name.path}` for saved outputs, loop names and `vars`; `${env.NAME}` for environment variables; `${workdir}`, `${case_dir}`, `${python}` and, in a reference command, `${out}`. Commands in a case file run in the case file's directory.
113
+
114
+ The checks:
115
+
116
+ | Check | Passes when |
117
+ |---|---|
118
+ | `value: {output, reference, tolerance}` | one value equals a reference scalar |
119
+ | `table: {output, reference, keys, columns, reference_columns, ignore_columns, tolerance}` | a list of row objects equals a reference table |
120
+ | `equals: {output, value}` | the output equals a literal; with `[*]`, every element does |
121
+ | `absent: SELECTOR`, `present: SELECTOR` | the output lacks or has a field |
122
+ | `same_keys: {output, reference}` | a list of names equals the keys of a reference object, in any order |
123
+ | `json: {output, reference, fields}` | plain JSON equals the reference, limited to `fields` in each object |
124
+ | `contains: {output, text}` | a string holds the text |
125
+
126
+ A table check matches rows by key columns, in any order. By default the keys are the reference columns that are not doubles. `columns` maps output column names to reference column names; `reference_columns` limits the check to some reference columns. Missing or extra rows, missing columns and output columns that are not in the reference fail, unless `ignore_columns` lists them; patterns such as `*_display` are allowed.
127
+
128
+ ### Comparison
129
+
130
+ - **Doubles** compare by bit pattern. NA and other NaNs compare by class, as JSON cannot carry a NaN payload. -0.0 and 0.0 differ.
131
+ - **Strings, integers and logicals** compare exactly, and an integer must be written as a JSON integer.
132
+ - **A tolerance** is declared on a `value` check or per column of a `table` check, as `{abs: ..., rel: ..., reason: "..."}`. It applies to finite doubles only. A tolerance without a reason is an error. The report lists every tolerance, with the number of values that differed in bits and passed within it.
133
+ - **Non-finite doubles.** JSON has no NaN or infinity, so a server writes them as strings. By default misclosure reads `"NA"`, `"NaN"`, `"Inf"` and `"-Inf"`. `numbers: {tokens: {...}, null: NA}` in the case file changes the strings, and says what JSON null means.
134
+
135
+ Each failure has a kind: `value` (a different double or value), `json_precision` (bits lost in JSON: the number written is the reference rounded to the digits the server wrote), `type`, `missing`, `extra`, `duplicate`, `error` (the call failed) or `client` (see below).
136
+
137
+ ### What the client reads
138
+
139
+ misclosure connects with the official MCP Python SDK. Its transports pass every message through and keep a copy of the text the server wrote. The runner reads each number from that text with Python's `json` module, which rounds a decimal literal to the nearest double, and compares it with the number the SDK parsed. A difference is a `client` failure. `tests/test_jsonlit_selectors.py` checks that the SDK's parser gives the correctly rounded double for about 80,000 literals.
140
+
141
+ ## Reference files and encoders
142
+
143
+ A reference file is JSON:
144
+
145
+ ```json
146
+ {"misclosure_reference": 1,
147
+ "model": {"name": "KITE", "version": "26.10", "commit": "5995dd1..."},
148
+ "values": {"run1": {"info": {"iterations": {"integer": 22}},
149
+ "tables": {"welfare_change": {"columns": [
150
+ {"name": "country", "type": "string", "values": ["c1", "c2"]},
151
+ {"name": "value", "type": "double",
152
+ "values": ["3feb40946d4761fc", "3fed778cd68f9a55"]}]}}}}}
153
+ ```
154
+
155
+ A double is the 16 hexadecimal digits of its big-endian IEEE 754 bit pattern. A reference may also write `"NA"`, `"NaN"`, `"Inf"` or `"-Inf"`. A scalar is `{"double": ...}`, `{"integer": ...}`, `{"logical": ...}` or `{"string": ...}`; a table is a list of typed columns. Missing values in string, integer and logical columns are null. Other JSON may sit between these nodes.
156
+
157
+ A case file declares its reference as `{file: path, sha256: ..., model: {...}}` or `{command: [...], model: {...}}`. The SHA-256, when given, is checked. A file without the `misclosure_reference` key is read as the values alone, with the model from the declaration.
158
+
159
+ The encoders write this format:
160
+
161
+ | Language | File | Functions |
162
+ |---|---|---|
163
+ | Python | `misclosure.encoding` | `encode_double`, `encode_column`, `encode_table`, `encode_scalar`, `write_reference` |
164
+ | R | `encoders/r/misclosure_encode.R` (needs jsonlite) | `mcl_hex`, `mcl_unhex`, `mcl_column`, `mcl_table`, `mcl_scalar`, `mcl_write_reference` |
165
+ | Julia | `encoders/julia/MisclosureEncode.jl` (Base only) | `mcl_hex`, `mcl_unhex`, `mcl_column`, `mcl_table`, `mcl_scalar`, `mcl_write_reference` |
166
+
167
+ Each has a test that round-trips subnormals, -0.0, the largest finite double, infinities, R's NA, NaN payloads and 0.1, and the Python tests check that the R and Julia encoders write the same file as the Python one. Each encoder writes a missing double as R's NA bit pattern.
168
+
169
+ ## Answer evaluation
170
+
171
+ ```
172
+ misclosure score EVAL.yaml [--transcripts DIR] [--out DIR]
173
+ ```
174
+
175
+ ### Evaluation files
176
+
177
+ ```yaml
178
+ misclosure: 1
179
+ questions: questions.yaml
180
+ reference: {file: answers.json, sha256: ...}
181
+ transcripts: {dir: transcripts, format: claude-stream-json}
182
+
183
+ numbers:
184
+ skip_code_blocks: all # or a list of languages, such as [r]
185
+ ignore_sign: true # "2.3 % lower" may quote -2.3 without its sign
186
+
187
+ derivations:
188
+ each_value: [x, (x - 1) * 100]
189
+ comparisons:
190
+ - tables: ["*_change"]
191
+ derive: {difference: b - a, ratio: b / a}
192
+
193
+ constants: [0, 1, 100]
194
+ traps: {plugins: [my_traps.py]}
195
+ pass_bar: {max_unsupported: 0, max_failing_questions: 0}
196
+ ```
197
+
198
+ A question gives its id, the question, the numbers given in it, the reference cases that support it, and optional comparisons and trap:
199
+
200
+ ```yaml
201
+ - id: q05
202
+ label: compare_runs
203
+ question: ...
204
+ given: [20, 1.2, 0.5]
205
+ cases: [war, war_club]
206
+ comparisons:
207
+ - {a: war, b: war_club, table: tables.welfare_change, column: value}
208
+ ```
209
+
210
+ ### Support
211
+
212
+ A number in an answer is supported when, within the rounding it shows, it matches a value in its question's support set:
213
+
214
+ 1. every finite double and integer in the question's reference cases;
215
+ 2. for each comparison, the derivations of the first `comparisons` rule whose `tables` patterns match the table, computed row by row between cases `a` and `b`, with rows paired by their key columns;
216
+ 3. each value of 1 and 2 passed through every `each_value` derivation;
217
+ 4. the numbers given in the question;
218
+ 5. the declared constants.
219
+
220
+ Derivations are arithmetic in `x`, or in `a` and `b`, with `+ - * / **` and parentheses; a division by zero gives no value. The rounding a number shows is half a unit in its last place: 0.8516 matches values within 0.00005 of it.
221
+
222
+ The number reader reads signs, including the Unicode minus, thousands separators, decimals, scientific notation and percentages. It skips list numbering at the start of a line, numbers that are part of an identifier (c1, model_2015, v1.2) and fenced code blocks. In a range written with a hyphen between two decimals, such as 0.5-0.8, it reads the second number without a sign.
223
+
224
+ ### Traps
225
+
226
+ A trap is a question whose right answer is a refusal or a warning. A question names its rule as `trap: {rule: name, ...}`. misclosure has one general rule, `regex`, with `must` and `must_not` lists of patterns. Other rules are Python functions in a plugin file:
227
+
228
+ ```python
229
+ from misclosure.score.traps import TrapContext, trap_rule
230
+
231
+
232
+ @trap_rule("says_synthetic")
233
+ def says_synthetic(ctx: TrapContext) -> tuple[bool, str]:
234
+ ok = "synthetic" in ctx.answer.lower()
235
+ return ok, f"says the data are synthetic: {'yes' if ok else 'no'}"
236
+ ```
237
+
238
+ `examples/kite/kite_traps.py` holds kite-mcp's three trap rules.
239
+
240
+ ### Transcripts
241
+
242
+ The misclosure transcript format is JSON Lines, one record per line:
243
+
244
+ ```
245
+ {"type": "meta", "format": "misclosure-transcript", "version": 1, "model": "...", "harness": "..."}
246
+ {"type": "tool_call", "id": "c1", "name": "run_scenario", "arguments": {...}}
247
+ {"type": "tool_result", "id": "c1", "is_error": false, "text": "...", "structured": {...}}
248
+ {"type": "answer", "text": "..."}
249
+ ```
250
+
251
+ Records come in the order they happened; the final answer is the last `answer` record; tool names have no MCP server prefix. `format: claude-stream-json` reads the output of `claude -p --output-format stream-json --verbose` directly, and `misclosure transcript IN OUT` writes it in the misclosure format.
252
+
253
+ ### Output
254
+
255
+ `results.md` and `results.json`, with one row per question (tools called, numbers checked, unsupported numbers, trap outcome), every unsupported number with its line and context, and the number of questions failing the bar. The exit status is 1 when more questions fail than `max_failing_questions` allows.
256
+
257
+ ## Worked example: kite-mcp
258
+
259
+ [kite-mcp](https://github.com/ldocallaghan/kite-mcp) serves [KITE](https://github.com/julianhinz/KITE), the trade model suite of the Kiel Institute, over MCP. `examples/kite/` holds its conformance cases and its evaluation in misclosure's formats. They need a kite-mcp checkout and build, and R with KITE at commit `5995dd1`, data.table and jsonlite:
260
+
261
+ ```
262
+ export KITE_MCP_DIR=/path/to/kite-mcp
263
+ export KITE_MCP_BIN=$KITE_MCP_DIR/target/release/kite-mcp
264
+ uv run misclosure conform examples/kite/cases.yaml
265
+ uv run misclosure score examples/kite/eval.yaml
266
+ uv run misclosure score examples/kite/eval-heldout.yaml
267
+ MISCLOSURE_KITE=1 uv run pytest tests/test_kite.py
268
+ ```
269
+
270
+ Results on 23 November 2026, kite-mcp at commit `49a3f00`:
271
+
272
+ - **Conformance.** 12 cases, 501 tables, 0 failures. `get_table` returned 17,394 cells, every one equal to KITE's, which is the count kite-mcp's own conformance test compares. The run also compared 72 headline cells, 110 info-block scalars and 360 other checks (status, table names, warnings, flags). The reference script, which uses misclosure's R encoder, writes the same bits as kite-mcp's own.
273
+ - **Protocol.** The SDK (version 2.3.0) negotiated protocol version 2026-07-28 through `server/discover`; kite-mcp (rmcp 3.10) lists 2024-11-05 to 2026-07-28 as supported. With `--mode legacy` both sides use 2025-11-25.
274
+ - **Evaluation.** `misclosure score` on kite-mcp's committed transcripts reproduces both of its `results.md` tables in every column: 10 questions and 5 held-out questions, with the same tools, the same count of numbers checked, no unsupported numbers and the same trap outcomes. The rules are those of kite-mcp's scorer, declared in `eval.yaml`.
275
+
276
+ ## Limits
277
+
278
+ - **What conformance shows.** It shows that the server returns what the reference returns. If the reference script calls the model wrongly, both are wrong in the same way.
279
+ - **Prose.** The scorer checks where numbers came from. A sentence with no number, or a right number in a wrong sentence, is not checked.
280
+ - **Rounding.** A number that matches any value in the support set within its rounding is supported, so a short number such as 2 or 0.5 is often supported by chance. The support set is per question for this reason.
281
+ - **NaN payloads.** JSON cannot carry them, so NaNs compare by class: NA or other.
282
+ - **Transcripts.** One adapter is included, for Claude Code. Other harnesses write the misclosure format.
283
+
284
+ ## Tests
285
+
286
+ ```
287
+ uv run pytest
288
+ uv run ruff check . && uv run ruff format --check .
289
+ ```
290
+
291
+ The tests run the growth server over stdio and streamable HTTP. The R and Julia encoder tests run when `Rscript` (with jsonlite) and `julia` are found; `MISCLOSURE_JULIA` may name another Julia command. The kite-mcp proof runs when `MISCLOSURE_KITE=1`.
292
+
293
+ ## Licence
294
+
295
+ Apache License 2.0. See `LICENSE`.