#!/usr/bin/env python3 """ Complete system startup script for PDF Parser MCP Server """ import os import sys import subprocess import asyncio from pathlib import Path from dotenv import load_dotenv # Load environment variables load_dotenv() def check_dependencies(): """Check if all required dependencies are installed""" try: import fitz import tiktoken import anthropic import fastapi import uvicorn import mcp print("✅ All dependencies are installed!") return True except ImportError as e: print(f"❌ Missing dependency: {e}") return False def check_env_vars(): """Check if required environment variables are set""" required_vars = ["ANTHROPIC_API_KEY"] missing_vars = [] for var in required_vars: if not os.getenv(var): missing_vars.append(var) if missing_vars: print(f"❌ Missing environment variables: {', '.join(missing_vars)}") print("Please create a .env file with your ANTHROPIC_API_KEY") return False print("✅ All environment variables are set!") return True def create_env_file(): """Create .env file if it doesn't exist""" env_file = Path(".env") if not env_file.exists(): print("Creating .env file...") with open(env_file, "w") as f: f.write("""ANTHROPIC_API_KEY=your_anthropic_api_key_here UPLOAD_DIR=uploads MAX_FILE_SIZE=50000000 CHUNK_SIZE=8000 MAX_TOKENS=180000 PORT=8000 HOST=0.0.0.0 """) print("✅ .env file created! Please add your ANTHROPIC_API_KEY") return False return True def start_fastapi_server(): """Start FastAPI server""" print("🚀 Starting FastAPI server...") try: import uvicorn from main import app port = int(os.getenv("PORT", "8000")) host = os.getenv("HOST", "0.0.0.0") uvicorn.run("main:app", host=host, port=port, log_level="info") except Exception as e: print(f"❌ Error starting FastAPI server: {e}") return False def start_mcp_server(): """Start MCP server""" print("🚀 Starting MCP server...") try: from mcp_server import mcp asyncio.run(mcp.run()) except Exception as e: print(f"❌ Error starting MCP server: {e}") return False def print_instructions(): """Print setup instructions""" print(""" 🎉 PDF Parser MCP Server Setup Complete! 📋 SETUP INSTRUCTIONS: 1. 📁 Create .env file with your Anthropic API key: ANTHROPIC_API_KEY=your_actual_api_key_here 2. 🚀 Start the FastAPI server: python start_system.py fastapi 3. 🔧 Start the MCP server (for Claude Desktop): python start_system.py mcp 4. 🖥️ Configure Claude Desktop: - Copy the contents of claude_desktop_config.json - Add to your Claude Desktop config file: Windows: %APPDATA%\\Claude\\claude_desktop_config.json macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/claude/claude_desktop_config.json 5. 📄 Upload PDFs: curl -X POST "http://localhost:8000/upload-pdf/" -F "file=@your_document.pdf" 6. 💬 Use with Claude Desktop: - "List all my documents" - "What is the summary of document [file_id]?" - "Search for 'keyword' in all documents" 🔗 API Documentation: http://localhost:8000/docs """) def main(): """Main function""" print("🔧 PDF Parser MCP Server Setup") print("=" * 50) # Check if .env file exists if not create_env_file(): return # Check dependencies if not check_dependencies(): print("Please install dependencies with: uv sync") return # Check environment variables if not check_env_vars(): return # Create upload directory upload_dir = Path(os.getenv("UPLOAD_DIR", "uploads")) upload_dir.mkdir(exist_ok=True) print(f"✅ Upload directory created: {upload_dir}") # Handle command line arguments if len(sys.argv) > 1: if sys.argv[1] == "fastapi": start_fastapi_server() elif sys.argv[1] == "mcp": start_mcp_server() else: print("Usage: python start_system.py [fastapi|mcp]") else: print_instructions() if __name__ == "__main__": main()