mysql-mcp

mysql-mcp

Enables AI clients to interact with MySQL databases through read-only queries, with optional write capabilities in a controlled, auto-rolled-back manner.

Category
Visit Server

README

@maxlmgc/mysql-mcp

MySQL MCP Server — a secure, read-only-by-default MySQL integration for AI clients via the Model Context Protocol.

中文文档

Tools

Tool Description Read-only mode
sql_query Execute SELECT / SHOW / DESCRIBE / EXPLAIN queries Allowed
sql_list_tables List all tables in the current database Allowed
sql_table_schema Get column structure and comments of a table Allowed
sql_execute Execute INSERT / UPDATE / DELETE (auto-rolled back) Blocked

Environment Variables

Database Connection (required)

Variable Description Default
MYSQL_HOST Database host -
MYSQL_PORT Database port 3306
MYSQL_USER Database user -
MYSQL_PASS Database password (empty)
MYSQL_DB Database name -

Read-only Mode

Variable Description Default
MYSQL_READONLY Set to false to disable read-only mode true (enabled)
MYSQL_READONLY_PREFIXES Custom SQL keyword whitelist (comma-separated, overrides defaults) SELECT,SHOW,DESCRIBE,DESC,EXPLAIN,WITH

Connection Pool

Variable Description Default
MYSQL_CONNECTION_LIMIT Max connections in pool 10
MYSQL_MULTIPLE_STATEMENTS Set to false to disable multi-statement execution true

Installation

npm install @maxlmgc/mysql-mcp

Usage

MCP Client Configuration

Add to your MCP client configuration:

{
  "mcpServers": {
    "mysql-mcp": {
      "command": "npx",
      "args": ["-y", "@maxlmgc/mysql-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASS": "your_password",
        "MYSQL_DB": "your_database"
      }
    }
  }
}

Read-only Mode (default)

By default only query operations are allowed; sql_execute is not exposed.

Disable Read-only Mode

"env": {
  "MYSQL_HOST": "localhost",
  "MYSQL_USER": "root",
  "MYSQL_DB": "your_database",
  "MYSQL_READONLY": "false"
}

Custom Whitelist

Only allow SELECT and SHOW:

"env": {
  "MYSQL_HOST": "localhost",
  "MYSQL_USER": "root",
  "MYSQL_DB": "your_database",
  "MYSQL_READONLY_PREFIXES": "SELECT,SHOW"
}

Security

  • Read-only by default: sql_execute is not registered in read-only mode
  • SQL injection prevention: Table names validated with regex; parameterized queries used
  • Startup validation: Missing required env vars cause immediate failure
  • Transaction rollback: sql_execute runs in a transaction that is always rolled back
  • Dual-layer protection: SQL validation at both tool layer and connection pool layer

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured