import sys from pathlib import Path # 添加项目根目录到 Python 路径 current_file = Path(__file__).resolve() package_dir = current_file.parent project_root = current_file.parent.parent # When this file is executed as `python app/main.py`, Python automatically puts # `/.../backend/app` on sys.path. That shadows the third-party `mcp` package # with our local `app/mcp` package and breaks `from mcp.server.fastmcp import FastMCP`. try: sys.path.remove(str(package_dir)) except ValueError: pass if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) import uvicorn from app.app_factory import create_app from app.core.config import API_CONFIG app = create_app() if __name__ == "__main__": uvicorn.run( "app.main:app", host=API_CONFIG['host'], port=API_CONFIG['port'], limit_max_requests=1000, timeout_keep_alive=30, reload=True, )