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.1.tar.gz (9.1 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.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_mysql_tool-0.2.1.tar.gz
  • Upload date:
  • Size: 9.1 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.1.tar.gz
Algorithm Hash digest
SHA256 ad53e3dae531176cd28330c1b5ffb22afae9e631304709f462d6850022f4f5a3
MD5 beaf3ba7c099f597f512abb92c396936
BLAKE2b-256 73305760e0c058d924caba44a15b2b770721c8a648d714d467d69d046bcfd9e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcp_mysql_tool-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b89b23b21f2f12a3e5fec04cfa76a94319a37c3e7aa7abef5e564c21166d6be
MD5 03684b2910bca35e560af3fdf98d731d
BLAKE2b-256 9c209e614f1ab1f7a14fd4a1d30ad12225a67b74b5e4f258d222a7acd3ddecf4

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