Spaces:
Sleeping
Sleeping
| #!/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() | |