Coverage for tests/test_mcp_metadata.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 19:28 +0000

1"""Regression tests for public MCP tool names and display titles.""" 

2 

3from fastmcp import Client 

4 

5from data_api.mcp.server import mcp 

6 

7 

8async def test_tool_names_and_titles_exposed_to_clients(): 

9 expected = { 

10 "search_directory": "搜尋清華通訊錄", 

11 "search_locations": "搜尋校園地點", 

12 "get_bus_schedule": "查詢公車時刻表", 

13 "search_courses": "搜尋課程列表", 

14 "get_announcements": "搜尋校園公告", 

15 "find_dining": "搜尋餐廳列表", 

16 "get_library_info": "查詢圖書館資訊", 

17 "get_newsletters": "搜尋電子報列表", 

18 "get_energy_usage": "查詢校園即時用電", 

19 } 

20 

21 async with Client(mcp) as client: 

22 tools = await client.list_tools() 

23 

24 assert len(tools) == len(expected) 

25 assert {tool.name: tool.title for tool in tools} == expected 

26 assert all(tool.description for tool in tools) 

27 bus_tool = next(tool for tool in tools if tool.name == "get_bus_schedule") 

28 assert {"stop", "day", "time", "details"} <= bus_tool.input_schema["properties"].keys() 

29 for name in ("search_directory", "search_locations"): 

30 tool = next(tool for tool in tools if tool.name == name) 

31 assert set(tool.input_schema["properties"]) == {"query", "fuzzy"} 

32 assert tool.input_schema["required"] == ["query"] 

33 assert tool.input_schema["properties"]["fuzzy"]["type"] == "boolean" 

34 assert tool.input_schema["properties"]["fuzzy"]["default"] is True