@lishenxydlgzs/aws-athena-mcp
A Model Context Protocol (MCP) server for running AWS Athena queries. This server enables AI assistants to execute SQL queries against your AWS Athena databases and retrieve results.
Usage
-
Configure AWS credentials using one of the following methods:
- AWS CLI configuration
- Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
- IAM role (if running on AWS)
-
Add the server to your MCP configuration:
1{ 2 "mcpServers": { 3 "athena": { 4 "command": "npx", 5 "args": ["-y", "@lishenxydlgzs/aws-athena-mcp"], 6 "env": { 7 // Required 8 "OUTPUT_S3_PATH": "s3://your-bucket/athena-results/", 9 10 // Optional AWS configuration 11 "AWS_REGION": "us-east-1", // Default: AWS CLI default region 12 "AWS_PROFILE": "default", // Default: 'default' profile 13 "AWS_ACCESS_KEY_ID": "", // Optional: AWS access key 14 "AWS_SECRET_ACCESS_KEY": "", // Optional: AWS secret key 15 "AWS_SESSION_TOKEN": "", // Optional: AWS session token 16 17 // Optional server configuration 18 "QUERY_TIMEOUT_MS": "300000", // Default: 5 minutes (300000ms) 19 "MAX_RETRIES": "100", // Default: 100 attempts 20 "RETRY_DELAY_MS": "500" // Default: 500ms between retries 21 } 22 } 23 } 24}
- The server provides the following tools:
-
run_query
: Execute 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
- Parameters:
-
get_status
: Check 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)
- Parameters:
-
get_result
: Retrieve 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
- Parameters:
Usage Examples
Show All Databases
Message to AI Assistant:
List all databases in Athena
MCP parameter:
1{ 2 "database": "default", 3 "query": "SHOW DATABASES" 4}
List Tables in a Database
Message to AI Assistant:
Show me all tables in the default database
MCP parameter:
1{ 2 "database": "default", 3 "query": "SHOW TABLES" 4}
Get Table Schema
Message to AI Assistant:
What's the schema of the asin_sitebestimg table?
MCP parameter:
1{ 2 "database": "default", 3 "query": "DESCRIBE default.asin_sitebestimg" 4}
Table Rows Preview
Message to AI Assistant:
Show some rows from my_database.mytable
MCP parameter:
1{ 2 "database": "my_database", 3 "query": "SELECT * FROM my_table LIMIT 10", 4 "maxRows": 10 5}
Advanced Query with Filtering and Aggregation
Message to AI Assistant:
Find the average price by category for in-stock products
MCP parameter:
1{ 2 "database": "my_database", 3 "query": "SELECT category, COUNT(*) as count, AVG(price) as avg_price FROM products WHERE in_stock = true GROUP BY category ORDER BY count DESC", 4 "maxRows": 100 5}
Checking Query Status
1{ 2 "queryExecutionId": "12345-67890-abcdef" 3}
Getting Results for a Completed Query
1{ 2 "queryExecutionId": "12345-67890-abcdef", 3 "maxRows": 10 4}
Requirements
- Node.js >= 16
- AWS credentials with appropriate Athena permissions
- S3 bucket for query results
License
MIT