mysql
A proper Model Context Protocol (MCP) server that enables natural language interaction with MySQL databases using Ollama
claude mcp add --transport stdio hanzala-sohrab-mysql-mcp-server python /path/to/your/project/mcp_server.py \ --env DB_HOST="localhost" \ --env DB_NAME="your_database_name" \ --env DB_PORT="3306" \ --env DB_USER="your_mysql_user" \ --env DB_PASSWORD="your_mysql_password"
How to use
This MCP server enables natural language and programmatic interaction with a MySQL database through the Model Context Protocol (MCP). It exposes a set of MCP tools that allow you to execute raw SQL, inspect database schema, and fetch sample data from tables. The server is designed to safely run SQL queries, provide schema and data as MCP resources, and assist with database analysis via dedicated prompts. Tools such as execute_sql_query, list_tables, describe_table, and get_table_data can be invoked by MCP clients to perform common database tasks without manually writing boilerplate code. In addition, the server exposes a suite of prompts to help construct SQL queries or perform in-depth database analysis, streamlining the interaction between the user and the database.
To use the server, configure your MCP client (e.g., Claude Desktop, Windsurf) to point to the Python-based MCP server script with the necessary environment variables for your database connection. Typical workflows include listing tables, describing a table to understand its structure, running custom SQL via execute_sql_query, and fetching sample rows from a table with get_table_data. The resources and prompts provided allow you to retrieve a complete schema, per-table details, and sample data as MCP resources for use in conversations and tooling.
How to install
Prerequisites:
- Python 3.10+
- MySQL server accessible from the host running the MCP server
- Optional: Ollama with Llama 3.2 if you plan to use local NLP models in your environment
Step-by-step installation:
- Create and activate a Python environment (recommended):
python3.10 -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
- Copy and configure environment settings:
cp .env.example .env
- Edit the .env file to include your MySQL connection details, for example:
# MySQL Database Configuration
DB_HOST=localhost
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=your_database_name
DB_PORT=3306
- Run the MCP server (production):
python mcp_server.py
- (Optional) Run tests if provided:
python test_mcp_server.py
Notes:
- Ensure MySQL allows connections from the host running this MCP server.
- If you use a virtual environment, always activate it before running the server.
Additional notes
Tips and considerations:
- Environment variables should be kept secure; avoid committing .env files to version control.
- If you encounter database connection errors, verify that MySQL is running and that credentials in .env are correct.
- The MCP tools (execute_sql_query, list_tables, describe_table, get_table_data) are designed to handle common database tasks safely; consider validating and sanitizing user inputs when integrating with client prompts.
- For production deployments, consider configuring proper logging (LOG_LEVEL) and enabling secure transport if exposing MCP endpoints over networks.
- If you enable Ollama or local LLM-based prompts, ensure model availability and compatibility with your environment and licensing terms.
Related MCP Servers
npcpy
The python library for research and development in NLP, multimodal LLMs, Agents, ML, Knowledge Graphs, and more.
mysql_mcp_server
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
jupyter
🪐 🔧 Model Context Protocol (MCP) Server for Jupyter.
falcon
Connect AI agents to CrowdStrike Falcon for automated security analysis and threat hunting
beemcp
BeeMCP: an unofficial Model Context Protocol (MCP) server that connects your Bee wearable lifelogger to AI via the Model Context Protocol
Helios
An AI IDE secure coding MCP service