You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2025/12/08 20:18:24 UTC

[PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

aminghadersohi opened a new pull request, #36460:
URL: https://github.com/apache/superset/pull/36460

   ### SUMMARY
   In production (Kubernetes/multi-tenant), the MCP service receives requests via internal networking, causing `request.host` to return internal k8s service URLs like `ws--xxx--main-superset-mcp.ws--xxx--main.svc.cluster.local:5008` which are not accessible externally.
   
   This fix changes the URL detection to use config-based values instead of request auto-detection:
   
   **Order of precedence:**
   1. `MCP_SERVICE_URL` config (explicit override)
   2. `SUPERSET_WEBSERVER_ADDRESS` + `/mcp` prefix (production)
   3. `localhost:5008` fallback (development)
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A - Backend change only
   
   ### TESTING INSTRUCTIONS
   1. In development: MCP service should use `localhost:5008` by default
   2. With `SUPERSET_WEBSERVER_ADDRESS` set to a non-localhost URL: MCP service URLs should use that address with `/mcp` prefix
   3. With explicit `MCP_SERVICE_URL` config: Should use that value directly
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600349932


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +77,35 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
+        if user_friendly_url and not _is_local_url(user_friendly_url):

Review Comment:
   nit: for those that prefer the walrus:
   ```suggestion
           if user_friendly_url := config["WEBDRIVER_BASEURL_USER_FRIENDLY"] and not _is_local_url(user_friendly_url):
   ```



##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +77,35 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
+        if user_friendly_url and not _is_local_url(user_friendly_url):
+            # Production/staging - use main URL with /mcp prefix
+            base_url = user_friendly_url.rstrip("/")
+            return f"{base_url}/mcp"
+
     except Exception as e:
-        # Log and fall back if config access fails
         import logging
 
         logging.getLogger(__name__).debug("Config access failed: %s", e)

Review Comment:
   This looks unnecessarily custom - usually we'd do this at the top and then just use `logger`:
   ```
   import logging
   
   logger = logging.getLogger(__name__)
   ```



##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -19,8 +19,22 @@
 URL utilities for MCP service
 """
 
+from urllib.parse import urlparse
+
 from flask import current_app
 
+# Hostnames that indicate a development/local environment
+LOCAL_HOSTNAMES = {"localhost", "127.0.0.1", "0.0.0.0"}

Review Comment:
   Not something that needs addresing now, but if we start having more of these, usually a `constants.py` can be a nice way to centralize these.



##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +77,35 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.

Review Comment:
   Vanilla Superset doesn't have a concept of multitenancy. Also, let's generalize this.
   ```suggestion
       In production, the MCP service is typically accessed via the main
       Superset URL with /mcp prefix. In development,
       it's accessed directly on port 5008.
   ```



##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +77,35 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
+        if user_friendly_url and not _is_local_url(user_friendly_url):
+            # Production/staging - use main URL with /mcp prefix
+            base_url = user_friendly_url.rstrip("/")
+            return f"{base_url}/mcp"

Review Comment:
   We may want to also support use cases where the MCP service is hosted on some other path/subdomain. So maybe we would want make it possible to specify the exact URL on which the MCP service is hosted? A typical use case that comes to mind is
   - Superset deployment: https://mysuperset.com
   - MCP service: https://mcp.mysuperset.com
   
   Not sure if this is going to be a typical pattern, but at any rate, it's always better to be more generic if possible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro merged PR #36460:
URL: https://github.com/apache/superset/pull/36460


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3628839289

   CodeAnt AI is reviewing your PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600334757


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +63,37 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config.get("WEBDRIVER_BASEURL_USER_FRIENDLY")

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600003927


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +63,34 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # SUPERSET_WEBSERVER_ADDRESS is dynamically set per workspace
+        webserver_address = config.get("SUPERSET_WEBSERVER_ADDRESS")

Review Comment:
   we could use WEBDRIVER_BASEURL_USER_FRIENDLY directly. what do people think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3629605040

   the fails seem flaky? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3630080444

   > the fails seem flaky?
   
   @aminghadersohi yeah that particular cypress test is notoriously flaky. I restarted the failed test, will keep restarting it if it flakes out again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600248431


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +63,37 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config.get("WEBDRIVER_BASEURL_USER_FRIENDLY")

Review Comment:
   We should add `WEBDRIVER_BASEURL_USER_FRIENDLY: str | None = None` to `config.py` and then assume it's always defined:
   ```suggestion
           user_friendly_url = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600008363


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +63,34 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # SUPERSET_WEBSERVER_ADDRESS is dynamically set per workspace
+        webserver_address = config.get("SUPERSET_WEBSERVER_ADDRESS")
+        if webserver_address and webserver_address != "http://localhost:9001":
+            # Production/staging - use main URL with /mcp prefix

Review Comment:
   **Suggestion:** URL concatenation bug: appending "/mcp" directly to `SUPERSET_WEBSERVER_ADDRESS` can produce a double slash or malformed URL if the configured address ends with a trailing slash; normalize by stripping trailing slashes before concatenation. [possible bug]
   
   **Severity Level:** Critical 🚨
   ```suggestion
               webserver_address = webserver_address.rstrip('/')
   ```
   <details>
   <summary><b>Why it matters? ⭐ </b></summary>
   
   Appending "/mcp" to a webserver_address that ends with a slash will produce "//mcp" which is ugly and potentially problematic. Stripping trailing slashes before concatenation is a minimal, correct fix that avoids malformed URLs without changing behavior otherwise.
   </details>
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/utils/url_utils.py
   **Line:** 85:85
   **Comment:**
   	*Possible Bug: URL concatenation bug: appending "/mcp" directly to `SUPERSET_WEBSERVER_ADDRESS` can produce a double slash or malformed URL if the configured address ends with a trailing slash; normalize by stripping trailing slashes before concatenation.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   ```
   </details>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3628839538

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3628848941

   CodeAnt AI finished reviewing your PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3628846982

   ## Nitpicks πŸ”
   
   <table>
   <tr><td>πŸ”’&nbsp;<strong>No security issues identified</strong></td></tr>
   <tr><td>⚑&nbsp;<strong>Recommended areas for review</strong><br><br>
   
   - [ ] <a href='https://github.com/apache/superset/pull/36460/files#diff-3abb30283385f77f2e6ca4665cf0965d4aa676754ec2a9a6318e7ca4134bde7fR76-R86'><strong>Missing scheme normalization</strong></a><br>The code assumes `SUPERSET_WEBSERVER_ADDRESS` already contains a scheme (http/https). If the value is e.g. "example.com" or "example.com:8088" the returned URL will be invalid (missing scheme). Normalize/validate and add a default scheme when absent.<br>
   
   - [ ] <a href='https://github.com/apache/superset/pull/36460/files#diff-3abb30283385f77f2e6ca4665cf0965d4aa676754ec2a9a6318e7ca4134bde7fR81-R86'><strong>Fragile localhost check</strong></a><br>The code compares `webserver_address` to the literal "http://localhost:9001" to detect local development. This is brittle: addresses like "localhost:9001", "http://127.0.0.1:9001", or addresses with/without trailing slashes won't be caught. Use hostname-based detection or reuse the superset base URL helper to determine if it's a local dev instance.<br>
   
   - [ ] <a href='https://github.com/apache/superset/pull/36460/files#diff-3abb30283385f77f2e6ca4665cf0965d4aa676754ec2a9a6318e7ca4134bde7fR83-R86'><strong>Path concatenation / trailing slash</strong></a><br>Appending "/mcp" with f"{webserver_address}/mcp" can lead to double slashes if `webserver_address` ends with a slash, or a malformed URL if scheme is missing. Use `urllib.parse.urljoin` or normalize/strip trailing slashes before joining.<br>
   
   </td></tr>
   </table>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #36460:
URL: https://github.com/apache/superset/pull/36460#issuecomment-3628931720

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/36460?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `5 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 48.10%. Comparing base ([`8d04c33`](https://app.codecov.io/gh/apache/superset/commit/8d04c33adfaa9e8f5513e84278dff767df64fb87?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`6d6baf4`](https://app.codecov.io/gh/apache/superset/commit/6d6baf440dcb6b4966d91d5f45b1272af1e3ccd4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/36460?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/mcp\_service/utils/url\_utils.py](https://app.codecov.io/gh/apache/superset/pull/36460?src=pr&el=tree&filepath=superset%2Fmcp_service%2Futils%2Furl_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvdXRpbHMvdXJsX3V0aWxzLnB5) | 0.00% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/36460?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #36460       +/-   ##
   ===========================================
   + Coverage        0   48.10%   +48.10%     
   ===========================================
     Files           0      635      +635     
     Lines           0    46824    +46824     
     Branches        0     5083     +5083     
   ===========================================
   + Hits            0    22527    +22527     
   - Misses          0    23644    +23644     
   - Partials        0      653      +653     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/36460/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/36460/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `43.71% <0.00%> (?)` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/36460/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `47.36% <0.00%> (?)` | |
   | [python](https://app.codecov.io/gh/apache/superset/pull/36460/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `48.10% <0.00%> (?)` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/36460/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ΓΈ> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/36460?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600003927


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +63,34 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # SUPERSET_WEBSERVER_ADDRESS is dynamically set per workspace
+        webserver_address = config.get("SUPERSET_WEBSERVER_ADDRESS")

Review Comment:
   we could use WEBDRIVER_BASEURL_USER_FRIENDLY directly. what do people think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): Use config-based URL for MCP service instead of request auto-detection [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #36460:
URL: https://github.com/apache/superset/pull/36460#discussion_r2600524703


##########
superset/mcp_service/utils/url_utils.py:
##########
@@ -63,40 +77,35 @@ def get_mcp_service_url() -> str:
     """
     Get the MCP service base URL where screenshot endpoints are served.
 
-    The MCP service auto-detects its own host and port since it's running
-    this code. Falls back to explicit configuration or default port.
+    In production (multi-tenant), the MCP service is accessed via the main
+    Superset URL with /mcp prefix (routed by api-gateway). In development,
+    it's accessed directly on port 5008.
 
     Returns:
-        Base URL for MCP service (always independent of Superset URL)
+        Base URL for MCP service endpoints
     """
     try:
-        # Try to auto-detect from Flask request context
-        from flask import request
-
-        if request:
-            # Get the host and port from the current request
-            scheme = request.scheme  # http or https
-            host = request.host  # includes port if non-standard
-            return f"{scheme}://{host}"
-
-    except (RuntimeError, AttributeError):
-        # Not in request context or Flask not available
-        pass
-
-    try:
-        # Check for explicit MCP_SERVICE_URL in config
         config = current_app.config
+
+        # Check for explicit MCP_SERVICE_URL first (allows override)
         mcp_service_url = config.get("MCP_SERVICE_URL")
         if mcp_service_url:
             return mcp_service_url
 
+        # In production, MCP service is accessed via main URL with /mcp prefix
+        # WEBDRIVER_BASEURL_USER_FRIENDLY is the user-facing URL for the instance
+        user_friendly_url = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
+        if user_friendly_url and not _is_local_url(user_friendly_url):
+            # Production/staging - use main URL with /mcp prefix
+            base_url = user_friendly_url.rstrip("/")
+            return f"{base_url}/mcp"

Review Comment:
   This is already supported via the `MCP_SERVICE_URL` config, which takes precedence over the auto-detection. Users can set `MCP_SERVICE_URL = "https://mcp.mysuperset.com"` for custom subdomain deployments.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org