fix saas issues
This commit is contained in:
+3
-2
@@ -4,7 +4,7 @@
|
|||||||
# Server Configuration
|
# Server Configuration
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
PORT=8000
|
PORT=8000
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
# Authentication Configuration
|
# Authentication Configuration
|
||||||
ENABLE_AUTH=false # Set to true in production for JWT validation
|
ENABLE_AUTH=false # Set to true in production for JWT validation
|
||||||
@@ -48,7 +48,8 @@ EMSAL_TIMEOUT=60
|
|||||||
# ------ Clerk ------
|
# ------ Clerk ------
|
||||||
CLERK_PUBLISHABLE_KEY=pk_test_xxx
|
CLERK_PUBLISHABLE_KEY=pk_test_xxx
|
||||||
CLERK_SECRET_KEY=sk_test_xxx
|
CLERK_SECRET_KEY=sk_test_xxx
|
||||||
CLERK_ISSUER=https://your-app.clerk.accounts.dev # issuer & JWKS root
|
CLERK_ISSUER=https://your-app.clerk.accounts.dev # issuer & JWKS root (optional if using CLERK_PUBLIC_KEY)
|
||||||
|
# CLERK_PUBLIC_KEY=-----BEGIN PUBLIC KEY-----\nMIIBIjANBg...\n-----END PUBLIC KEY-----
|
||||||
|
|
||||||
# ------ Stripe ------
|
# ------ Stripe ------
|
||||||
STRIPE_SECRET=sk_live_xxx
|
STRIPE_SECRET=sk_live_xxx
|
||||||
|
|||||||
+15
-17
@@ -15,15 +15,12 @@ from fastapi.responses import JSONResponse
|
|||||||
from starlette.middleware import Middleware
|
from starlette.middleware import Middleware
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
# Import the main MCP app
|
# Import the fully configured MCP app with all tools
|
||||||
from mcp_factory import create_app
|
from mcp_server_main import app as mcp_server
|
||||||
|
|
||||||
# Import Stripe webhook router
|
# Import Stripe webhook router
|
||||||
from stripe_webhook import router as stripe_router
|
from stripe_webhook import router as stripe_router
|
||||||
|
|
||||||
# Create MCP server instance
|
|
||||||
mcp_server = create_app()
|
|
||||||
|
|
||||||
# Configure CORS middleware
|
# Configure CORS middleware
|
||||||
cors_origins = os.getenv("ALLOWED_ORIGINS", "*").split(",")
|
cors_origins = os.getenv("ALLOWED_ORIGINS", "*").split(",")
|
||||||
custom_middleware = [
|
custom_middleware = [
|
||||||
@@ -36,23 +33,24 @@ custom_middleware = [
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Create FastAPI wrapper application
|
# Create MCP Starlette sub-application first
|
||||||
app = FastAPI(
|
|
||||||
title="Yargı MCP Server",
|
|
||||||
description="MCP server for Turkish legal databases with JWT authentication",
|
|
||||||
version="0.1.0",
|
|
||||||
middleware=custom_middleware
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add Stripe webhook router to FastAPI
|
|
||||||
app.include_router(stripe_router, prefix="/api")
|
|
||||||
|
|
||||||
# Create MCP Starlette sub-application
|
|
||||||
mcp_app = mcp_server.http_app(
|
mcp_app = mcp_server.http_app(
|
||||||
path="/",
|
path="/",
|
||||||
middleware=custom_middleware
|
middleware=custom_middleware
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create FastAPI wrapper application with MCP app's lifespan
|
||||||
|
app = FastAPI(
|
||||||
|
title="Yargı MCP Server",
|
||||||
|
description="MCP server for Turkish legal databases with JWT authentication",
|
||||||
|
version="0.1.0",
|
||||||
|
middleware=custom_middleware,
|
||||||
|
lifespan=mcp_app.lifespan # Critical: Get lifespan from mcp_app, not mcp_server
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add Stripe webhook router to FastAPI
|
||||||
|
app.include_router(stripe_router, prefix="/api")
|
||||||
|
|
||||||
# Mount MCP app as sub-application
|
# Mount MCP app as sub-application
|
||||||
app.mount("/mcp", mcp_app)
|
app.mount("/mcp", mcp_app)
|
||||||
|
|
||||||
|
|||||||
+15
-7
@@ -13,13 +13,21 @@ def create_app() -> FastMCP:
|
|||||||
dependencies=["httpx", "beautifulsoup4", "markitdown", "pydantic", "aiohttp", "playwright"]
|
dependencies=["httpx", "beautifulsoup4", "markitdown", "pydantic", "aiohttp", "playwright"]
|
||||||
)
|
)
|
||||||
|
|
||||||
issuer = os.environ["CLERK_ISSUER"] # e.g. https://cool-app.clerk.accounts.dev
|
# Public key'i environment variable'dan al, yoksa None
|
||||||
auth = BearerAuthProvider(
|
public_key_pem = os.environ.get("CLERK_PUBLIC_KEY")
|
||||||
jwks_uri=f"{issuer}/.well-known/jwks.json", # Clerk JWKS pattern
|
|
||||||
issuer=issuer,
|
if public_key_pem:
|
||||||
audience=os.environ["CLERK_PUBLISHABLE_KEY"], # PK appears in aud claim
|
# Eğer public key varsa, onu kullan (production)
|
||||||
required_scopes=["yargi.read"],
|
auth = BearerAuthProvider(
|
||||||
)
|
public_key=public_key_pem,
|
||||||
|
# issuer, audience ve required_scopes kontrollerini yapmıyoruz
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Public key yoksa JWKS endpoint kullan (development/fallback)
|
||||||
|
clerk_issuer = os.environ.get("CLERK_ISSUER", "https://clerk.accounts.dev")
|
||||||
|
auth = BearerAuthProvider(
|
||||||
|
jwks_uri=f"{clerk_issuer}/.well-known/jwks.json",
|
||||||
|
)
|
||||||
return FastMCP(
|
return FastMCP(
|
||||||
name="Yargı MCP – PROD",
|
name="Yargı MCP – PROD",
|
||||||
auth=auth,
|
auth=auth,
|
||||||
|
|||||||
Reference in New Issue
Block a user