fix: Windows MCP encoding crash and build abort on empty/corrupted PDFs - #391
Merged
ASuresh0524 merged 2 commits intoJul 31, 2026
Merged
Conversation
added 2 commits
July 31, 2026 17:05
Two Windows fixes in the MCP stdio server:
- _run_leann now decodes subprocess output with encoding='utf-8'
(errors='replace'). text=True alone falls back to the locale
encoding (e.g. GBK on Chinese Windows), which crashed the
subprocess reader thread on any emoji/CJK output and made every
tool call return {"text": null}.
- _run_leann now actually uses the existing _leann_cmd() helper
(sys.executable -m leann) instead of a bare 'leann' lookup, so the
CLI is found even when the leann console-script is not on PATH
(common when leann_mcp is launched by MCP client wrappers).
A 0-byte or corrupted PDF made fitz.open()/pdfplumber.open() raise (pymupdf.EmptyFileError etc.) and aborted the entire 'leann build'. Return an empty string for unopenable/empty PDFs so the rest of the document set still gets indexed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Two Windows fixes, both reproduced on Windows 11 + Python 3.11 (leann-core 0.3.7):
errors="replace").Plain
text=Truedecodes subprocess output with the locale encoding (GBK onChinese Windows). Since the
leannCLI prints emoji/CJK (UTF-8), the subprocessreader thread crashed with
UnicodeDecodeErrorand every MCP tool call returned{"text": null}. Fixed by passingencoding="utf-8"explicitly._leann_cmd()helper._leann_cmd()(sys.executable -m leann) was defined but never called;_run_leannstill did a bare["leann", ...]lookup, which fails withWinError 2when theleannconsole-script is not on PATH — exactly thesituation the helper's docstring describes (MCP client wrappers on Windows).
leann build.A 0-byte or damaged PDF raised
pymupdf.EmptyFileError(or similar) fromfitz.open()/pdfplumber.open()and aborted the entire build. Bothextract_pdf_text_with_pymupdfandextract_pdf_text_with_pdfplumbernowreturn
""for empty/unopenable files so the rest of the document set stillgets indexed.
Note: the related Windows crash in
search_documentsJSON mode (ctypes.CDLL(None))was already fixed by #312.
Related Issues
Relates to #14
Checklist
uv run pytest) — ran related suites:test_mcp_standalone.py,test_mcp_integration.py,test_cli_verbosity.py,test_rebuild_cli.py(26 passed); empty-PDF extraction verified manually
ruff formatandruff check)pre-commit run --all-files) — not run (pre-commit not installed locally)