Update asgi_app.py

This commit is contained in:
saidsurucu
2025-07-02 03:44:23 +03:00
parent 732edba35c
commit 698a9db0fb
+5 -39
View File
@@ -81,42 +81,8 @@ async def custom_401_handler(request: Request, exc: HTTPException):
return response return response
# Mount MCP app as sub-application # Mount MCP app as sub-application
app.mount("/mcp/", mcp_app) app.mount("/mcp", mcp_app)
# Add simple handler for /mcp POST requests
@app.post("/mcp")
@app.get("/mcp")
async def mcp_handler(request: Request):
"""Handle /mcp requests by forwarding to MCP app"""
# Modify scope to look like /mcp/ request
scope = request.scope.copy()
scope["path"] = "/mcp/"
scope["path_info"] = "/mcp/"
# Forward to mcp_app
async def receive():
return await request.receive()
# Capture response
response_data = {"body": b"", "status_code": 200, "headers": []}
async def send(message):
if message["type"] == "http.response.start":
response_data["status_code"] = message["status"]
response_data["headers"] = message["headers"]
elif message["type"] == "http.response.body":
response_data["body"] += message.get("body", b"")
# Call mcp_app
await mcp_app(scope, receive, send)
# Return response
from starlette.responses import Response
return Response(
content=response_data["body"],
status_code=response_data["status_code"],
headers=dict(response_data["headers"])
)
# FastAPI health check endpoint # FastAPI health check endpoint
@app.get("/health") @app.get("/health")
@@ -138,7 +104,7 @@ async def root():
"service": "Yargı MCP Server", "service": "Yargı MCP Server",
"description": "MCP server for Turkish legal databases with OAuth authentication", "description": "MCP server for Turkish legal databases with OAuth authentication",
"endpoints": { "endpoints": {
"mcp": "/mcp/", "mcp": "/mcp",
"health": "/health", "health": "/health",
"status": "/status", "status": "/status",
"stripe_webhook": "/api/stripe/webhook", "stripe_webhook": "/api/stripe/webhook",
@@ -209,7 +175,7 @@ async def mcp_info():
"provider": "clerk" "provider": "clerk"
}, },
"endpoints": { "endpoints": {
"mcp_protocol": "/mcp/", "mcp_protocol": "/mcp",
"discovery": "/mcp/discovery", "discovery": "/mcp/discovery",
"well_known": "/.well-known/mcp", "well_known": "/.well-known/mcp",
"health": "/health", "health": "/health",
@@ -255,7 +221,7 @@ async def well_known_mcp():
"mcp_server": { "mcp_server": {
"name": "Yargı MCP Server", "name": "Yargı MCP Server",
"version": "0.1.0", "version": "0.1.0",
"endpoint": f"{BASE_URL}/mcp/", "endpoint": f"{BASE_URL}/mcp",
"authentication": { "authentication": {
"type": "oauth2", "type": "oauth2",
"authorization_url": f"{BASE_URL}/auth/login", "authorization_url": f"{BASE_URL}/auth/login",
@@ -276,7 +242,7 @@ async def mcp_discovery():
"version": "0.1.0", "version": "0.1.0",
"protocol": "mcp", "protocol": "mcp",
"transport": "http", "transport": "http",
"endpoint": "/mcp/", "endpoint": "/mcp",
"authentication": { "authentication": {
"type": "oauth2", "type": "oauth2",
"authorization_url": "/auth/login", "authorization_url": "/auth/login",