Skip to content

fix(mcp): analyze_search year window, no-extra default and speed; real-world tests - #381

Merged
JonasHeinickeBio merged 1 commit into
mainfrom
fix/analyze-search-real-world
Oct 26, 2026
Merged

JonasHeinickeBio merged 1 commit into
mainfrom
fix/analyze-search-real-world

Conversation

@JonasHeinickeBio

Copy link
Copy Markdown
Owner

Summary

Real-world testing of the released MCP features (4.4.0, installed fresh from PyPI) against the live Europe PMC and a real HTTP client. Most claims held: every exact number of analyze_search equalled an independent count, the paper resources matched the tool on real articles (including the non-open-access and unknown-id errors), and the bearer token was enforced on both HTTP transports with the official MCP client. Three things in analyze_search did not:

  1. Future-dated records broke by_year. Europe PMC holds records dated far ahead (2096). On a live search for cancer the 60-year window ended there, so 5.6 million records fell into one before bucket and the years shown were meaningless. The years now end with the current year; later-dated records are one after bucket (years + before + after + undated == hit_count). Live: 1967-2026, 123 records after, 119,956 before.
  2. The default call failed without pandas. A plain uvx pyeuropepmc mcp (the registry's install command) has no analytics extra, and the default metrics includes the sample ones, so analyze_search(query) raised. It now returns by_year, open_access and the citation thresholds and marks the others basis: unavailable with the install hint; naming a sample metric still fails with that hint.
  3. Slow. 60 yearly counts took about 40 s through the shared client, which sends one request at a time (the lock from feat(mcp): add analyze_search (#316) #365). Each worker thread now counts through its own client: about 24 s for cancer.

New real-world tests (tests/mcp/e2e/test_mcp_real_world.py, -m e2e, 9 tests, ~3 min): exact numbers vs independent count_papers queries (years, open access, CITED thresholds, max citations), the 2096 case, complete-sample exactness, no-hit queries, the three resources vs the tool, and the bearer token on a real socket (session id alone is not enough).

Other real-world findings are fixed in #380 (they need its changes): rate_limit_delay was never applied by the HTTP source clients, unified_search(sources=[...]) skipped sources outside the default set, and swallowed provider failures looked like empty sources.

Test plan

  • unit tests updated and extended (future bucket, all-future set, no-extra default, per-thread clients)
  • real-world e2e: 9 passed live on SDK 1.30 (201 s) and SDK 2.3 (160 s)
  • full suite on brws039: exit 0; mypy src/: no issues in 220 files

🤖 Generated with Claude Code

…l-world tests

Found by running analyze_search against the live Europe PMC:
- records dated in the future (2096) pushed the 60-year window out of range, so
  millions of records fell into one "before" bucket: the years now end with the
  current year and later-dated records are one "after" bucket
- without pandas (a plain uvx install) the default call failed outright: it now
  returns the counted metrics and marks the others basis "unavailable"
- 60 yearly counts took ~40 s through the shared client: each worker thread
  counts through a client of its own (~24 s)
- real-world tests: exact numbers vs independent counts, paper resources vs the
  tool on real articles, the bearer token on a real socket

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d6d33924-012d-467b-a395-994cc221c387
Commits

Reviewing files that changed from the base of the PR and between a1eee06 and f7a4bdf.

Files selected for processing: 6
  • CHANGELOG.md
  • docs/features/mcp-server.md
  • src/pyeuropepmc/mcp/_analytics.py
  • src/pyeuropepmc/mcp/server.py
  • tests/mcp/e2e/test_mcp_real_world.py
  • tests/mcp/unit/test_mcp_analytics.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests labels Oct 26, 2026
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyeuropepmc/mcp/server.py 97.22% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #381      +/-   ##
==========================================
+ Coverage   82.46%   82.47%   +0.01%     
==========================================
  Files         216      216              
  Lines       32931    32966      +35     
  Branches     5952     5957       +5     
==========================================
+ Hits        27156    27190      +34     
- Misses       4490     4491       +1     
  Partials     1285     1285              
Files with missing lines Coverage Δ
src/pyeuropepmc/mcp/_analytics.py 90.90% <100.00%> (+0.71%) ⬆️
src/pyeuropepmc/mcp/server.py 96.56% <97.22%> (-0.01%) ⬇️

@JonasHeinickeBio
JonasHeinickeBio merged commit 53c1753 into main Oct 26, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant