@achmadya-dev/mcp-mysql-query
v0.3.2
Published
Model Context Protocol (MCP) server for MySQL to run SQL queries via stdio (read-only by default)
Maintainers
Readme
@achmadya-dev/mcp-mysql-query
MCP server for MySQL. Runs a single SQL statement per tool call over stdio. Read-only by default — writes and DDL require explicit env flags.
Requirements
- Node.js ≥ 20
- A reachable MySQL server (local, Docker, or remote)
Install from npm
Add to Cursor Settings → MCP or .cursor/mcp.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@achmadya-dev/mcp-mysql-query"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Or load credentials from a file (Cursor envFile):
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@achmadya-dev/mcp-mysql-query"],
"envFile": "/absolute/path/to/.env"
}
}
}Develop from source
git clone https://github.com/achmadya-dev/mcp-mysql-query.git
cd mcp-mysql-query
pnpm install
pnpm run build
pnpm testOpen the repo root in Cursor. You need a reachable MySQL instance — set connection env in .cursor/mcp.json or via envFile:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["${workspaceFolder}/dist/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Environment variables
Connection
| Variable | Default | Description |
| ---------------- | ------------ | ------------------------------- |
| MYSQL_HOST | localhost | MySQL host |
| MYSQL_PORT | 3306 | Port |
| MYSQL_USER | (empty) | Username |
| MYSQL_PASSWORD | (empty) | Password |
| MYSQL_DATABASE | (optional) | Database selected after connect |
| MYSQL_MAX_ROWS | 500 | Max rows returned for SELECT |
Write access
Enabled when the value is true, 1, yes, or on (case-insensitive). If unset, that operation type is rejected.
| Variable | Allows |
| ------------------------ | ---------------------------------- |
| ALLOW_INSERT_OPERATION | INSERT, REPLACE |
| ALLOW_UPDATE_OPERATION | UPDATE |
| ALLOW_DELETE_OPERATION | DELETE |
| ALLOW_DDL_OPERATION | DDL (CREATE, ALTER, DROP, …) |
Tools
| Tool | Statements | Env flag |
| -------------- | ----------------------------------------------- | ------------------------ |
| mysql_select | SELECT, SHOW, DESCRIBE, EXPLAIN, DESC | always on |
| mysql_insert | INSERT, REPLACE | ALLOW_INSERT_OPERATION |
| mysql_update | UPDATE | ALLOW_UPDATE_OPERATION |
| mysql_delete | DELETE | ALLOW_DELETE_OPERATION |
| mysql_ddl | DDL | ALLOW_DDL_OPERATION |
Each tool accepts one sql string. Results are JSON text; SELECT output is capped by MYSQL_MAX_ROWS.
Behavior and security
- One SQL statement per request (no
;-separated batches). - Dangerous patterns are blocked regardless of flags.
- Read operations are always permitted.
Package scripts
pnpm run build
pnpm test
pnpm start