Skip to main content
Glama

MySQL MCP Server

by yuki777

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

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

{ "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 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:

  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

local-only server

The server can only run on the client's local machine because it depends on local resources.

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. Requirements
    1. function
      1. Installation and Usage
        1. Temporary execution in NPX
        2. option
        3. Save and reuse connection information
        4. Using configuration files
      2. Communication method
        1. Important points to note
      3. MCP Tools Provided
        1. Database Connection Management
        2. SQL Query Operations
      4. Connection Management Function
        1. How to use Connection Management
        2. Test script
      5. Developer Information
        1. Setting up your development environment
        2. Build
      6. license
        1. contribution

          Related MCP Servers

          • -
            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 -
            MIT License
            • Apple
            • Linux
          • -
            security
            A
            license
            -
            quality
            An MCP server implementation that allows Large Language Models to directly interact with YugabyteDB databases, supporting table listing and read-only SQL queries.
            Last updated -
            8
            Apache 2.0
            • Apple
          • -
            security
            F
            license
            -
            quality
            A Model Context Protocol (MCP) server that converts natural language queries into SQL statements, allowing users to query MySQL databases using conversational language instead of writing SQL code.
            Last updated -
            3
          • -
            security
            F
            license
            -
            quality
            An MCP server that enables interaction with MySQL databases through the Model Context Protocol, allowing execution of SQL queries and database table listing operations from Cline AI.
            Last updated -

          View all related MCP servers

          MCP directory API

          We provide all the information about MCP servers via our MCP API.

          curl -X GET 'https://glama.ai/api/mcp/v1/servers/yuki777/mysql-mcp-server'

          If you have feedback or need assistance with the MCP directory API, please join our Discord server