feat: add McpConfigHelper for task metadata extraction and update MCP schema to support diverse value types

This commit is contained in:
wess09 2026-04-12 00:28:08 +08:00
parent 9652cc3450
commit abd73a5c8e
3 changed files with 34 additions and 33 deletions

39
gui.py
View File

@ -122,9 +122,21 @@ def func(ev: Optional[Event]):
except Exception as e:
logger.error(f"Uvicorn服务崩溃: {str(e)}")
raise
def _stop_process(process, timeout=5):
"""
Safely stop a multiprocessing.Process with escalating termination.
"""
if not process or not process.is_alive():
return
logger.info(f"正在停止服务进程 (PID: {process.pid})...")
process.terminate()
process.join(timeout=timeout)
if process.is_alive():
logger.warning(f"服务进程 (PID: {process.pid}) 超时未退出,强制终止...")
process.kill()
process.join(timeout=3)
if __name__ == "__main__":
@ -161,33 +173,18 @@ if __name__ == "__main__":
if restart_triggered:
logger.info("重启事件触发,终止当前服务...")
process.join(timeout=5)
if process.is_alive():
logger.warning("无法终止服务进程,强制退出")
_stop_process(process)
break
elif not process.is_alive():
logger.error("Alas Web服务意外退出")
should_exit = True
# 确保子进程完全退出
if process.is_alive():
process.terminate()
process.join(timeout=3)
if process.is_alive():
process.terminate()
process.join(timeout=3)
_stop_process(process)
# 最终清理
if process.is_alive():
process.kill()
process.join()
if process.is_alive():
process.kill()
process.join()
# 最终清理(预防性)
_stop_process(process)
logger.info("Alas Web服务已成功退出")
else:
# 非重载模式:直接运行
try:
func(None)
finally:
pass
func(None)

View File

@ -93,7 +93,17 @@ async def list_tools() -> List[Tool]:
"task": {"type": "string"},
"group": {"type": "string"},
"arg": {"type": "string"},
"value": {"type": "any"}
"value": {
"oneOf": [
{"type": "string"},
{"type": "number"},
{"type": "boolean"},
{"type": "object"},
{"type": "array"},
{"type": "null"}
],
"description": "新的配置值"
}
},
"required": ["instance", "task", "group", "arg", "value"]
}

View File

@ -38,17 +38,11 @@ class McpConfigHelper:
if group_name == "Storage": # Skip storage
continue
group_info = spec_i18n.get("_info", {})
if not group_info and group_name in spec_i18n:
# Some groups might have their own top-level entry or be sub-keys
pass
# Group localized info
group_display = group_name
group_help = ""
if group_name in spec_i18n:
group_display = spec_i18n[group_name].get("_info", {}).get("name", group_name)
group_help = spec_i18n[group_name].get("_info", {}).get("help", "")
# Resolve group i18n metadata once
group_meta = spec_i18n.get(group_name, {})
info = group_meta.get("_info", {})
group_display = info.get("name", group_name)
group_help = info.get("help", "")
group_result = {
"display_name": group_display,