Enables interaction with MySQL databases through tools for executing queries, listing and describing table schemas, and performing insert, update, and delete operations on database records.
MCP MySQL Server
This is a Node.js-based MCP (Managed Connector Platform) server for MySQL, exposing functionalities to interact with a MySQL database.
Features
query: Executes a SQL query with optional parameters.
describe_table: Describes the schema of a specified table.
list_tables: Lists all tables in the connected database.
update: Performs update operations on a table.
insert: Inserts a single record into a table.
delete: Deletes records from a table based on a condition (implemented by
deleteSingleinternally).
Setup and Configuration
Prerequisites
Node.js (LTS version recommended)
npm (Node Package Manager)
MySQL Server running and accessible
Express.js (included as a dependency)
Installation
Clone the repository (or create the project structure manually):
git clone <repository-url> cd mcp-mysqlIf you are setting this up manually, ensure you have
package.jsonandindex.jsas provided.Install dependencies:
Navigate to the project directory and run:
npm install
Configuration
Create a
In the root directory of the project, create a file named
.env.Add database credentials to
Populate the
.envfile with your MySQL database connection details:DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=password DB_DATABASE=mysql_dbNote: Replace
localhost,3306,root,password,mysql_db, andyour_mysql_portwith your actual database host, port, username, password, database name, and desired server port respectively.
MCP JSON Configuration for IDEs (e.g., Cursor AI, VS Code)
To allow IDEs to automatically discover and interact with your MCP MySQL server, you can add the following JSON configuration to your IDE's .cursor/mcp.json file.
Docker Usage
This MCP server runs as a stdio application. Below are the instructions to build a Docker image and run the server within a container.
Build the Docker Image:
Navigate to the project directory containing the
Dockerfileandpackage.json, then run:docker build -t mcp_mysql_dheer .Run the Docker Container (as a stdio server):
When running the Docker container, you'll need to provide the MySQL database credentials as environment variables.
docker run -i mcp_mysql_dheer node index.js \ -e DB_HOST=your_mysql_host \ -e DB_USER=your_mysql_user \ -e DB_PASSWORD=your_mysql_password \ -e DB_DATABASE=your_mysql_database \ -e DB_PORT=your_mysql_portNote:
-iflag is crucial forSTDINto remain open, allowing the MCP client to communicate with the server.Replace
your_mysql_host,your_mysql_user,your_mysql_password,your_mysql_database, andyour_mysql_portwith your actual database connection details.
Usage (Example with a hypothetical MCP Client)
This server is designed to be consumed by an MCP client. Here's a conceptual example of how an MCP client might interact with these functionalities:
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.