# MySQL (security-first) [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/Kurok1/mcp-server-mysql  
**GitHub Stars:** 2  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/mysql-security-first

## Description
Security-first MySQL MCP server: AST-validated SQL (fail-closed), default-deny whitelist, audit.

## Tools
Capabilities this server exposes over MCP:

- **list_profile** — No arguments; return names and descriptions sorted by name as text and structured `{profiles: [{name, description}]}`; no connection probe or credentials
- **mysql_query** — Run one read-only statement (`SELECT` / `SHOW` / `DESCRIBE` / `EXPLAIN`)
- **mysql_execute** — Run one write statement (`INSERT` / `UPDATE` / `DELETE` / DDL — each type must be enabled in config); returns affected rows
- **mysql_script** — Run a `;`-separated multi-statement script atomically in one transaction — all-or-nothing; DDL banned
- **mysql_explain** — Execution plan for a single `SELECT` (`format`: `traditional` / `json` / `tree`; `analyze: true` runs `EXPLAIN ANALYZE`)
- **mysql_list_tables** — List the base tables visible through the whitelist
- **mysql_describe_table** — Column structure of a whitelisted table
- **mysql_stats** — Selected profile's process-lifetime stats window: profile name, totals / denials, average & P95 latency, top-N slow queries, per-table access counts

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/Kurok1/mcp-server-mysql), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Install:

```sh
go install github.com/Kurok1/mcp-server-mysql/cmd/mcp-server-mysql@latest
```

2. Install:

```sh
docker pull ghcr.io/kurok1/mcp-server-mysql:latest
```

3. Configure:

```sh
mkdir -p ~/.mcp-server-mysql
```

4. Configure:

```sh
cp config.example.yaml ~/.mcp-server-mysql/config.yaml
```

5. Add to Claude Code:

```sh
claude mcp add mysql --env MYSQL_MCP_PASSWORD=your-password -- \
  ~/go/bin/mcp-server-mysql --config ~/.mcp-server-mysql/config.yaml
```

6. Start the server:

```sh
MYSQL_MCP_PASSWORD=your-password mcp-server-mysql \
  --config ~/.mcp-server-mysql/config.yaml \
  --transport streamable-http \
  --listen 127.0.0.1:3001
```

## Documentation

## What MySQL (security-first) does

MySQL (security-first) MCP server exposes multiple configured MySQL connections as MCP tools. Each SQL operation must name a profile; there is no implicit default connection. `list_profile` returns available profile names and descriptions without probing the database or exposing credentials.

The server supports read-only queries, selectively enabled writes, table discovery, schema inspection, query-plan analysis, transactional scripts, and process-lifetime statistics. It can also publish whitelisted base-table schemas as MCP resources. These resources contain live normalized `SHOW CREATE TABLE` output, while the discovered resource set is refreshed on initialization or reconnect.

## How it works

Before execution, SQL is parsed into an abstract syntax tree using the TiDB MySQL-compatible parser. Statements the parser cannot understand are rejected. Statement classes are allowlisted individually: reads cover `SELECT`, `SHOW`, `DESCRIBE`, and `EXPLAIN`, while `INSERT`, `UPDATE`, `DELETE`, and DDL require corresponding configuration. Statements such as `SET`, `GRANT`, `CALL`, `USE`, `LOAD DATA`, `LOCK TABLES`, and transaction-control commands are rejected.

The MySQL (security-first) MCP server checks every referenced table against a default-deny whitelist. The check covers joins, subqueries, CTEs, derived tables, multi-table writes, `INSERT ... SELECT`, and versioned comments. Additional execution controls include a maximum row count, query timeouts, single-statement enforcement, and a guard against `UPDATE` or `DELETE` statements without `WHERE` clauses.

`mysql_script` accepts semicolon-separated statements and executes them in one transaction after validating each statement. A failure rolls back the script. DDL is not allowed in scripts because MySQL can implicitly commit DDL and would undermine all-or-nothing behavior. `mysql_explain` handles one `SELECT` and supports traditional, JSON, and tree output, including `EXPLAIN ANALYZE`.

## Setup and configuration

The project can run as a prebuilt static binary, a Go-installed command, or a Docker image from GitHub Container Registry.

Create `~/.mcp-server-mysql/config.yaml` from the example configuration, then define profiles with connection details and security rules. The example uses a dedicated least-privilege MySQL account rather than `root` and obtains the password from `MYSQL_MCP_PASSWORD`. Profiles can have separate connection pools, whitelist rules, audit files, and statistics.

Resources are enabled by default. Set the root-level `resources.enabled` option to `false` to prevent initialization-time table discovery and disable schema resources and the interactive query-results app. The tools remain available when resources are disabled.

## Tools and capabilities

- `mysql_query`: Executes one permitted read statement.
- `mysql_execute`: Performs an enabled write or DDL operation and reports affected rows.
- `mysql_script`: Runs validated non-DDL statements atomically.
- `mysql_explain`: Returns a plan for one `SELECT`.
- `mysql_list_tables`: Lists whitelist-visible base tables.
- `mysql_describe_table`: Returns the structure of a permitted table.
- `mysql_stats`: Reports totals, denials, latency, slow queries, and per-table access counts for a profile.
- `mysql_query` results can be rendered as filterable and sortable tables by MCP Apps-capable hosts; other hosts receive text results.

## Limitations and notes

The MySQL (security-first) MCP server does not provide a default profile, and missing or unknown profiles are rejected before database access. The table-resource list is a discovery-time snapshot: newly created tables appear after discovery or reconnect, while resource content reflects later schema changes when read. Views are not registered.

Audit logging is opt-in and uses rotating JSONL files. Denied SQL includes the rule that caused rejection when auditing is enabled. Resource discovery and reads do not contribute to audit logs or `mysql_stats`. Resource visibility depends on both the MySQL account's privileges and the configured whitelist.

_Full upstream README: https://allmcps.com/mcp/mysql-security-first/readme_

