File size: 2,190 Bytes
4920545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
Entrypoint for GNoME Materials Discovery MCP Service.

This script starts the MCP server for HuggingFace Spaces deployment
with SSE transport for Cursor connection.
"""

import os
import sys
import logging
import glob

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)


def find_start_mcp():
    """Find the start_mcp.py file."""
    # Check in the same directory first
    script_dir = os.path.dirname(os.path.abspath(__file__))
    start_mcp = os.path.join(script_dir, "start_mcp.py")
    
    if os.path.exists(start_mcp):
        return start_mcp
    
    # Search in common locations
    search_paths = [
        "/app/start_mcp.py",
        "/app/mcp_output/start_mcp.py",
        os.path.join(os.getcwd(), "start_mcp.py"),
    ]
    
    for path in search_paths:
        if os.path.exists(path):
            return path
    
    # Glob search as fallback
    matches = glob.glob("/app/**/start_mcp.py", recursive=True)
    if matches:
        return matches[0]
    
    return None


def main():
    """Main entry point - delegates to start_mcp.py"""
    logger.info("=" * 60)
    logger.info("GNoME Materials Discovery MCP Server - Entrypoint")
    logger.info("=" * 60)
    
    # Find start_mcp.py
    start_mcp = find_start_mcp()
    
    if not start_mcp:
        logger.error("Could not find start_mcp.py!")
        sys.exit(1)
    
    logger.info(f"Found start_mcp.py at: {start_mcp}")
    
    # Get configuration from environment
    mode = os.environ.get("MCP_MODE", "sse")
    host = os.environ.get("MCP_HOST", "0.0.0.0")
    port = os.environ.get("PORT", os.environ.get("MCP_PORT", "7860"))
    
    logger.info(f"Configuration: mode={mode}, host={host}, port={port}")
    
    # Build arguments
    args = [
        sys.executable,
        start_mcp,
        "--mode", mode,
        "--host", host,
        "--port", str(port)
    ]
    
    logger.info(f"Executing: {' '.join(args)}")
    
    # Execute start_mcp.py - replaces current process
    os.execv(sys.executable, args)


if __name__ == "__main__":
    main()