The MySQL MCP Server provides an interface between AI models and MySQL databases, enabling AI agents to interact with, query, and analyze MySQL data through a structured protocol. This server follows the Model Context Protocol specification and can be used in web server or CLI modes.
You can install the MySQL MCP Server either globally or locally:
# Global installation
npm install -g mysql-mcp
# Local installation
npm install mysql-mcp
The MySQL MCP Server is available on Smithery.ai for easy integration with AI assistants:
Access the server at https://smithery.ai/server/@sussa3007/mysql-mcp
Configure your database connection parameters:
Use with supported AI platforms including:
Log in to Smithery.ai to save configurations and generate auth tokens.
Once connected, you can ask AI assistants to perform MySQL operations in your conversations.
After installing the package locally, configure it as follows:
npm link
in your project directory{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["mysql-mcp"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"MYSQL_READONLY": "true"
}
}
}
}
Check current database connection status.
No parameters required
Returns connection information including host, port, database, and username if connected.
Establish a MySQL database connection.
Parameters:
- host (optional): Database server hostname or IP
- port (optional): Database server port
- user (optional): Database username
- password (optional): Database password
- database (optional): Database name to connect to
Returns a connection success message or error details.
Close the current database connection.
No parameters required
Returns disconnection confirmation or error message.
Run an SQL query on the connected database.
Parameters:
- sql (required): SQL query to execute
- params (optional): Array of parameters for prepared statements
Returns query results as JSON or an error message.
Get all tables in the current database.
No parameters required
Returns a list of table names in the current database.
Get the structure details of a specific table.
Parameters:
- table (required): Name of the table to describe
Returns table structure including columns, types, keys, and other attributes.
Get all accessible databases on the server.
No parameters required
Returns a list of available database names.
Switch to a different database.
Parameters:
- database (required): Name of the database to switch to
Returns a confirmation message or error details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.