Files
sanguo_llmwiki/mcp_server/tools/wiki_status.py
T
claude_dev dfd8421dc6 feat(§03): 实现 MCP Server 核心 - Storage/Service/Tool/MCP Protocol Layers
**Storage Layer:**
- Database 类(aiosqlite + WAL + 并发保护)
- WikiPage 数据模型
- fix_dirty_states 恢复机制
- FTS5 全文搜索支持
- 完整的 SQLite 表结构

**Service Layer:**
- CacheService(LRU 缓存 + TTL + 大小限制)
- QueryService(查询服务)
- ParserService(Markdown 解析)
- IndexerService(索引服务)
- GraphService(链接图服务)

**Tool Layer (8 个 MCP Tools):**
- wiki_query - FTS5 全文搜索 + 标签过滤
- memory_bridge - 按工具来源浏览
- wiki_status - 索引状态
- wiki_lint - 健康审计
- cross_linker - 缺失链接发现
- tag_taxonomy - 标签一致性
- wiki_synthesize - 跨概念综合分析
- daily_update - 日常维护 + hot.md 生成

**MCP Protocol Layer:**
- MCP 协议解析和封装
- 工具注册和路由
- 错误处理和日志
- stdio 模式支持

**配置和部署:**
- requirements.txt
- config.example.yaml
- ecosystem.config.cjs (PM2)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 11:32:43 +08:00

76 lines
2.2 KiB
Python

"""
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": {}
}
}