Files
yargi-mcp/mcp_factory.py
T
2025-07-01 18:50:36 +03:00

33 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from functools import lru_cache
from fastmcp import FastMCP
from fastmcp.server.auth import BearerAuthProvider
from oauth_middleware import ClerkOAuthMiddleware
@lru_cache
def create_app() -> FastMCP:
"""Return a FastMCP instance; OAuth authentication when ENABLE_AUTH=true."""
# Base app configuration
app_config = {
"instructions": "MCP server for TR legal databases (Yargitay, Danistay, Emsal, Uyusmazlik, Anayasa-Norm, Anayasa-Bireysel, KIK, Sayistay, Rekabet).",
"dependencies": ["httpx", "beautifulsoup4", "markitdown", "pydantic", "aiohttp", "playwright"]
}
if os.getenv("ENABLE_AUTH", "false").lower() != "true":
# Development mode - no authentication
app = FastMCP(
name="Yargı MCP DEV",
**app_config
)
else:
# Production mode - OAuth authentication via middleware
app_config["instructions"] += " with OAuth authentication via Clerk."
app = FastMCP(
name="Yargı MCP PROD",
**app_config
)
# Add OAuth middleware instead of BearerAuthProvider
app.add_middleware(ClerkOAuthMiddleware())
return app