""" Tool Layer - wiki_status 工具 显示 wiki 当前状态(页面数、待处理项、增量差异)。 参考设计文档:第 2.2 节 """ import logging from typing import Dict, Any from ..services import QueryService, IndexerService, GraphService logger = logging.getLogger(__name__) class WikiStatusTool: """wiki_status 工具实现""" def __init__(self, query_service: QueryService, indexer_service: IndexerService, graph_service: GraphService): self.query_service = query_service self.indexer_service = indexer_service self.graph_service = graph_service async def handle(self) -> Dict[str, Any]: """ 显示 wiki 当前状态 Returns: { "stats": { "total_pages": 1353, "total_links": 4200, "total_tags": 156, "last_indexed": "2024-06-26T10:30:00" }, "orphans": ["path1", "path2"], "orphans_count": 5, "dirty_pages": 12, "cache_stats": { "size": 100, "max_size": 1000, "utilization": 0.1 } } """ # 获取统计信息 stats = await self.query_service.get_stats() # 获取孤立页面 orphans = await self.graph_service.find_orphans() # 获取索引状态 index_status = await self.indexer_service.get_index_status() # 获取缓存统计 cache_stats = await self.query_service.cache.get_stats() return { "stats": stats, "orphans": sorted(list(orphans)), "orphans_count": len(orphans), "dirty_pages": index_status.get("dirty_pages", 0), "cache_stats": cache_stats } def get_schema(self) -> dict: """返回 MCP Tool schema""" return { "name": "wiki_status", "description": "显示 wiki 当前状态(页面数、待处理项、增量差异)", "inputSchema": { "type": "object", "properties": {} } }