dcs5star/AWS-RDS-MySQL-MCP-Server-Client
If you are the rightful owner of AWS-RDS-MySQL-MCP-Server-Client and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project implements a Model Context Protocol (MCP) server for MySQL database operations, featuring integration with AWS Bedrock and a Streamlit UI, as well as a standalone server for general MCP clients.
AWS RDS MySQL MCP Integration
A Model Context Protocol (MCP) implementation for MySQL database operations with dual server configurations - one integrated with AWS Bedrock and Streamlit UI as MCP client, and another standalone server for general MCP clients like Claude Desktop.
Features
- Dual MCP Server Implementation
- Integrated Streamlit UI app with AWS Bedrock agent which also act as MCP Client
- Standalone FastMCP server (fastmcp_server.py) for Claude Desktop and other MCP clients
- Secure MySQL Operations with built-in safety checks
- Natural Language SQL via AWS Bedrock integration
- Real-time Database Interaction through web interface
Project Structure
MCP/
āāā app.py # Streamlit frontend with Bedrock integration
āāā mcp_server.py # MCP server for Bedrock integration
āāā fastmcp_server.py # Standalone MCP server
āāā config.py # Configuration loader
āāā .env.example # Environment variables template
āāā .env # Your environment variables (create from .env.example)
āāā README.md # This file
Setup Instructions
1. Create Virtual Environment
# Create virtual environment
python -m venv venv-mcp
# Activate virtual environment
# Windows:
venv-mcp\Scripts\activate
# macOS/Linux:
source venv-mcp/bin/activate
2. Install Dependencies
pip install fastmcp pymysql streamlit boto3 python-dotenv
3. Environment Configuration
Note: Make sure you have AWS IAM credential profile configured on the machine from where you running app and/or MCP server.
Copy the example environment file and configure your settings:
# Copy the example file
cp .env.example .env
# Edit .env with your actual values
.env will have below config. Update it with the actual values:
# AWS Configuration
AWS_REGION=us-east-1
BEDROCK_MODEL_ID=anthropic.claude-3-haiku-20240307-v1:0
# MySQL Database Configuration
RDS_HOST=your-mysql-host.amazonaws.com
RDS_PORT=3306
RDS_USER=your-username
RDS_PASS=your-password
RDS_DB=your-database-name
Security Note:
- Never commit
.env
files to version control - Add
.env
to your.gitignore
file - Use AWS IAM roles in production environments
Usage
Option 1: Streamlit App with Bedrock Integration
Run the integrated Streamlit application:
streamlit run app.py
- Access the web interface at
http://localhost:8501
- Enter natural language commands (e.g., "Create a users table with id and name columns")
- The app uses AWS Bedrock to interpret commands and execute SQL
Option 2: Standalone MCP Server
For use with Claude Desktop or other MCP clients:
python fastmcp_server.py
Claude Desktop Configuration
Add to your Claude Desktop config file:
{
"mcpServers": {
"mysql-server": {
"command": "python",
"args": ["path/to/your/fastmcp_server.py"],
"cwd": "path/to/your/MCP/directory"
}
}
}
Configuration Details
Database Settings
Configure your MySQL connection in the .env
file:
- RDS_HOST: Your MySQL server hostname
- RDS_PORT: MySQL port (default: 3306)
- RDS_USER: Database username
- RDS_PASS: Database password
- RDS_DB: Database name
AWS Bedrock Settings
- AWS_REGION: AWS region for Bedrock service
- MODEL_ID: Bedrock model identifier
Security Features
- SQL Injection Protection: Input validation and parameterized queries
- Dangerous Operation Blocking: Prevents DROP DATABASE, TRUNCATE operations
- Connection Timeout: 10-second connection timeout
- Transaction Rollback: Automatic rollback on errors
Supported SQL Operations
SELECT
- Query dataINSERT
- Add new recordsUPDATE
- Modify existing recordsDELETE
- Remove recordsCREATE
- Create tables/indexesDROP
- Drop tables (with restrictions)SHOW
- Display database informationDESCRIBE
- Show table structure
Example Commands
Natural Language (Streamlit App & Claude Desktop)
- "Show all tables in the database"
- "Create a user table with id, name, and email"
- "Insert a new user with name John and email "
- "Find all users whose name starts with J"
Troubleshooting
Common Issues
-
Connection Refused
- Verify MySQL server is running
- Check firewall settings
- Confirm connection credentials
-
AWS Bedrock Errors
- Ensure AWS credentials are configured
- Verify Bedrock model access permissions
- Check AWS region settings
-
MCP Client Connection
- Confirm server is running on stdio
- Verify client configuration paths
- Check Python environment activation
Debug Mode
Enable debug logging by setting:
export PYTHONPATH=.
python -v fastmcp_server.py
License
This project is provided as-is for educational and development purposes without any liability to author.
Note: This implementation requires proper AWS credentials and MySQL database access. Ensure all security best practices are followed & tested in non-production environments.