Skip to content

mcp: structured JSON from eval/hol_load, output truncation, built-in timing#163

Merged
jrh13 merged 3 commits intojrh13:masterfrom
sgmenda:mcp-context-improvements
Apr 9, 2026
Merged

mcp: structured JSON from eval/hol_load, output truncation, built-in timing#163
jrh13 merged 3 commits intojrh13:masterfrom
sgmenda:mcp-context-improvements

Conversation

@sgmenda
Copy link
Copy Markdown
Contributor

@sgmenda sgmenda commented Apr 7, 2026

Reduces LLM context window bloat from the MCP server by making eval and hol_load return structured, truncated JSON instead of raw strings.

Motivation

During the AES-GCM formalization, I found that large outputs from eval and hol_load fill up the context window quickly---the S-box precomputation dumps ~15K chars, needs prints every intermediate val binding (~10K chars), and large let bindings print full values. All this noise leaves less room for actual reasoning.

Changes

eval returns structured JSON

{
  "success": true,
  "output": "val it : thm = |- 1 + 1 = 2",
  "output_truncated": false,
  "full_output_chars": 42,
  "time_seconds": 0.003
}
  • max_output_chars parameter (default 4000, configurable per-call and in hol-mcp.toml)
  • success field uses heuristic error detection (checks for Error:, Exception:, Failure, and Unbound)
  • Built-in timing eliminates the need to wrap calls in time (...)

hol_load returns quiet structured JSON

  {"success": true, "file": "Library/words.ml", "time_seconds": 0.45}

hol_load is meant for loading known-good files, so intermediate val bindings are suppressed entirely.

If it fails, an error field is included, and you can debug by using eval with needs "file.ml" to get the full output.

Other

Note on truncation safety

Truncation is purely cosmetic. It is implemented in Python after all output has been read from the HOL Light subprocess. Specifically, this does not break pipes or SIGPIPE.

sgmenda added 3 commits April 7, 2026 19:32
…timing

eval now returns structured JSON:
  {success, output, output_truncated, full_output_chars, time_seconds}

Large outputs are truncated to max_output_chars (default 4000, configurable
in hol-mcp.toml and per-call).

hol_load now returns quiet structured JSON:
  {success, file, time_seconds} (plus error on failure)
Intermediate val bindings are suppressed. Use eval with needs for verbose output.

Built-in timing on all eval/hol_load calls via _eval_raw returning
(output, elapsed_seconds) tuples.

Also: add hol_interrupt smoke test (all 14 tools now covered), bump all deps
(mcp 1.27, starlette 1.0, cryptography 46.0.6, etc.), fix README test counts.

Breaking change: eval and hol_load return types changed from raw strings
to JSON. All tests and smoke tests updated.
this was a typo, and now it matches the unit test.
@jrh13
Copy link
Copy Markdown
Owner

jrh13 commented Apr 9, 2026

All looks great, thanks!

@jrh13 jrh13 merged commit 9359987 into jrh13:master Apr 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants