Skip to main content

MySQL MCP Server for AI database operations

Project description

MCP MySQL Tool

A powerful and comprehensive MySQL Model Context Protocol (MCP) server that allows AI assistants to interact with MySQL databases effortlessly. Features 11 specialized tools for different database operations.

🚀 Features

Core Operations

  • mysql_query - Execute any SQL query with parameters
  • mysql_select - Smart SELECT with WHERE, LIMIT, ORDER BY
  • mysql_insert - Insert data with key-value pairs
  • mysql_update - Update with required WHERE clause (safety)
  • mysql_delete - Delete with required WHERE clause (safety)

Database Exploration

  • mysql_show_databases - List all available databases
  • mysql_show_tables - List all tables in current database
  • mysql_describe_table - Show table structure and columns
  • mysql_table_info - Comprehensive table analysis (structure, indexes, constraints)
  • mysql_count_rows - Count rows with optional WHERE conditions

Advanced Features

  • mysql_custom_connection - Execute queries with custom host/user/password
  • Safe parameterized queries to prevent SQL injection
  • Environment-based configuration
  • Comprehensive error handling
  • JSON responses optimized for AI parsing

📦 Installation

pip install mcp-mysql-tool

⚙️ Configuration

Environment Variables

Set these environment variables for default connection:

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=your_username
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database  # Optional

MCP Client Configuration

Add to your MCP client configuration:

{
	"mcpServers": {
		"mysql": {
			"command": "mcp-mysql-tool",
			"env": {
				"MYSQL_HOST": "localhost",
				"MYSQL_USER": "root",
				"MYSQL_PASSWORD": "password",
				"MYSQL_DATABASE": "mydb"
			}
		}
	}
}

🛠️ Usage Examples

Basic Operations

# List all databases
mysql_show_databases()

# Smart SELECT with conditions
mysql_select({
  "table": "users",
  "columns": ["id", "name", "email"],
  "where": "active = 1",
  "limit": 10,
  "order_by": "created_at DESC"
})

# Safe INSERT
mysql_insert({
  "table": "users",
  "data": {
    "name": "John Doe",
    "email": "john@example.com",
    "active": 1
  }
})

# Safe UPDATE (WHERE required)
mysql_update({
  "table": "users",
  "data": {"last_login": "2024-01-01"},
  "where": "id = 123"
})

Custom Connection

# Connect to different server
mysql_custom_connection({
  "host": "remote-server.com",
  "user": "remote_user",
  "password": "remote_pass",
  "database": "remote_db",
  "query": "SELECT COUNT(*) FROM products"
})

Table Analysis

# Get comprehensive table info
mysql_table_info({"table_name": "users"})

# Count rows with conditions
mysql_count_rows({
  "table": "orders",
  "where": "status = 'completed' AND created_at > '2024-01-01'"
})

🔒 Safety Features

  • Required WHERE clauses for UPDATE and DELETE operations
  • Parameterized queries to prevent SQL injection
  • Connection isolation for custom connections
  • Comprehensive error handling with detailed error codes
  • Input validation for all parameters

📋 Available Tools

Tool Description Safety
mysql_query Execute any SQL query ⚠️ Raw SQL
mysql_select Smart SELECT builder ✅ Safe
mysql_insert Insert with key-value pairs ✅ Safe
mysql_update Update with required WHERE 🔒 WHERE required
mysql_delete Delete with required WHERE 🔒 WHERE required
mysql_custom_connection Custom host/user/password ⚠️ Raw SQL
mysql_show_databases List databases ✅ Safe
mysql_show_tables List tables ✅ Safe
mysql_describe_table Table structure ✅ Safe
mysql_table_info Comprehensive table analysis ✅ Safe
mysql_count_rows Count with optional WHERE ✅ Safe
mysql_test_connection Test connection (env/custom) ✅ Safe

🎯 Perfect for AI

This MCP server is specifically designed to be AI-friendly:

  • Structured responses in JSON format
  • Clear error messages with error codes
  • Flexible parameters for different use cases
  • Safety guardrails to prevent dangerous operations
  • Comprehensive toolset for all database needs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_mysql_tool-0.2.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_mysql_tool-0.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_mysql_tool-0.2.0.tar.gz.

File metadata

  • Download URL: mcp_mysql_tool-0.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for mcp_mysql_tool-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bcfeb7d59983d65b85aa89cae8f84d55a366cca20627b85a4803234084135308
MD5 bf7459757934a58f196ea04d58b42e5c
BLAKE2b-256 3de4f9549b01d4a472d25488ff64e92ef2392fc72708e2db1803c82fa667e607

See more details on using hashes here.

File details

Details for the file mcp_mysql_tool-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_mysql_tool-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for mcp_mysql_tool-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e516d1143bc20578baba826273874920a97352cc4dd5f1ffcd928ebceb847dd
MD5 d2baec2f205d51cfd9d40be3d5dc7ecd
BLAKE2b-256 4d0264d82f829abe23ef3d60e643c0810c7081125f8bca6bbd032861d3637a2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page