fix optional deps issue

This commit is contained in:
saidsurucu
2025-07-01 23:01:28 +03:00
parent 424960fafb
commit 0d8cd181b8
3 changed files with 49 additions and 8 deletions
+17 -2
View File
@@ -2,7 +2,15 @@ import os
from functools import lru_cache
from fastmcp import FastMCP
from fastmcp.server.auth import BearerAuthProvider
from oauth_middleware import ClerkOAuthMiddleware
# Conditional import for OAuth middleware
try:
from oauth_middleware import ClerkOAuthMiddleware
OAUTH_AVAILABLE = True
except ImportError:
# OAuth middleware not available - will disable OAuth features
OAUTH_AVAILABLE = False
ClerkOAuthMiddleware = None
@lru_cache
def create_app() -> FastMCP:
@@ -13,12 +21,19 @@ def create_app() -> FastMCP:
"dependencies": ["httpx", "beautifulsoup4", "markitdown", "pydantic", "aiohttp", "playwright"]
}
if os.getenv("ENABLE_AUTH", "false").lower() != "true":
enable_auth = os.getenv("ENABLE_AUTH", "false").lower() == "true"
if not enable_auth or not OAUTH_AVAILABLE:
# Development mode - no authentication
# Either auth is disabled OR OAuth dependencies not available
app = FastMCP(
name="Yargı MCP DEV",
**app_config
)
if enable_auth and not OAUTH_AVAILABLE:
print("Warning: OAuth authentication requested but dependencies not available.")
print("Install with: uv pip install .[saas]")
else:
# Production mode - OAuth authentication via middleware
app_config["instructions"] += " with OAuth authentication via Clerk."