Skip to content

Release 0.8.9: NEMAR assistant on the MCP server - #366

Merged
neuromechanist merged 13 commits into
mainfrom
develop
Sep 17, 2026
Merged

neuromechanist merged 13 commits into
mainfrom
develop

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Promotes develop to main. 12 commits, 15 files, +1468/-751.

src/version.py is 0.8.9.dev0; ensure-stable-version.yml strips the suffix on main, so do not hand-edit it.

What ships

The NEMAR assistant works again (#352). On main today it calls https://nemar.org/api/dataexplorer/datapipeline, which 404s, and links nemar.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 by https://mcp.nemar.org/mcp and deletes src/assistants/nemar/tools.py entirely. 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 update in the image failed, so Build and Push to GHCR (which declares needs: build-and-test) has pushed nothing for main, 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). a277f08 added CODE_OF_CONDUCT.md and CONTRIBUTING.md directly on main and never reached develop; the sync-develop workflow only fires after a release tag, and that commit carried none. Without the sync this release would have deleted both files. OpenScience-Collective has no org-level .github repository, 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..develop as 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_assistant is uncached and called per request on the streaming path (src/api/routers/community.py:1995), and CommunityAssistant.__init__ calls _load_mcp_tools unconditionally (src/assistants/community.py:213). So every NEMAR chat turn spawns a thread, starts an event loop, opens a connection to mcp.nemar.org, and lists tools before the model is called.

The server already advertises the fix: its tools/list response carries a cache hint of ttlMs: 86400000, scope: "public", documented on docs.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 _discover and _call wrap only the operation in asyncio.wait_for; the async 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 mcp SDK applies its own connect timeout is unverified: the package is in the server extra 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 the wait_for and give .result() a bound.

What holds up well

  • mcp>=2.2.0 is pinned to 2.x with the reason recorded in pyproject.toml: langchain-mcp-adapters pins mcp<2.0.0 and the 2026-07-28 revision does not exist there.
  • Failure degrades rather than breaks; an unreachable server yields an empty tool list and a log line, matching _load_plugin_tools.
  • tests/test_tools/test_mcp_client.py boots a real server on a real socket rather than mocking the client, which is the right shape.
  • The rewritten prompt drops the dead dataexplorer link that the old tools pointed users at.

Test

Full CI green on develop at f7fe4f7, 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 /health reporting 0.8.9.dev0, and gh resolving at 2.101.0.

…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
@neuromechanist
neuromechanist merged commit b869884 into main Sep 17, 2026
20 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.

1 participant