Spaces:
Sleeping
Sleeping
Update mcp_output/start_mcp.py
Browse files- 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 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
if
|
| 13 |
-
sys.path.insert(0,
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
transport
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
print(f"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
| 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()
|