mysql-mcp-server
Connects to a MySQL database (5.7+/8.0+) and lets AI agents explore and understand its data: execute read-only SQL queries, list databases and tables, describe table schemas, retrieve sample rows, show EXPLAIN query plans, and count rows. Write operations are blocked by default unless explicitly enabled.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mysql-mcp-server
A Model Context Protocol (MCP) server that connects AI tools and agents to MySQL databases. It enables LLMs to safely query, explore, and understand your MySQL data through a standardized protocol.
Features
Read-only by default — all write operations are blocked unless explicitly enabled
7 built-in tools —
query,describe_table,sample_data,explain_query,row_count,list_tables,list_databasesSQL injection protection — table name validation and parameterized queries
MCP standard compliant — uses
StdioServerTransport, zod schemas, and proper content array responsesWorks with any MCP client — Claude Desktop, Cursor, Continue, and other MCP-compatible tools
Related MCP server: MCP MySQL Server
Prerequisites
Node.js >= 18
MySQL 5.7+ or 8.0+
An MCP-compatible client (e.g., Claude Desktop)
Installation
git clone https://github.com/your-username/mysql-mcp-server.git
cd mysql-mcp-server
npm install
npm run buildConfiguration
The server is configured via environment variables:
Variable | Description | Default |
| MySQL host |
|
| MySQL port |
|
| MySQL user |
|
| MySQL password | (empty) |
| Default database name | (empty) |
| Block write operations ( |
|
You can create a .env file for local development (it is git-ignored).
Usage with Claude Desktop
Add the following to your Claude Desktop configuration file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["/absolute/path/to/mysql-mcp-server/dist/index.js"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USER": "your_user",
"DB_PASSWORD": "your_password",
"DB_NAME": "your_database",
"READ_ONLY": "true"
}
}
}
}Restart Claude Desktop after saving the configuration.
Available Tools
query
Execute a read-only SQL query against the connected database.
Parameter | Type | Required | Description |
| string | yes | The SQL query to execute |
list_tables
List all tables in the connected database. No parameters.
list_databases
List all accessible databases on the MySQL server. No parameters.
describe_table
Show the schema/structure of a table (columns, types, keys).
Parameter | Type | Required | Description |
| string | yes | The table name |
sample_data
Retrieve sample rows from a table.
Parameter | Type | Required | Description |
| string | yes | The table name |
| number | no | Number of rows, 1-100 (default: 10) |
explain_query
Show the execution plan for a SQL query using EXPLAIN.
Parameter | Type | Required | Description |
| string | yes | The SQL query to explain |
row_count
Count the total number of rows in a table.
Parameter | Type | Required | Description |
| string | yes | The table name |
Testing
Run unit tests
npm testRun tests in watch mode
npm run test:watchTest with MCP Inspector
The MCP Inspector provides an interactive UI to test your server:
npx @modelcontextprotocol/inspector node dist/index.jsThis opens a web UI at http://localhost:6274 where you can:
Browse all registered tools
Fill in parameters and execute tools interactively
View raw JSON-RPC request/response messages
Debug errors in real time
Test structure
tests/
└── unit/
├── guards.test.ts # Read-only enforcement & bypass prevention
├── validation.test.ts # Table name validation & SQL injection prevention
├── config.test.ts # Environment variable parsing & defaults
└── tools/
├── describeTable.test.ts
├── sampleData.test.ts
├── explainQuery.test.ts
├── rowCount.test.ts
├── listTables.test.ts
└── listDatabases.test.tsDevelopment
# Run in development mode
npm run dev
# Build TypeScript to JavaScript
npm run build
# Run compiled server
npm start
# Run tests
npm testSecurity
Read-only mode (enabled by default): Blocks
INSERT,UPDATE,DELETE,DROP,ALTER,CREATE,TRUNCATE,REPLACE,RENAME,GRANT,REVOKE,LOAD, and other write operations. SQL comments are stripped before keyword detection to prevent bypass attempts.Table name validation: All table and database name parameters are validated against a strict character allowlist (
a-z,A-Z,0-9,_,-,.) with a maximum length of 64 characters.Parameterized queries: Numeric parameters (like
limit) use parameterized queries to prevent injection.
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely query MySQL databases with read-only access by default, supporting table listing, structure inspection, and SQL queries with optional write operation control.17 npmMIT
- AlicenseAqualityDmaintenanceEnables AI assistants to safely query MySQL databases with read-only access, featuring SQL injection protection, connection pooling, and automatic query limits for secure database exploration.4MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to inspect and query a MySQL database through safe, structured tools, including schema discovery and read-only queries.951 npmMIT