Skip to content

fix(core): keep index metadata when MCP status counts passages - #430

Merged
ASuresh0524 merged 1 commit into
StarTrail-org:mainfrom
Lesereingrape:fix/mcp-status-keeps-index-metadata
Oct 9, 2026
Merged

ASuresh0524 merged 1 commit into
StarTrail-org:mainfrom
Lesereingrape:fix/mcp-status-keeps-index-metadata

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

What

handle_status() in packages/leann-core/src/leann/mcp.py loaded the index metadata into meta and then reused that same name for each passage's metadata dict while counting chunks. The four fields reported after the loop were therefore read from the last passage's metadata instead of the index's, so leann_status answered Backend: unknown, Embedding: unknown (unknown), Dimensions: unknown for every index that has at least one passage.

This renames the loop-local dict to passage_meta and adds a regression test.

Why

Fixes #429.

api.py writes backend_name, embedding_model, embedding_mode and dimensions into <index>.meta.json on every build, and leann_status is the tool an MCP client uses to inspect an index — so the tool's description of a healthy index was wrong on all four fields. The counters from the same loop (Chunks, Files indexed, Size) stayed correct, which is why the response still looked plausible.

How I checked

The new test drives handle_status() through the same _base_dir seam as tests/test_mcp_base_dir.py, and writes a meta.json plus a passages.jsonl — no embeddings, index build or network needed.

Against the unfixed source (RED):

tests/test_mcp_status_metadata.py::test_index_metadata_survives_the_passage_count FAILED
tests/test_mcp_status_metadata.py::test_a_malformed_final_passage_line_does_not_change_the_report FAILED
AssertionError: assert 'Backend: ivf' in 'Index: docs\nBackend: unknown\nEmbedding: unknown (unknown)\nDimensions: unknown\nChunks: 2\nFiles indexed: 2\n...'
2 failed, 1 passed

The passing case is test_passage_counting_still_reports_chunks_and_files, i.e. the counters were never the problem.

After the rename (GREEN), together with the neighbouring MCP tests:

pytest tests/test_mcp_status_metadata.py tests/test_mcp_base_dir.py tests/test_mcp_dispatch.py tests/test_mcp_standalone.py
13 passed

Repo gates on the two changed files:

  • ruff check and ruff format --check: clean
  • ty check packages/leann-core/src/leann/mcp.py tests/test_mcp_status_metadata.py: clean

Not run locally: the full pytest tests/ suite. This environment has the published leann wheel and neither faiss nor hnswlib importable, so the build/search tests cannot run here; CI covers them, and the change touches only a stdlib-only reporting function.

I also reproduced the issue end-to-end against the published leann 0.3.8 wheel (see #429), which is what produced the unknown output quoted there.

Note

This PR was prepared by an autonomous coding agent (AI-assisted); the diff is minimal and was verified as above, but no human on the author's side has read it before filing.

handle_status() read the index metadata into `meta`, then reused that name
for each passage's own metadata dict while counting chunks. After the loop
the four fields reported by `leann_status` were read from the last passage's
metadata, so every index with at least one passage reported
Backend/Embedding/Dimensions as "unknown".
@ASuresh0524
ASuresh0524 merged commit 7f51f6c into StarTrail-org:main Oct 9, 2026
36 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.

leann_status reports backend/embedding/dimensions as "unknown" for every index that has passages

2 participants