Spaces:
Sleeping
Sleeping
| """ | |
| Configuration settings for PowerPoint MCP Server | |
| Handles environment variables and deployment settings | |
| CORRECT filename - works with existing repository structure | |
| """ | |
| import os | |
| def get_server_config(): | |
| """Get server configuration based on environment""" | |
| # Default configuration | |
| config = { | |
| "mcp_port": 8000, | |
| "gradio_port": 7860, | |
| "host": "0.0.0.0", | |
| "debug": False, | |
| "deployment_platform": "huggingface_spaces" | |
| } | |
| # Override with environment variables if available | |
| config["mcp_port"] = int(os.getenv("MCP_PORT", config["mcp_port"])) | |
| config["gradio_port"] = int(os.getenv("GRADIO_PORT", config["gradio_port"])) | |
| config["host"] = os.getenv("HOST", config["host"]) | |
| config["debug"] = os.getenv("DEBUG", "false").lower() == "true" | |
| # Deployment-specific settings | |
| if is_huggingface_spaces(): | |
| # Hugging Face Spaces exposes a single PORT env var for the app. | |
| # Bind both MCP and Gradio to the same PORT so the MCP endpoint is reachable at /mcp. | |
| hf_port = int(os.getenv("PORT", config["gradio_port"])) | |
| config["mcp_port"] = hf_port | |
| config["gradio_port"] = hf_port | |
| config["deployment_platform"] = "huggingface_spaces" | |
| config["base_url"] = get_huggingface_url() | |
| else: | |
| config["deployment_platform"] = "local" | |
| config["base_url"] = f"http://{config['host']}:{config['mcp_port']}" | |
| return config | |
| def is_huggingface_spaces(): | |
| """Check if running on Hugging Face Spaces""" | |
| # Some Spaces builds may not expose SPACE_ID inside custom containers. | |
| # Treat presence of PORT (the HF-assigned port) as indicator as well. | |
| return os.getenv("SPACE_ID") is not None or os.getenv("PORT") is not None | |
| def get_huggingface_url(): | |
| """Get the Hugging Face Space URL""" | |
| space_id = os.getenv("SPACE_ID") | |
| if space_id: | |
| # Format: https://huggingface.co/spaces/username/space-name | |
| return f"https://{space_id.replace('/', '-')}.hf.space" | |
| return None | |
| def get_mcp_endpoint_url(): | |
| """Get the full MCP endpoint URL""" | |
| config = get_server_config() | |
| base_url = config["base_url"] | |
| if base_url: | |
| return f"{base_url}/mcp" | |
| else: | |
| return f"http://{config['host']}:{config['mcp_port']}/mcp" | |
| # Export configuration functions | |
| __all__ = [ | |
| 'get_server_config', | |
| 'is_huggingface_spaces', | |
| 'get_huggingface_url', | |
| 'get_mcp_endpoint_url' | |
| ] | |