Skip to content

feat(mcp): ensure_kb + ground_paper grounding tools (+ fastmcp 3.x test fix)#28

Merged
lfnothias merged 2 commits into
mainfrom
feat/grounding-mcp-tools
Jun 22, 2026
Merged

feat(mcp): ensure_kb + ground_paper grounding tools (+ fastmcp 3.x test fix)#28
lfnothias merged 2 commits into
mainfrom
feat/grounding-mcp-tools

Conversation

@lfnothias

Copy link
Copy Markdown
Collaborator

What

Adds the Perspicacité side of the ASB grounding consolidation — two thin MCP tools so an agent (via the asb-skill-collections /ground command or the bundled binder) can install + query a skill's source-paper KB on demand:

  • ensure_kb(doi, mode="paper") — idempotently create + ingest a per-paper KB named asb-paper-<doi> (slug matches the ASB binder convention exactly). Returns status: "exists" (skips re-ingest when the KB already has chunks) or "created" with chunk counts. Reuses create_knowledge_base + add_dois_to_kb.
  • ground_paper(doi, question, tier="paper"|"si")ensure_kb, then a RAG query (generate_report) scoped to that paper's KB. tier="si" steers retrieval toward the supplementary information. Returns {kb_slug, answer, sources}.

Both are thin compositions of existing tools, degrade gracefully to _json_error (never raise), and are registered in _TOOL_NAMES.

Why

This is the MCP-owned, on-first-query grounding path designed in the asb-skill-collections consolidation (asb side already merged: HolobiomicsLab/asb-skill-collections#5, #6). The asb packs ship the /ground command + binder; these tools are what make the KB "auto-install + query via the MCP" in-session.

Commits

  1. test(mcp) — fastmcp 3.x test migration (separate commit). The MCP test suite was red at baseline (8/21 failing): fastmcp 3.2.4 removed mcp._tool_manager, which the tests still used. Migrated to module-attr tool access (_tool_fn) + mcp._list_tools() enumeration; accommodated generate_report's new message_id kwarg; refreshed stale tool-count constants. 8 failing → 21 passing. (Pre-existing issue, surfaced while adding these tools.)
  2. feat(mcp) — the two tools + 14 new tests (idempotency, create path, zero-chunk re-ingest, graceful failure, SI hint, error propagation).

Suite: 35 passed (tests/test_mcp_server.py, via .venv).

Notes / review points

  • generate_report has no context param, so the tier="si" hint is prepended to the query string rather than passed separately. If you'd prefer a first-class context/SI-steering arg on generate_report, say so and I'll wire it.
  • ensure_kb's mode param is reserved (currently unused) to match the agreed signature.
  • Ingestion is awaited inside the call (on-demand model) — fine for /ground, but if you want async/background ingest, that's a follow-up.

🤖 Generated with Claude Code

lfnothias and others added 2 commits June 22, 2026 14:29
…reen baseline)

fastmcp 3.2.4 removed mcp._tool_manager; the @mcp.tool() functions remain
directly callable at module level. Replace _tool_manager._tools[name].fn access
with a module-attr lookup (_tool_fn) and mcp._list_tools() for enumeration;
accommodate generate_report's new message_id kwarg in the fake engine; refresh
stale tool-count constants (15->49; ==->>= for the non-exhaustive EXPECTED_TOOLS).
8 failing -> 21 passing. Pre-existing issue, surfaced while adding grounding tools.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two thin MCP tools for ASB grounding, composing existing tools:
- ensure_kb(doi, mode='paper'): idempotently create + ingest a per-paper KB
  named asb-paper-<doi> (matches the ASB binder slug). Skips re-ingest when the
  KB already has chunks. Reuses create_knowledge_base + add_dois_to_kb.
- ground_paper(doi, question, tier='paper'|'si'): ensure_kb, then a RAG query
  (generate_report) scoped to that KB; tier='si' steers toward the SI.
Both degrade gracefully to _json_error; registered in _TOOL_NAMES. 14 new tests.

Perspicacite side of the asb-skill-collections grounding consolidation: /ground
and the binder can now install + query a skill's source-paper KB via the MCP.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lfnothias lfnothias merged commit fcbfe7e into main Jun 22, 2026
1 of 2 checks passed
@lfnothias lfnothias deleted the feat/grounding-mcp-tools branch June 22, 2026 17:42
lfnothias added a commit that referenced this pull request Jun 23, 2026
PR #28 added the ensure_kb and ground_paper MCP tools but did not add
their required-argument fixtures to _TOOL_ARGS, so test_tool_inventory
invoked them with no args and raised TypeError, failing CI. Add the
missing entries using the existing fake-DOI convention.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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