You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/07/16 22:32:39 UTC
(superset) branch master updated: feat(mcp): register /health HTTP endpoint (#41755)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new c45b9002e64 feat(mcp): register /health HTTP endpoint (#41755)
c45b9002e64 is described below
commit c45b9002e6431bdb7dde76295754b7f15e512378
Author: Gabriel Wong <ga...@gmail.com>
AuthorDate: Fri Jul 17 06:32:33 2026 +0800
feat(mcp): register /health HTTP endpoint (#41755)
---
superset/mcp_service/server.py | 17 +++++++
tests/unit_tests/mcp_service/test_mcp_server.py | 60 +++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/superset/mcp_service/server.py b/superset/mcp_service/server.py
index 50a03b91127..9d6b7a5d487 100644
--- a/superset/mcp_service/server.py
+++ b/superset/mcp_service/server.py
@@ -841,6 +841,21 @@ def _build_starlette_middleware(
]
+def _register_health_endpoint(mcp_instance: Any) -> None:
+ """
+ Register /health for load balancers and K8s probes.
+
+ The health_check MCP tool exists but is only reachable via the MCP
+ protocol, not httpGet probes.
+ """
+ from starlette.requests import Request
+ from starlette.responses import JSONResponse
+
+ @mcp_instance.custom_route("/health", methods=["GET"])
+ async def _health(_: Request) -> JSONResponse:
+ return JSONResponse({"status": "ok"})
+
+
def run_server(
host: str = "127.0.0.1",
port: int = 5008,
@@ -918,6 +933,8 @@ def run_server(
search_name = tool_search_config.get("search_tool_name", "search_tools")
size_guard_middleware.excluded_tools.add(search_name)
+ _register_health_endpoint(mcp_instance)
+
# Create EventStore for session management (Redis for multi-pod, None for in-memory)
event_store = create_event_store(event_store_config)
diff --git a/tests/unit_tests/mcp_service/test_mcp_server.py b/tests/unit_tests/mcp_service/test_mcp_server.py
index 322de3637af..9b2de2c74ca 100644
--- a/tests/unit_tests/mcp_service/test_mcp_server.py
+++ b/tests/unit_tests/mcp_service/test_mcp_server.py
@@ -17,9 +17,16 @@
"""Tests for MCP server EventStore creation."""
+from collections.abc import Awaitable, Callable
+from typing import cast
from unittest.mock import MagicMock, patch
import pytest
+from starlette.requests import Request
+from starlette.responses import Response
+
+# A Starlette-style ASGI endpoint, matching FastMCP's custom_route contract.
+Endpoint = Callable[[Request], Awaitable[Response]]
def test_create_event_store_returns_none_when_no_redis_url():
@@ -162,6 +169,59 @@ def test_create_event_store_returns_none_when_redis_store_fails():
assert result is None
+@pytest.mark.asyncio
+async def test_register_health_endpoint_registers_get_health() -> None:
+ """/health is registered as an HTTP GET custom route on the MCP instance."""
+ from superset.mcp_service.server import _register_health_endpoint
+
+ captured: dict[str, object] = {}
+
+ def custom_route(path: str, methods: list[str]) -> Callable[[Endpoint], Endpoint]:
+ captured["path"] = path
+ captured["methods"] = methods
+
+ def decorator(fn: Endpoint) -> Endpoint:
+ captured["fn"] = fn
+ return fn
+
+ return decorator
+
+ mcp_instance = MagicMock()
+ mcp_instance.custom_route = custom_route
+
+ _register_health_endpoint(mcp_instance)
+
+ assert captured["path"] == "/health"
+ assert captured["methods"] == ["GET"]
+
+
+@pytest.mark.asyncio
+async def test_health_endpoint_returns_ok() -> None:
+ """The /health handler returns 200 with a JSON status body."""
+ from superset.mcp_service.server import _register_health_endpoint
+ from superset.utils import json
+
+ captured: dict[str, object] = {}
+
+ def custom_route(path: str, methods: list[str]) -> Callable[[Endpoint], Endpoint]:
+ def decorator(fn: Endpoint) -> Endpoint:
+ captured["fn"] = fn
+ return fn
+
+ return decorator
+
+ mcp_instance = MagicMock()
+ mcp_instance.custom_route = custom_route
+
+ _register_health_endpoint(mcp_instance)
+
+ handler = cast(Callable[..., Awaitable[Response]], captured["fn"])
+ response = await handler(MagicMock(spec=Request))
+
+ assert response.status_code == 200
+ assert json.loads(response.body) == {"status": "ok"}
+
+
def test_create_auth_provider_uses_default_factory_for_mcp_api_key_only() -> None:
"""MCP_API_KEY_ENABLED=True should install auth even when FAB API keys are off."""
from superset.mcp_service.server import _create_auth_provider