aminghadersohi opened a new pull request, #36035:
URL: https://github.com/apache/superset/pull/36035
### SUMMARY
This PR implements selective column serialization for MCP service list tools
(charts, dashboards, datasets). Previously, when users specified
`select_columns` to limit which fields to return, the API would return all
fields with `null` values for unselected columns. This was confusing and
wasteful.
**Problem:**
- List tools accepted `select_columns` parameter but ignored it during
serialization
- All fields were always returned, with `null` for columns not queried from
database
- Impossible to distinguish "field is null" from "field was not selected"
- Wasted bandwidth sending unnecessary nulls
**Solution:**
- Updated serializers for charts, dashboards, and datasets to use Pydantic's
`model_dump(exclude=...)`
- Only requested columns (plus `id` which is always included) are present in
response
- Unselected fields are completely excluded from JSON response
- Cleaner API responses for LLM agents and API consumers
**Implementation Details:**
- Chart serializer: `list_charts.py` - Added `_serialize_chart()` with
column filtering
- Dashboard serializer: `list_dashboards.py` - Added
`_serialize_dashboard()` with column filtering
- Dataset serializer: `list_datasets.py` - Added `_serialize_dataset()` with
column filtering
- All serializers follow same pattern: build full model, then exclude
unselected fields
- Primary key (`id`) is always included regardless of selection
**Example:**
Before (requesting only `id` and `slice_name`):
```json
{
"id": 123,
"slice_name": "Sales Chart",
"viz_type": null,
"datasource_name": null,
"url": null,
"description": null,
"cache_timeout": null,
"changed_by": null,
"changed_on": null,
"uuid": null,
"tags": null,
"owners": null
}
```
After (requesting only `id` and `slice_name`):
```json
{
"id": 123,
"slice_name": "Sales Chart"
}
```
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend API behavior change only, no UI changes
### TESTING INSTRUCTIONS
**Prerequisites:**
- Superset instance with MCP service configured
- Test data (charts, dashboards, datasets)
**Test 1: Chart listing with column selection**
```bash
# Using MCP client or direct API call
# Request only specific columns
curl -X POST http://localhost:5008/list_charts \
-H "Content-Type: application/json" \
-d '{
"page": 1,
"page_size": 5,
"select_columns": ["id", "slice_name", "viz_type"]
}'
# Verify response only contains: id, slice_name, viz_type
# Verify no null fields for unselected columns
```
**Test 2: Dashboard listing with column selection**
```bash
curl -X POST http://localhost:5008/list_dashboards \
-H "Content-Type: application/json" \
-d '{
"page": 1,
"page_size": 5,
"select_columns": ["id", "dashboard_title"]
}'
# Verify response only contains: id, dashboard_title
```
**Test 3: Dataset listing with column selection**
```bash
curl -X POST http://localhost:5008/list_datasets \
-H "Content-Type: application/json" \
-d '{
"page": 1,
"page_size": 5,
"select_columns": ["id", "table_name", "schema"]
}'
# Verify response only contains: id, table_name, schema
```
**Test 4: Default behavior (no select_columns specified)**
```bash
curl -X POST http://localhost:5008/list_charts \
-H "Content-Type: application/json" \
-d '{"page": 1, "page_size": 5}'
# Verify response contains all default columns as before
```
**Expected Results:**
- ✅ Only requested columns appear in response
- ✅ ID always included even if not requested
- ✅ No null fields for unselected columns
- ✅ Response size smaller when fewer columns selected
- ✅ Default behavior unchanged when select_columns not provided
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI: No
- [ ] Includes DB Migration: No
- [x] Introduces new feature or API: Yes (enhances existing list tools)
- [ ] Removes existing feature or API: No
--
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]