mcpField
M
MySQL MCP Server

MySQL MCP Server

Local
github.com/SuMiaoALiDatabases2Updated 74w ago

About MySQL MCP Server

MySQL MCP Server exposes selected MySQL operations to AI assistants and other MCP clients. It supports querying and inserting data, inspecting tables, and provides safeguards such as parameterized queries and automatic SELECT limits.

Key features

  1. 01Run SELECT, INSERT, SHOW, and DESCRIBE
  2. 02Insert data with parameterization
  3. 03List tables and inspect schemas
  4. 04Parameterized queries and automatic limits
  5. 05Connection pooling

Use cases

  1. 01Query MySQL data from an MCP client
  2. 02Insert records with supplied values
  3. 03Review available tables and schemas

MCP support

The server exposes MySQL operations as MCP tools and database metadata and table structures as resources.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"mysql-mcp-server-sumiaoali": {
"command": "npx",
"args": [
"-y",
"mysql-mcp-server"
]
}
}
}
Run commandnpx -y mysql-mcp-server

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npmmysql-mcp-server

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MySQL MCP Server

A Model Context Protocol (MCP) server that provides secure MySQL database operations for AI assistants and other MCP clients.

Features

🛠️ Tools
  • execute_query - Execute safe SQL queries (SELECT, INSERT, SHOW, DESCRIBE)
  • get_table_info - Get detailed table structure information
  • insert_data - Convenient data insertion with automatic parameterization
  • list_tables - List all tables in the database
📊 Resources
  • Database Info (mysql://database/info) - Database metadata and table list
  • Table Structure (mysql://table/{table_name}) - Detailed table schema information
🔒 Security Features
  • Limited Operations: Only allows safe operations (SELECT, INSERT, SHOW, DESCRIBE)
  • SQL Injection Protection: Uses parameterized queries
  • Automatic LIMIT: Adds LIMIT clauses to SELECT queries to prevent large data dumps
  • Connection Pooling: Efficient database connection management

Installation

npm install mysql-mcp-server

Configuration

The server can be configured using environment variables:

VariableDefaultDescription
MYSQL_HOSTlocalhostMySQL server hostname
MYSQL_PORT3306MySQL server port
MYSQL_USERrootMySQL username
MYSQL_PASSWORD(empty)MySQL password
MYSQL_DBmysqlDefault database name
MYSQL_TIMEZONE+00:00MySQL timezone

Usage with MCP Clients

Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["mysql-mcp-server"],
      "env": {
        "MYSQL_HOST": "your-mysql-host",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your-username",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DB": "your-database"
      }
    }
  }
}
Other MCP Clients

For other MCP clients, use the server with stdio transport:

npx mysql-mcp-server

Development

Prerequisites
  • Node.js 18+
  • TypeScript
  • Access to a MySQL database
Setup
  1. Clone the repository:
git clone https://github.com/your-username/mysql-mcp-server.git
cd mysql-mcp-server
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your database configuration
  1. Build the server:
npm run build
Development Commands
# Build the server
npm run build

# Watch mode for development
npm run watch

# Debug with MCP Inspector
npm run inspector
Testing

You can test the server using the MCP Inspector:

npm run inspector

This will start the inspector and provide a URL to test the server in your browser.

Example Usage

Once connected through an MCP client, you can:

  1. List all tables:

    Use the list_tables tool
    
  2. Get table structure:

    Use get_table_info with table_name: "users"
    
  3. Query data:

    Use execute_query with sql: "SELECT * FROM users LIMIT 10"
    
  4. Insert data:

    Use insert_data with table_name: "users" and data: {"name": "John", "email": "[email protected]"}
    

Security Considerations

This server is designed with security in mind:

  • Read-mostly operations: Only SELECT, INSERT, SHOW, and DESCRIBE operations are allowed
  • No destructive operations: UPDATE and DELETE are explicitly forbidden
  • Parameterized queries: All user inputs are properly escaped
  • Connection limits: Uses connection pooling to prevent resource exhaustion
  • Query limits: Automatic LIMIT clauses prevent large data dumps

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Related

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.