mcp mysql app
A Model Context Protocol (MCP) server that enables AI assistants to interact with MySQL databases by executing SQL queries and checking database connectivity.
A Model Context Protocol (MCP) server that enables AI assistants to interact with MySQL databases by executing SQL queries and checking database connectivity.
A Model Context Protocol (MCP) tools server implementation for interacting with MySQL databases through AI interfaces.
This project provides a set of tools that allow AI systems to connect to and query MySQL databases through the Model Context Protocol. It enables AI assistants to execute SQL queries and check database connectivity.
npm install
Clone this repository:
git clone <repository-url>
cd mcp-mysql-app
Install dependencies:
npm install
Create a .env
file in the root directory:
MYSQL_HOST=your_mysql_host
MYSQL_USER=your_mysql_username
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=your_database_name
MYSQL_PORT=3306
Build the project:
npm run build
The dist
folder is now ready to be used for configuration in various AI platforms.
Find your Cursor MCP configuration file:
C:Users<username>.cursormcp.json
~/.cursor/mcp.json
~/.cursor/mcp.json
Edit the file to add the MySQL MCP server configuration:
{
"mcpServers": {
"mysql": {
"command": "<path-to-node>",
"args": [
"<path-to-project>/dist/index.js"
],
"env": {
"MYSQL_HOST": "your_mysql_host",
"MYSQL_USER": "your_mysql_username",
"MYSQL_PASSWORD": "your_mysql_password",
"MYSQL_DATABASE": "your_database_name",
"MYSQL_PORT": "3306"
}
}
}
}
Replace the placeholders:
- <path-to-node>
: Path to your Node.js executable
- <path-to-project>
: Absolute path to your MCP MySQL App project directory
- MySQL environment variables with your actual database connection details
Example configuration:
{
"mcpServers": {
"mysql": {
"command": "C:nvm4wnodejsnode.exe",
"args": [
"H:mcpmy-mysqldistindex.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "password123",
"MYSQL_DATABASE": "todo_app",
"MYSQL_PORT": "3306"
}
}
}
}
Save the file and restart Cursor for the changes to take effect.
To use MCP MySQL Tools with Claude, you need to add configuration to Claude's settings file. Follow these steps:
{
"tools": {
"mysql": {
"command": "<path-to-node>",
"args": [
"<path-to-project>/dist/index.js"
],
"env": {
"MYSQL_HOST": "your_mysql_host",
"MYSQL_USER": "your_mysql_username",
"MYSQL_PASSWORD": "your_mysql_password",
"MYSQL_DATABASE": "your_database_name",
"MYSQL_PORT": "3306"
}
}
}
}
Replace the placeholders:
- <path-to-node>
: Path to your Node.js executable
- <path-to-project>
: Absolute path to your MCP MySQL App project directory
- MySQL environment variables with your actual database connection details
Example configuration:
{
"tools": {
"mysql": {
"command": "/usr/local/bin/node",
"args": [
"/Users/username/projects/mcp-mysql-app/dist/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "password123",
"MYSQL_DATABASE": "todo_app",
"MYSQL_PORT": "3306"
}
}
}
}
The basic principle is the same for other AI platforms that support MCP:
dist/index.js
file from this repositoryAfter configuration, your AI will have access to the following MySQL tools:
sql_check_connection
- Check if the MySQL connection is workingsql_query
- Execute SQL queries on the connected databaseOnce you've configured the MySQL tools in your AI environment, you can start using them by prompting the AI. Here are some examples:
In Cursor, you can simply ask Claude to perform MySQL-related tasks:
Here's an example workflow showing how you might use these tools:
"Check if the MySQL connection is working."
Claude will use the sql_check_connection
tool to verify the database connection.
"Show me all the databases on this MySQL server."
Claude will use the sql_query
tool with SHOW DATABASES;
.
"List all tables in the current database."
Claude will use the sql_query
tool with SHOW TABLES;
.
"Show me the first 10 records from the users table."
Claude will use the sql_query
tool with SELECT * FROM users LIMIT 10;
.
"Create a new table named 'products' with columns for id, name, price, and description."
Claude will use the sql_query
tool to create the table with an appropriate CREATE TABLE statement.
"Insert a new product with the name 'Smartphone', price 499.99, and description 'Latest model'."
Claude will use the sql_query
tool with an INSERT statement.
"Update the price of the 'Smartphone' product to 449.99."
Claude will use the sql_query
tool with an UPDATE statement.
These examples demonstrate how naturally you can interact with MySQL through your AI assistant once the tools are properly configured.
If you experience problems using this tool, please:
This project is licensed under the MIT License - see the LICENSE file for details.