https://github.com/achmadya-dev/mcp-mysql-query
Model Context Protocol (MCP) server for MySQL to run SQL queries via stdio
https://github.com/achmadya-dev/mcp-mysql-query
cursor database mcp model-context-protocol mysql typescript
Last synced: 1 day ago
JSON representation
Model Context Protocol (MCP) server for MySQL to run SQL queries via stdio
- Host: GitHub
- URL: https://github.com/achmadya-dev/mcp-mysql-query
- Owner: achmadya-dev
- License: mit
- Created: 2026-05-21T02:52:35.000Z (26 days ago)
- Default Branch: main
- Last Pushed: 2026-06-14T02:45:51.000Z (1 day ago)
- Last Synced: 2026-06-14T03:07:27.785Z (1 day ago)
- Topics: cursor, database, mcp, model-context-protocol, mysql, typescript
- Language: TypeScript
- Homepage:
- Size: 187 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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`:
```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`):
```json
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@achmadya-dev/mcp-mysql-query"],
"envFile": "/absolute/path/to/.env"
}
}
}
```
## Develop from source
```bash
git clone https://github.com/achmadya-dev/mcp-mysql-query.git
cd mcp-mysql-query
pnpm install
pnpm run build
pnpm test
```
Open the repo root in Cursor. You need a reachable MySQL instance — set connection env in `.cursor/mcp.json` or via `envFile`:
```json
{
"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
```bash
pnpm run build
pnpm test
pnpm start
```