Security-first MySQL MCP server: AST-validated SQL (fail-closed), default-deny whitelist, audit.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent โ or use 1-click editor setup below.
๐ก Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
Inspect callable tools, capabilities, and parameters exposed to AI agents by MySQL (security First).
list_profileNo arguments; return names and descriptions sorted by name as text and structured `{profiles: [{name, description}]}`; no connection probe or credentials
mysql_queryRun one read-only statement (`SELECT` / `SHOW` / `DESCRIBE` / `EXPLAIN`)
mysql_executeRun one write statement (`INSERT` / `UPDATE` / `DELETE` / DDL โ each type must be enabled in config); returns affected rows
mysql_scriptRun a `;`-separated multi-statement script atomically in one transaction โ all-or-nothing; DDL banned
mysql_explainExecution plan for a single `SELECT` (`format`: `traditional` / `json` / `tree`; `analyze: true` runs `EXPLAIN ANALYZE`)
mysql_list_tablesList the base tables visible through the whitelist
English | ็ฎไฝไธญๆ
A security-first MySQL MCP server. Every SQL statement must survive a full AST parse by an industrial-grade SQL parser (TiDB parser) before it can touch your database โ backed by a read-only transaction fallback and a driver-level multi-statement lockout. Three independent layers of defense-in-depth: let AI query your database, without letting it walk off with your database.
Most MySQL MCP servers enforce "read-only" with regex/keyword matching, or by wrapping queries in a read-only transaction. Both are broken:
COMMIT; DROP TABLE ... stacked-statement injection โ the exact attack Datadog demonstrated against the official Postgres reference server, which has since been archived.This project puts the security boundary on real SQL semantic parsing instead. Every statement is parsed into an AST by the TiDB parser (MySQL 8.0-grammar compatible); anything the parser cannot understand is rejected โ fail-closed, so incomplete grammar coverage can only over-block, never under-block. And because the parser sees real MySQL semantics, tricks like hiding a JOIN mysql.user inside a versioned comment /*!80000 ... */ are extracted and checked like any other table reference.
list_profile, then pass an explicit profile to every SQL tool.SELECT / INSERT / UPDATE / DELETE / DDL are individually switchable; the default is read-only. SET, GRANT, CALL, USE, LOAD DATA, LOCK TABLES, and transaction control (BEGIN/COMMIT/ROLLBACK) are rejected unconditionally โ classification itself is an allowlist, so unknown statement types land on the deny side by construction.db.*, db.table, app_*.logs (glob per side, case-insensitive). Every table reference is extracted from the AST: JOINs, subqueries, derived tables, CTEs (scope-aware โ a CTE name can't shadow a real table to smuggle it past the check), multi-table DML, INSERT ... SELECT, and versioned comments.mysql:///schema/{profile}/{database}/{table}. Reading a resource returns live SHOW CREATE TABLE SQL with only the volatile table-level AUTO_INCREMENT=N counter removed.UPDATE/DELETE without WHERE.mysql_stats tool so you can ask "which query was slowest?" right in the conversation.mysql_script runs a multi-statement script in a single transaction with every statement individually re-validated; any failure rolls back everything. DDL is banned inside scripts because MySQL's implicit commit would break atomicity.mysql_explain with traditional / json / tree formats and EXPLAIN ANALYZE support.mysql_query as a filterable, sortable table with per-view history, selection, column controls, and TSV/CSV/JSON copy; other hosts keep receiving the original text result.All seven mysql_* tools require a non-empty profile string matching a configured name. There is no default connection: missing or unknown profiles are rejected before database access. mysql_describe_table defaults its optional database argument to the selected profile's database.
| Tool | What it does |
|---|---|
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 |
For example, call list_profile with {}, then mysql_query with {"profile":"dev","sql":"SELECT * FROM myapp.orders LIMIT 10"} or mysql_stats with {"profile":"dev","top_n":5}. Keep the same profile when inspecting, changing, and verifying data.
The server takes a table snapshot for each profile during MCP initialization/discovery and registers one direct resource per visible base table. Resource names also identify the profile, so identical database and table names on different servers stay distinct:
| URI | MIME type | Content |
|---|---|---|
mysql:///schema/{profile}/{database}/{table} | application/sql | Current normalized SHOW CREATE TABLE output |
"Visible" is the intersection of what the profile's MySQL account can see and its security.table_whitelist. Views are not registered. Resource discovery is not capped by security.max_rows, and resource reads remain available even when select is absent from allowed_statements, because both operations execute fixed server-owned metadata SQL rather than user-submitted SQL.
The resource set is a discovery-time snapshot: a table created later appears after the next discovery or reconnect, while a dropped or newly inaccessible table returns MCP Resource Not Found. The resource content is live, so ALTER TABLE is reflected on the next read. Resource discovery and reads do not enter the audit log or mysql_stats; a discovery failure is logged with the profile name and clears only that profile's table resources; other profiles, tools, and the shared query-results App remain available.
The root-level resources.enabled switch applies to every profile. Set it to false to disable the entire resource feature. It defaults to true; when disabled, the server does not advertise Resources, register table or MCP App resources, or query any profile's MySQL during initialization/discovery. The interactive MCP App is therefore unavailable, while all eight tools, including mysql_query's text and structured results, remain available.
Prebuilt โ download the tarball for your platform (linux_amd64 / linux_arm64 / darwin_arm64) from Releases (checksums included), or install with Go:
Docker โ multi-arch images are published to GitHub Container Registry:
Copy config.example.yaml and adjust:
A minimal config:
Add sibling entries under profiles for other connections; each accepts the same mysql, security, and audit fields. The annotated example includes two profiles. The client examples below use this minimal config; for other configurations, pass every referenced password environment variable to the MCP process.
Claude Code:
Claude Desktop or any JSON-configured client:
Docker:
Factual signals from GitHub, npm, and our automated checks โ not a rating.
No reviews yet โ be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/mysql-security-first)<a href="https://allmcps.com/mcp/mysql-security-first"><img src="https://allmcps.com/api/badge/mysql-security-first?style=directory" alt="MySQL (security First) on AllMCPs" /></a>