## Add MCP tool for biblio graph expansion The core graph expansion logic alrea
Add MCP tool for biblio graph expansion¶
The core graph expansion logic already exists in packages/biblio/src/biblio/graph.py (expand_openalex_reference_graph), but it has no MCP tool exposure. Three files need changes:
1. packages/biblio/src/biblio/mcp.py — append after library_set_bulk¶
Add a graph_expand function that:
- Accepts root: Path, citekeys: list[str] | None, direction: str = "references", merge: bool = True, force: bool = False
- Loads config via _load_cfg(root)
- Imports expand_openalex_reference_graph and load_openalex_seed_records from .graph
- Loads seed records from cfg.repo_root / "bib" / "derivatives" / "openalex" / "resolved.jsonl"
- Returns {"error": "No seed records found", ...} if no records
- Calls expand_openalex_reference_graph(cfg=cfg.openalex_client, cache=cfg.openalex_cache, records=records, out_path=..., direction=direction, force=force, merge=merge, seed_citekeys=citekeys)
- Output path: cfg.repo_root / "bib" / "derivatives" / "openalex" / "graph_candidates.json"
- Returns dict with total_inputs, seeds_with_openalex, candidates, output_path
2. src/projio/mcp/biblio.py — add before biblio_rag_sync¶
Add biblio_graph_expand(citekeys, direction, merge, force) -> JsonDict following the same pattern as other wrappers: check _biblio_available(), get root, import from biblio.mcp import graph_expand, call it, wrap in json_dict().
3. src/projio/mcp/server.py — add after biblio_rag_sync registration, before # --- Notio tools ---¶
Register @server.tool("biblio_graph_expand") that calls biblio.biblio_graph_expand(citekeys=citekeys or None, direction=direction, merge=merge, force=force). Parameters: citekeys: list[str] = [], direction: str = "references", merge: bool = True, force: bool = False.
4. Smoke test at packages/biblio/tests/test_biblio_graph_mcp.py¶
Test that graph_expand from biblio.mcp:
- Returns error dict when resolved.jsonl doesn't exist (needs a minimal repo with biblio.yml config)
- Correctly calls expand_openalex_reference_graph with right args when seeds exist (use monkeypatch like existing test_biblio_graph.py)
Verification¶
After edits: python3 -c "from biblio.mcp import graph_expand; print('OK')" and cd packages/biblio && python3 -m pytest tests/test_biblio_graph_mcp.py -v
Source context: labpy¶
Labpy (labpy): sirota lab main python package; initiated as a translation of labbox Matlab code into python
Recent commits:
9404ac9 Add labbox↔labpy correspondence map and audit notes
3fe54eb Fix timefrequency API inconsistencies and add smoke tests
2c0ebb2 Add labbox ↔ labpy correspondence map
Related Notes¶
- [[issue-arash-20260328-145700-791144.md]] — Directly related: both concern the biblio graph feature — this note adds the MCP exposure, the other covers the graph migration itself
- [[issue-arash-20260326-174001-720656.md]] — Same pattern: both are about missing MCP tool registrations that need to be wired into server.py
- [[issue-arash-20260326-142709-728239.md]] — Both touch the biblio subsystem and its integration surface