2026-01-19 11:03:08 +00:00
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
# 添加项目根目录到 Python 路径
|
|
|
|
|
current_file = Path(__file__).resolve()
|
2026-04-14 10:36:22 +00:00
|
|
|
package_dir = current_file.parent
|
2026-04-08 11:19:33 +00:00
|
|
|
project_root = current_file.parent.parent
|
2026-04-14 10:36:22 +00:00
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2026-01-19 11:03:08 +00:00
|
|
|
if str(project_root) not in sys.path:
|
|
|
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
|
|
|
|
|
|
import uvicorn
|
|
|
|
|
|
2026-04-08 11:19:33 +00:00
|
|
|
from app.app_factory import create_app
|
|
|
|
|
from app.core.config import API_CONFIG
|
2026-01-19 11:03:08 +00:00
|
|
|
|
2026-02-06 07:57:34 +00:00
|
|
|
|
2026-04-08 11:19:33 +00:00
|
|
|
app = create_app()
|
2026-01-19 11:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
)
|