MySQL MCP Server

695
  • Linux
  • Apple

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

npx -y https://github.com/yuki777/mysql-mcp-server --host 127.0.0.1 --port 13306 --user root

option

optionexplanationDefault value
-h, --host <host>MySQL Hostlocalhost
-p, --port <port>MySQL Port13306
-u, --user <user>MySQL Userroot
--password <password>MySQL Password(empty string)
-d, --database <database>Default Database(option)
-c, --config <path>Configuration File Path(option)
--auto-connectAutomatically connect to database at server startupfalse
--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 Rows1000
--debugDebug Modefalse

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):

{ "server": { "port": 3000, "host": "localhost" }, "mysql": { "host": "localhost", "port": 13306, "user": "root", "password": "yourpassword", "database": "mydb" }, "debug": false, "queryTimeout": 30000, "maxResultSize": 1000 }

If you use a configuration file:

npx -y https://github.com/yuki777/mysql-mcp-server -c ./mysql-mcp-config.json

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:

  1. Avoid port conflicts : No specific ports are used, so no port conflict issues occur
  2. Improved security : No network communication is used, reducing the risk of network-level attacks
  3. 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 NameexplanationRequired parameters
connect_databaseConnect to the databasehost, port, user
disconnect_databaseDisconnects the current database connectionnone
get_connection_statusGets the status of the database connectionnone

SQL Query Operations

Tool NameexplanationRequired parameters
execute_queryRun a MySQL queryquery: SQL statement
get_databasesGet a list of available databasesnone
get_tablesGets a list of tables in a specified database.database (optional)
describe_tableGets 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:

  1. Start without connection information : The server can be started without database connection information.
  2. Multiple database connections : You can switch connections to different databases after the server is started.
  3. Simple installation : just run npx -y https://github.com/yuki777/mysql-mcp-server

How to use Connection Management

  1. Start the server without auto-connect :
    npx -y https://github.com/yuki777/mysql-mcp-server
  2. Connect to the database using the connection tool :
    { "type": "tool_call", "request_id": "req_1", "tool": "connect_database", "arguments": { "host": "localhost", "port": 3306, "user": "root", "password": "your_password", "database": "your_db" } }
  3. Check your connection status :
    { "type": "tool_call", "request_id": "req_2", "tool": "get_connection_status", "arguments": {} }
  4. Loss of connection :
    { "type": "tool_call", "request_id": "req_3", "tool": "disconnect_database", "arguments": {} }

Test script

The repository contains a test script called test-connection-management.js , which you can use to test the connection management functionality:

node test-connection-management.js

Developer Information

Setting up your development environment

# リポジトリのクローン git clone [repository-url] cd mysql-mcp-server # 依存関係のインストール npm install # 開発モードでの実行 npm run dev

Build

npm run build

license

ISC

contribution

Bug reports, feature requests and pull requests are welcome.

-
security - not tested
F
license - not found
-
quality - not tested

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).

  1. 要件
    1. 機能
      1. インストールと使用方法
        1. NPXでの一時実行
        2. オプション
        3. 接続情報の保存と再利用
        4. 設定ファイルの使用
      2. 通信方式
        1. 注意点
      3. 提供されるMCPツール
        1. データベース接続管理
        2. SQLクエリ操作
      4. 接続管理機能
        1. 接続管理の使用方法
        2. テスト用スクリプト
      5. 開発者向け情報
        1. 開発環境のセットアップ
        2. ビルド
      6. ライセンス
        1. 貢献

          Related MCP Servers

          • -
            security
            A
            license
            -
            quality
            A 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,219
            133
            TypeScript
            MIT License
            • Linux
            • Apple
          • -
            security
            A
            license
            -
            quality
            A 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,219
            TypeScript
            MIT License
            • Linux
            • Apple
          • -
            security
            A
            license
            -
            quality
            A 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,219
            MIT License
          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol (MCP) server that enables AI assistants to interact with MySQL databases by executing SQL queries and checking database connectivity.
            Last updated -
            TypeScript
            MIT License
            • Apple
            • Linux

          View all related MCP servers

          ID: 6mng75cdh9