Used for environment variable management to securely store and access database credentials from a .env file.
Provides tools for querying and managing MySQL databases, including executing SELECT and modification queries, listing tables, describing table structures, testing connections, and exporting query results to CSV format.
Supports various Python runtime environments (system Python, virtual environments, and Conda) for executing the MCP server.
MySQL MCP Tools
This is a Model Context Protocol (MCP) server that provides tools for querying and managing a MySQL database.
Features
The server provides the following tools:
- query_database - Execute SELECT queries on the MySQL database
- execute_sql - Execute INSERT, UPDATE, or DELETE operations
- list_tables - List all tables in the database
- describe_table - Get the structure/schema of a specific table
- test_connection - Test the database connection
- query_to_csv - Execute a SELECT query and save results to a CSV file
- query_to_csv_string - Execute a SELECT query and return results as a CSV string
Resources
The server also provides these resources:
- greeting://{name} - Get a personalized greeting
- database://tables - Get all tables from the database with metadata
Database Configuration
The database connection is configured using environment variables in the .env
file:
- Configure your database credentials in the
.env
file - Run the MCP server:
Usage Examples
Query Database
Execute a SELECT query:
Execute SQL Operations
Execute INSERT, UPDATE, or DELETE:
List Tables
Get all tables in the database:
Describe Table
Get table structure:
Test Connection
Check database connectivity:
Export Query Results to CSV
Save query results to a CSV file:
Get Query Results as CSV String
Get query results as CSV string in memory:
MCP Client Configuration
To use this MCP server with MCP clients, you need to configure the client to connect to this server.
Configuration File (mcp.json)
Create or update your MCP client configuration file (usually mcp.json
or similar):
Using System Python:
Using Virtual Environment Python:
Using Conda Environment:
Claude Desktop Configuration
For Claude Desktop, add this configuration to your claude_desktop_config.json
:
Using System Python:
Using Virtual Environment Python:
VS Code MCP Extension
If using VS Code with an MCP extension:
- Open VS Code settings
- Search for "MCP" settings
- Add the server configuration:
- Name:
database-tools
- Command:
python
(or full path to your Python executable) - Args:
["/path/to/your/mcptools/database_mcp.py"]
- Working Directory:
/path/to/your/mcptools
- Name:
Finding Your Python Environment Path
To find the correct Python path for your environment:
For Virtual Environment:
For Conda Environment:
For System Python:
Example Output:
- Virtual Environment:
/home/user/myproject/venv/bin/python
- Conda Environment:
/home/user/miniconda3/envs/myenv/bin/python
- System Python:
/usr/bin/python3
Available Resources
The server also provides resources that can be accessed by MCP clients:
greeting://{name}
- Get a personalized greetingdatabase://tables
- Get all tables from the database with metadata
Troubleshooting Client Configuration
- Path Issues: Ensure all paths in the configuration are absolute paths
- Python Environment: Make sure the Python environment has all required dependencies installed
- Permissions: Ensure the MCP client has permission to execute the server script
- Database Connection: Verify the
.env
file is properly configured with database credentials - Server Status: Check if the server starts without errors by running
python database_mcp.py
manually
Security Notes
- The database credentials are stored in environment variables for better security
- Use parameterized queries to prevent SQL injection
- Ensure your MySQL server is properly secured
Dependencies
- mcp - Model Context Protocol framework
- mysql-connector-python - MySQL database connector
- python-dotenv - Environment variable management
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A Model Context Protocol server that provides tools for querying and managing MySQL databases, offering functionalities like executing SQL queries, listing tables, describing table structure, and exporting query results to CSV.
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol server that enables SQL query execution, database management, and business intelligence capabilities through MySQL connections.Last updated -JavaScript
- -security-license-qualityA Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.Last updated -MIT License
- -security-license-qualityA Model Context Protocol server that provides tools for connecting to and interacting with various database systems (SQLite, PostgreSQL, MySQL/MariaDB, SQL Server) through a unified interface.Last updated -Python
- -security-license-qualityA Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.Last updated -JavaScript