"""MCP server scaffold. This is a stub showing the three tools any MCP-based RAG integration wants: search, generate, verify. Wire these into your real MCP server (e.g. the `mcp-builder` skill of this workspace) when you're ready. """ from __future__ import annotations from typing import Any, Dict, List from ..core.config import Config from ..core.types import Query from ..pipeline import Pipeline _pipeline: Pipeline = Pipeline.from_config(Config.default()) def mcp_search(query: str, k: int = 10) -> Dict[str, Any]: q = Query(text=query, k=k) per = _pipeline.retrievers.search_per_retriever(q, k) flat = [r for lst in per.values() for r in lst] flat.sort(key=lambda r: r.score, reverse=True) return { "results": [ {"doc": r.chunk.doc_id, "chunk": r.chunk.chunk_id, "score": r.score, "retriever": r.retriever, "text": r.chunk.text[:500]} for r in flat[:k] ] } def mcp_generate(query: str, k: int = 10) -> Dict[str, Any]: resp = _pipeline.run(Query(text=query, k=k)) return resp.to_dict() def mcp_verify(answer: str, source_ids: List[str]) -> Dict[str, Any]: # Minimal: verify against current cache q = Query(text="__verify__") # collect retrieved chunks that match the given source ids ctx = [] for resp in _pipeline.cache.values(): for r in resp.retrieved: if r.chunk.doc_id in source_ids: ctx.append(r) res = _pipeline.verifier.verify(q, answer, ctx) return {"passed": res.passed, "coverage": res.citation_coverage, "faithfulness": res.faithfulness, "alerts": [a.__dict__ for a in res.alerts]}