File size: 1,248 Bytes
c890eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03ec451
c890eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03ec451
 
 
c890eff
 
03ec451
c890eff
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
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()