mysql-mcp-database-server
v1.0.0
Published
MySQL MCP Server for database operations with Claude and MCP
Downloads
15
Maintainers
Readme
MySQL MCP Server
A Model Context Protocol (MCP) server for MySQL database operations, enabling Claude and other MCP clients to interact with MySQL databases.
Features
- Database Connection: Connect to MySQL databases with configurable credentials
- Query Execution: Execute SQL queries with parameter binding
- Schema Exploration: List tables, describe table structures, and show databases
- Environment Variables: Auto-connect using environment variables
- Query Validation: Built-in query validation with helpful tips
Installation
npm install -g mysql-mcp-serverQuick Start
1. Environment Variables
Set up your MySQL connection using environment variables:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=your_username
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database2. Run the Server
mysql-mcp-server3. Configure Claude Desktop
Add to your Claude Desktop configuration file:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql": {
"command": "mysql-mcp-server",
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Available Tools
connect_mysql
Connect to a MySQL database with custom credentials.
Parameters:
host(string, optional): Database host (default: localhost)port(number, optional): Database port (default: 3306)user(string, required): Database usernamepassword(string, required): Database passworddatabase(string, required): Database name
execute_query
Execute a SQL query on the connected database.
Parameters:
query(string, required): SQL query to executeparams(array, optional): Query parameters for prepared statements
Example:
SELECT * FROM users WHERE id = ? AND status = ?With params: ["123", "active"]
show_tables
List all tables in the current database.
describe_table
Show the structure of a specific table.
Parameters:
table_name(string, required): Name of the table to describe
show_databases
List all available databases.
Usage Examples
Basic Query
SELECT COUNT(*) FROM users WHERE active = 1;Parameterized Query
SELECT * FROM orders WHERE user_id = ? AND created_at > ?;Schema Exploration
DESCRIBE users;
SHOW TABLES;
SHOW DATABASES;Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| MYSQL_HOST | MySQL server host | localhost |
| MYSQL_PORT | MySQL server port | 3306 |
| MYSQL_USER | MySQL username | - |
| MYSQL_PASSWORD | MySQL password | - |
| MYSQL_DATABASE | Database name | - |
| MYSQL_DB | Alternative for MYSQL_DATABASE | - |
Security
- Always use environment variables for sensitive credentials
- Use parameterized queries to prevent SQL injection
- The server validates queries and provides security warnings
- Connections use UTF8MB4 charset by default
Requirements
- Node.js 18.0.0 or higher
- MySQL 5.7 or higher (or compatible database like MariaDB)
Development
Local Development
- Clone the repository
- Install dependencies:
npm install - Run in development mode:
npm run dev
Testing
Set up a test database and run:
export MYSQL_HOST=localhost
export MYSQL_USER=test_user
export MYSQL_PASSWORD=test_password
export MYSQL_DATABASE=test_db
npm testContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
- GitHub Issues: https://github.com/kaedim/mysql-mcp-server/issues
- Documentation: https://github.com/kaedim/mysql-mcp-server
