Skip to main content
Glama
aptro

Superset MCP Integration

by aptro

superset_sqllab_execute_query

Execute SQL queries against databases in Apache Superset to retrieve data or run analysis through the SQL Lab interface.

Instructions

Execute a SQL query in SQL Lab

Makes a request to the /api/v1/sqllab/execute/ endpoint to run a SQL query against the specified database.

Args: database_id: ID of the database to query sql: SQL query to execute

Returns: A dictionary with query results or execution status for async queries

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYes
sqlYes

Implementation Reference

  • The handler function for the 'superset_sqllab_execute_query' tool. It is registered via @mcp.tool() decorator and implements the logic to execute a SQL query against a Superset database by making a POST request to the /api/v1/sqllab/execute/ endpoint. Includes decorators for authentication (@requires_auth) and error handling (@handle_api_errors).
    @mcp.tool()
    @requires_auth
    @handle_api_errors
    async def superset_sqllab_execute_query(
        ctx: Context, database_id: int, sql: str
    ) -> Dict[str, Any]:
        """
        Execute a SQL query in SQL Lab
    
        Makes a request to the /api/v1/sqllab/execute/ endpoint to run a SQL query
        against the specified database.
    
        Args:
            database_id: ID of the database to query
            sql: SQL query to execute
    
        Returns:
            A dictionary with query results or execution status for async queries
        """
        # Ensure we have a CSRF token before executing the query
        superset_ctx: SupersetContext = ctx.request_context.lifespan_context
        if not superset_ctx.csrf_token:
            await get_csrf_token(ctx)
    
        payload = {
            "database_id": database_id,
            "sql": sql,
            "schema": "",
            "tab": "MCP Query",
            "runAsync": False,
            "select_as_cta": False,
        }
    
        return await make_api_request(ctx, "post", "/api/v1/sqllab/execute/", data=payload)
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aptro/superset-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server