# MySQL MCP Server
**Last Updated February 18, 2026**
[](https://github.com/neverinfamous/mysql-mcp)
[](https://opensource.org/licenses/MIT)
[](https://github.com/neverinfamous/mysql-mcp/actions/workflows/codeql.yml)
[](https://www.npmjs.com/package/@neverinfamous/mysql-mcp)
[](https://hub.docker.com/r/writenotenow/mysql-mcp)
[](SECURITY.md)



**[π Full Documentation (Wiki)](https://github.com/neverinfamous/mysql-mcp/wiki)** β’ **[Changelog](https://github.com/neverinfamous/mysql-mcp/blob/master/CHANGELOG.md)** β’ **[Security](https://github.com/neverinfamous/mysql-mcp/blob/master/SECURITY.md)** β’ **[Release Article](https://adamic.tech/articles/mysql-mcp-server)**
## The Most Comprehensive MySQL MCP Server Available
**mysql-mcp** is the definitive **Model Context Protocol server for MySQL** β empowering AI assistants like AntiGravity, Claude, Cursor, and other MCP clients with **unparalleled database capabilities**. Built for developers who demand enterprise-grade features without sacrificing ease of use.
### π― What Sets Us Apart
| Feature | Description |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **193 Specialized Tools** | The largest MySQL tool collection for MCP β from core CRUD and native JSON functions (MySQL 5.7+) to advanced spatial/GIS, document store, and cluster management |
| **18 Observability Resources** | Real-time schema, performance metrics, process lists, status variables, replication status, and InnoDB diagnostics |
| **19 AI-Powered Prompts** | Guided workflows for query building, schema design, performance tuning, and infrastructure setup |
| **OAuth 2.1 + Access Control** | Enterprise-ready security with RFC 9728/8414 compliance, granular scopes (`read`, `write`, `admin`, `full`, `db:*`, `table:*:*`), and Keycloak integration |
| **Smart Tool Filtering** | 25 tool groups + 11 shortcuts let you stay within IDE limits while exposing exactly what you need |
| **HTTP Streaming Transport** | SSE-based streaming with `/sse`, `/messages`, and `/health` endpoints for remote deployments |
| **High-Performance Pooling** | Built-in connection pooling for efficient, concurrent database access |
| **Ecosystem Integrations** | First-class support for **MySQL Router**, **ProxySQL**, and **MySQL Shell** utilities |
| **Advanced Encryption** | Full TLS/SSL support for secure connections, plus tools for managing data masking, encryption monitoring, and compliance |
| **Production-Ready Security** | SQL injection protection, parameterized queries, input validation, and audit capabilities |
| **Strict TypeScript** | 100% type-safe codebase with 1833 tests and 86% coverage |
| **MCP 2025-11-25 Compliant** | Full protocol support with tool safety hints, resource priorities, and progress notifications |
---
## π Quick Start
### Prerequisites
- Node.js 24+
- MySQL 5.7+ or 8.0+ server
- npm or yarn
### Installation
#### NPM (Recommended)
```bash
npm install -g @neverinfamous/mysql-mcp
```
Run the server:
```bash
mysql-mcp --transport stdio --mysql mysql://user:password@localhost:3306/database
```
Or use npx without installing:
```bash
npx @neverinfamous/mysql-mcp --transport stdio --mysql mysql://user:password@localhost:3306/database
```
#### Docker
```bash
docker run -i --rm writenotenow/mysql-mcp:latest \
--transport stdio \
--mysql mysql://user:password@host.docker.internal:3306/database
```
#### From Source
```bash
git clone https://github.com/neverinfamous/mysql-mcp.git
cd mysql-mcp
npm install
npm run build
node dist/cli.js --transport stdio --mysql mysql://user:password@localhost:3306/database
```
---
## β‘ MCP Client Configuration
### HTTP/SSE Server Usage (Advanced)
> **When to use HTTP mode:** Use HTTP mode when deploying `mysql-mcp` as a standalone server that multiple clients can connect to remotely. For local development with Claude Desktop or Cursor IDE, use the default `stdio` mode shown below instead.
**Use cases for HTTP mode:**
- Running the server in a Docker container accessible over a network
- Deploying to cloud platforms (AWS, GCP, Azure)
- Enabling OAuth 2.1 authentication for enterprise security
- Allowing multiple AI clients to share one database connection
## OAuth 2.1 Authentication
For enterprise deployments, mysql-mcp supports OAuth 2.1 authentication with Keycloak or any RFC-compliant provider.
### Quick Setup
**1. Start with OAuth disabled (default)**
```bash
mysql-mcp --mysql mysql://root:pass@localhost/db
```
**2. Enable OAuth with an identity provider**
```bash
mysql-mcp --mysql mysql://root:pass@localhost/db \
--oauth-enabled \
--oauth-issuer http://localhost:8080/realms/mysql-mcp \
--oauth-audience mysql-mcp
```
**Start the HTTP server:**
Local installation:
```bash
node dist/cli.js --transport http --port 3000 --server-host 0.0.0.0 --mysql mysql://user:password@localhost:3306/database
```
Docker (expose port 3000):
```bash
docker run -p 3000:3000 writenotenow/mysql-mcp \
--transport http \
--port 3000 \
--server-host 0.0.0.0 \
--mysql mysql://user:password@host.docker.internal:3306/database
```
**Available endpoints:**
- `GET /sse` - Establish MCP connection via Server-Sent Events
- `POST /messages` - Send JSON-RPC messages to the server
- `GET /health` - Health check endpoint
- `GET /.well-known/oauth-protected-resource` - OAuth 2.1 metadata (when OAuth enabled)
> **π‘ Tip:** Most users should skip this section and use the stdio configuration below for local AI IDE integration.
### Cursor IDE / Claude Desktop
```json
{
"mcpServers": {
"mysql-mcp": {
"command": "node",
"args": [
"C:/path/to/mysql-mcp/dist/cli.js",
"--transport",
"stdio",
"--mysql",
"mysql://user:password@localhost:3306/database"
]
}
}
}
```
### Using Environment Variables (Recommended)
```json
{
"mcpServers": {
"mysql-mcp": {
"command": "node",
"args": ["C:/path/to/mysql-mcp/dist/cli.js", "--transport", "stdio"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"MYSQL_XPORT": "33060"
}
}
}
}
> **Note:** `MYSQL_XPORT` (X Protocol port) defaults to `33060` if omitted. Only needed for `mysqlsh_import_json` and `docstore` tools. Set to your MySQL Router X Protocol port (e.g., `6448`) when using InnoDB Cluster.
```
> **π See the [Configuration Wiki](https://github.com/neverinfamous/mysql-mcp/wiki/Configuration)** for more configuration options.
---
## π Database Connection Scenarios
| Scenario | Host to Use | Example Connection String |
| ------------------------- | ------------------------- | ------------------------------------------------ |
| **MySQL on host machine** | `host.docker.internal` | `mysql://user:pass@host.docker.internal:3306/db` |
| **MySQL in Docker** | Container name or network | `mysql://user:pass@mysql-container:3306/db` |
| **Remote/Cloud MySQL** | Hostname or IP | `mysql://user:pass@db.example.com:3306/db` |
> **Tip:** For remote connections, ensure your MySQL server allows connections from Docker's IP range and that firewalls/security groups permit port 3306.
---
## Code Mode: Maximum Efficiency
Code Mode (`mysql_execute_code`) dramatically reduces token usage (70β90%) and is included by default in all presets.
> [!TIP]
> **Maximize Token Savings:** For the best results, instruct your AI agent to prefer Code Mode over individual tool calls. Add a rule like this to your agent's prompt or system configuration:
>
> _"When using mysql-mcp, prefer `mysql_execute_code` (Code Mode) for multi-step database operations to minimize token usage."_
>
> This ensures the agent batches operations into single calls instead of making many individual tool calls. See the [Code Mode wiki](https://github.com/neverinfamous/mysql-mcp/wiki/Code-Mode) for full API documentation.
> [!NOTE]
> **AntiGravity Users:** Server instructions are automatically sent to MCP clients during initialization. However, AntiGravity does not currently support MCP server instructions. For optimal Code Mode usage in AntiGravity, manually provide the contents of [`src/constants/ServerInstructions.ts`](https://github.com/neverinfamous/mysql-mcp/blob/master/src/constants/ServerInstructions.ts) to the agent in your prompt or user rules.
---
## π οΈ Tool Filtering
> [!IMPORTANT]
> **AI IDEs like Cursor have tool limits (typically 40-50 tools).** With 193 tools available, you MUST use tool filtering to stay within your IDE's limits. We recommend `starter` (39 tools) as a starting point. Code Mode is included in all presets by default for 70-90% token savings on multi-step operations.
### What Can You Filter?
The `--tool-filter` argument accepts **shortcuts**, **groups**, or **tool names** β mix and match freely:
| Filter Pattern | Example | Tools | Description |
| ---------------- | --------------------------- | ----- | ------------------------- |
| Shortcut only | `starter` | 39 | Use a predefined bundle |
| Groups only | `core,json,transactions` | 32 | Combine individual groups |
| Shortcut + Group | `starter,spatial` | 51 | Extend a shortcut |
| Shortcut - Tool | `starter,-mysql_drop_table` | 38 | Remove specific tools |
### Shortcuts (Predefined Bundles)
| Shortcut | Tools | Use Case | What's Included |
| --------------- | ------ | ------------------ | ------------------------------------------------------------------ |
| `starter` | **39** | π **Recommended** | core, json, transactions, text, codemode |
| `essential` | 16 | Minimal footprint | core, transactions, codemode |
| `dev-power` | 47 | Power Developer | core, schema, performance, stats, fulltext, transactions, codemode |
| `ai-data` | 46 | AI Data Analyst | core, json, docstore, text, fulltext, codemode |
| `ai-spatial` | 44 | AI Spatial Analyst | core, spatial, stats, performance, transactions, codemode |
| `dba-monitor` | 36 | DBA Monitoring | core, monitoring, performance, sysschema, optimization, codemode |
| `dba-manage` | 34 | DBA Management | core, admin, backup, replication, partitioning, events, codemode |
| `dba-secure` | 33 | DBA Security | core, security, roles, transactions, codemode |
| `base-core` | 49 | Base Ops | core, json, transactions, text, schema, codemode |
| `base-advanced` | 41 | Advanced Features | docstore, spatial, stats, fulltext, events, codemode |
| `ecosystem` | 42 | External Tools | cluster, proxysql, router, shell, codemode |
### Tool Groups (25 Available)
| Group | Tools | Description |
| -------------- | ----- | ---------------------------------------- |
| `core` | 8 | Read/write queries, tables, indexes |
| `transactions` | 7 | BEGIN, COMMIT, ROLLBACK, savepoints |
| `json` | 17 | JSON functions, merge, diff, stats |
| `text` | 6 | REGEXP, LIKE, SOUNDEX |
| `fulltext` | 5 | Natural language & boolean search |
| `performance` | 8 | EXPLAIN, query analysis, slow queries |
| `optimization` | 4 | Index hints, recommendations |
| `admin` | 6 | OPTIMIZE, ANALYZE, CHECK |
| `monitoring` | 7 | PROCESSLIST, status variables |
| `backup` | 4 | Export, import, mysqldump |
| `replication` | 5 | Master/slave, binlog |
| `partitioning` | 4 | Partition management |
| `schema` | 10 | Views, procedures, triggers, constraints |
| `shell` | 10 | MySQL Shell utilities |
| `events` | 6 | Event Scheduler management |
| `sysschema` | 8 | sys schema diagnostics |
| `stats` | 8 | Statistical analysis tools |
| `spatial` | 12 | Spatial/GIS operations |
| `security` | 9 | Audit, SSL, encryption, masking |
| `roles` | 8 | MySQL 8.0 role management |
| `docstore` | 9 | Document Store collections |
| `cluster` | 10 | Group Replication, InnoDB Cluster |
| `proxysql` | 12 | ProxySQL management |
| `router` | 9 | MySQL Router REST API |
| `codemode` | 1 | Sandboxed code execution |
---
> **π See the [Tool Filtering Wiki](https://github.com/neverinfamous/mysql-mcp/wiki/Tool-Filtering)** for IDE configuration examples and advanced usage.
---
## π‘ Usage Instructions
> [!NOTE]
> Usage instructions are **automatically provided** to AI agents via the MCP protocol during server initialization.
For debugging or manual reference, see the source: [`src/constants/ServerInstructions.ts`](src/constants/ServerInstructions.ts)
---
## π€ AI-Powered Prompts
**19 intelligent prompts** for guided workflows including query building, schema design, performance analysis, migration planning, backup strategy, index tuning, and ecosystem setup (Router, ProxySQL, Replication, Shell, Cluster, Spatial, Events, Document Store).
---
## π Resources
**18 real-time resources** for database observability: schema, tables, variables, status, processlist, connection pool, capabilities, health, performance, indexes, replication, InnoDB metrics, events, sys schema, locks, cluster status, spatial metadata, and document store collections.
---
## π§ Advanced Configuration
For specialized setups, see these Wiki pages:
| Topic | Description |
| ---------------------------------------------------------------------------- | --------------------------------------------------- |
| [MySQL Router](https://github.com/neverinfamous/mysql-mcp/wiki/MySQL-Router) | Configure Router REST API access for InnoDB Cluster |
| [ProxySQL](https://github.com/neverinfamous/mysql-mcp/wiki/ProxySQL) | Configure ProxySQL admin interface access |
| [MySQL Shell](https://github.com/neverinfamous/mysql-mcp/wiki/MySQL-Shell) | Configure MySQL Shell for dump/load operations |
---
## β‘ Performance Tuning
Schema metadata is cached to reduce repeated queries during tool/resource invocations.
| Variable | Default | Description |
| ----------------------- | ------- | -------------------------------------------------- |
| `METADATA_CACHE_TTL_MS` | `30000` | Cache TTL for schema metadata (milliseconds) |
| `LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warning`, `error` |
> **Tip:** Lower `METADATA_CACHE_TTL_MS` for development (e.g., `5000`), or increase it for production with stable schemas (e.g., `300000` = 5 min).
> **Built-in payload optimization:** Many tools support optional `summary: true` for condensed responses and `limit` parameters to cap result sizes. These are particularly useful for cluster status, monitoring, and sys schema tools where full responses can be large. See [`ServerInstructions.ts`](https://github.com/neverinfamous/mysql-mcp/blob/master/src/constants/ServerInstructions.ts) for per-tool details.
---
### CLI Options
| Option | Environment Variable | Description |
| ------------------------- | ----------------------- | --------------------------------------------------- |
| `--server-host` | `MCP_HOST` | Host to bind HTTP transport to (default: localhost) |
| `--oauth-enabled` | `OAUTH_ENABLED` | Enable OAuth authentication |
| `--oauth-issuer` | `OAUTH_ISSUER` | Authorization server URL |
| `--oauth-audience` | `OAUTH_AUDIENCE` | Expected token audience |
| `--oauth-jwks-uri` | `OAUTH_JWKS_URI` | JWKS URI (auto-discovered) |
| `--oauth-clock-tolerance` | `OAUTH_CLOCK_TOLERANCE` | Clock tolerance in seconds |
### Scopes
| Scope | Access Level |
| ------- | ------------------------- |
| `read` | Read-only queries |
| `write` | Read + write operations |
| `admin` | Administrative operations |
| `full` | All operations |
> **π See the [OAuth Wiki](https://github.com/neverinfamous/mysql-mcp/wiki/OAuth)** for Keycloak setup and detailed configuration.
---
## Contributing & Security
[Contributing Guidelines](CONTRIBUTING.md) β’ [Security Policy](SECURITY.md) β’ [MIT License](LICENSE) β’ [Code of Conduct](CODE_OF_CONDUCT.md)