File size: 1,038 Bytes
14fdc5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations

from fastmcp import FastMCP

from core.db import SessionLocal
from services.candidate_service import CandidateService


def register(mcp: FastMCP) -> None:
    candidate_service = CandidateService()

    @mcp.tool()
    def candidate_metadata_query(query: str, limit: int = 10) -> dict:
        """Query candidate metadata from SQLite using keyword matching."""
        with SessionLocal() as db:
            rows = candidate_service.search_candidates(db=db, query=query, limit=limit)

        if not rows:
            return {
                "status": "no_results",
                "message": "No metadata matches found in SQLite.",
                "results": [],
            }

        ui_payload = candidate_service.build_genui_payload(query=query, candidates=rows)
        return {
            "status": "success",
            "count": len(ui_payload.get("cards") or []),
            "results": ui_payload.get("cards") or [],
            "ui": ui_payload,
        }