aminghadersohi commented on code in PR #36458:
URL: https://github.com/apache/superset/pull/36458#discussion_r2665407749


##########
superset/mcp_service/common/schema_discovery.py:
##########
@@ -0,0 +1,300 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Schema discovery models for MCP tools.
+
+These schemas provide comprehensive metadata about available columns,
+filters, and sorting options for each model type (chart, dataset, dashboard).
+This enables LLM clients to discover valid parameters without guessing.
+"""
+
+from typing import Dict, List, Literal
+
+from pydantic import BaseModel, Field
+
+
+class ColumnMetadata(BaseModel):
+    """Metadata for a selectable column."""
+
+    name: str = Field(..., description="Column name to use in select_columns")
+    description: str | None = Field(None, description="Column description")
+    type: str | None = Field(None, description="Data type (str, int, datetime, 
etc.)")
+    is_default: bool = Field(
+        False, description="Whether this column is included by default"
+    )
+
+
+class ModelSchemaInfo(BaseModel):
+    """
+    Comprehensive schema information for a model type.
+
+    Provides all metadata needed for LLM clients to construct valid queries:
+    - Which columns can be selected
+    - Which columns can be used for filtering (with operators)
+    - Which columns can be used for sorting
+    - Default values for each
+    """
+
+    model_type: Literal["chart", "dataset", "dashboard"] = Field(
+        ..., description="The model type this schema describes"
+    )
+    select_columns: List[ColumnMetadata] = Field(
+        ..., description="All columns available for selection via 
select_columns"
+    )
+    filter_columns: Dict[str, List[str]] = Field(
+        ..., description="Filterable columns mapped to their supported 
operators"
+    )
+    sortable_columns: List[str] = Field(
+        ..., description="Columns that can be used with order_column"
+    )
+    default_select: List[str] = Field(
+        ..., description="Columns returned when select_columns is not 
specified"
+    )
+    default_sort: str = Field(
+        ..., description="Default column used for sorting when order_column is 
not set"
+    )
+    default_sort_direction: Literal["asc", "desc"] = Field(
+        "desc", description="Default sort direction"
+    )
+    search_columns: List[str] = Field(
+        default_factory=list,
+        description="Columns searched when using the search parameter",
+    )
+
+
+class GetSchemaRequest(BaseModel):
+    """Request schema for unified get_schema tool."""
+
+    model_type: Literal["chart", "dataset", "dashboard"] = Field(
+        ..., description="Model type to get schema for"
+    )
+
+
+class GetSchemaResponse(BaseModel):
+    """Response for unified get_schema tool."""
+
+    schema_info: ModelSchemaInfo = Field(
+        ..., description="Comprehensive schema information"
+    )
+
+
+# Column definitions for each model type
+# These are the source of truth for available columns
+
+CHART_SELECT_COLUMNS: List[ColumnMetadata] = [

Review Comment:
   good point. let me do that and see what happens



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to