A
Aws Athena MCP
by @diasrafael
MCP server by diasrafael
Created 5/29/2025
Updated 4 days ago
README
Repository documentation and setup instructions
AWS Athena MCP Server
A Model Context Protocol (MCP) server for AWS Athena that enables SQL queries and database exploration through a standardized interface.
๐๏ธ Project Structure
The project follows best practices for Python project organization:
aws-athena-mcp/
โโโ src/
โ โโโ athena_mcp/
โ โโโ core/ # Core system modules
โ โ โโโ config.py # Centralized configurations
โ โ โโโ exceptions.py # Custom exceptions
โ โ โโโ __init__.py
โ โโโ services/ # Business services
โ โ โโโ athena_client.py # Athena client factory and management
โ โ โโโ athena_service.py # Main Athena operations
โ โ โโโ __init__.py
โ โโโ utils/ # Utilities and helpers
โ โ โโโ formatters.py # Output formatters
โ โ โโโ helpers.py # Helper functions
โ โ โโโ validators.py # Validators
โ โ โโโ __init__.py
โ โโโ handlers/ # MCP handlers
โ โ โโโ tool_handlers.py # MCP tool handlers
โ โ โโโ __init__.py
โ โโโ server.py # Main MCP server
โ โโโ __init__.py
โโโ tests/
โ โโโ unit/ # Unit tests
โ โโโ integration/ # Integration tests
โ โโโ __init__.py
โโโ main.py # Main entry point
โโโ setup.py # Installation configuration
โโโ pyproject.toml # Development tools configuration
โโโ requirements.txt # Dependencies
โโโ README.md
๐ Features
- Modular Architecture: Code organized in well-defined modules following single responsibility principle
- Complete Type Hints: Static typing for better maintainability
- Robust Error Handling: Custom exceptions and proper error handling
- Centralized Configuration: All configurations in a single location
- Tests Included: Unit and integration test structure
- Structured Logging: Configurable logging system
- Input Validation: Validators for different data types
๐ MCP Configuration
To use this server in MCP clients like Cursor, add the following configuration to your mcp.json
file:
{
"mcpServers": {
"athena-connector": {
"command": "python3",
"args": ["/path/to/aws-athena-mcp/main.py"],
"env": {
"AWS_ACCESS_KEY_ID": "your-access-key",
"AWS_SECRET_ACCESS_KEY": "your-secret-key",
"AWS_REGION": "us-east-1",
"AWS_S3_OUTPUT_LOCATION": "s3://your-bucket/athena-results/"
}
}
}
}
Configuration Options
Using Direct Credentials:
{
"command": "python3",
"args": ["/path/to/aws-athena-mcp/main.py"],
"env": {
"AWS_ACCESS_KEY_ID": "AKIA...",
"AWS_SECRET_ACCESS_KEY": "your-secret-key",
"AWS_REGION": "us-east-1",
"AWS_S3_OUTPUT_LOCATION": "s3://your-bucket/results/"
}
}
Using AWS Profile:
{
"command": "python3",
"args": ["/path/to/aws-athena-mcp/main.py"],
"env": {
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1",
"AWS_S3_OUTPUT_LOCATION": "s3://your-bucket/results/"
}
}
Using System Default Credentials:
{
"command": "python3",
"args": ["/path/to/aws-athena-mcp/main.py"],
"env": {
"AWS_S3_OUTPUT_LOCATION": "s3://your-bucket/results/"
}
}
Required Environment Variables
- AWS_S3_OUTPUT_LOCATION: S3 location where query results will be stored
Optional Environment Variables
- AWS_ACCESS_KEY_ID: AWS access key (if not using profile)
- AWS_SECRET_ACCESS_KEY: AWS secret key (if not using profile)
- AWS_PROFILE: Locally configured AWS profile
- AWS_REGION or AWS_DEFAULT_REGION: AWS region (default: us-east-1)
- LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR)
โ ๏ธ Security: For production environments, we recommend using IAM roles or AWS profiles instead of direct credentials in the configuration file.
๐ฆ Installation
Development Installation
# Clone the repository
git clone <repository-url>
cd aws-athena-mcp
# Install in development mode
pip install -e .[dev]
Production Installation
pip install .
โ๏ธ Configuration
Configure the following environment variables:
# AWS credentials (optional if using profile)
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
# AWS region
export AWS_DEFAULT_REGION="us-east-1"
# Or use an AWS profile
export AWS_PROFILE="your-profile"
# S3 output location (required)
export AWS_S3_OUTPUT_LOCATION="s3://your-bucket/athena-results/"
๐ฏ Usage
Run the Server
# Using the main entry point
python main.py
# Or using the installed command
athena-mcp
Available Tools
- list_databases: Lists all available databases in Athena
- query_athena: Executes SQL queries in Athena
- describe_data_structure: Describes the structure of a database
๐งช Testing
# Run all tests
pytest
# Run only unit tests
pytest tests/unit/
# Run with coverage
pytest --cov=src/athena_mcp
# Run specific tests
pytest tests/unit/test_validators.py -v
๐ ๏ธ Development
Code Quality Tools
# Code formatting
black src/ tests/
# Import sorting
isort src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/
Development Environment Setup
# Install development dependencies
pip install -e .[dev]
# Or install manually
pip install pytest pytest-asyncio black isort flake8 mypy
๐ Implemented Best Practices
Architecture
- Separation of Concerns: Each module has a specific responsibility
- Dependency Inversion: Use of interfaces and dependency injection
- Single Responsibility Principle: Classes and functions with single purpose
- Factory Pattern: For AWS client creation
- Strategy Pattern: For different types of formatting and validation
Code Quality
- Type Hints: Static typing in all functions and methods
- Docstrings: Complete documentation in Google Style format
- Error Handling: Custom exceptions and proper handling
- Logging: Structured and configurable logging system
- Validation: Rigorous input validation
Project Structure
- src/ Layout: Clear separation between source code and other files
- Namespace Packages: Hierarchical organization of modules
- Test Structure: Tests organized mirroring code structure
- Configuration Files: Centralized and externalized configuration
๐ง Troubleshooting
Consult the TROUBLESHOOTING.md file for common issues and solutions.
๐ Module Structure
Core (src/athena_mcp/core/
)
- config.py: Centralized system configurations
- exceptions.py: Custom domain exceptions
Services (src/athena_mcp/services/
)
- athena_client.py: AWS Athena client factory and management
- athena_service.py: High-level services for Athena operations
Utils (src/athena_mcp/utils/
)
- formatters.py: Formatters for different output types
- helpers.py: General helper functions and utilities
- validators.py: Validators for different input types
Handlers (src/athena_mcp/handlers/
)
- tool_handlers.py: Handlers for MCP tools
๐ค Contributing
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Quick Setup
Installation guide for this server
Cursor configuration (mcp.json)
{
"mcpServers": {
"diasrafael-aws-athena-mcp": {
"command": "diasrafael-aws-athena-mcp",
"args": []
}
}
}