Spaces:
Running on Zero
Running on Zero
File size: 1,685 Bytes
c86be6a 7434732 c86be6a | 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 | #!/usr/bin/env python3
"""
Run script for PDF Parser MCP Server
"""
import asyncio
import sys
from pathlib import Path
import logging
from dotenv import load_dotenv
import os
# Add current directory to path
sys.path.insert(0, str(Path(__file__).parent))
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
async def run_mcp_server():
"""Run the MCP server"""
try:
from mcp_server import mcp
logger.info("Starting MCP server...")
await mcp.run()
except Exception as e:
logger.error(f"Error running MCP server: {str(e)}")
raise
def run_fastapi_server():
"""Run the FastAPI server"""
try:
import uvicorn
from main import app
port = int(os.getenv("PORT", "8000"))
host = os.getenv("HOST", "0.0.0.0")
logger.info(f"Starting FastAPI server on {host}:{port}")
uvicorn.run("main:app", host=host, port=port, log_level="info")
except Exception as e:
logger.error(f"Error running FastAPI server: {str(e)}")
raise
if __name__ == "__main__":
if len(sys.argv) > 1:
if sys.argv[1] == "mcp":
asyncio.run(run_mcp_server())
elif sys.argv[1] == "fastapi":
run_fastapi_server()
else:
print("Usage: python run_server.py [mcp|fastapi]")
sys.exit(1)
else:
# Default: run FastAPI server
run_fastapi_server() |