Skip to main content

A simple, clean MCP server for AWS Athena integration

Project description

AWS Athena MCP Server

A simple, clean MCP (Model Context Protocol) server for AWS Athena integration. Execute SQL queries, discover schemas, and manage query executions through a standardized interface.

โœจ Features

  • Simple Setup - Get running in under 5 minutes
  • Clean Architecture - Modular, well-tested, easy to understand
  • Essential Tools - Query execution and schema discovery
  • Type Safe - Full type hints and Pydantic models
  • Async Support - Built for performance with async/await
  • Good Defaults - Works out of the box with minimal configuration

๐Ÿš€ Quick Start

1. Install

# From PyPI with uvx (recommended for Claude Desktop)
uvx install aws-athena-mcp

# From PyPI with pip
pip install aws-athena-mcp

# Or from source
git clone https://github.com/ColeMurray/aws-athena-mcp
cd aws-athena-mcp
pip install -e .

2. Configure

Set the required environment variables:

# Required
export ATHENA_S3_OUTPUT_LOCATION=s3://your-bucket/athena-results/

# Optional (with defaults)
export AWS_REGION=us-east-1
export ATHENA_WORKGROUP=primary
export ATHENA_TIMEOUT_SECONDS=60

3. Run

# Start the MCP server
aws-athena-mcp

# Or run directly
python -m athena_mcp.server

That's it! The server is now running and ready to accept MCP connections.

๐Ÿค– Claude Desktop Integration

To use this MCP server with Claude Desktop:

1. Install Claude Desktop

Download and install Claude Desktop if you haven't already.

2. Configure Claude Desktop

Add the following configuration to your claude_desktop_config.json:

Location of config file:

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

Configuration:

{
  "mcpServers": {
    "aws-athena-mcp": {
      "command": "uvx",
      "args": [
        "aws-athena-mcp"
      ],
      "env": {
        "ATHENA_S3_OUTPUT_LOCATION": "s3://your-bucket/athena-results/",
        "AWS_REGION": "us-east-1",
        "ATHENA_WORKGROUP": "primary",
        "ATHENA_TIMEOUT_SECONDS": "60"
      }
    }
  }
}

3. Set AWS Credentials

Configure your AWS credentials using one of these methods:

# Method 1: Environment variables (add to your shell profile)
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key

# Method 2: AWS CLI
aws configure

# Method 3: AWS Profile
export AWS_PROFILE=your-profile

4. Restart Claude Desktop

Restart Claude Desktop to load the new MCP server configuration.

5. Verify Connection

In Claude Desktop, you should now be able to:

  • Execute SQL queries against your Athena databases
  • List tables and describe schemas
  • Get query results and status

Example conversation:

You: "List all tables in my 'analytics' database"
Claude: I'll help you list the tables in your analytics database using the Athena MCP server.
[Uses list_tables tool]

๐Ÿ› ๏ธ Automated Setup (Alternative)

For easier setup, you can use the included setup script:

# Clone the repository
git clone https://github.com/ColeMurray/aws-athena-mcp
cd aws-athena-mcp

# Run the setup script
python scripts/setup_claude_desktop.py

The script will:

  • Check if uvx is installed
  • Guide you through configuration
  • Update your Claude Desktop config file
  • Verify AWS credentials
  • Provide next steps

You can also copy the example configuration:

cp examples/claude_desktop_config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Then edit the file to add your S3 bucket and AWS settings

๐Ÿ”ง Configuration

The server uses environment variables for configuration:

Variable Required Default Description
ATHENA_S3_OUTPUT_LOCATION โœ… - S3 path for query results
AWS_REGION โŒ us-east-1 AWS region
ATHENA_WORKGROUP โŒ None Athena workgroup
ATHENA_TIMEOUT_SECONDS โŒ 60 Query timeout

AWS Credentials

Configure AWS credentials using any of these methods:

# Method 1: Environment variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key

# Method 2: AWS CLI
aws configure

# Method 3: AWS Profile
export AWS_PROFILE=your-profile

# Method 4: IAM roles (for EC2/Lambda)
# No configuration needed

๐Ÿ”’ Security

Environment Variables

โš ๏ธ NEVER commit credentials to version control!

Use the provided example file to set up your environment:

# Copy the example file
cp examples/environment_variables.example .env

# Edit with your values
nano .env

# Make sure .env is in .gitignore (it already is)
echo ".env" >> .gitignore

AWS Credentials Best Practices

  1. Use IAM Roles (recommended for production):

    # No credentials needed - uses instance/container role
    export ATHENA_S3_OUTPUT_LOCATION=s3://your-bucket/results/
    
  2. Use AWS CLI profiles (recommended for development):

    aws configure --profile athena-mcp
    export AWS_PROFILE=athena-mcp
    
  3. Use temporary credentials when possible:

    aws sts assume-role --role-arn arn:aws:iam::123456789012:role/AthenaRole \
      --role-session-name athena-mcp-session
    
  4. Avoid long-term access keys in environment variables

Required AWS Permissions

Your AWS credentials need these minimum permissions:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "athena:StartQueryExecution",
        "athena:GetQueryExecution", 
        "athena:GetQueryResults",
        "athena:ListWorkGroups",
        "athena:GetWorkGroup"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::your-bucket/athena-results/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::your-bucket"
    },
    {
      "Effect": "Allow",
      "Action": [
        "glue:GetDatabase",
        "glue:GetDatabases",
        "glue:GetTable",
        "glue:GetTables"
      ],
      "Resource": "*"
    }
  ]
}

SQL Injection Protection

The server includes built-in SQL injection protection:

  • Query validation - Dangerous patterns are blocked
  • Input sanitization - Database/table names are validated
  • Query size limits - Prevents resource exhaustion
  • Parameterized queries - When possible

Network Security

For production deployments:

  • Use VPC endpoints for AWS services
  • Restrict network access to the MCP server
  • Use TLS for all communications
  • Monitor and log all queries

Monitoring and Auditing

Enable CloudTrail logging for Athena:

{
  "eventVersion": "1.05",
  "userIdentity": {...},
  "eventTime": "2024-01-01T12:00:00Z",
  "eventSource": "athena.amazonaws.com",
  "eventName": "StartQueryExecution",
  "resources": [...]
}

๐Ÿ› ๏ธ Available Tools

The server provides these MCP tools:

Query Execution

  • run_query - Execute SQL queries against Athena
  • get_status - Check query execution status
  • get_result - Get results for completed queries

Schema Discovery

  • list_tables - List all tables in a database
  • describe_table - Get detailed table schema

๐Ÿ“– Usage Examples

Basic Query Execution

# Using the MCP client (pseudo-code)
result = await mcp_client.call_tool("run_query", {
    "database": "default",
    "query": "SELECT * FROM my_table LIMIT 10",
    "max_rows": 10
})

Schema Discovery

# List tables
tables = await mcp_client.call_tool("list_tables", {
    "database": "default"
})

# Describe a table
schema = await mcp_client.call_tool("describe_table", {
    "database": "default",
    "table_name": "my_table"
})

Handling Timeouts

# Long-running query
result = await mcp_client.call_tool("run_query", {
    "database": "default",
    "query": "SELECT COUNT(*) FROM large_table"
})

if "query_execution_id" in result:
    # Query timed out, check status later
    status = await mcp_client.call_tool("get_status", {
        "query_execution_id": result["query_execution_id"]
    })

๐Ÿงช Testing

Test your configuration:

# Test configuration and AWS connection
python scripts/test_connection.py

# Run the test suite
pytest

# Run with coverage
pytest --cov=athena_mcp

๐Ÿ—๏ธ Development

Setup Development Environment

# Clone and install in development mode
git clone https://github.com/ColeMurray/aws-athena-mcp
cd aws-athena-mcp
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src tests
isort src tests

# Type checking
mypy src

Project Structure

aws-athena-mcp/
โ”œโ”€โ”€ src/athena_mcp/          # Main package
โ”‚   โ”œโ”€โ”€ server.py            # MCP server
โ”‚   โ”œโ”€โ”€ athena.py            # AWS Athena client
โ”‚   โ”œโ”€โ”€ config.py            # Configuration
โ”‚   โ””โ”€โ”€ models.py            # Data models
โ”œโ”€โ”€ src/tools/               # MCP tools
โ”‚   โ”œโ”€โ”€ query.py             # Query tools
โ”‚   โ””โ”€โ”€ schema.py            # Schema tools
โ”œโ”€โ”€ tests/                   # Test suite
โ”œโ”€โ”€ examples/                # Usage examples
โ”œโ”€โ”€ scripts/                 # Utility scripts
โ””โ”€โ”€ docs/                    # Documentation

Adding New Tools

  1. Create tool functions in src/tools/
  2. Register them in the appropriate module
  3. Add tests in tests/
  4. Update documentation

Example:

# In src/tools/query.py
def register_query_tools(mcp, athena_client):
    @mcp.tool()
    async def my_new_tool(param: str) -> str:
        """My new tool description."""
        # Implementation here
        return result

๐Ÿ” Troubleshooting

Common Issues

Configuration Error

โŒ Configuration error: ATHENA_S3_OUTPUT_LOCATION environment variable is required

Solution: Set the required environment variable:

export ATHENA_S3_OUTPUT_LOCATION=s3://your-bucket/results/

AWS Credentials Error

โŒ AWS credentials error: AWS credentials not found

Solution: Configure AWS credentials (see Configuration section)

Permission Denied

โŒ AWS credentials error: AWS credentials are invalid or insufficient permissions

Solution: Ensure your AWS credentials have these permissions:

  • athena:StartQueryExecution
  • athena:GetQueryExecution
  • athena:GetQueryResults
  • athena:ListWorkGroups
  • s3:GetObject, s3:PutObject on your S3 bucket

Debug Mode

Enable debug logging:

export PYTHONPATH=src
python -c "
import logging
logging.basicConfig(level=logging.DEBUG)
from athena_mcp.server import main
main()
"

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Contributions welcome! Please read our contributing guidelines and:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“ž Support


Made with โค๏ธ for the MCP community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_athena_mcp-1.0.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_athena_mcp-1.0.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file aws_athena_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: aws_athena_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aws_athena_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1c7227368ec36b031ecd264e537f9a18f3089b6dc729f7b5de11999bde6da96b
MD5 d52cd194b2267e6049ccd5c3eb2dbdb3
BLAKE2b-256 2eea869013dca3b48d5ccf4d7bade5a638e7b4376d5990fbf29f4460ed0deff9

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_athena_mcp-1.0.0.tar.gz:

Publisher: release.yml on ColeMurray/aws-athena-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aws_athena_mcp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aws_athena_mcp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aws_athena_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27c21cbdee5c313e070eac4a6ef8a8bf19031adffccd49bab366cc49f4521607
MD5 e1cf56107842fa6f63289f4c4517ee1a
BLAKE2b-256 1b12dd8447c61ac5aa3213a9145db05af9a87e8641ec92e96fd15d0d8952beb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_athena_mcp-1.0.0-py3-none-any.whl:

Publisher: release.yml on ColeMurray/aws-athena-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page