AWS Athena MCP server

Integrates with AWS SDK to execute SQL queries against Athena databases, enabling large-scale data analysis and business intelligence for AWS data lakes.
Back to servers
Setup instructions
Provider
lishenxydlgzs
Release date
Feb 26, 2025
Language
TypeScript
Package
Stats
1.7K downloads
26 stars

This MCP server enables AI assistants to execute SQL queries against AWS Athena databases and retrieve results. It provides a seamless way to interact with your Athena data through an MCP interface.

Installation and Configuration

To use the AWS Athena MCP server, you'll need to configure AWS credentials and add the server to your MCP configuration.

AWS Credentials Setup

Configure your AWS credentials using one of these methods:

  • AWS CLI configuration
  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • IAM role (if running on AWS)

Server Configuration

Add the server to your MCP configuration:

{
  "mcpServers": {
    "athena": {
      "command": "npx",
      "args": ["-y", "@lishenxydlgzs/aws-athena-mcp"],
      "env": {
        "OUTPUT_S3_PATH": "s3://your-bucket/athena-results/",
        
        "AWS_REGION": "us-east-1",
        "AWS_PROFILE": "default",
        "AWS_ACCESS_KEY_ID": "",
        "AWS_SECRET_ACCESS_KEY": "",
        "AWS_SESSION_TOKEN": "",
        
        "ATHENA_WORKGROUP": "default_workgroup",
        "QUERY_TIMEOUT_MS": "300000",
        "MAX_RETRIES": "100",
        "RETRY_DELAY_MS": "500"
      }
    }
  }
}

Required Environment Variables:

  • OUTPUT_S3_PATH: S3 location where Athena will store query results

Optional Environment Variables:

  • AWS_REGION: AWS region (default: AWS CLI default region)
  • AWS_PROFILE: AWS CLI profile (default: 'default')
  • AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN: Optional AWS credentials
  • ATHENA_WORKGROUP: Athena WorkGroup to use (default: 'primary')
  • QUERY_TIMEOUT_MS: Query timeout in milliseconds (default: 300000ms/5min)
  • MAX_RETRIES: Maximum retry attempts (default: 100)
  • RETRY_DELAY_MS: Delay between retries in milliseconds (default: 500ms)

Available Tools

run_query

Executes a SQL query using AWS Athena.

Parameters:

  • database: The Athena database to query
  • query: SQL query to execute
  • maxRows: Maximum number of rows to return (default: 1000, max: 10000)

Returns:

  • If query completes within timeout: Full query results
  • If timeout reached: Only the queryExecutionId for later retrieval

get_status

Checks the status of a query execution.

Parameters:

  • queryExecutionId: The ID returned from run_query

Returns:

  • state: Query state (QUEUED, RUNNING, SUCCEEDED, FAILED, or CANCELLED)
  • stateChangeReason: Reason for state change (if any)
  • submissionDateTime: When the query was submitted
  • completionDateTime: When the query completed (if finished)
  • statistics: Query execution statistics (if available)

get_result

Retrieves results for a completed query.

Parameters:

  • queryExecutionId: The ID returned from run_query
  • maxRows: Maximum number of rows to return (default: 1000, max: 10000)

Returns:

  • Full query results if the query has completed successfully
  • Error if query failed or is still running

list_saved_queries

Lists all saved (named) queries in Athena.

Returns:

  • An array of saved queries with id, name, and optional description
  • Queries are returned from the configured ATHENA_WORKGROUP and AWS_REGION

run_saved_query

Runs a previously saved query by its ID.

Parameters:

  • namedQueryId: ID of the saved query
  • databaseOverride: Optional override of the saved query's default database
  • maxRows: Maximum number of rows to return (default: 1000)
  • timeoutMs: Timeout in milliseconds (default: 60000)

Returns:

  • Same behavior as run_query: full results or execution ID

Usage Examples

Show All Databases

Message to AI Assistant:

List all databases in Athena

MCP parameter:

{
  "database": "default",
  "query": "SHOW DATABASES"
}

List Tables in a Database

Message to AI Assistant:

Show me all tables in the default database

MCP parameter:

{
  "database": "default",
  "query": "SHOW TABLES"
}

Get Table Schema

Message to AI Assistant:

What's the schema of the asin_sitebestimg table?

MCP parameter:

{
  "database": "default",
  "query": "DESCRIBE default.asin_sitebestimg"
}

Table Rows Preview

Message to AI Assistant:

Show some rows from my_database.mytable

MCP parameter:

{
  "database": "my_database",
  "query": "SELECT * FROM my_table LIMIT 10",
  "maxRows": 10
}

Advanced Query with Filtering and Aggregation

Message to AI Assistant:

Find the average price by category for in-stock products

MCP parameter:

{
  "database": "my_database",
  "query": "SELECT category, COUNT(*) as count, AVG(price) as avg_price FROM products WHERE in_stock = true GROUP BY category ORDER BY count DESC",
  "maxRows": 100
}

Checking Query Status

{
  "queryExecutionId": "12345-67890-abcdef"
}

Getting Results for a Completed Query

{
  "queryExecutionId": "12345-67890-abcdef",
  "maxRows": 10
}

Listing Saved Queries

{
  "name": "list_saved_queries",
  "arguments": {}
}

Running a Saved Query

{
  "name": "run_saved_query",
  "arguments": {
    "namedQueryId": "abcd-1234-efgh-5678",
    "maxRows": 100
  }
}

System Requirements

  • Node.js >= 16
  • AWS credentials with appropriate Athena and S3 permissions
  • S3 bucket for query results
  • Named queries (optional) must exist in the specified ATHENA_WORKGROUP and AWS_REGION

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "athena" '{"command":"npx","args":["-y","@lishenxydlgzs/aws-athena-mcp"],"env":{"OUTPUT_S3_PATH":"s3://your-bucket/athena-results/","AWS_REGION":"us-east-1","AWS_PROFILE":"default","AWS_ACCESS_KEY_ID":"","AWS_SECRET_ACCESS_KEY":"","AWS_SESSION_TOKEN":"","ATHENA_WORKGROUP":"default_workgroup","QUERY_TIMEOUT_MS":"300000","MAX_RETRIES":"100","RETRY_DELAY_MS":"500"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "athena": {
            "command": "npx",
            "args": [
                "-y",
                "@lishenxydlgzs/aws-athena-mcp"
            ],
            "env": {
                "OUTPUT_S3_PATH": "s3://your-bucket/athena-results/",
                "AWS_REGION": "us-east-1",
                "AWS_PROFILE": "default",
                "AWS_ACCESS_KEY_ID": "",
                "AWS_SECRET_ACCESS_KEY": "",
                "AWS_SESSION_TOKEN": "",
                "ATHENA_WORKGROUP": "default_workgroup",
                "QUERY_TIMEOUT_MS": "300000",
                "MAX_RETRIES": "100",
                "RETRY_DELAY_MS": "500"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "athena": {
            "command": "npx",
            "args": [
                "-y",
                "@lishenxydlgzs/aws-athena-mcp"
            ],
            "env": {
                "OUTPUT_S3_PATH": "s3://your-bucket/athena-results/",
                "AWS_REGION": "us-east-1",
                "AWS_PROFILE": "default",
                "AWS_ACCESS_KEY_ID": "",
                "AWS_SECRET_ACCESS_KEY": "",
                "AWS_SESSION_TOKEN": "",
                "ATHENA_WORKGROUP": "default_workgroup",
                "QUERY_TIMEOUT_MS": "300000",
                "MAX_RETRIES": "100",
                "RETRY_DELAY_MS": "500"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later