- 新增 mcp_service 文件,移除原本的 src/agents/common/mcp.py,所有功能合并到mcp_service,MCP服务来处理服务器配置的增删改查操作、数据库与缓存之间的同步以及MCP客户端和工具的管理。 - 将重构的 MCP 和现有智能体做适配,引入全局缓存和状态管理机制用于MCP服务器和工具。 - 数据库表更新,在MCPServer模型中为StdIO传输类型添加了command和args字段。 - 其他代码优化、增强样式以提升用户体验和可读性。
22 lines
537 B
Python
22 lines
537 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from server.services import tasker
|
|
from src.services.mcp_service import init_mcp_servers
|
|
from src.utils import logger
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""FastAPI lifespan事件管理器"""
|
|
# 初始化 MCP 服务器配置
|
|
try:
|
|
await init_mcp_servers()
|
|
except Exception as e:
|
|
logger.error(f"Failed to initialize MCP servers during startup: {e}")
|
|
|
|
await tasker.start()
|
|
yield
|
|
await tasker.shutdown()
|