Enables direct interaction with MySQL databases through SQL query execution, database exploration, schema understanding, and permission-controlled data operations including SELECT, INSERT, UPDATE, DELETE, and DDL commands.
MySQL MCP Server
Give Claude AI direct access to your MySQL databases through the Model Context Protocol (MCP).
MySQL MCP Server enables Claude Desktop and Claude Code to execute SQL queries, explore databases, and interact with your MySQL data - all through a secure, permission-controlled interface.
Table of Contents
What is MCP?
The Model Context Protocol is an open standard that lets AI assistants like Claude securely connect to external data sources and tools. This MySQL MCP Server implements that protocol, giving Claude the ability to:
š Query your databases - Execute SQL queries with natural language
š Explore your data - Browse tables, understand schema, and analyze data
š Switch contexts - Move between different databases seamlessly
š Stay secure - Every operation is validated against your permission rules
Quick Start
Installation
Setup Guide for Claude Desktop
Important: You must generate an API token before configuring Claude Desktop. Follow these steps in order:
Step 1: Generate Your API Token
Before setting up Claude Desktop, generate an authentication token:
This will output something like:
Copy this token - you'll need it in the next step.
Step 2: Configure Claude Desktop
Add this configuration to your Claude Desktop config file:
Config file location:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Configuration:
Replace paste-your-token-here with the token from Step 1.
Note: If you installed globally with
npm install -g, you can also use"command": "mysql-mcp-webui"without theargsfield.
Step 3: Start Claude Desktop
Save the config file
Restart Claude Desktop completely (quit and reopen)
Claude Desktop will automatically start the MCP server
The Web UI will be available at http://localhost:9274
Step 4: Configure MySQL Connections
Open the Web UI at http://localhost:9274:
Login with default credentials:
admin/adminYou'll be prompted to change the password on first login
Add a MySQL connection:
Enter your MySQL server host, port, username, and password
Click "Test Connection" to verify it works
Discover databases:
Click "Discover Databases" to auto-detect all available databases
Set permissions:
For each database, enable the operations Claude can perform
Start with SELECT only for production databases
Set a default connection (optional):
Makes it easier to start new Claude Desktop instances
Step 5: Start Using Claude
You're all set! Now you can ask Claude to query your databases:
Troubleshooting Setup
"AUTH_TOKEN is required" error:
Make sure you ran
mysql-mcp-webui --generate-tokenfirstVerify the token is correctly pasted in the config file (no extra spaces or quotes)
Check that the config file is valid JSON
Claude Desktop doesn't see the MCP server:
Verify the config file location is correct for your OS
Restart Claude Desktop completely (quit and reopen, don't just reload)
Check for syntax errors in the JSON (use a JSON validator)
Web UI not accessible:
The server only starts when Claude Desktop launches it
Check if port 9274 is already in use:
lsof -i :9274(macOS/Linux)Try a different port by adding
"HTTP_PORT": "3001"to theenvsection
Setup Guide for Claude Code (HTTP Mode)
Claude Code can connect to MySQL MCP Server via HTTP mode, allowing remote access and multiple concurrent sessions.
Option 1: Using npx (No Docker)
Step 1: Start the Server
Step 2: Generate API Token
Open the Web UI at http://localhost:9274 (or your custom port):
Login with default credentials:
admin/adminNavigate to API Keys section
Click Generate New API Key
Copy the generated key
Step 3: Configure Claude Code
Add this to your Claude Code MCP settings (.claude/mcp_settings.json or via UI):
For remote/production deployment, use your domain:
Option 2: Using Docker (Recommended for Production)
Step 1: Deploy with Docker
Quick Start (No cloning needed):
Using docker-compose (for advanced configuration):
Step 2: Get API Key
Step 3: Configure Claude Code
Step 4: Configure MySQL Connections
Same as Claude Desktop setup - use the Web UI to:
Add MySQL connections
Discover databases
Set permissions
Optionally set a default connection
Docker Deployment Options
Basic HTTP Mode:
Custom Port:
With HTTPS (Production):
Using docker-compose.yml:
The repository includes a ready-to-use docker-compose.yml:
For detailed production deployment with HTTPS, rate limiting, and security hardening, see DEPLOYMENT.md.
The Four MCP Tools
Once configured, Claude can use four powerful tools to interact with your MySQL databases:
1. mysql_query - Execute SQL Queries
Claude can run SQL queries against your active database with automatic permission validation.
Example conversation:
What happens:
Claude generates appropriate SQL based on your request
Query is validated against database permissions (e.g., must have SELECT permission)
Executes in a transaction (auto-rollback on error)
Results formatted for easy reading
2. list_databases - Explore Available Databases
Claude can see all databases you've configured and their permissions.
Example conversation:
What happens:
Lists all databases from your active MySQL connection
Shows which database is currently active
Displays configured permissions for each
Optionally includes metadata (table count, size)
3. switch_database - Change Active Database
Claude can switch between databases within your MySQL connection using database aliases.
Example conversation:
What happens:
Validates database exists in your connection
Switches active database for all future queries
Returns new database's permissions
Persists the change (survives restarts)
4. add_connection - Create New MySQL Connections
Claude can add new MySQL database connections programmatically without using the Web UI.
Example conversation:
What happens:
Validates connection credentials by testing the connection
Encrypts password with AES-256-GCM before storage
Saves connection to the database
Auto-discovers all available databases
Adds discovered databases with default SELECT permission
Returns connection details and discovery results
How It Works
Permission System
Every database has granular permissions. Configure what Claude can do:
Permission | What It Allows | Example Use Case |
SELECT | Read data from tables | "Show me all orders from last week" |
INSERT | Add new records | "Create a new user account" |
UPDATE | Modify existing records | "Update the user's email address" |
DELETE | Remove records | "Delete spam comments" |
CREATE | Create tables/indexes | "Create a new analytics table" |
ALTER | Modify table structure | "Add a new column to users table" |
DROP | Delete tables/databases | "Drop the temporary test table" |
TRUNCATE | Empty tables | "Clear all data from logs table" |
Best Practice: Start with SELECT only for production databases. Grant additional permissions as needed.
Use Cases
Data Analysis
Database Exploration
Schema Understanding
Data Migration
Debugging
Configuration Options
Transport Modes
stdio Mode (Default for Claude Desktop):
MCP communication via stdin/stdout (managed by Claude Desktop)
Web UI runs on separate HTTP port (default: 9274, customizable)
Each Claude Desktop instance spawns its own process
Perfect for local development and desktop use
Custom port in stdio mode:
HTTP Mode (For Claude Code and remote access):
MCP communication via HTTP endpoint at
/mcpSupports multiple concurrent sessions with isolation
Includes REST API and Web UI on same port
Perfect for remote access, Docker deployment, and Claude Code
Environment Variables
Variable | Default | Description |
|
| Transport mode:
or
|
|
| Port for Web UI, API, and MCP endpoint (customizable in both modes) |
| - | API key (required for stdio mode) |
|
| Environment:
or
|
|
| MCP response format:
or
(see below) |
|
| Enable HTTPS/TLS |
| - | Path to SSL certificate (required if HTTPS enabled) |
| - | Path to SSL private key (required if HTTPS enabled) |
| (auto-generated) | Secret for JWT tokens (optional in development, recommended for production) |
|
| JWT token expiration (e.g., 1h, 24h, 7d, 30d) |
|
| Enable rate limiting |
|
| Rate limit window in milliseconds (15 minutes) |
|
| Maximum requests per window |
TOON Format (Token Optimization)
MySQL MCP Server supports TOON (Token-Oriented Object Notation), an optimized format for returning query results to Claude with ~40% fewer tokens compared to JSON.
When to use TOON:
Large query results (100+ rows)
Cost-sensitive applications where token usage matters
Maximizing context window efficiency
How to enable:
For Claude Desktop (stdio mode):
For Claude Code / HTTP mode (per-client via header):
For Docker/HTTP mode (server-wide via environment):
Priority order for HTTP mode:
X-Response-Formatheader (per-client) - RecommendedMCP_RESPONSE_FORMATenvironment variable (server-wide)Default:
json
Example comparison:
Standard JSON response (verbose):
TOON format (compact):
Benefits:
ā ~40% fewer tokens for tabular data
ā Better Claude comprehension on structured data
ā Explicit row counts help LLM validation
ā Works in both stdio and HTTP modes
ā HTTP mode: Per-client configuration via
X-Response-Formatheader (different Claude Code instances can use different formats on the same server)
Note: TOON is optional. The default JSON format works perfectly fine for most use cases.
Learn more about TOON: github.com/toon-format/toon
Web UI Features
Access the management interface at http://localhost:9274
Dashboard - Overview of connections and activity
Connections - Manage MySQL server connections with enable/disable controls
Databases - Configure permissions, enable/disable databases, and manage custom aliases
Browser - Explore tables, view data, check indexes
Query Editor - Test SQL queries with syntax highlighting
API Keys - Manage authentication tokens
Users - Multi-user access control
Logs - Audit trail of all MCP tool calls
Dark Mode - System preference detection
New in v0.1.0
Database Aliases - Create custom, user-friendly names for your databases
Connection Controls - Enable/disable connections to control which are active
add_connection Tool - Claude can now add MySQL connections programmatically
Security
Built-in Protections
ā Permission Validation - Every query checked against database permissions ā SQL Parsing - Validates query type before execution ā Transaction Safety - Auto-rollback on errors ā Password Encryption - AES-256-GCM for MySQL passwords ā API Key Authentication - Token-based access control ā Request Logging - Complete audit trail ā Rate Limiting - Prevent abuse ā Input Sanitization - SQL injection prevention
Best Practices
Use Read-Only Permissions for production databases initially
Create Dedicated MySQL Users with limited privileges
Rotate API Keys Regularly via the Web UI
Review Audit Logs to monitor Claude's database access
Enable Only Required Databases - disable others
Use HTTPS in Production for remote access
Multi-Instance Support
Run multiple Claude Desktop instances or sessions safely:
stdio mode: Each Claude Desktop instance gets its own process
HTTP mode: Multiple sessions with isolated state
Concurrent access: Safe SQLite writes with WAL mode
Session cleanup: Automatic cleanup of inactive sessions (30 min)
Set a default connection in Web UI so all new instances start with the same setup.
Troubleshooting
MCP server fails to start with AUTH_TOKEN error
Symptom: Claude Desktop logs show "AUTH_TOKEN environment variable is required" or "Invalid AUTH_TOKEN provided"
Solution:
Generate a new token (if you haven't already):
mysql-mcp-webui --generate-tokenCopy the generated token from the output
Update your Claude Desktop config file with the new token:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Verify the JSON syntax is correct (no extra spaces, quotes, or commas)
Restart Claude Desktop completely (quit and reopen)
Note: You must generate the token before starting Claude Desktop, not after.
Claude can't connect to MCP server
Check Claude Desktop config file syntax (valid JSON)
Generate a new API key if needed:
mysql-mcp-webui --generate-tokenVerify the token is correctly pasted in the config file
Restart Claude Desktop completely (quit and reopen, not just reload)
Check Web UI is accessible at http://localhost:9274
Permission denied errors
Open Web UI ā Databases
Verify database has required permissions enabled
Check database is enabled (not disabled)
Ensure MySQL user has actual database permissions
Connection errors
Test connection in Web UI (Connections page ā Test button)
Verify MySQL server is running and accessible
Check firewall rules
Confirm MySQL credentials are correct
Port already in use
Advanced Usage
Custom Installation Path
Production Deployment
See DEPLOYMENT.md for:
Docker deployment
HTTPS/TLS configuration
Rate limiting setup
Multi-instance architecture
Security hardening
Development
See README_DEVELOPMENT.md for:
Architecture details
API documentation
Development setup
Contributing guidelines
CLI Commands
What's New in v0.1.4
š¦ Official TOON Library - Integrated official
@toon-format/toonlibrary for proper nested data handlingšļø Better Nested Structures - Proper indentation-based encoding for nested objects and arrays
š Smart Formatting - Automatic format detection for optimal representation (tabular, list, or inline)
ā” Improved Efficiency - Better token optimization for complex MySQL JSON column data
šÆ Dotted-Key Folding - Compact representation for single-key chains (e.g.,
config.db.host: localhost)š ļø Maintained Library - Official library ensures ongoing spec compliance and updates
Previous Updates
v0.1.0:
š§ New MCP Tool: add_connection - Claude can now create MySQL connections programmatically
š·ļø Database Aliasing - Create custom, user-friendly names for databases
šļø Connection Management - Enable/disable connections to control which are active
v0.0.7:
š Enhanced Documentation - New user-focused README with MCP workflow examples
š Documentation Reorganization - Technical details moved to README_DEVELOPMENT.md
Resources
Documentation: GitHub Repository
Issues & Support: GitHub Issues
Model Context Protocol: modelcontextprotocol.io
Development Guide: README_DEVELOPMENT.md
Deployment Guide: DEPLOYMENT.md
Changelog: CHANGELOG.md
License
MIT License - see LICENSE file for details.
Acknowledgments
Built with Model Context Protocol by Anthropic
Powers Claude Desktop and Claude Code
Created by Yash Agarwal
Ready to give Claude access to your databases? Install now and start exploring your data with natural language! š
This server cannot be installed