Repository: apache/superset
File: superset/mcp_service/app.py (Python)

Code before:
from typing import Any, Callable, Dict, List, Sequence, Set

from fastmcp import FastMCP
from fastmcp.server.middleware import Middleware

logger = logging.getLogger(__name__)


def get_default_instructions(
    branding: str = "Apache Superset",
    unavailable_features: list[str] | None = None,
) -> str:
    """Get default instructions with configurable branding.

    Args:
        branding: Product name to use in instructions
            (e.g., "ACME Analytics", "Apache Superset")
        unavailable_features: List of features not available in this deployment
            that LLMs should not suggest to users.

    Returns:
        Formatted instructions string with branding applied
    """
    unavailable_section = ""
    if unavailable_features:
        features_list = "\n".join(f"- {f}" for f in unavailable_features)
        unavailable_section = f"""

IMPORTANT - Unavailable Features:
The following features are NOT available in this deployment. Do NOT suggest
or reference them when helping users, even if they exist in other deployments:
{features_list}

If a user asks about functionality related to these features, let them know
it is not available and suggest alternatives using the MCP tools listed above.
"""

    return f"""
You are connected to the {branding} MCP (Model Context Protocol) service.
This service provides programmatic access to {branding} dashboards, charts, datasets,
SQL Lab, and instance metadata via a comprehensive set of tools.

Available tools:

Dashboard Management:
- list_dashboards: List dashboards with advanced filters (1-based pagination)
- get_dashboard_info: Get detailed dashboard information by ID
- generate_dashboard: Create a dashboard from chart IDs
- add_chart_to_existing_dashboard: Add a chart to an existing dashboard

Dataset Management:

Review comment (suggestion):
Is there a standard and automatic way to know what these features are (all) by default? should we have a list somewhere so we can easy to grab the name to use? Asking because it's a string, we can pass anything (not tied to a tool name etc so very wide)

Code after:
from typing import Any, Callable, Dict, List, Sequence, Set

from fastmcp import FastMCP
from fastmcp.server.middleware import Middleware

logger = logging.getLogger(__name__)


def get_default_instructions(branding: str = "Apache Superset") -> str:
    """Get default instructions with configurable branding.

    Args:
        branding: Product name to use in instructions
            (e.g., "ACME Analytics", "Apache Superset")

    Returns:
        Formatted instructions string with branding applied
    """
    return f"""
You are connected to the {branding} MCP (Model Context Protocol) service.
This service provides programmatic access to {branding} dashboards, charts, datasets,
SQL Lab, and instance metadata via a comprehensive set of tools.

Available tools:

Dashboard Management:
- list_dashboards: List dashboards with advanced filters (1-based pagination)
- get_dashboard_info: Get detailed dashboard information by ID
- generate_dashboard: Create a dashboard from chart IDs
- add_chart_to_existing_dashboard: Add a chart to an existing dashboard

Dataset Management:
- list_datasets: List datasets with advanced filters (1-based pagination)
- get_dataset_info: Get detailed dataset information by ID (includes columns/metrics)

Chart Management:
- list_charts: List charts with advanced filters (1-based pagination)
- get_chart_info: Get detailed chart information by ID
- get_chart_preview: Get a visual preview of a chart with image URL
- get_chart_data: Get underlying chart data in text-friendly format
- generate_chart: Create and save a new chart permanently
- generate_explore_link: Create an interactive explore URL (preferred for exploration)
- update_chart: Update existing saved chart configuration
- update_chart_preview: Update cached chart preview without saving

SQL Lab Integration:
- execute_sql: Execute SQL queries and get results (requires database_id)
- open_sql_lab_with_context: Generate SQL Lab URL with pre-filled query

Schema Discovery:
- get_schema: Get schema metadata for chart/dataset/dashboard (columns, filters)