SEUyishu commited on
Commit
c890eff
·
verified ·
1 Parent(s): 0d972ae

Update mcp_output/start_mcp.py

Browse files
Files changed (1) hide show
  1. mcp_output/start_mcp.py +45 -44
mcp_output/start_mcp.py CHANGED
@@ -1,44 +1,45 @@
1
- """
2
- MatDeepLearn MCP Service Startup Entry
3
- """
4
- import sys
5
- import os
6
-
7
- # Add project root to path
8
- project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9
- matdeeplearn_root = os.path.dirname(project_root)
10
-
11
- # Add paths
12
- if matdeeplearn_root not in sys.path:
13
- sys.path.insert(0, matdeeplearn_root)
14
-
15
- mcp_plugin_dir = os.path.join(project_root, "mcp_plugin")
16
- if mcp_plugin_dir not in sys.path:
17
- sys.path.insert(0, mcp_plugin_dir)
18
-
19
- from mcp_service import create_app
20
-
21
-
22
- def main():
23
- """Start FastMCP service"""
24
- app = create_app()
25
-
26
- # Use environment variable to configure port, default 7860 (HuggingFace default)
27
- port = int(os.environ.get("MCP_PORT", "7860"))
28
-
29
- # Choose transport mode based on environment variable
30
- transport = os.environ.get("MCP_TRANSPORT", "stdio")
31
-
32
- print(f"Starting MatDeepLearn MCP Service...")
33
- print(f"Transport: {transport}")
34
-
35
- if transport == "http":
36
- print(f"Port: {port}")
37
- app.run(transport="http", host="0.0.0.0", port=port)
38
- else:
39
- # Default to STDIO mode
40
- app.run()
41
-
42
-
43
- if __name__ == "__main__":
44
- main()
 
 
1
+ """
2
+ MatDeepLearn MCP Service Startup Entry
3
+ """
4
+ import sys
5
+ import os
6
+
7
+ # 获取当前脚本所在目录
8
+ current_dir = os.path.dirname(os.path.abspath(__file__))
9
+
10
+ # 添加 mcp_plugin 目录到路径
11
+ mcp_plugin_dir = os.path.join(current_dir, "mcp_plugin")
12
+ if mcp_plugin_dir not in sys.path:
13
+ sys.path.insert(0, mcp_plugin_dir)
14
+
15
+ # 添加项目根目录到路径 (MatDeepLearn)
16
+ project_root = os.path.dirname(current_dir)
17
+ if project_root not in sys.path:
18
+ sys.path.insert(0, project_root)
19
+
20
+ from mcp_service import create_app
21
+
22
+
23
+ def main():
24
+ """Start FastMCP service"""
25
+ app = create_app()
26
+
27
+ # Use environment variable to configure port, default 7860 (HuggingFace default)
28
+ port = int(os.environ.get("MCP_PORT", "7860"))
29
+
30
+ # Choose transport mode based on environment variable
31
+ transport = os.environ.get("MCP_TRANSPORT", "stdio")
32
+
33
+ print(f"Starting MatDeepLearn MCP Service...")
34
+ print(f"Transport: {transport}")
35
+
36
+ if transport == "http":
37
+ print(f"Port: {port}")
38
+ app.run(transport="http", host="0.0.0.0", port=port)
39
+ else:
40
+ # Default to STDIO mode
41
+ app.run()
42
+
43
+
44
+ if __name__ == "__main__":
45
+ main()