Skip to content

execute_adhoc_query fails on MSSQL data sources due to hardcoded apply_auto_limit: true #58

@sibest19

Description

@sibest19

Problem

executeAdhocQuery in redashClient.ts hardcodes apply_auto_limit: true in the request payload:

// redashClient.ts, line ~530
const payload = {
  query: query,
  data_source_id: dataSourceId,
  max_age: 0,
  apply_auto_limit: true,  // Apply auto limit like in the web version
  parameters: {}
};

When the target data source is MSSQL (type: "mssql" or "mssql_odbc"), Redash appends LIMIT 1000 to the query — which is valid PostgreSQL/MySQL syntax but invalid T-SQL. Every ad-hoc query against an MSSQL source fails with:

Incorrect syntax near 'LIMIT'.

This makes execute_adhoc_query completely unusable against MSSQL data sources (e.g. data source IDs with supports_auto_limit: true and type mssql/mssql_odbc).

Workaround

The current workaround is to use create_query + execute_query instead, which bypasses auto-limit injection for saved queries.

Proposed Fix

Expose apply_auto_limit as an optional parameter on executeAdhocQuery, keeping the default true for backwards compatibility:

async executeAdhocQuery(
  query: string,
  dataSourceId: number,
  applyAutoLimit = true   // default preserved for backwards compatibility
): Promise<RedashQueryResult> {
  const payload = {
    query,
    data_source_id: dataSourceId,
    max_age: 0,
    apply_auto_limit: applyAutoLimit,
    parameters: {}
  };
  // ...
}

And expose it as an optional boolean input in the MCP tool definition (default true). Callers targeting MSSQL data sources can then pass apply_auto_limit: false to avoid the broken LIMIT injection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions