Repository: apache/superset
File: superset/mcp_service/dashboard/tool/get_dashboard_info.py (Python)

Code before:
from superset_core.mcp import tool

from superset.mcp_service.dashboard.schemas import (
    dashboard_serializer,
    DashboardError,
    DashboardInfo,
    GetDashboardInfoRequest,
)
from superset.mcp_service.mcp_core import ModelGetInfoCore
from superset.mcp_service.utils.schema_utils import parse_request

logger = logging.getLogger(__name__)


def _get_permalink_state(permalink_key: str) -> Dict[str, Any] | None:
    """Retrieve dashboard filter state from permalink.

    Returns the permalink value containing dashboardId and state if found,
    None otherwise.
    """
    from superset.commands.dashboard.permalink.get import GetDashboardPermalinkCommand

    try:
        result = GetDashboardPermalinkCommand(permalink_key).run()
        # Convert TypedDict to regular dict for type compatibility
        return dict(result) if result else None
    except Exception as e:
        logger.warning("Failed to retrieve permalink state: %s", e)
        return None


@tool(tags=["discovery"])
@parse_request(GetDashboardInfoRequest)
async def get_dashboard_info(
    request: GetDashboardInfoRequest, ctx: Context
) -> DashboardInfo | DashboardError:
    """
    Get dashboard metadata by ID, UUID, or slug.

    Returns title, charts, and layout details.

    When permalink_key is provided, also returns the filter state from that
    permalink, allowing you to see what filters the user has applied to the
    dashboard (not just the default filter state).

    Example usage:
    ```json
    {
        "identifier": 123
    }
    ```

Review comment (suggestion):
`result` is already a dict, all you're doing here is losing type information.

It's better to make:

```python
def _get_permalink_state(permalink_key: str) -> DashboardPermalinkValue | None:
```

And fix whatever is calling `_get_permalink_state()`.

Code after:

from superset.dashboards.permalink.exceptions import DashboardPermalinkGetFailedError
from superset.dashboards.permalink.types import DashboardPermalinkValue
from superset.extensions import event_logger
from superset.mcp_service.dashboard.schemas import (
    dashboard_serializer,
    DashboardError,
    DashboardInfo,
    GetDashboardInfoRequest,
)
from superset.mcp_service.mcp_core import ModelGetInfoCore
from superset.mcp_service.utils.schema_utils import parse_request

logger = logging.getLogger(__name__)


def _get_permalink_state(permalink_key: str) -> DashboardPermalinkValue | None:
    """Retrieve dashboard filter state from permalink.

    Returns the permalink value containing dashboardId and state if found,
    None otherwise.
    """
    from superset.commands.dashboard.permalink.get import GetDashboardPermalinkCommand

    try:
        return GetDashboardPermalinkCommand(permalink_key).run()
    except DashboardPermalinkGetFailedError as e:
        logger.warning("Failed to retrieve permalink state: %s", e)
        return None


@tool(tags=["discovery"])
@parse_request(GetDashboardInfoRequest)
async def get_dashboard_info(
    request: GetDashboardInfoRequest, ctx: Context
) -> DashboardInfo | DashboardError:
    """
    Get dashboard metadata by ID, UUID, or slug.

    Returns title, charts, and layout details.

    When permalink_key is provided, also returns the filter state from that
    permalink, allowing you to see what filters the user has applied to the
    dashboard (not just the default filter state).

    Example usage:
    ```json
    {
        "identifier": 123
    }
    ```