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
| Name | Required | Description | Default |
|---|---|---|---|
| database_id | Yes | ||
| sql | Yes |
Implementation Reference
- main.py:1168-1202 (handler)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)