hf-eda-mcp / src /hf_eda_mcp /__main__.py
KhalilGuetari's picture
build source code as package
316c2dc
"""
Main entry point for the hf-eda-mcp server.
This module allows the package to be run as a module using:
python -m hf_eda_mcp
"""
import argparse
import sys
from hf_eda_mcp.config import ServerConfig
from hf_eda_mcp.server import launch_server
def main():
"""Main entry point with command line argument parsing."""
parser = argparse.ArgumentParser(
description="HuggingFace EDA MCP Server - Provides EDA tools for HuggingFace datasets via MCP",
prog="hf-eda-mcp",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python -m hf_eda_mcp # Start server with default settings
python -m hf_eda_mcp --port 8080 # Start server on port 8080
python -m hf_eda_mcp --no-mcp # Start without MCP server functionality
python -m hf_eda_mcp --share # Create public shareable link
python -m hf_eda_mcp --host 0.0.0.0 # Listen on all interfaces
Environment Variables:
HF_TOKEN HuggingFace access token for private datasets
HF_EDA_PORT Server port (default: 7860)
HF_EDA_HOST Server host (default: 127.0.0.1)
HF_EDA_MCP_ENABLED Enable MCP server (default: true)
HF_EDA_SHARE Enable public sharing (default: false)
HF_EDA_LOG_LEVEL Logging level (default: INFO)
HF_EDA_CACHE_DIR Cache directory for datasets
HF_EDA_MAX_SAMPLE_SIZE Maximum sample size (default: 50000)
HF_EDA_MAX_CONCURRENT Max concurrent requests (default: 10)
HF_EDA_REQUEST_TIMEOUT Request timeout in seconds (default: 300)
"""
)
parser.add_argument(
"--port",
type=int,
help="Port to run the server on (overrides HF_EDA_PORT)"
)
parser.add_argument(
"--host",
type=str,
help="Host to bind the server to (overrides HF_EDA_HOST)"
)
parser.add_argument(
"--no-mcp",
action="store_true",
help="Disable MCP server functionality (web interface only)"
)
parser.add_argument(
"--share",
action="store_true",
help="Create a public shareable link via Gradio"
)
parser.add_argument(
"--verbose", "-v",
action="store_true",
help="Enable verbose logging (DEBUG level)"
)
parser.add_argument(
"--log-level",
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
help="Set logging level (overrides HF_EDA_LOG_LEVEL)"
)
parser.add_argument(
"--cache-dir",
type=str,
help="Directory for caching datasets (overrides HF_EDA_CACHE_DIR)"
)
parser.add_argument(
"--max-sample-size",
type=int,
help="Maximum sample size for analysis (overrides HF_EDA_MAX_SAMPLE_SIZE)"
)
args = parser.parse_args()
# Load base configuration from environment
config = ServerConfig.from_env()
# Override with command line arguments
if args.port is not None:
config.port = args.port
if args.host is not None:
config.host = args.host
if args.no_mcp:
config.mcp_server = False
if args.share:
config.share = True
if args.verbose:
config.log_level = "DEBUG"
if args.log_level:
config.log_level = args.log_level
if args.cache_dir:
config.cache_dir = args.cache_dir
if args.max_sample_size is not None:
config.max_sample_size = args.max_sample_size
try:
# Launch server with configuration
launch_server(config)
except KeyboardInterrupt:
print("\n👋 Server stopped by user")
sys.exit(0)
except Exception as e:
print(f"❌ Error starting server: {e}")
sys.exit(1)
if __name__ == "__main__":
main()