Repository navigation
Release 0.8.9: NEMAR assistant on the MCP server - #366
Merged
Merged
Conversation
…p-after-v0.8.8 chore: sync develop with main after v0.8.8
) test_hed_routes_mounted did `[r.path for r in app.routes]`. Starlette 1.x puts _IncludedRouter objects in app.routes for anything added via include_router, and those have no .path, so the comprehension raises AttributeError and every PR in the repo goes red at once. CI installs unlocked (`uv pip install -e ".[dev]"`), so it resolved starlette 1.6.0 while uv.lock pins 0.50.0, and the break arrived without any change here. The app was never broken. Verified directly under fastapi 0.141.1 / starlette 1.6.0: /hed/ask answers 422 and /hed/sessions answers 200, so the routes are mounted and serving. Only the test was wrong, because it asserted a framework internal rather than the property its own docstring names. Now it reaches the three routes and requires that none answers 404, which is the only status that means "not mounted" -- a 422 is the route rejecting an empty body and a 405 would be a method mismatch, both of which are mounted. That cannot break on the next internals rename. Verified under both majors: 36 passed on the locked starlette 0.50.0 and 36 on CI's starlette 1.6.0.
The NEMAR assistant's two dataset tools were dead. Both called nemar.org/api/dataexplorer/datapipeline/..., which returns 404: the legacy dataexplorer site was retired and its URLs now redirect to nemar.org/dataset/<id>. So this replaces them rather than supplementing them. Adds an MCP client runtime. Two design points worth knowing before changing it: Discovery runs in a worker thread with its own loop, and that is not a workaround. Tools are assembled in CommunityAssistant.__init__, which is synchronous and which the FastAPI app calls from inside a running event loop, where asyncio.run raises. A dedicated thread is correct whether or not the caller has a loop. Invocation needs none of this: it is a plain coroutine. Mutation-checked, and with a bare asyncio.run the running-loop test fails while the plain synchronous one still passes. A session per call is the right shape for this server, not laziness. The NEMAR server is stateless by design: no session id, GET and DELETE on the endpoint are 405, and there is nothing to keep alive. Connect-call-close costs one round trip and removes every piece of lifecycle management a persistent client would need. This wraps the SDK directly rather than using langchain-mcp-adapters, which pins mcp<2.0.0 and so cannot negotiate the 2026-07-28 revision the server implements. The dependency goes in the server extra, next to langchain. Failure degrades and never breaks: an unreachable server yields an empty tool list and a log line, matching _load_plugin_tools' contract. A tool error comes back as TEXT rather than raised, because the server's refusals name the cap they hit or a public URL to read instead, and handing that sentence to the model lets it correct itself. The system prompt is rewritten around the six prefixed tools as a cost ladder, with correct nm/on dataset ids and nemar.org/dataset links, plus what to relay about the streaming copy: lossy is always true, effective_rate_hz below source_rate_hz means a downsampled view, zarr_verify_status null means not yet checked rather than wrong, and a non-empty filled_ranges means part of a window is not real signal. Tests are real, no mocks: a genuine MCPServer over Streamable HTTP on a real socket, driven by the real client through the real LangChain wrappers. Plus a wiring test that reads the shipped config.yaml and asserts the prompt names the tools the loader actually produces, and a network-marked tier that runs against https://mcp.nemar.org and passes.
My MCP PR (#352) replaced the NEMAR doc entry's dead-looking nemar.org/dataexplorer with nemar.org/dataset, which 404s: there is no bare dataset index, only /dataset/<id>. The network-tier URL check caught it. The right target is /discover, and I should have read that rather than guessed it. nemarOrg/website src/lib/host.ts is the authoritative redirect map and says so outright -- "Legacy dataset browser. The new site's equivalent is /discover" -- and src/pages/discover.astro is the route. /dataexplorer 301s there, so the browser MOVED rather than being retired. What IS gone is the dataexplorer API under /api/dataexplorer/, which is why this assistant's two old tools returned 404. Conflating the retired API with the moved browser is what produced the bad guess, so the comment now records the distinction and cites its source. Verified: the nemar documentation-URL network test passes.
test_documentation_urls_accessible reported a WORKING page as broken. The openneuropet PetSurfer entry points at surfer.nmr.mgh.harvard.edu, a third-party FreeSurfer host, which answers 403 to requests' default python-requests/2.32.5 and 200 to a browser UA. Measured both ways, plus curl with the same UA string getting 200, so the block is on what requests sends as a whole rather than the string alone. Nothing was wrong with openneuropet's docs, and nothing for its maintainers to fix: the page serves fine to a human. The checker was the problem. It now sends a named UA identifying the project, which is also the polite thing to do when hitting someone else's server on a schedule, and falls back to GET when HEAD comes back 403 or 405. Some hosts and CDNs refuse HEAD while serving the same URL happily over GET, and the question here is whether the page exists, not whether the host implements HEAD. Verified: openneuropet now passes, and so do bids, eeglab, hed, mne, openneuropet, and the rest. nemar still fails on this branch for an unrelated reason -- the /dataset URL I introduced in #352 -- which #354 fixes.
…p-after-docs chore: sync develop with main after the community docs commit
* docs: browser execution tool design note Client-executed execute_code tool: Pyodide in a widget worker, LangGraph interrupt/resume on the server, per-community runtime config with lockfile-pinned lazy loading. NEMAR is the first adopter; the design is community-agnostic. * docs: fold the review into the browser execution design note * docs: decide the transport, two-run continuation * docs: deterministic results and conversation caching * docs: TTL on evidence, and fold in the AWS platform move
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.
Promotes
developtomain. 12 commits, 15 files, +1468/-751.src/version.pyis0.8.9.dev0;ensure-stable-version.ymlstrips the suffix onmain, so do not hand-edit it.What ships
The NEMAR assistant works again (#352). On
maintoday it callshttps://nemar.org/api/dataexplorer/datapipeline, which 404s, and linksnemar.org/dataexplorer/detail, which 301s. Both of its tools are dead, so the deployed assistant currently has no working tools at all. This release replaces them with the six tools served byhttps://mcp.nemar.org/mcpand deletessrc/assistants/nemar/tools.pyentirely. The system prompt is rewritten to teach the cost ladder rather than two tool names.The Docker image builds again (#359). Debian bullseye went end of life and the first
apt-get updatein the image failed, soBuild and Push to GHCR(which declaresneeds: build-and-test) has pushed nothing formain,develop, or any tag since. Nothing could deploy regardless of what merged. Base image moved to bookworm.A sync that had to happen first (#358).
a277f08addedCODE_OF_CONDUCT.mdandCONTRIBUTING.mddirectly onmainand never reacheddevelop; thesync-developworkflow only fires after a release tag, and that commit carried none. Without the sync this release would have deleted both files.OpenScience-Collectivehas no org-level.githubrepository, so there is no fallback copy.Also: a failing HED route test fixed by reaching the routes rather than reading
app.routes(#353), a named User-Agent on documentation URL checks (#355), a NEMAR browser doc repointed at/discover(#354), and the browser-execution design note (#351), which is documentation only.Review of the full diff
Reviewed
main..developas a whole rather than relying on the per-PR reviews. Two findings, neither blocking, both worth filing as follow-ups.1. MCP discovery runs on every chat request
create_community_assistantis uncached and called per request on the streaming path (src/api/routers/community.py:1995), andCommunityAssistant.__init__calls_load_mcp_toolsunconditionally (src/assistants/community.py:213). So every NEMAR chat turn spawns a thread, starts an event loop, opens a connection tomcp.nemar.org, and lists tools before the model is called.The server already advertises the fix: its
tools/listresponse carries a cache hint ofttlMs: 86400000, scope: "public", documented ondocs.nemar.org. Caching the discovered tool list per server URL against that hint removes the round trip from the request path entirely.2. Connection setup is outside both timeouts
In
src/tools/mcp_client.py, both_discoverand_callwrap only the operation inasyncio.wait_for; theasync with Client(url)that establishes the connection sits outside it.pool.submit(...).result()also takes no timeout. A server that hangs rather than refusing is therefore unbounded, and finding 1 means that lands on every chat request rather than only at startup.Whether the
mcpSDK applies its own connect timeout is unverified: the package is in theserverextra and is not installed in the local checkout's venv. Either way, a request-path call should not depend on an unexamined library default. The fix is small: move the connect inside thewait_forand give.result()a bound.What holds up well
mcp>=2.2.0is pinned to 2.x with the reason recorded inpyproject.toml:langchain-mcp-adapterspinsmcp<2.0.0and the 2026-07-28 revision does not exist there._load_plugin_tools.tests/test_tools/test_mcp_client.pyboots a real server on a real socket rather than mocking the client, which is the right shape.dataexplorerlink that the old tools pointed users at.Test
Full CI green on
developatf7fe4f7, including the Docker build and smoke test for the first time since bullseye expired. The bookworm image was also built and exercised locally with CI's own commands: container healthy in 3 seconds,GET /healthreporting0.8.9.dev0, andghresolving at 2.101.0.