Skip to main content
Glama
suthio

Redash MCP Server

by suthio

execute_query

Execute a Redash query by providing its ID and optional parameters to retrieve results.

Instructions

Execute a Redash query and return results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryIdYesID of the query to execute
parametersNoParameters to pass to the query (if any)

Implementation Reference

  • The MCP tool handler function for 'execute_query'. Validates params via executeQuerySchema, calls redashClient.executeQuery(), and returns the result as JSON text.
    async function executeQuery(params: z.infer<typeof executeQuerySchema>) {
      try {
        const { queryId, parameters } = params;
        const result = await redashClient.executeQuery(queryId, parameters);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      } catch (error) {
        console.error(`Error executing query ${params.queryId}:`, error);
        return {
          isError: true,
          content: [
            {
              type: "text",
              text: `Error executing query ${params.queryId}: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        };
      }
    }
  • Input schema (Zod) for the execute_query tool, defining queryId (number) and optional parameters (record of any).
    const executeQuerySchema = z.object({
      queryId: z.coerce.number(),
      parameters: z.record(z.any()).optional()
    });
  • src/index.ts:1684-1699 (registration)
    Registration of the 'execute_query' tool in the MCP ListTools handler, including its name, description, and JSON Schema input definition.
    {
      name: "execute_query",
      description: "Execute a Redash query and return results",
      inputSchema: {
        type: "object",
        properties: {
          queryId: { type: "number", description: "ID of the query to execute" },
          parameters: {
            type: "object",
            description: "Parameters to pass to the query (if any)",
            additionalProperties: true
          }
        },
        required: ["queryId"]
      }
    },
  • src/index.ts:2356-2358 (registration)
    Dispatch in CallToolRequestSchema switch statement routing the 'execute_query' tool name to the executeQuery handler function.
    case "execute_query":
      logger.debug(`Handling execute_query`);
      return await executeQuery(executeQuerySchema.parse(args));
  • The underlying Redash API client method executeQuery() that sends a POST request to /api/queries/{queryId}/results, optionally polls async job results, and returns a RedashQueryResult.
    // Execute a query and return results
    async executeQuery(queryId: number, parameters?: Record<string, any>): Promise<RedashQueryResult> {
      try {
        const response = await this.client.post(`/api/queries/${queryId}/results`, { parameters });
    
        if (response.data.job) {
          // Query is being executed asynchronously, poll for results
          return await this.pollQueryResults(response.data.job.id);
        }
    
        return response.data;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          const axiosError = error as AxiosError;
          logger.error(`Error executing query ${queryId}: ${axiosError.message}`);
    
          // Extract detailed error information
          if (axiosError.response) {
            const statusCode = axiosError.response.status;
            const errorData = axiosError.response.data as any;
            const errorMessage = errorData?.message || errorData?.error || JSON.stringify(errorData);
            throw new Error(`Failed to execute query ${queryId}: Redash API error (${statusCode}): ${errorMessage}`);
          } else if (axiosError.request) {
            throw new Error(`Failed to execute query ${queryId}: No response received from Redash API: ${axiosError.message}`);
          } else {
            throw new Error(`Failed to execute query ${queryId}: ${axiosError.message}`);
          }
        } else {
          // Handle non-axios errors
          const errorMessage = error instanceof Error ? error.message : String(error);
          logger.error(`Error executing query ${queryId}: ${errorMessage}`);
          throw new Error(`Failed to execute query ${queryId}: ${errorMessage}`);
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states 'return results' without disclosing side effects, rate limits, or whether execution modifies state. This is minimal disclosure for a potential mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that is front-loaded with the action. No unnecessary words, though it could be slightly expanded with key constraints.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description lacks information about how parameters work, the requirement that the query be a saved query, or error handling. Given the presence of sibling tools and no output schema, it is minimally complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline is 3. The description adds no additional meaning beyond what the schema already provides for 'queryId' and 'parameters'.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute a Redash query and return results' uses a specific verb and resource, clearly distinguishing it from siblings like 'execute_adhoc_query' which targets ad-hoc queries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'execute_adhoc_query', nor does it specify any prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/suthio/redash-mcp'

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