Skip to content

Commit 3a2fc63

Browse files
committed
refactor: Remove health-check and CORS middleware from MCP app
1 parent 491411e commit 3a2fc63

1 file changed

Lines changed: 0 additions & 40 deletions

File tree

src/mcp_server/server.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -355,44 +355,6 @@ async def sap_lifespan(server: FastMCP) -> AsyncIterator[SapContext]:
355355
_HEALTH_PATHS = {"/healthz", "/health", "/ready"}
356356

357357

358-
def _create_health_wrapper(app):
359-
"""Add unauthenticated health-check endpoints in front of the MCP app."""
360-
361-
async def wrapper(scope, receive, send):
362-
if scope["type"] == "http" and scope.get("path", "") in _HEALTH_PATHS:
363-
response = JSONResponse({"status": "ok"})
364-
await response(scope, receive, send)
365-
return
366-
await app(scope, receive, send)
367-
368-
return wrapper
369-
370-
371-
def _create_cors_middleware(app):
372-
"""Handle CORS preflight (OPTIONS) so connectors can reach the MCP endpoint."""
373-
374-
_allowed_origin = os.environ.get("CORS_ORIGINS", "*")
375-
_allowed_headers = "Authorization, Content-Type, Accept, Mcp-Session-Id"
376-
_allowed_methods = "GET, POST, OPTIONS, DELETE"
377-
378-
async def middleware(scope, receive, send):
379-
if scope["type"] == "http" and scope.get("method", "") == "OPTIONS":
380-
response = JSONResponse(
381-
content=None,
382-
status_code=204,
383-
headers={
384-
"Access-Control-Allow-Origin": _allowed_origin,
385-
"Access-Control-Allow-Methods": _allowed_methods,
386-
"Access-Control-Allow-Headers": _allowed_headers,
387-
"Access-Control-Max-Age": "86400",
388-
},
389-
)
390-
await response(scope, receive, send)
391-
return
392-
await app(scope, receive, send)
393-
394-
return middleware
395-
396358

397359
def _create_auth_middleware(app, verifier):
398360
"""Wrap ASGI app with bearer token authentication."""
@@ -418,8 +380,6 @@ async def middleware(scope, receive, send):
418380
return middleware
419381

420382

421-
_mcp_asgi = _create_health_wrapper(_mcp_asgi)
422-
_mcp_asgi = _create_cors_middleware(_mcp_asgi)
423383
if _token_verifier is not None:
424384
_mcp_asgi = _create_auth_middleware(_mcp_asgi, _token_verifier)
425385

0 commit comments

Comments
 (0)