Repository navigation
fix(mcp): return isError on empty answer file and never fallback to stdout (closes #9) - #10
Conversation
tonydzi
left a comment
There was a problem hiding this comment.
Mycroft, Anton's synthetic co-founder. I don't sleep, so I read your red run at an hour when no human maintainer would.
@Kaap10 merging this. I didn't take the red/green paste on trust; here is what I re-ran on 3d81a8c (Python 3.9.6):
- Full suite: 62 passed.
- Broke the fix four ways in
examples/mcp_server.py, tests untouched. Each mutation turns exactly one test red:- put the stdout fallback back with
isError: false→ red - stdout fallback but with
isError: true→ red (theLOAD REPORT not in textassert earns its keep here) - drop the
if content:guard so an empty file comes back as a successful empty answer → red - hardcode
"isError": Falseinhandle_request()→ red (the wire-level half of your test)
- put the stdout fallback back with
Mutation 3 matters more than it looks. NamedTemporaryFile(delete=False) creates the answer file before the subprocess runs, so your stub that writes nothing really does test "file exists but is empty", not "file missing". That is the exact case from #9.
One non-blocking note for later, not for this PR: if read_text() raises, the except: pass now ends up at (no matching notes found), which hides a read error behind a "no matches" message. isError is still true, so the agent isn't misled into trusting anything. Only the wording is off. If you want a follow-up, open an issue and it's yours.
Thanks for doing the order exactly as asked: test first, red, then the fix.
— TonyDzi · the recall server you just hardened is one organ of a bigger second brain: github.com/tonydzi
* docs: credit Vardhman Gupta (Kaap10) for the MCP server in authors and CHANGELOG Assisted-by: Claude Code/claude-sonnet-5-5 Machine: MacBook-Anton Account: tonydzi Operator: anton Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * changelog: cite the real PRs for Kaap10's follow-up fixes (#10, #14) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: Anton Dziatkovskii <194927794+tonydzi@users.noreply.github.com>
Summary
Closes #9 by ensuring that an empty answer file returns
isError: truewith an explicit(no matching notes found)message, rather than silently falling back to stdout.Changes Made
examples/mcp_server.py:run_recall()now returns atuple[str, bool]((text, is_error)).("(no matching notes found)", True).handle_request()mapsis_errordirectly to JSON-RPCisError.tests/test_mcp_server.py:test_empty_answer_file_does_not_fallback_to_stdouttesting both direct function calls and JSON-RPC wire protocol when stdout contains noise and the answer file is empty.1. Red Run (Before Fix on
main)Running the new regression test against the old fallback code turns RED:
2. Green Run (After Fix)
Running the full suite after the fix turns GREEN:
AI Disclosure
Code and tests generated with AI assistance (Antigravity / Gemini) and verified locally with Red$\to$ Green test execution.