MatDeepLearn / mcp_output /start_mcp.py
SEUyishu's picture
Update mcp_output/start_mcp.py
03ec451 verified
"""
MatDeepLearn MCP Service Startup Entry
"""
import sys
import os
# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 添加 mcp_plugin 目录到路径
mcp_plugin_dir = os.path.join(current_dir, "mcp_plugin")
if mcp_plugin_dir not in sys.path:
sys.path.insert(0, mcp_plugin_dir)
# 添加项目根目录到路径 (MatDeepLearn)
project_root = os.path.dirname(current_dir)
if project_root not in sys.path:
sys.path.insert(0, project_root)
from mcp_service import mcp
def main():
"""Start FastMCP service"""
# Use environment variable to configure port, default 7860 (HuggingFace default)
port = int(os.environ.get("MCP_PORT", "7860"))
# Choose transport mode based on environment variable
transport = os.environ.get("MCP_TRANSPORT", "stdio")
print(f"Starting MatDeepLearn MCP Service...")
print(f"Transport: {transport}")
if transport == "http":
print(f"Port: {port}")
print(f"SSE endpoint: http://0.0.0.0:{port}/sse")
# FastMCP 2.x 使用 streamable-http 传输
mcp.run(transport="sse", host="0.0.0.0", port=port)
else:
# Default to STDIO mode
mcp.run()
if __name__ == "__main__":
main()