A fast, read-only MySQL Server for the Model Context Protocol (MCP) written in Go.
This project exposes safe MySQL introspection tools to Claude Desktop via MCP. Claude can explore databases, describe schemas, and execute controlled read-only SQL queries — ideal for secure development assistance, debugging, analytics, and schema documentation.
- Fully read-only (blocks all non-SELECT/SHOW/DESCRIBE/EXPLAIN)
- Multi-DSN Support: Connect to multiple MySQL or MariaDB instances, switch via tool
- MariaDB Support: Native compatibility with MariaDB 10.x and 11.x
- Vector Search (MySQL 9.0+): Similarity search on vector columns
- MCP tools:
- list_databases, list_tables, describe_table
- run_query (safe and row-limited)
- ping, server_info
- list_connections, use_connection (multi-DSN)
- vector_search, vector_info (MySQL 9.0+)
- Supports MySQL 8.0, 8.4, 9.0+ and MariaDB 10.x, 11.x
- Query timeouts, structured logging, audit logs
- Single Go binary
- Unit and integration tests (Testcontainers)
- Native integration with Claude Desktop MCP
brew install askdba/tap/mysql-mcp-serverUpdate local installation (after a new release):
brew update && brew upgrade mysql-mcp-serverdocker pull ghcr.io/askdba/mysql-mcp-server:latestNote: Docker image tags use the raw version number without a leading "v" (e.g.,
1.5.0, notv1.5.0).
Download the latest release from GitHub Releases.
Available for:
- macOS (Intel & Apple Silicon)
- Linux (amd64 & arm64)
- Windows (amd64)
git clone https://github.com/askdba/mysql-mcp-server.git
cd mysql-mcp-server
make buildBinary output: bin/mysql-mcp-server
brew install askdba/tap/mysql-mcp-server
mysql-mcp-server --versionThen follow the client-specific setup in the Claude Desktop, Claude Code, or Cursor IDE sections below.
Tip:
brew info askdba/tap/mysql-mcp-servershows a config reminder after install.
git clone https://github.com/askdba/mysql-mcp-server.git
cd mysql-mcp-server
make buildWhen running from a cloned repo you can also use the interactive setup script:
./scripts/quickstart.shThis will test your MySQL connection, optionally create a read-only MCP user, and generate your Claude Desktop configuration.
Environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
| MYSQL_DSN | Yes | – | MySQL DSN |
| MYSQL_MAX_ROWS | No | 200 | Max rows returned |
| MYSQL_QUERY_TIMEOUT_SECONDS | No | 30 | Query timeout |
| MYSQL_MCP_EXTENDED | No | 0 | Enable extended tools (set to 1) |
| MYSQL_MCP_JSON_LOGS | No | 0 | Enable JSON structured logging (set to 1) |
| MYSQL_MCP_TOKEN_TRACKING | No | 0 | Enable estimated token usage tracking (set to 1) |
| MYSQL_MCP_TOKEN_MODEL | No | cl100k_base | Tokenizer encoding to use for estimation |
| MYSQL_MCP_AUDIT_LOG | No | – | Path to audit log file |
| MYSQL_MCP_VECTOR | No | 0 | Enable vector tools for MySQL 9.0+ (set to 1) |
| MYSQL_MCP_HTTP | No | 0 | Enable REST API mode (set to 1) |
| MYSQL_HTTP_PORT | No | 9306 | HTTP port for REST API mode |
| MYSQL_HTTP_RATE_LIMIT | No | 0 | Enable rate limiting for HTTP mode (set to 1) |
| MYSQL_HTTP_RATE_LIMIT_RPS | No | 100 | Rate limit: requests per second |
| MYSQL_HTTP_RATE_LIMIT_BURST | No | 200 | Rate limit: burst size |
| MYSQL_MAX_OPEN_CONNS | No | 10 | Max open database connections |
| MYSQL_MAX_IDLE_CONNS | No | 5 | Max idle database connections |
| MYSQL_CONN_MAX_LIFETIME_MINUTES | No | 30 | Connection max lifetime in minutes |
| MYSQL_CONN_MAX_IDLE_TIME_MINUTES | No | 5 | Max idle time before connection is closed |
| MYSQL_PING_TIMEOUT_SECONDS | No | 5 | Database ping/health check timeout |
| MYSQL_HTTP_REQUEST_TIMEOUT_SECONDS | No | 60 | HTTP request timeout in REST API mode |
| MYSQL_SSL | No | – | Enable SSL/TLS for connections (true, false, skip-verify, preferred) |
Enable encrypted connections to MySQL servers:
| SSL Value | Description |
|---|---|
true |
Enable TLS with certificate verification |
false |
Disable TLS (default) |
skip-verify |
Enable TLS without certificate verification (self-signed certs) |
preferred |
Maps to skip-verify (Go MySQL driver limitation) |
Note: The Go MySQL driver doesn't support
tls=preferred. When you specifypreferred, it is automatically mapped toskip-verifyto ensure TLS is enabled.
Environment variable:
# Enable SSL for all connections
export MYSQL_SSL="true"
# Or per-connection SSL
export MYSQL_DSN_1_SSL="skip-verify"Config file:
connections:
production:
dsn: "user:pass@tcp(prod:3306)/db?parseTime=true"
ssl: "true"Connect to MySQL through an SSH bastion when the database is not directly reachable:
| Variable | Description |
|---|---|
MYSQL_SSH_HOST |
Bastion hostname |
MYSQL_SSH_USER |
SSH username |
MYSQL_SSH_KEY_PATH |
Path to private key file |
MYSQL_SSH_PORT |
SSH port (default 22) |
Environment variables:
export MYSQL_SSH_HOST="bastion.example.com"
export MYSQL_SSH_USER="deploy"
export MYSQL_SSH_KEY_PATH="$HOME/.ssh/id_rsa"
export MYSQL_DSN="user:pass@tcp(mysql.internal:3306)/mydb?parseTime=true"Config file:
connections:
production:
dsn: "user:pass@tcp(mysql.internal:3306)/mydb?parseTime=true"
ssh:
host: "bastion.example.com"
user: "deploy"
key_path: "~/.ssh/id_rsa"
port: 22 # optional, default 22Configure multiple MySQL connections using numbered environment variables:
# Default connection
export MYSQL_DSN="user:pass@tcp(localhost:3306)/db1?parseTime=true"
# Additional connections
export MYSQL_DSN_1="user:pass@tcp(prod-server:3306)/production?parseTime=true"
export MYSQL_DSN_1_NAME="production"
export MYSQL_DSN_1_DESC="Production database"
export MYSQL_DSN_1_SSL="true" # Enable SSL for this connection
export MYSQL_DSN_2="user:pass@tcp(staging:3306)/staging?parseTime=true"
export MYSQL_DSN_2_NAME="staging"
export MYSQL_DSN_2_DESC="Staging database"Or use JSON configuration:
export MYSQL_CONNECTIONS='[
{"name": "production", "dsn": "user:pass@tcp(prod:3306)/db?parseTime=true", "description": "Production", "ssl": "true"},
{"name": "staging", "dsn": "user:pass@tcp(staging:3306)/db?parseTime=true", "description": "Staging"}
]'As an alternative to environment variables, you can use a YAML or JSON configuration file.
Config file search order:
--config /path/to/config.yaml(command line flag)MYSQL_MCP_CONFIGenvironment variable./mysql-mcp-server.yaml(current directory)~/.config/mysql-mcp-server/config.yaml(user config)/etc/mysql-mcp-server/config.yaml(system config)
Example config file (mysql-mcp-server.yaml):
# Database connections
connections:
default:
dsn: "user:pass@tcp(localhost:3306)/mydb?parseTime=true"
description: "Local development database"
production:
dsn: "readonly:pass@tcp(prod:3306)/prod?parseTime=true"
description: "Production (read-only)"
ssl: "true" # Enable TLS with certificate verification
# Query settings
query:
max_rows: 200
timeout_seconds: 30
# Connection pool
pool:
max_open_conns: 10
max_idle_conns: 5
conn_max_lifetime_minutes: 30
# Features
features:
extended_tools: true
vector_tools: false
# HTTP/REST API (optional)
http:
enabled: false
port: 9306Command line options:
# Use specific config file
mysql-mcp-server --config /path/to/config.yaml
# Validate config file
mysql-mcp-server --validate-config /path/to/config.yaml
# Print current configuration as YAML
mysql-mcp-server --print-config
# Silent mode: suppress INFO/WARN logs (only errors to stderr)
mysql-mcp-server --silent --config /path/to/config.yaml
# Daemon mode: run HTTP server in background (Unix; use with MYSQL_MCP_HTTP=1)
MYSQL_MCP_HTTP=1 mysql-mcp-server --daemon --config /path/to/config.yamlSilent and daemon mode: Use -s / --silent to reduce log noise in production (INFO and WARN are suppressed; ERROR still goes to stderr). Use -d / --daemon to run the HTTP server detached in the background on Unix. For long-running services, use the example systemd unit or launchd plist. See Silent and daemon mode for details.
Priority: Environment variables override config file values, allowing:
- Base configuration in file
- Environment-specific overrides via env vars
- Docker/K8s secret injection via env vars
See examples/config.yaml and examples/config.json for complete examples.
Example:
export MYSQL_DSN="root:password@tcp(127.0.0.1:3306)/mysql?parseTime=true"
export MYSQL_MAX_ROWS=200
export MYSQL_QUERY_TIMEOUT_SECONDS=30Run:
make runCheck the installed version:
mysql-mcp-server --versionOutput:
mysql-mcp-server v1.6.0
Build time: 2025-12-21T11:43:11Z
Git commit: a1b2c3d
Edit your Claude Desktop configuration file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
Linux:
~/.config/Claude/claude_desktop_config.json
Add:
{
"mcpServers": {
"mysql": {
"command": "mysql-mcp-server",
"env": {
"MYSQL_DSN": "user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
"MYSQL_MAX_ROWS": "200",
"MYSQL_MCP_EXTENDED": "1"
}
}
}
}Note: If Claude Desktop cannot find the binary, replace
"mysql-mcp-server"with the full path fromwhich mysql-mcp-server.
Restart Claude Desktop.
Cursor IDE supports the Model Context Protocol (MCP). Configure it to use mysql-mcp-server:
Edit your Cursor MCP configuration file:
macOS:
~/.cursor/mcp.json
Windows:
%APPDATA%\Cursor\mcp.json
Linux:
~/.config/Cursor/mcp.json
Add:
{
"mcpServers": {
"mysql": {
"command": "mysql-mcp-server",
"env": {
"MYSQL_DSN": "root:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
"MYSQL_MAX_ROWS": "200",
"MYSQL_MCP_EXTENDED": "1"
}
}
}
}With Docker:
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MYSQL_DSN=root:password@tcp(host.docker.internal:3306)/mydb?parseTime=true",
"-e", "MYSQL_MCP_EXTENDED=1",
"ghcr.io/askdba/mysql-mcp-server:latest"
]
}
}
}Restart Cursor after saving the configuration.
Claude Code supports MCP servers via the CLI or a project-scoped .mcp.json file.
claude mcp add --transport stdio \
--env MYSQL_DSN="user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true" \
--env MYSQL_MCP_EXTENDED=1 \
mysql -- mysql-mcp-serverThis repo includes a .mcp.json that Claude Code auto-discovers when you open the project. Set your DSN in the shell before starting Claude Code:
export MYSQL_DSN="user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true"
claude # start Claude Code — MySQL tools will be available automaticallyTo use the same config in your own project, copy .mcp.json to your project root and set MYSQL_DSN in your shell.
Verify the integration by asking Claude Code: "List all databases on this MySQL server."
Returns non-system databases.
Input:
{ "database": "employees" }Input:
{ "database": "employees", "table": "salaries" }Input:
{ "sql": "SELECT id, name FROM users LIMIT 5" }Optional database context:
{ "sql": "SELECT * FROM users LIMIT 5", "database": "myapp" }- Rejects non-read-only SQL
- Enforces row limit
- Enforces timeout
Tests database connectivity and returns latency.
Output:
{ "success": true, "latency_ms": 2, "message": "pong" }Returns MySQL server details.
Output:
{
"version": "8.0.36",
"version_comment": "MySQL Community Server - GPL",
"uptime_seconds": 86400,
"current_database": "myapp",
"current_user": "mcp@localhost",
"character_set": "utf8mb4",
"collation": "utf8mb4_0900_ai_ci",
"max_connections": 151,
"threads_connected": 5
}List all configured MySQL connections.
Output:
{
"connections": [
{"name": "production", "dsn": "user:****@tcp(prod:3306)/db", "active": true},
{"name": "staging", "dsn": "user:****@tcp(staging:3306)/db", "active": false}
],
"active": "production"
}Switch to a different MySQL connection.
Input:
{ "name": "staging" }Output:
{
"success": true,
"active": "staging",
"message": "Switched to connection 'staging'",
"database": "staging_db"
}Enable with:
export MYSQL_MCP_VECTOR=1Perform similarity search on vector columns.
Input:
{
"database": "myapp",
"table": "embeddings",
"column": "embedding",
"query": [0.1, 0.2, 0.3, ...],
"limit": 10,
"select": "id, title, content",
"distance_func": "cosine"
}Output:
{
"results": [
{"distance": 0.123, "data": {"id": 1, "title": "Doc 1", "content": "..."}},
{"distance": 0.456, "data": {"id": 2, "title": "Doc 2", "content": "..."}}
],
"count": 2
}Distance functions: cosine (default), euclidean, dot
List vector columns in a database.
Input:
{ "database": "myapp" }Output:
{
"columns": [
{"table": "embeddings", "column": "embedding", "dimensions": 768, "index_name": "vec_idx"}
],
"vector_support": true,
"mysql_version": "9.0.0"
}Enable with:
export MYSQL_MCP_EXTENDED=1List indexes on a table.
{ "database": "myapp", "table": "users" }Get the CREATE TABLE statement.
{ "database": "myapp", "table": "users" }Get execution plan for a SELECT query.
{ "sql": "SELECT * FROM users WHERE id = 1", "database": "myapp" }List views in a database.
{ "database": "myapp" }List triggers in a database.
{ "database": "myapp" }List stored procedures.
{ "database": "myapp" }List stored functions.
{ "database": "myapp" }List table partitions.
{ "database": "myapp", "table": "events" }Get database size information.
{ "database": "myapp" }Or get all databases:
{}Get table size information.
{ "database": "myapp" }List foreign key constraints.
{ "database": "myapp", "table": "orders" }List MySQL server status variables.
{ "pattern": "Threads%" }List MySQL server configuration variables.
{ "pattern": "%buffer%" }The server enforces strict SQL validation:
Allowed operations:
SELECT,SHOW,DESCRIBE,EXPLAIN
Blocked patterns:
- Multi-statement queries (semicolons)
- File operations:
LOAD_FILE(),INTO OUTFILE,INTO DUMPFILE - DDL:
CREATE,ALTER,DROP,TRUNCATE,RENAME - DML:
INSERT,UPDATE,DELETE,REPLACE - Admin:
GRANT,REVOKE,FLUSH,KILL,SHUTDOWN - Dangerous functions:
SLEEP(),BENCHMARK(),GET_LOCK() - Transaction control:
BEGIN,COMMIT,ROLLBACK
CREATE USER 'mcp'@'localhost' IDENTIFIED BY 'strongpass';
GRANT SELECT ON *.* TO 'mcp'@'localhost';Enable JSON logs for production:
export MYSQL_MCP_JSON_LOGS=1Output:
{"timestamp":"2025-01-15T10:30:00.123Z","level":"INFO","message":"query executed","fields":{"tool":"run_query","duration_ms":15,"row_count":42}}Enable query audit trail:
export MYSQL_MCP_AUDIT_LOG=/var/log/mysql-mcp-audit.jsonlEach query is logged with timing, success/failure, and row counts.
Enable estimated token counting for tool inputs/outputs to monitor LLM context usage:
export MYSQL_MCP_TOKEN_TRACKING=1
export MYSQL_MCP_TOKEN_MODEL=cl100k_base # default, used by GPT-4/ClaudeOr via YAML config file:
logging:
token_tracking: true
token_model: "cl100k_base"When enabled:
- JSON logs include a
tokensobject with estimated input/output/total tokens - Audit log entries for
run_queryincludeinput_tokensandoutput_tokens - All other tools also emit token estimates when
token_trackingis enabled
Example JSON log output:
{
"level": "INFO",
"msg": "query executed",
"tool": "run_query",
"duration_ms": 45,
"row_count": 10,
"tokens": {
"input_estimated": 25,
"output_estimated": 150,
"total_estimated": 175,
"model": "cl100k_base"
}
}Notes:
- Token counts are estimates using tiktoken encoding, not actual LLM billing
- For payloads exceeding 1MB, a heuristic (~4 bytes per token) is used to prevent memory spikes
- The feature is disabled by default to avoid overhead when not needed
All queries are automatically timed and logged with:
- Execution duration (milliseconds)
- Row count returned
- Tool name
- Truncated query (for debugging)
Configure the connection pool for your workload:
export MYSQL_MAX_OPEN_CONNS=20 # Max open connections
export MYSQL_MAX_IDLE_CONNS=10 # Max idle connections
export MYSQL_CONN_MAX_LIFETIME_MINUTES=60 # Connection lifetime- Go 1.24+
- Docker and Docker Compose (for integration tests)
- MySQL client (optional, for manual database access)
Run unit tests (no external dependencies):
make testIntegration tests run against real MySQL instances using Docker Compose.
Test against MySQL 8.0 (default):
make test-integration-80Test against MySQL 8.4:
make test-integration-84Test against MySQL 9.0:
make test-integration-90Test against all supported versions (MySQL & MariaDB):
make test-integration-allTest specifically against MariaDB 11.4:
make test-integration-mariadb-11The Sakila sample database provides comprehensive integration testing with a realistic DVD rental store schema featuring:
- 16 tables with foreign key relationships
- Views, stored procedures, and triggers
- FULLTEXT indexes and ENUM/SET types
- Sample data for complex query testing
Run Sakila tests:
# Against MySQL 8.0
make test-sakila
# Against MySQL 8.4
make test-sakila-84
# Against MySQL 9.0
make test-sakila-90For a multi-version Sakila test matrix (including alternate ports), see docs/sakila-test-steps.md.
The Sakila tests cover:
- Multi-table JOINs (film→actors, customer→address→city→country)
- Aggregation queries (COUNT, SUM, AVG, GROUP BY)
- Subqueries (IN, NOT IN, correlated)
- View queries
- FULLTEXT search
- Index and foreign key verification
Run SQL injection and validation security tests:
make test-securityStart and stop test MySQL containers manually:
# Start MySQL 8.0 container
make test-mysql-up
# Start all MySQL versions (8.0, 8.4, 9.0)
make test-mysql-all-up
# Stop all test containers
make test-mysql-down
# View container logs
make test-mysql-logsWhen running tests manually, set the DSN:
# MySQL 8.0 (port 3306)
export MYSQL_TEST_DSN="root:testpass@tcp(localhost:3306)/testdb?parseTime=true"
# MySQL 8.4 (port 3307)
export MYSQL_TEST_DSN="root:testpass@tcp(localhost:3307)/testdb?parseTime=true"
# MySQL 9.0 (port 3308)
export MYSQL_TEST_DSN="root:testpass@tcp(localhost:3308)/testdb?parseTime=true"Then run tests directly:
go test -v -tags=integration ./tests/integration/...Integration tests use two databases:
testdb (tests/sql/init.sql):
- Tables:
users,orders,products,special_data - Views:
user_orders - Stored procedures:
get_user_by_id - Sample test data for basic integration tests
sakila (tests/sql/sakila-schema.sql, tests/sql/sakila-data.sql):
- 16 tables:
actor,film,customer,rental,payment,inventory, etc. - 6 views:
film_list,customer_list,staff_list,sales_by_store, etc. - Stored functions and procedures
- FULLTEXT indexes on
film_text - Realistic sample data (50 actors, 30 films, 10 customers, 20 rentals)
Basic usage:
docker run -e MYSQL_DSN="user:password@tcp(host.docker.internal:3306)/mydb" \
ghcr.io/askdba/mysql-mcp-server:latestNote: Use
host.docker.internalinstead oflocalhostto connect from inside the container to MySQL on your host machine (macOS/Windows).
With extended tools enabled:
docker run \
-e MYSQL_DSN="user:password@tcp(host.docker.internal:3306)/mydb" \
-e MYSQL_MCP_EXTENDED=1 \
ghcr.io/askdba/mysql-mcp-server:latestWith all options:
docker run \
-e MYSQL_DSN="user:password@tcp(host.docker.internal:3306)/mydb" \
-e MYSQL_MCP_EXTENDED=1 \
-e MYSQL_MCP_VECTOR=1 \
-e MYSQL_MAX_ROWS=500 \
-e MYSQL_QUERY_TIMEOUT_SECONDS=60 \
ghcr.io/askdba/mysql-mcp-server:latestEdit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MYSQL_DSN=user:password@tcp(host.docker.internal:3306)/mydb",
"ghcr.io/askdba/mysql-mcp-server:latest"
]
}
}
}With extended tools:
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MYSQL_DSN=user:password@tcp(host.docker.internal:3306)/mydb",
"-e", "MYSQL_MCP_EXTENDED=1",
"ghcr.io/askdba/mysql-mcp-server:latest"
]
}
}
}services:
mysql:
image: mysql:8.4
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: testdb
ports:
- "3306:3306"
mcp:
image: ghcr.io/askdba/mysql-mcp-server:latest
depends_on:
- mysql
environment:
MYSQL_DSN: "root:rootpass@tcp(mysql:3306)/testdb?parseTime=true"
MYSQL_MCP_EXTENDED: "1"Run:
docker compose updocker build -t mysql-mcp-server .Enable HTTP REST API mode to use with ChatGPT, Gemini, or any HTTP client:
export MYSQL_DSN="user:password@tcp(localhost:3306)/mydb"
export MYSQL_MCP_HTTP=1
export MYSQL_HTTP_PORT=9306 # Optional, defaults to 9306
mysql-mcp-serverEnable per-IP rate limiting for production deployments:
export MYSQL_HTTP_RATE_LIMIT=1
export MYSQL_HTTP_RATE_LIMIT_RPS=100 # 100 requests/second
export MYSQL_HTTP_RATE_LIMIT_BURST=200 # Allow bursts up to 200When rate limited, clients receive HTTP 429 (Too Many Requests) with a Retry-After: 1 header.
To run the REST API server in the background or under a process manager:
- Unix (foreground detach):
MYSQL_MCP_HTTP=1 mysql-mcp-server --daemon --config /path/to/config.yaml(forks and exits the parent; child runs detached). - systemd: Copy and customize contrib/systemd/mysql-mcp-server.service, then
systemctl enable --now mysql-mcp-server. - macOS launchd: Copy and customize contrib/launchd/com.askdba.mysql-mcp-server.plist into
~/Library/LaunchAgents/or/Library/LaunchDaemons/. - Windows: Use a Windows Service wrapper or run in a terminal;
--daemonis not supported.
Use --silent to suppress INFO/WARN logs when running under a service manager. See docs/silent-and-daemon.md.
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /api |
API index with all endpoints |
| GET | /api/databases |
List databases |
| GET | /api/tables?database= |
List tables |
| GET | /api/describe?database=&table= |
Describe table |
| POST | /api/query |
Run SQL query |
| GET | /api/ping |
Ping database |
| GET | /api/server-info |
Server info |
| GET | /api/connections |
List connections |
| POST | /api/connections/use |
Switch connection |
Extended endpoints (requires MYSQL_MCP_EXTENDED=1):
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/indexes?database=&table= |
List indexes |
| GET | /api/create-table?database=&table= |
Show CREATE TABLE |
| POST | /api/explain |
Explain query |
| GET | /api/views?database= |
List views |
| GET | /api/triggers?database= |
List triggers |
| GET | /api/procedures?database= |
List procedures |
| GET | /api/functions?database= |
List functions |
| GET | /api/partitions?database=&table= |
List table partitions |
| GET | /api/size/database?database= |
Database size |
| GET | /api/size/tables?database= |
Table sizes |
| GET | /api/foreign-keys?database= |
Foreign keys |
| GET | /api/status?pattern= |
Server status |
| GET | /api/variables?pattern= |
Server variables |
Vector endpoints (requires MYSQL_MCP_VECTOR=1):
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/vector/search |
Vector similarity search |
| GET | /api/vector/info?database= |
Vector column info |
List databases:
curl http://localhost:9306/api/databasesRun a query:
curl -X POST http://localhost:9306/api/query \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT * FROM users LIMIT 5", "database": "myapp"}'Get server info:
curl http://localhost:9306/api/server-infoAll responses follow this format:
{
"success": true,
"data": { ... }
}Error responses:
{
"success": false,
"error": "error message"
}- Start the REST API server on a publicly accessible host
- Create a Custom GPT with Actions
- Import the OpenAPI schema from
/api - Configure authentication if needed
docker run -p 9306:9306 \
-e MYSQL_DSN="user:password@tcp(host.docker.internal:3306)/mydb" \
-e MYSQL_MCP_HTTP=1 \
-e MYSQL_MCP_EXTENDED=1 \
ghcr.io/askdba/mysql-mcp-server:latest- SQL Query Optimization Guide: Practical optimization patterns and query rewriting techniques using the Stack Exchange schema.
- Comprehensive MySQL Query Optimization Guide: Deep technical insights into the query optimizer, advanced indexing strategies, execution plan analysis, and operational best practices.
cmd/mysql-mcp-server/
├── main.go -> Server entrypoint and tool registration
├── types.go -> Input/output struct types for tools
├── tools.go -> Core MCP tool handlers
├── tools_extended.go -> Extended MCP tool handlers
├── http.go -> HTTP REST API handlers and server
├── connection.go -> Multi-DSN connection manager
└── logging.go -> Structured and audit logging
internal/
├── api/ -> HTTP middleware and response utilities
├── config/ -> Configuration loader from environment
├── mysql/ -> MySQL client wrapper + tests
└── util/ -> Shared utilities (SQL validation, identifiers)
examples/ -> Example configs and test data
scripts/ -> Quickstart and utility scripts
bin/ -> Built binaries
The examples/ folder contains:
claude_desktop_config.json- Example Claude Desktop configurationtest-dataset.sql- Demo database with tables, views, and sample data
Load the test dataset:
mysql -u root -p < examples/test-dataset.sqlThis creates a mcp_demo database with:
- 5 categories, 13 products, 8 customers
- 9 orders with 16 order items
- Views:
order_summary,product_inventory - Stored procedure:
GetCustomerOrders - Stored function:
GetProductStock
make fmt # Format code
make lint # Run linter
make test # Run unit tests
make build # Build binary
make release # Build release binariesReleases are automated via GitHub Actions and GoReleaser. Full checklist: docs/releasing.md.
Quick steps: update CHANGELOG.md, commit, then git tag vX.Y.Z and git push origin vX.Y.Z. After the workflow runs, complete post-release steps (CHANGELOG on main if needed, Homebrew tap README, local brew upgrade). See the doc for details.
Apache License 2.0
© 2025 Alkin Tezuysal
