pdfparsing / run_server.py
uppalmaurya's picture
Fix uvicorn runtime error by using import string
7434732
Raw
History Blame Contribute Delete
1.69 kB
#!/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()