Skip to main content
Glama
lishenxydlgzs

aws-athena-mcp

run_query

Execute SQL queries on AWS Athena to analyze data from AWS Glue catalog. Returns query results or execution ID for monitoring.

Instructions

Execute a SQL query using AWS Athena. Returns full results if query completes before timeout, otherwise returns queryExecutionId.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesThe Athena database to query
queryYesSQL query to execute
maxRowsNoMaximum number of rows to return (default: 1000)
timeoutMsNoTimeout in milliseconds (default: 60000)

Implementation Reference

  • src/index.ts:44-72 (registration)
    Registration of the 'run_query' tool in the MCP ListTools response, including name, description, and input schema.
    {
      name: "run_query",
      description: "Execute a SQL query using AWS Athena. Returns full results if query completes before timeout, otherwise returns queryExecutionId.",
      inputSchema: {
        type: "object",
        properties: {
          database: {
            type: "string",
            description: "The Athena database to query",
          },
          query: {
            type: "string",
            description: "SQL query to execute",
          },
          maxRows: {
            type: "number",
            description: "Maximum number of rows to return (default: 1000)",
            minimum: 1,
            maximum: 10000,
          },
          timeoutMs: {
            type: "number",
            description: "Timeout in milliseconds (default: 60000)",
            minimum: 1000,
          },
        },
        required: ["database", "query"],
      },
    },
  • MCP CallToolRequest handler case for 'run_query': validates arguments, prepares QueryInput, invokes AthenaService.executeQuery, and returns JSON-formatted result.
    case "run_query": {
      if (!request.params.arguments ||
          typeof request.params.arguments.database !== 'string' ||
          typeof request.params.arguments.query !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Missing or invalid required parameters: database (string) and query (string)"
        );
      }
    
      const queryInput: QueryInput = {
        database: request.params.arguments.database,
        query: request.params.arguments.query,
        maxRows: typeof request.params.arguments.maxRows === 'number' ?
          request.params.arguments.maxRows : undefined,
        timeoutMs: typeof request.params.arguments.timeoutMs === 'number' ?
          request.params.arguments.timeoutMs : undefined,
      };
      const result = await this.athenaService.executeQuery(queryInput);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Core execution logic for run_query: starts Athena query, waits/polls for completion with configurable timeout, fetches results if complete or returns queryExecutionId on timeout.
    async executeQuery(input: QueryInput): Promise<QueryResult | { queryExecutionId: string }> {
      try {
        // Start query execution
        const startResponse = await this.client.send(
          new StartQueryExecutionCommand({
            QueryString: input.query,
            QueryExecutionContext: {
              Database: input.database,
            },
            ResultConfiguration: {
              OutputLocation: this.outputLocation,
            },
            ...(this.workGroup && { WorkGroup: this.workGroup })
          })
        );
    
        if (!startResponse.QueryExecutionId) {
          throw new Error("Failed to start query execution");
        }
    
        const timeoutMs = input.timeoutMs || 60000; // Default 60 second timeout
        const startTime = Date.now();
    
        try {
          // Wait for query completion or timeout
          const queryExecution = await this.waitForQueryCompletion(
            startResponse.QueryExecutionId,
            100,
            timeoutMs
          );
    
          // If we got here, query completed before timeout
          return await this.getQueryResults(startResponse.QueryExecutionId, input.maxRows);
        } catch (error) {
          if (error && typeof error === "object" && "code" in error) {
            const athenaError = error as AthenaError;
            if (athenaError.code === "TIMEOUT") {
              // Return just the execution ID on timeout
              return { queryExecutionId: startResponse.QueryExecutionId };
            }
          }
          throw error;
        }
      } catch (error) {
        if (error instanceof InvalidRequestException) {
          throw {
            message: error.message,
            code: "INVALID_REQUEST",
          };
        }
        throw error;
      }
    }
  • TypeScript interface QueryInput used for input validation and typing in the run_query tool.
    export interface QueryInput {
      database: string;
      query: string;
      maxRows?: number;
      timeoutMs?: number;
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it executes queries, returns full results if completed before timeout, otherwise returns a queryExecutionId. However, it lacks details on permissions, error handling, rate limits, or what 'full results' entails (e.g., format, pagination).

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

Conciseness5/5

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

The description is two sentences, front-loaded with the core purpose and followed by critical behavioral detail. Every word earns its place with no redundancy or fluff, making it highly efficient and well-structured.

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?

Given no annotations, no output schema, and 4 parameters, the description is moderately complete. It covers the core action and timeout behavior but misses details like result format, error cases, or integration with sibling tools (e.g., how queryExecutionId relates to get_result). For a query execution tool, more context would be helpful.

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 the schema fully documents all parameters. The description does not add meaning beyond what the schema provides (e.g., it doesn't explain parameter interactions or usage nuances). Baseline 3 is appropriate as the schema handles parameter documentation.

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 clearly states the specific action ('Execute a SQL query using AWS Athena') and the resource ('Athena'), distinguishing it from siblings like get_result (which retrieves results), get_status (checks status), list_saved_queries (lists saved queries), and run_saved_query (runs saved queries). It precisely defines what this tool does.

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

Usage Guidelines3/5

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

The description implies usage by mentioning timeout behavior, but it does not explicitly state when to use this tool versus alternatives like run_saved_query or get_result. No explicit exclusions or prerequisites are provided, leaving usage context somewhat vague.

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/lishenxydlgzs/aws-athena-mcp'

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