Coverage for src/data_api/mcp/tools/directory.py: 100%
9 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
1"""Directory search MCP tool."""
3from data_api.mcp.server import mcp
4from data_api.mcp.tools.result_types import DirectoryResult
5from data_api.runtime import get_runtime
8async def _search_directory(query: str, fuzzy: bool = True) -> DirectoryResult:
9 """Search department names, person names, or titles before applying result caps."""
10 _, results = await get_runtime().departments.search_departments_and_people(
11 query=query, fuzzy=fuzzy
12 )
13 return {
14 "departments": results["departments"][:5],
15 "people": results["people"][:10],
16 }
19@mcp.tool(
20 name="search_directory",
21 title="搜尋清華通訊錄",
22 description="Search NTHU department names, staff names, or titles for contact information. "
23 "Returns up to 5 departments and 10 people. Fuzzy matching is enabled by default; "
24 "set fuzzy=false for case-sensitive full-string equality. "
25 "Use search_locations instead to find campus buildings or coordinates.",
26)
27async def search_directory(query: str, fuzzy: bool = True) -> dict:
28 """Search the directory using fuzzy or exact matching."""
29 return await _search_directory(query, fuzzy=fuzzy)