MCP Hub
Back to servers

easy-mysql-mcp

Enables AI assistants to inspect and query a MySQL database through safe, structured tools, including schema discovery and read-only queries.

glama
Updated
May 3, 2026

easy-mysql-mcp

A lightweight Model Context Protocol (MCP) server that lets AI assistants inspect and query a MySQL database through a safe, structured tool interface.

This project uses Node.js, TypeScript, the official MCP SDK, and mysql2/promise. It runs over stdio, so it can be used directly by MCP clients such as Claude Desktop.

Features

  • MySQL connection pooling powered by mysql2/promise
  • Read-only query tool for data retrieval
  • Execute tool for data modification statements
  • Schema discovery tools for tables, views, indexes, and triggers
  • Query plan inspection with EXPLAIN
  • Current user and privilege inspection
  • stdout protection to prevent non-MCP logs from polluting the stdio protocol

Requirements

  • Node.js 18 or newer
  • npm
  • A reachable MySQL-compatible database

Installation

Run the server directly with npx:

npx -y easy-mysql-mcp

For local development after cloning the repository:

cd easy-mysql-mcp
npm install
npm run build

Configuration

Configure the server with environment variables. You can provide them through your MCP client configuration or by creating a local .env file.

VariableRequiredDefaultDescription
MYSQL_HOSTYes-MySQL host name or IP address
MYSQL_PORTNo3306MySQL port
MYSQL_USERYes-MySQL user name
MYSQL_PASSWORDYes-MySQL password
MYSQL_DATABASEYes-Default database/schema
MYSQL_CONNECTION_LIMITNo10Maximum number of active pool connections
MYSQL_MAX_IDLENo10Maximum number of idle pool connections
MYSQL_IDLE_TIMEOUTNo60000Idle connection timeout in milliseconds
MYSQL_QUEUE_LIMITNo0Maximum queued connection requests, where 0 means unlimited
MYSQL_WAIT_FOR_CONNECTIONSNotrueWhether the pool waits when all connections are busy
MYSQL_ENABLE_KEEP_ALIVENotrueWhether TCP keep-alive is enabled
MYSQL_KEEP_ALIVE_INITIAL_DELAYNo0Initial TCP keep-alive delay in milliseconds

Example .env:

MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database

Usage

Configure your MCP client to launch the package through npx.

For local development, build the TypeScript source first:

npm run build

Start the MCP server:

npm start

The server communicates over stdio and is normally launched by an MCP client rather than run manually.

Claude Desktop Example

Add the server to your claude_desktop_config.json:

{
  "mcpServers": {
    "easy-mysql-mcp": {
      "command": "npx",
      "args": ["-y", "easy-mysql-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Restart Claude Desktop after updating the configuration.

Available Tools

ToolDescription
mysql_queryExecute a SQL query intended for data retrieval, such as SELECT
mysql_executeExecute a data modification statement, such as INSERT, UPDATE, or DELETE
explain_queryRun EXPLAIN for a SQL query and return the execution plan
list_tablesList base tables in the current database, including approximate row counts and comments
list_viewsList views in the current database
describe_tableShow column information for one or more tables
describe_indexShow indexes for a table
list_triggersList triggers in the current database
get_current_privilegesShow the current MySQL user and grants

Security Notes

  • Use a dedicated MySQL user with the minimum permissions your assistant needs.
  • Prefer read-only database credentials if you only need inspection and reporting.
  • Be careful with mysql_execute, because it can modify data.
  • Do not commit .env files or real database credentials to GitHub.
  • Review generated SQL before running it against production data.

Development

npm run dev

This runs TypeScript in watch mode.

To create a production build:

npm run build

Project Structure

src/
  db.ts       MySQL pool and query helpers
  index.ts    MCP server and tool registration
  proxy.ts    stdout protection for stdio-based MCP transport

License

ISC

Reviews

No reviews yet

Sign in to write a review