Skip to main content
Glama

mysql-mcp

Query MySQL tables from Claude Code — read-only by default.

An MCP server that gives Claude Code (and any MCP client) read access to a MySQL database through structured, parameterized query tools. No raw SQL passthrough by default — the tool surface is designed so the worst possible outcome is a SELECT that returns too many rows.

Modeled on Agent360's browser-mcp (same MCP server patterns: stdio transport, lifecycle handling, LLM-facing tool descriptions).

Testing

npm test

Three layers, all under node --test (no test framework dependency):

File

Layer

Needs DB?

test/query-builder.test.js

SQL builder security contract (identifiers, params, clamps, footgun defense)

No

test/error-classifier.test.js

Error → LLM-hint mapping + result truncation

No

test/integration.test.js

Full MCP protocol against a real MySQL, via test/helpers/mcp-client.js

Yes — suites skip gracefully when unreachable

Integration env (defaults match the local Docker dev setup; override freely):

TEST_DB_HOST / TEST_DB_PORT / TEST_DB_USER / TEST_DB_PASSWORD / TEST_DB_NAME
TEST_DB_RW_USER / TEST_DB_RW_PASSWORD   → write suite (skipped if unset)
TEST_DB_ADMIN_PASSWORD                  → cleanup of write-test rows

Related MCP server: mysql-mcp

Status — M5

Five read tools plus two opt-in write tools, all integration-tested against a real MySQL:

Tool

What it does

ping

Verify MCP + MySQL connectivity, returns guiding errors

list_tables

SHOW TABLES

describe_table

Column names/types/keys/defaults/comments via information_schema

query_table

Structured queries — key/value WHERE, column lists, order, limit (hard cap 200)

check_permissions

Shows the account's grants and whether it is read-only

insert_row (opt-in)

INSERT + read-back of the inserted row

update_rows (opt-in)

UPDATE with REQUIRED where, default LIMIT 1 (cap 100) + read-back of the new state

Writing — opt-in at two levels

Write tools exist only when both hold:

  1. Server: started with ALLOW_WRITES=1 — otherwise the tools are not even advertised in tools/list, and dispatch refuses them anyway.

  2. Database: the connected account holds INSERT/UPDATE grants (verify with check_permissions).

Safety defaults on update_rows: where is required (a where-less UPDATE is rejected — the classic footgun), limit defaults to 1 and caps at 100. Every write reads the affected rows back and returns the verified new state.

Security — three tiers, all enforced

Tier

Defense

Where

1. Database

SELECT-only account (GRANT SELECT, ideally on a replica)

Your DBA work — verified by check_permissions

2. Connection

multipleStatements: false, connectTimeout: 5s, per-query timeout 10s (DB_QUERY_TIMEOUT_MS to tune)

db.js

3. Application

No raw SQL passthrough; identifier allowlist + ?? escaping; values via ? only; LIMIT hard cap 200

db.js buildSelectQuery

Every tool call is audited to stderr — shape only (tool, table name, row count), never values. Same secret-hygiene contract as browser-mcp's action log.

Reliability & LLM experience

  • Errors are LLM-actionable. Raw MySQL/network errors are classified and shipped with a hint that says what to do next: Error: Table 'x' doesn't exist → Hint: Call list_tables..., Unknown column → Hint: Call describe_table..., connection failures → Hint: Check DB_HOST / DB_PORT... (marked retryable).

  • Retry policy. Transient connection failures retry once automatically (SELECTs are idempotent); SQL errors never retry. Same read-only/retryable split as browser-mcp's CDP whitelist.

  • Result truncation. Results are capped at 50,000 serialized chars (on top of the 200-row cap). When truncated, the response carries truncated: true, fetched, and a hint telling the model to narrow (WHERE filters, fewer columns, offset paging) instead of re-querying bigger.

Roadmap

  • ✅ M1–M6 core done: skeleton, query tools, security, reliability, opt-in writes, test suite

  • ⏸️ npm publishing — skipped by decision; add @scope name, LICENSE, registry metadata (server.json / glama.json) if you ever publish

Install (local — no npm publish needed)

cd /path/to/mysql-mcp
node bin/cli.js install

This writes the mysql-mcp server into ~/.claude/mcp.json, pointing at this checkout's index.js by absolute path (dev-mode install, same pattern as browser-mcp's install.sh). Credentials use ${VAR} placeholders — Claude Code resolves them from your environment, never stored in the config file:

{
  "mcpServers": {
    "mysql-mcp": {
      "command": "node",
      "args": ["/path/to/mysql-mcp/index.js"],
      "env": {
        "DB_HOST": "${DB_HOST}",
        "DB_PORT": "${DB_PORT}",
        "DB_USER": "${DB_USER}",
        "DB_PASSWORD": "${DB_PASSWORD}",
        "DB_NAME": "${DB_NAME}"
      }
    }
  }
}

Database account — read-only, always

CREATE USER 'mcp_ro'@'%' IDENTIFIED BY '<strong-password>';
GRANT SELECT ON <your_db>.* TO 'mcp_ro'@'%';

Point it at a read replica if you have one.

Dev

npm ci
node index.js    # → [mysql-mcp] MySQL MCP server running (stdio)

Environment variables

Var

Default

Description

DB_HOST

127.0.0.1

MySQL host

DB_PORT

3306

MySQL port

DB_USER

(required)

MySQL user

DB_PASSWORD

(empty)

MySQL password

DB_NAME

(none)

Default database

DB_QUERY_TIMEOUT_MS

10000

Per-query timeout in ms

ALLOW_WRITES

(unset)

Set to 1 to enable insert_row / update_rows

License

MIT

Available Tools

5 tools
check_permissionsA

Show the connected MySQL account's privileges and whether it is read-only. Call this when the user asks about database security, or to verify that writes are impossible before running queries. If read_only is false, the account CAN modify data — recommend switching to a SELECT-only account.

Inputs: no named parameters.

describe_tableA

Describe a table: column names, types, nullability, keys, defaults, and column comments. Always call this BEFORE query_table so you query with real column names. Returns a warning (not an error) if the table does not exist.

Inputs: table (required).

list_tablesA

List all tables in the connected database. Always start here when you do not know what tables exist — do not guess table names.

Inputs: no named parameters.

pingA

Check MCP server and MySQL connectivity. Returns whether the database connection works. Call this first whenever you are unsure whether the database is reachable — the error field tells you what to fix (missing env vars, wrong credentials, host unreachable).

Inputs: no named parameters.

query_tableA

Query rows from a table with structured parameters — no SQL strings are accepted. WHERE conditions are equality-only key/value pairs ({ status: "active" }); use columns to narrow the output; limit defaults to 20 and is hard-capped at 200 rows. Workflow: describe_table first to learn column names, then query with a small limit and narrow columns, expanding only when needed.

Inputs: table (required), limit, where, offset, +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct role: connectivity check (ping), table discovery (list_tables), schema inspection (describe_table), row retrieval (query_table), and privilege audit (check_permissions). Descriptions even prescribe an explicit workflow order, leaving no room for misselection.

    Naming Consistency4/5

    Four of five tools follow a consistent verb_noun snake_case pattern (list_tables, describe_table, query_table, check_permissions). The lone bare verb 'ping' is a minor, conventional deviation that does not impede readability.

    Tool Count4/5

    Five tools is a tight, well-scoped surface for a read-only MySQL inspection server, and each one earns its place. It sits at the thin end of the range, with the database-level discovery and diagnostic tools consuming two of the five slots.

    Completeness3/5

    For read-only exploration the surface is workable, but there are notable gaps: no offset/pagination (limit hard-capped at 200), no ordering or range/inequality predicates (equality-only WHERE), and no cross-table or aggregate queries, so common asks like 'latest N rows' or 'counts over time' become dead ends. Absence of any write path appears intentional given the read-only recommendation.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A lightweight MCP server providing safe, read-only access to MySQL databases. It enables users to query multiple MySQL instances securely while preventing write operations.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A production-ready MCP server for MySQL database operations, providing secure HTTP endpoints for read-only queries, performance analysis, and server monitoring.
      22
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      A MySQL MCP server for local stdio clients, enabling database queries and management with read-only/write modes, audit logging, and configurable security.
      554 npm
      MIT