feat(admin): 服务状态面板(基建/服务探活 + MCP 工具注册)+ mcp-go 工具注册表
管理端新增「运维 › 服务状态」:总览横幅 + 摘要数字 + 请求链路拓扑 (客户端→网关→NATS→调度→MCP,按健康三态着色)+ 应用服务卡(含探针 延迟)+ 基建磁贴 + MCP 工具按能力域分组(中文名/作用)。 探活机制(全走 NATS,无 HTTP): - mcp-go/mcp-py 新增 list_tools 自省工具,能应答=在线 + 上报工具清单 - dispatcher 无端点 → 新增 NATS 心跳主题 sundynix.health.dispatcher (ServeHealth 应答 model/ready/uptime),网关用 bus.Ping 探 - 网关 GET /api/v1/admin/status 并发聚合四探针 + 各项延迟 mcp-go 重构:switch → map 注册表(buildRegistry),dispatch 与 list_tools 共用单一事实源,杜绝漂移;每个工具带中文名 + 作用描述。mcp-py 同样补元信息。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,14 @@ log = logging.getLogger("mcp_py")
|
||||
SUBJECT_PY_ALL = "sundynix.tools.py.>"
|
||||
QUEUE_PY = "mcp-py-workers"
|
||||
|
||||
# 工具元信息:名称 → (中文名, 作用简述)。list_tools 据此上报给管理端展示。
|
||||
TOOL_META = {
|
||||
"echo": ("回显", "原样返回入参(调试用)"),
|
||||
"run_code": ("代码执行", "静态守卫 + Docker 隔离沙箱运行代码(标准档 256m/10s)"),
|
||||
"parse_document": ("文档解析", "文件 → 纯文本(MinerU / PaddleOCR)"),
|
||||
"secure_sandbox": ("安全沙箱", "更严资源档(128m/5s)的隔离执行,用于高风险代码"),
|
||||
}
|
||||
|
||||
|
||||
class McpGateway:
|
||||
def __init__(self) -> None:
|
||||
@@ -41,6 +49,7 @@ class McpGateway:
|
||||
"run_code": self._run_code,
|
||||
"parse_document": self._parse_document,
|
||||
"secure_sandbox": self._secure_sandbox,
|
||||
"list_tools": self._list_tools,
|
||||
}
|
||||
|
||||
async def serve(self, url: str | None = None) -> None:
|
||||
@@ -92,6 +101,15 @@ class McpGateway:
|
||||
async def _echo(self, args: dict) -> str:
|
||||
return str(args.get("text", ""))
|
||||
|
||||
async def _list_tools(self, args: dict) -> str:
|
||||
"""自省:上报业务工具清单(名称 + 中文名 + 作用),供管理端探活 + 展示。"""
|
||||
tools = [
|
||||
{"name": n, "cn": cn, "desc": d}
|
||||
for n, (cn, d) in TOOL_META.items()
|
||||
if n in self._tools # 仅上报真正注册的业务工具(list_tools 自身不计入)
|
||||
]
|
||||
return json.dumps({"service": "mcp-py", "tools": tools})
|
||||
|
||||
async def _run_code(self, args: dict) -> str:
|
||||
"""静态守卫 → Docker 隔离执行(标准档 256m/0.5cpu/10s)。"""
|
||||
code = str(args.get("code", ""))
|
||||
|
||||
Reference in New Issue
Block a user