MySQL MCP Server

MySQL MCP Server

Provides secure access to MySQL databases for AI assistants, enabling safe SQL queries, table information retrieval, and data insertion with built-in security protections.

Category
Visit Server

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:

Variable Default Description
MYSQL_HOST localhost MySQL server hostname
MYSQL_PORT 3306 MySQL server port
MYSQL_USER root MySQL username
MYSQL_PASSWORD (empty) MySQL password
MYSQL_DB mysql Default database name
MYSQL_TIMEZONE +00:00 MySQL 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": "john@example.com"}
    

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

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
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
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
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
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
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