Integrations
Connects to a MySQL database, allowing LLMs to execute SQL queries, retrieve database information (databases, tables, and table structures), with configurable query timeout and result size limits.
MySQL MCP Server
The MySQL Model Context Protocol (MCP) Server is a tool that allows you to connect to a local MySQL database and allow large language models (LLMs) to execute SQL queries against it.
Requirements
- Node.js : 20.0.0 or later
- MySQL : MySQL or MariaDB server version 5.7 or later
function
- Run MySQL queries : Run SQL queries directly from LLM
- Obtaining database information : List of databases, list of tables, confirm table structure
- MCP Compliant : Supports Model Context Protocol and can be integrated with LLM
- stdio communication : communicate with LLM using standard input/output, no port binding
- Save connection information : Save database connection information locally and reuse it
Installation and Usage
Temporary execution in NPX
option
option | explanation | Default value |
---|---|---|
-h, --host <host> | MySQL Host | localhost |
-p, --port <port> | MySQL Port | 13306 |
-u, --user <user> | MySQL User | root |
--password <password> | MySQL Password | (empty string) |
-d, --database <database> | Default Database | (option) |
-c, --config <path> | Configuration File Path | (option) |
--auto-connect | Automatically connect to database at server startup | false |
--server-port <port> | MCP server port (not used in stdio mode) | 3000 |
--server-host <host> | MCP server host (not used in stdio mode) | localhost |
--query-timeout <ms> | Query Timeout (ms) | 30000 |
--max-results <count> | Maximum Result Rows | 1000 |
--debug | Debug Mode | false |
Save and reuse connection information
MySQL MCP Server locally saves information about databases that it has successfully connected to, so that it can automatically reuse the connection information the next time it starts. Saved connection information is stored in .mysql-mcp-connections.json
file in the user's home directory.
Connection information includes:
- Hostname
- Port number
- Username
- password
- Database name (if set)
Using configuration files
You can also configure the connection information using a configuration file (in JSON format):
If you use a configuration file:
Communication method
MySQL MCP Server operates in "stdio" mode according to the MCP (Model Context Protocol), which means it does not bind to a specific port but communicates via standard input and output. This has the following advantages:
- Avoid port conflicts : No specific ports are used, so no port conflict issues occur
- Improved security : No network communication is used, reducing the risk of network-level attacks
- Simple Inter-Process Communication : Simplified communication with LLM
Important points to note
- In stdio mode, messages are sent in JSON format.
- You must send one JSON message per line
- Error information and connection logs are output to standard error (stderr).
MCP Tools Provided
Database Connection Management
Tool Name | explanation | Required parameters |
---|---|---|
connect_database | Connect to the database | host, port, user |
disconnect_database | Disconnects the current database connection | none |
get_connection_status | Gets the status of the database connection | none |
SQL Query Operations
Tool Name | explanation | Required parameters |
---|---|---|
execute_query | Run a MySQL query | query: SQL statement |
get_databases | Get a list of available databases | none |
get_tables | Gets a list of tables in a specified database. | database (optional) |
describe_table | Gets the structure of the specified table. | table |
Connection Management Function
MySQL MCP Server allows you to separate server startup and database connections. This approach provides the following benefits:
- Start without connection information : The server can be started without database connection information.
- Multiple database connections : You can switch connections to different databases after the server is started.
- Simple installation : just run
npx -y https://github.com/yuki777/mysql-mcp-server
How to use Connection Management
- Start the server without auto-connect :Copy
- Connect to the database using the connection tool :Copy
- Check your connection status :Copy
- Loss of connection :Copy
Test script
The repository contains a test script called test-connection-management.js
, which you can use to test the connection management functionality:
Developer Information
Setting up your development environment
Build
license
ISC
contribution
Bug reports, feature requests and pull requests are welcome.
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 tool that connects to local MySQL databases and enables large language models (LLMs) to execute SQL queries through the Model Context Protocol (MCP).
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.Last updated -1,219133TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server providing read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.Last updated -1,219TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.Last updated -1,219MIT License
- -securityAlicense-qualityA Model Context Protocol (MCP) server that enables AI assistants to interact with MySQL databases by executing SQL queries and checking database connectivity.Last updated -TypeScriptMIT License