You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ms...@apache.org on 2026/05/20 09:04:08 UTC

(superset) 01/01: fix(mcp): use `name` URL param so AI-generated SQL Lab titles render

This is an automated email from the ASF dual-hosted git repository.

msyavuz pushed a commit to branch msyavuz/feat/sqllab-mcp-tab-title
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b1b21be0408135f8be6a4284d6eec6205df0b1c4
Author: Mehmet Salih Yavuz <sa...@proton.me>
AuthorDate: Wed May 20 12:03:50 2026 +0300

    fix(mcp): use `name` URL param so AI-generated SQL Lab titles render
    
    `open_sql_lab_with_context` emitted `?title=...`, but SQL Lab's
    `PopEditorTab` only reads `?name=...` (the QueryEditor.name field), so
    the LLM-provided title was silently dropped and the tab opened with no
    label. Keep the MCP-facing field as `title` (natural for LLMs) but emit
    `name` on the URL, and sharpen the field description so the model
    actually generates a descriptive label from conversation context.
---
 superset/mcp_service/sql_lab/schemas.py                       | 11 ++++++++++-
 .../mcp_service/sql_lab/tool/open_sql_lab_with_context.py     |  7 +++++--
 .../sql_lab/tool/test_open_sql_lab_with_context.py            | 11 ++++++-----
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/superset/mcp_service/sql_lab/schemas.py b/superset/mcp_service/sql_lab/schemas.py
index 729413a9d53..5dfe6fa283e 100644
--- a/superset/mcp_service/sql_lab/schemas.py
+++ b/superset/mcp_service/sql_lab/schemas.py
@@ -285,7 +285,16 @@ class OpenSqlLabRequest(BaseModel):
         description="SQL to pre-populate in the editor",
         validation_alias=AliasChoices("sql", "query"),
     )
-    title: str | None = Field(None, description="Title for the SQL Lab tab/query")
+    title: str | None = Field(
+        None,
+        description=(
+            "Title for the SQL Lab tab. Generate a succinct, descriptive label "
+            "(roughly 3-6 words) from the conversation context or the query "
+            "intent — e.g. 'Top customers by revenue Q3' — instead of leaving "
+            "the tab untitled. Avoid generic names like 'Untitled Query'."
+        ),
+        max_length=256,
+    )
 
 
 class SqlLabResponse(_SchemaFieldNormalizer):
diff --git a/superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py b/superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py
index 17485b67da3..e5bbf68b550 100644
--- a/superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py
+++ b/superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py
@@ -37,7 +37,7 @@ from superset.mcp_service.utils.url_utils import get_superset_base_url
 
 logger = logging.getLogger(__name__)
 
-SQL_LAB_QUERY_PARAMS_TO_SANITIZE = frozenset({"sql", "title"})
+SQL_LAB_QUERY_PARAMS_TO_SANITIZE = frozenset({"sql", "name"})
 
 
 def _sanitize_sql_lab_url_for_llm_context(url: str) -> str:
@@ -128,7 +128,10 @@ def open_sql_lab_with_context(
             params["sql"] = request.sql
 
         if request.title:
-            params["title"] = request.title
+            # SQL Lab's PopEditorTab reads `name` from query string to set the
+            # tab label; keep the MCP-facing field as `title` (more natural for
+            # LLMs) but emit `name` on the URL.
+            params["name"] = request.title
 
         if request.dataset_in_context:
             # Add dataset context as a comment in the SQL if no SQL provided
diff --git a/tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py b/tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
index fd67fd2bff2..e72a19604b5 100644
--- a/tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
+++ b/tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
@@ -143,9 +143,10 @@ class TestOpenSqlLabWithContext:
             assert parsed.path == "/sqllab"
             assert params["dbid"] == ["7"]
             assert params["schema"] == ["analytics"]
-            assert params["title"] == [
-                sanitize_for_llm_context("Review this query", field_path=("title",))
+            assert params["name"] == [
+                sanitize_for_llm_context("Review this query", field_path=("name",))
             ]
+            assert "title" not in params
             assert params["sql"] == [
                 sanitize_for_llm_context(
                     "SELECT * FROM users LIMIT 10",
@@ -243,7 +244,7 @@ class TestOpenSqlLabWithContext:
         try:
             url = (
                 "https://superset.example.com/sqllab?"
-                "dbid=7&schema=analytics&sql=SELECT+1&title=Inspect+query"
+                "dbid=7&schema=analytics&sql=SELECT+1&name=Inspect+query"
             )
 
             response = mod._sanitize_sql_lab_response_for_llm_context(
@@ -261,8 +262,8 @@ class TestOpenSqlLabWithContext:
             assert params["sql"] == [
                 sanitize_for_llm_context("SELECT 1", field_path=("sql",))
             ]
-            assert params["title"] == [
-                sanitize_for_llm_context("Inspect query", field_path=("title",))
+            assert params["name"] == [
+                sanitize_for_llm_context("Inspect query", field_path=("name",))
             ]
             assert response.title == sanitize_for_llm_context(
                 "Inspect query",