A Model Context Protocol (MCP) server for AWS Athena
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iflow_mcp_aws_athena_mcp-1.0.0.tar.gz.
File metadata
- Download URL: iflow_mcp_aws_athena_mcp-1.0.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82b5bfa6fb48c33c5bef93c448de6ab9581dd6ae26ffbf76894316f5f124e8e0
|
|
| MD5 |
2c6b34aefffe682c8d661ef414b9f4a2
|
|
| BLAKE2b-256 |
b6cae06b2dc9379fbc7718193504f08cc0c191c89538b2613936108dcc6c3d04
|
File details
Details for the file iflow_mcp_aws_athena_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: iflow_mcp_aws_athena_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a390145d970a515bedda96ecf4215101444c132ccd95c265a7ac8a17147e579b
|
|
| MD5 |
a878d2a7dc07d459d7bb086255162d54
|
|
| BLAKE2b-256 |
0c697ca13be71ad00a5b13b0ea303e6560ab00ce8757a0f52a055a6d3cd13c87
|