Repository navigation
fix(mcp): positional row sampling, lazy server import, and read-only cache invariant tests - #17
Merged
Conversation
- Use iloc for positional sampling in _sample_rows to handle duplicate index labels without corruption and eliminate O(n^2) scan (fixes #16) - Make cache purge optional in create_server and move startup purge to main CLI runner so importing server does not purge on-disk cache (fixes #16) - Add CI invariant test asserting read-only MCP tools do not mutate shared in-memory EHRData instances (fixes #13)
Empty commit. This fork's Actions were disabled by default (GitHub disables Actions on forks until manually approved) until just now, so Check Build and CPU tests have never actually run here -- not on this branch, not anywhere in the fork's history. This commit's only purpose is to fire the pull_request:synchronize event and confirm Check Build runs green for the first time.
* refactor(mcp): split run_dispatch into per-kind branch functions
run_dispatch had grown to a 434-line, complexity-103 function covering all
six dispatch kinds (demo, io-read, get, plot, io-write, edata) in one body.
Split along its own existing numbered comment boundaries into
_dispatch_demo/_dispatch_io_read/_dispatch_get/_dispatch_plot/
_dispatch_io_write/_dispatch_edata, plus small shared helpers for the
suggested-next/path-policy/op-log scaffolding every branch repeated.
run_dispatch is now a ~70-line linear guard-clause dispatcher.
Pure structural move: no behavior change, verified with pytest tests/mcp
(50/50) and topos_assess_worktree_change (IMPROVEMENT; max function
complexity 103 -> 13).
* refactor(mcp): extract helpers to clear topos SIMPLE gates in catalog/serialization/dispatch_tools
Same treatment as the run_dispatch split, applied to the next-worst offenders
from a topos_evaluate_project sweep of ehrapy/mcp/:
- catalog.py: _extract_choices (16) and function_help (15) each did several
unrelated things inline; split into _literal_choices/_looks_like_choice_param/
_quoted_choices and _param_info_entry/_first_example_snippet. Now IDEAL
(all four topos pillars).
- serialization.py: _serialize_result_inner (37) was a 147-line type switch;
split into one small serializer per result type (_serialize_visual,
_serialize_ehrdata, _serialize_single_dataframe, ...). _json_safe (18) and
_serialize_dataframe (16) got the same per-branch treatment. Now IDEAL.
- tools/dispatch_tools.py: get_edata_snapshot (18) had its struct/markdown
building inlined; split into _edata_snapshot_payload and small formatting
helpers. Now GOLD (SIMPLE achieved; composable/instability left as-is --
this module's job is orchestrating five sibling modules, so its fan-out
isn't fixable without a real architecture change).
Pure structural moves throughout: no behavior change. Verified after every
step with pytest tests/mcp (50/50), scripts/mcp_eval.py (44/44 live steps),
ruff, and topos_assess_worktree_change/topos_evaluate_file.
* chore(release): start this fork's own version line at 0.1.0
This fork carries upstream theislab/ehrapy's tag history (v0.14.0, v0.15.0,
...), and the version was already static (version = "0.15.0") despite a
[tool.hatch.version] source = "vcs" block claiming otherwise -- confirmed by
building before/after: the vcs config was dead, hatchling needs
dynamic = ["version"] for it to activate, so it silently no-op'd.
Reset to 0.1.0 as Krv-Labs' own MCP-focused release line, decoupled from
upstream's numbering, and dropped the dead vcs block rather than wire it up
properly -- a real tag-derived scheme would fight with upstream's tags on
future merges. Sets up the tag-triggered release workflow in the next commit.
* ci(mcp): tag-triggered GitHub Release + packaged-wheel MCP handshake check
Adds a real release path for consuming this fork's ehrapy[mcp] from other
projects (e.g. Reyni) without waiting on a private package index:
- .github/actions/mcp-handshake-check: composite action that installs
dist/*.whl with the mcp extra into a clean venv and drives the packaged
server over stdio (list tools, load a demo dataset, run preprocessing,
read it back, ingest a CSV). Verifies the shipped artifact, not just the
dev checkout, which would catch missing package data, a broken
console-script entry point, or an extras misconfiguration that pytest
can't see.
- release.yml: was upstream's "on release published, publish to public
PyPI" flow, which is wrong here since the package name collides with the
real theislab/ehrapy on PyPI, and this fork has no trusted publisher
configured for it anyway. Replaced with a "push tag v*.*.*" trigger that
builds, runs the handshake check, and attaches dist/* to a GitHub Release
via gh release create. Consume with:
uv tool run --from "git+https://github.com/Krv-Labs/ehrapy.git@<tag>#egg=ehrapy[mcp]" ehrapy-mcp
- build.yml: runs the same handshake check on every push/PR to main, so a
packaging regression is caught immediately rather than at the next tag.
Verified locally end-to-end: built the wheel, installed it with the mcp
extra into a throwaway venv, and ran the handshake logic against it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PC6jVtnaLvJS5mYNzE6XYF
* ci: trigger Check Build against main to verify the new MCP handshake step
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This fork has no cirun-aws-gpu self-hosted runner provisioned, so the "Triage: Check if GPU tests are allowed to run" gate could never actually pass on a PR -- it always showed red, unrelated to whether the PR's own changes were good. No branch protection currently requires this check, so it wasn't blocking merges, but it made the PR checks list meaningless noise. Dropped the pull_request trigger; kept push-to-main (upstream's original scope) since that doesn't show up in PR checks either way. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PC6jVtnaLvJS5mYNzE6XYF
Apache 2.0 doesn't require this (LICENSE/attribution were already carried through correctly -- hatchling bundles LICENSE into every wheel, authors and the scanpy sub-license are untouched), but it's good practice and easy to strip if this work goes up as a PR to theislab/ehrapy later: - README: one-line fork notice above the badges. - pyproject.toml: urls.Source now points at Krv-Labs/ehrapy instead of upstream, so anyone reading a built wheel's metadata finds the actual source it came from. Left Home-page/Documentation pointing at upstream, since those are genuinely still accurate (this fork has no separate docs site). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PC6jVtnaLvJS5mYNzE6XYF
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.
Summary
_sample_rows): Useilocpositionally instead of index-label lookups (loc). Handles non-unique index labels without corrupting/duplicating output and avoids O(n²) scans (fixes mcp: housekeeping — _sample_rows breaks on duplicate index values; importing server.py purges the cache #16).create_server(purge_cache=False)and invoke purge inmain()CLI runner soimport ehrapy.mcp.serverdoes not wipe on-disk cache (fixes mcp: housekeeping — _sample_rows breaks on duplicate index values; importing server.py purges the cache #16).run_get,get_edata_snapshot,run_plot) on sharedEHRDatacache handles (fixes mcp: load_edata shares one mutable EHRData across callers, and mtime can't detect in-memory mutation #13).Also merged in (#18): quality sweep + release automation
ehrapy/mcpfunctions (run_dispatch,catalog.py,serialization.py,tools/dispatch_tools.py) into small single-purpose helpers. No behavior change — 14 of 17 files inehrapy/mcp/now score IDEAL on topos's four-pillar code quality check.0.1.0(its own release line, separate from upstream's tags) and removed a dead, no-ophatch-vcsconfig block.v*.*.*) release workflow: builds the wheel/sdist, verifies it actually runs as an MCP server, and attaches the build to a GitHub Release. Also added the same verification to every PR viaCheck Build.Test plan
uv run pytest tests/mcp(all 50 tests pass)uv run python scripts/mcp_eval.py(all 44 eval steps pass)uv run ruff check ehrapy/mcp/ tests/mcp/uv run ruff format --check ehrapy/mcp/ tests/mcp/Check Build(incl. the new MCP handshake check) verified green in GitHub Actions